Skip to content

Commit d2aa0b3

Browse files
authored
Merge pull request #213 from tgross35/clippy
Fix Clippy errors and enable Clippy checks in CI
2 parents 238553a + e482305 commit d2aa0b3

File tree

2 files changed

+79
-73
lines changed

2 files changed

+79
-73
lines changed

.github/workflows/main.yml

+13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ env:
66
RUSTFLAGS: -D warnings
77

88
jobs:
9+
clippy:
10+
name: clippy
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Install Rust
15+
run: |
16+
rustup update beta --no-self-update
17+
rustup default beta
18+
rustup component add clippy
19+
- uses: Swatinem/rust-cache@v2
20+
- run: cargo clippy --all-features --all-targets -- -D warnings
21+
922
test:
1023
name: Test
1124
runs-on: ${{ matrix.os }}

src/lib.rs

+66-73
Original file line numberDiff line numberDiff line change
@@ -443,55 +443,53 @@ impl Config {
443443
if !self.defined("CMAKE_TOOLCHAIN_FILE") {
444444
if let Some(s) = self.getenv_target_os("CMAKE_TOOLCHAIN_FILE") {
445445
self.define("CMAKE_TOOLCHAIN_FILE", s);
446-
} else {
447-
if target.contains("redox") {
448-
if !self.defined("CMAKE_SYSTEM_NAME") {
449-
self.define("CMAKE_SYSTEM_NAME", "Generic");
450-
}
451-
} else if target != host && !self.defined("CMAKE_SYSTEM_NAME") {
452-
// Set CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_PROCESSOR when cross compiling
453-
let os = getenv_unwrap("CARGO_CFG_TARGET_OS");
454-
let arch = getenv_unwrap("CARGO_CFG_TARGET_ARCH");
455-
// CMAKE_SYSTEM_NAME list
456-
// https://gitlab.kitware.com/cmake/cmake/-/issues/21489#note_1077167
457-
//
458-
// CMAKE_SYSTEM_PROCESSOR
459-
// some of the values come from https://en.wikipedia.org/wiki/Uname
460-
let (system_name, system_processor) = match (os.as_str(), arch.as_str()) {
461-
("android", arch) => ("Android", arch),
462-
("dragonfly", arch) => ("DragonFly", arch),
463-
("macos", "x86_64") => ("Darwin", "x86_64"),
464-
("macos", "aarch64") => ("Darwin", "arm64"),
465-
("freebsd", "x86_64") => ("FreeBSD", "amd64"),
466-
("freebsd", arch) => ("FreeBSD", arch),
467-
("fuchsia", arch) => ("Fuchsia", arch),
468-
("haiku", arch) => ("Haiku", arch),
469-
("ios", "aarch64") => ("iOS", "arm64"),
470-
("ios", arch) => ("iOS", arch),
471-
("linux", arch) => {
472-
let name = "Linux";
473-
match arch {
474-
"powerpc" => (name, "ppc"),
475-
"powerpc64" => (name, "ppc64"),
476-
"powerpc64le" => (name, "ppc64le"),
477-
_ => (name, arch),
478-
}
479-
}
480-
("netbsd", arch) => ("NetBSD", arch),
481-
("openbsd", "x86_64") => ("OpenBSD", "amd64"),
482-
("openbsd", arch) => ("OpenBSD", arch),
483-
("solaris", arch) => ("SunOS", arch),
484-
("tvos", arch) => ("tvOS", arch),
485-
("watchos", arch) => ("watchOS", arch),
486-
("windows", "x86_64") => ("Windows", "AMD64"),
487-
("windows", "x86") => ("Windows", "X86"),
488-
("windows", "aarch64") => ("Windows", "ARM64"),
489-
// Others
490-
(os, arch) => (os, arch),
491-
};
492-
self.define("CMAKE_SYSTEM_NAME", system_name);
493-
self.define("CMAKE_SYSTEM_PROCESSOR", system_processor);
446+
} else if target.contains("redox") {
447+
if !self.defined("CMAKE_SYSTEM_NAME") {
448+
self.define("CMAKE_SYSTEM_NAME", "Generic");
494449
}
450+
} else if target != host && !self.defined("CMAKE_SYSTEM_NAME") {
451+
// Set CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_PROCESSOR when cross compiling
452+
let os = getenv_unwrap("CARGO_CFG_TARGET_OS");
453+
let arch = getenv_unwrap("CARGO_CFG_TARGET_ARCH");
454+
// CMAKE_SYSTEM_NAME list
455+
// https://gitlab.kitware.com/cmake/cmake/-/issues/21489#note_1077167
456+
//
457+
// CMAKE_SYSTEM_PROCESSOR
458+
// some of the values come from https://en.wikipedia.org/wiki/Uname
459+
let (system_name, system_processor) = match (os.as_str(), arch.as_str()) {
460+
("android", arch) => ("Android", arch),
461+
("dragonfly", arch) => ("DragonFly", arch),
462+
("macos", "x86_64") => ("Darwin", "x86_64"),
463+
("macos", "aarch64") => ("Darwin", "arm64"),
464+
("freebsd", "x86_64") => ("FreeBSD", "amd64"),
465+
("freebsd", arch) => ("FreeBSD", arch),
466+
("fuchsia", arch) => ("Fuchsia", arch),
467+
("haiku", arch) => ("Haiku", arch),
468+
("ios", "aarch64") => ("iOS", "arm64"),
469+
("ios", arch) => ("iOS", arch),
470+
("linux", arch) => {
471+
let name = "Linux";
472+
match arch {
473+
"powerpc" => (name, "ppc"),
474+
"powerpc64" => (name, "ppc64"),
475+
"powerpc64le" => (name, "ppc64le"),
476+
_ => (name, arch),
477+
}
478+
}
479+
("netbsd", arch) => ("NetBSD", arch),
480+
("openbsd", "x86_64") => ("OpenBSD", "amd64"),
481+
("openbsd", arch) => ("OpenBSD", arch),
482+
("solaris", arch) => ("SunOS", arch),
483+
("tvos", arch) => ("tvOS", arch),
484+
("watchos", arch) => ("watchOS", arch),
485+
("windows", "x86_64") => ("Windows", "AMD64"),
486+
("windows", "x86") => ("Windows", "X86"),
487+
("windows", "aarch64") => ("Windows", "ARM64"),
488+
// Others
489+
(os, arch) => (os, arch),
490+
};
491+
self.define("CMAKE_SYSTEM_NAME", system_name);
492+
self.define("CMAKE_SYSTEM_PROCESSOR", system_processor);
495493
}
496494
}
497495

@@ -550,7 +548,7 @@ impl Config {
550548
let mut cmake_prefix_path = Vec::new();
551549
for dep in &self.deps {
552550
let dep = dep.to_uppercase().replace('-', "_");
553-
if let Some(root) = env::var_os(&format!("DEP_{}_ROOT", dep)) {
551+
if let Some(root) = env::var_os(format!("DEP_{}_ROOT", dep)) {
554552
cmake_prefix_path.push(PathBuf::from(root));
555553
}
556554
}
@@ -627,14 +625,11 @@ impl Config {
627625
// If we're on MSVC we need to be sure to use the right generator or
628626
// otherwise we won't get 32/64 bit correct automatically.
629627
// This also guarantees that NMake generator isn't chosen implicitly.
630-
let using_nmake_generator = {
631-
if generator.is_none() {
632-
cmd.arg("-G").arg(self.visual_studio_generator(&target));
633-
false
634-
} else {
635-
generator.as_ref().unwrap() == "NMake Makefiles"
636-
|| generator.as_ref().unwrap() == "NMake Makefiles JOM"
637-
}
628+
let using_nmake_generator = if let Some(g) = &generator {
629+
g == "NMake Makefiles" || g == "NMake Makefiles JOM"
630+
} else {
631+
cmd.arg("-G").arg(self.visual_studio_generator(&target));
632+
false
638633
};
639634
if !is_ninja && !using_nmake_generator {
640635
if target.contains("x86_64") {
@@ -661,15 +656,13 @@ impl Config {
661656
panic!("unsupported msvc target: {}", target);
662657
}
663658
}
664-
} else if target.contains("darwin") {
665-
if !self.defined("CMAKE_OSX_ARCHITECTURES") {
666-
if target.contains("x86_64") {
667-
cmd.arg("-DCMAKE_OSX_ARCHITECTURES=x86_64");
668-
} else if target.contains("aarch64") {
669-
cmd.arg("-DCMAKE_OSX_ARCHITECTURES=arm64");
670-
} else {
671-
panic!("unsupported darwin target: {}", target);
672-
}
659+
} else if target.contains("darwin") && !self.defined("CMAKE_OSX_ARCHITECTURES") {
660+
if target.contains("x86_64") {
661+
cmd.arg("-DCMAKE_OSX_ARCHITECTURES=x86_64");
662+
} else if target.contains("aarch64") {
663+
cmd.arg("-DCMAKE_OSX_ARCHITECTURES=arm64");
664+
} else {
665+
panic!("unsupported darwin target: {}", target);
673666
}
674667
}
675668
if let Some(ref generator) = generator {
@@ -679,7 +672,7 @@ impl Config {
679672
cmd.arg("-T").arg(generator_toolset);
680673
}
681674
let profile = self.get_profile().to_string();
682-
for &(ref k, ref v) in &self.defines {
675+
for (k, v) in &self.defines {
683676
let mut os = OsString::from("-D");
684677
os.push(k);
685678
os.push("=");
@@ -696,7 +689,7 @@ impl Config {
696689
let build_type = self
697690
.defines
698691
.iter()
699-
.find(|&&(ref a, _)| a == "CMAKE_BUILD_TYPE")
692+
.find(|&(a, _)| a == "CMAKE_BUILD_TYPE")
700693
.map(|x| x.1.to_str().unwrap())
701694
.unwrap_or(&profile);
702695
let build_type_upcase = build_type
@@ -798,14 +791,14 @@ impl Config {
798791
}
799792

800793
if !self.defined("CMAKE_BUILD_TYPE") {
801-
cmd.arg(&format!("-DCMAKE_BUILD_TYPE={}", profile));
794+
cmd.arg(format!("-DCMAKE_BUILD_TYPE={}", profile));
802795
}
803796

804797
if self.verbose_make {
805798
cmd.arg("-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON");
806799
}
807800

808-
for &(ref k, ref v) in c_compiler.env().iter().chain(&self.env) {
801+
for (k, v) in c_compiler.env().iter().chain(&self.env) {
809802
cmd.env(k, v);
810803
}
811804

@@ -820,13 +813,13 @@ impl Config {
820813
let mut cmd = self.cmake_build_command(&target);
821814
cmd.current_dir(&build);
822815

823-
for &(ref k, ref v) in c_compiler.env().iter().chain(&self.env) {
816+
for (k, v) in c_compiler.env().iter().chain(&self.env) {
824817
cmd.env(k, v);
825818
}
826819

827820
// If the generated project is Makefile based we should carefully transfer corresponding CARGO_MAKEFLAGS
828821
let mut use_jobserver = false;
829-
if fs::metadata(&build.join("Makefile")).is_ok() {
822+
if fs::metadata(build.join("Makefile")).is_ok() {
830823
match env::var_os("CARGO_MAKEFLAGS") {
831824
// Only do this on non-windows and non-bsd
832825
// On Windows, we could be invoking make instead of
@@ -967,7 +960,7 @@ impl Config {
967960
}
968961

969962
fn defined(&self, var: &str) -> bool {
970-
self.defines.iter().any(|&(ref a, _)| a == var)
963+
self.defines.iter().any(|(a, _)| a == var)
971964
}
972965

973966
// If a cmake project has previously been built (e.g. CMakeCache.txt already

0 commit comments

Comments
 (0)