From 9228de68b1795e335e1e1197ef2fde9cf431e5b9 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 21 Jan 2020 17:23:27 +0100 Subject: [PATCH 01/15] risc-v: Use medany model (#467) With rust-lang/rust#62281, rust compiles in mcmodel=medium mode which is equivalent to GCC medany. This prevents linker relocation errors code is placed outside the range `-0x80000000..0x7ffffffff`. --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index cc1d58c88..63cc9d487 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1603,6 +1603,7 @@ impl Build { } else { cmd.args.push("-mabi=ilp32".into()); } + cmd.args.push("-mcmodel=medany".into()); } } } From 57afb423dcd237347e9d7629e66ad3b7ae83fe42 Mon Sep 17 00:00:00 2001 From: Stepan Snigirev Date: Mon, 27 Jan 2020 16:01:37 +0100 Subject: [PATCH 02/15] disable pic for bare metal by default (#470) --- src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 63cc9d487..ded082e6e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -847,7 +847,7 @@ impl Build { /// Configures whether the compiler will emit position independent code. /// - /// This option defaults to `false` for `windows-gnu` and `riscv` targets and + /// This option defaults to `false` for `windows-gnu` and bare metal targets and /// to `true` for all other targets. pub fn pic(&mut self, pic: bool) -> &mut Build { self.pic = Some(pic); @@ -1371,11 +1371,11 @@ impl Build { cmd.push_cc_arg("-ffunction-sections".into()); cmd.push_cc_arg("-fdata-sections".into()); } - // Disable generation of PIC on bare-metal RISC-V for now: rust-lld doesn't support this yet - if self.pic.unwrap_or( - !target.contains("windows-gnu") - && !(target.contains("riscv") && target.contains("-none-")), - ) { + // Disable generation of PIC on bare-metal for now: rust-lld doesn't support this yet + if self + .pic + .unwrap_or(!target.contains("windows-gnu") && !target.contains("-none-")) + { cmd.push_cc_arg("-fPIC".into()); // PLT only applies if code is compiled with PIC support, // and only for ELF targets. From b3efc44c3d18cec312594040f0f09f7d39f00832 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Mon, 27 Jan 2020 20:59:52 +0100 Subject: [PATCH 03/15] Clear CFLAGS and CXXFLAGS before tests (#472) Some test cases check that a compiler flag is not present. But cc::Build loads additional flags from the CFLAGS and CXXFLAGS environment variables. If these are set, they might interfere with the test cases. Therefore we clear the CFLAGS and CXXFLAGS environment variables before running a test that requires an absent flag. --- tests/test.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/test.rs b/tests/test.rs index def11f025..3c9b4dc49 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -2,8 +2,18 @@ use crate::support::Test; mod support; +// Some tests check that a flag is *not* present. These tests might fail if the flag is set in the +// CFLAGS or CXXFLAGS environment variables. This function clears the CFLAGS and CXXFLAGS +// variables to make sure that the tests can run correctly. +fn reset_env() { + std::env::set_var("CFLAGS", ""); + std::env::set_var("CXXFLAGS", ""); +} + #[test] fn gnu_smoke() { + reset_env(); + let test = Test::gnu(); test.gcc().file("foo.c").compile("foo"); @@ -19,6 +29,8 @@ fn gnu_smoke() { #[test] fn gnu_opt_level_1() { + reset_env(); + let test = Test::gnu(); test.gcc().opt_level(1).file("foo.c").compile("foo"); @@ -27,6 +39,8 @@ fn gnu_opt_level_1() { #[test] fn gnu_opt_level_s() { + reset_env(); + let test = Test::gnu(); test.gcc().opt_level_str("s").file("foo.c").compile("foo"); @@ -56,6 +70,8 @@ fn gnu_debug_fp() { #[test] fn gnu_debug_nofp() { + reset_env(); + let test = Test::gnu(); test.gcc() .debug(true) @@ -100,6 +116,8 @@ fn gnu_warnings() { #[test] fn gnu_extra_warnings0() { + reset_env(); + let test = Test::gnu(); test.gcc() .warnings(true) @@ -113,6 +131,8 @@ fn gnu_extra_warnings0() { #[test] fn gnu_extra_warnings1() { + reset_env(); + let test = Test::gnu(); test.gcc() .warnings(false) @@ -126,6 +146,8 @@ fn gnu_extra_warnings1() { #[test] fn gnu_warnings_overridable() { + reset_env(); + let test = Test::gnu(); test.gcc() .warnings(true) @@ -154,6 +176,8 @@ fn gnu_x86_64() { #[test] fn gnu_x86_64_no_pic() { + reset_env(); + for vendor in &["unknown-linux-gnu", "apple-darwin"] { let target = format!("x86_64-{}", vendor); let test = Test::gnu(); @@ -215,6 +239,8 @@ fn gnu_x86_64_no_plt() { #[test] fn gnu_set_stdlib() { + reset_env(); + let test = Test::gnu(); test.gcc() .cpp_set_stdlib(Some("foo")) @@ -253,6 +279,8 @@ fn gnu_compile_assembly() { #[test] fn gnu_shared() { + reset_env(); + let test = Test::gnu(); test.gcc() .file("foo.c") @@ -265,6 +293,8 @@ fn gnu_shared() { #[test] fn gnu_flag_if_supported() { + reset_env(); + if cfg!(windows) { return; } @@ -301,6 +331,8 @@ fn gnu_flag_if_supported_cpp() { #[test] fn gnu_static() { + reset_env(); + let test = Test::gnu(); test.gcc() .file("foo.c") @@ -313,6 +345,8 @@ fn gnu_static() { #[test] fn msvc_smoke() { + reset_env(); + let test = Test::msvc(); test.gcc().file("foo.c").compile("foo"); @@ -327,6 +361,8 @@ fn msvc_smoke() { #[test] fn msvc_opt_level_0() { + reset_env(); + let test = Test::msvc(); test.gcc().opt_level(0).file("foo.c").compile("foo"); From aebeaddd61251000ce2a4ea5facc51a0e1f4e077 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 28 Jan 2020 00:39:34 -0800 Subject: [PATCH 04/15] Update CI installation of Rust on macos --- .github/workflows/main.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9c35a4193..b3fb30e8b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -58,13 +58,7 @@ jobs: - uses: actions/checkout@master - name: Install Rust (rustup) run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }} - if: matrix.os != 'macos-latest' shell: bash - - name: Install Rust (macos) - run: | - curl https://sh.rustup.rs | sh -s -- -y - echo "##[add-path]$HOME/.cargo/bin" - if: matrix.os == 'macos-latest' - run: rustup target add ${{ matrix.target }} - name: Install g++-multilib run: | From 4b72474342c3d75d5122f7fec446018adf25e5e0 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Tue, 4 Feb 2020 13:55:01 -0600 Subject: [PATCH 05/15] Detect and use sccache by introspecting RUSTC_WRAPPER (#475) * Detect and use `sccache` via `RUSTC_WRAPPER` If no other C/C++ caching tool is found by inspecting `CC` and `CXX`, `RUSTC_WRAPPER` is tested to see if an output-caching wrapper for `rustc` is in use. If that is the case and it is a wrapper known to also support C/C++ caching, use it. (Also correct/clarify a misnamed variable that caused me some confusion looking over the code.) * Support RUSTC_WRAPPER on Windows and with absolute paths When checking for possible `RUSTC_WRAPPER`s that we can use to cache C/C++ output, allow for filename extensions (e.g. `sccache.exe`) and absolute paths (e.g. `/usr/local/bin/sccache`). Closes #473 --- src/lib.rs | 35 +++++++++++++++++++++++++++++------ tests/support/mod.rs | 12 ++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ded082e6e..738714fa2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1867,7 +1867,7 @@ impl Build { cmd.args.push(sdk_path.trim().into()); cmd.args.push("-fembed-bitcode".into()); /* - * TODO we probably ultimatedly want the -fembed-bitcode-marker flag + * TODO we probably ultimately want the -fembed-bitcode-marker flag * but can't have it now because of an issue in LLVM: * https://github.com/alexcrichton/cc-rs/issues/301 * https://github.com/rust-lang/rust/pull/48896#comment-372192660 @@ -1919,13 +1919,13 @@ impl Build { .iter() .find(|a| a.starts_with(DRIVER_MODE)) .map(|a| &a[DRIVER_MODE.len()..]); - // chop off leading/trailing whitespace to work around + // Chop off leading/trailing whitespace to work around // semi-buggy build scripts which are shared in // makefiles/configure scripts (where spaces are far more // lenient) let mut t = Tool::with_clang_driver(PathBuf::from(tool.trim()), driver_mode); - if let Some(cc) = wrapper { - t.cc_wrapper_path = Some(PathBuf::from(cc)); + if let Some(cc_wrapper) = wrapper { + t.cc_wrapper_path = Some(PathBuf::from(cc_wrapper)); } for arg in args { t.cc_wrapper_args.push(arg.into()); @@ -2065,7 +2065,12 @@ impl Build { } else { default.to_string() }; - Tool::new(PathBuf::from(compiler)) + + let mut t = Tool::new(PathBuf::from(compiler)); + if let Some(cc_wrapper) = Self::rustc_wrapper_fallback() { + t.cc_wrapper_path = Some(PathBuf::from(cc_wrapper)); + } + t } }; @@ -2141,6 +2146,24 @@ impl Build { .collect() } + /// Returns a fallback `cc_compiler_wrapper` by introspecting `RUSTC_WRAPPER` + fn rustc_wrapper_fallback() -> Option { + // No explicit CC wrapper was detected, but check if RUSTC_WRAPPER + // is defined and is a build accelerator that is compatible with + // C/C++ compilers (e.g. sccache) + let valid_wrappers = ["sccache"]; + + let rustc_wrapper = std::env::var_os("RUSTC_WRAPPER")?; + let wrapper_path = Path::new(&rustc_wrapper); + let wrapper_stem = wrapper_path.file_stem()?; + + if valid_wrappers.contains(&wrapper_stem.to_str()?) { + Some(rustc_wrapper.to_str()?.to_owned()) + } else { + None + } + } + /// Returns compiler path, optional modifier name from whitelist, and arguments vec fn env_tool(&self, name: &str) -> Option<(String, Option, Vec)> { let tool = match self.get_var(name) { @@ -2200,7 +2223,7 @@ impl Build { Some(( maybe_wrapper.to_string(), - None, + Self::rustc_wrapper_fallback(), parts.map(|s| s.to_string()).collect(), )) } diff --git a/tests/support/mod.rs b/tests/support/mod.rs index fe8acded1..cde930e90 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -22,6 +22,18 @@ pub struct Execution { impl Test { pub fn new() -> Test { + // This is ugly: `sccache` needs to introspect the compiler it is + // executing, as it adjusts its behavior depending on the + // language/compiler. This crate's test driver uses mock compilers that + // are obviously not supported by sccache, so the tests fail if + // RUSTC_WRAPPER is set. rust doesn't build test dependencies with + // the `test` feature enabled, so we can't conditionally disable the + // usage of `sccache` if running in a test environment, at least not + // without setting an environment variable here and testing for it + // there. Explicitly deasserting RUSTC_WRAPPER here seems to be the + // lesser of the two evils. + env::remove_var("RUSTC_WRAPPER"); + let mut gcc = PathBuf::from(env::current_exe().unwrap()); gcc.pop(); if gcc.ends_with("deps") { From 27ca8c2cafbace2bcc2e92cea1b33f29e9bcb02f Mon Sep 17 00:00:00 2001 From: Anton Ageev Date: Tue, 25 Feb 2020 18:53:51 +0300 Subject: [PATCH 06/15] Add 'armv5te-unknown-linux-musleabi' target support (#478) --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 738714fa2..46f0b4da0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1994,6 +1994,7 @@ impl Build { "arm-unknown-linux-gnueabi" => Some("arm-linux-gnueabi"), "armv4t-unknown-linux-gnueabi" => Some("arm-linux-gnueabi"), "armv5te-unknown-linux-gnueabi" => Some("arm-linux-gnueabi"), + "armv5te-unknown-linux-musleabi" => Some("arm-linux-gnueabi"), "arm-frc-linux-gnueabi" => Some("arm-frc-linux-gnueabi"), "arm-unknown-linux-gnueabihf" => Some("arm-linux-gnueabihf"), "arm-unknown-linux-musleabi" => Some("arm-linux-musleabi"), From a885236506a1cff6cb0c58af12fad911c2ffe0a7 Mon Sep 17 00:00:00 2001 From: datalus <2110472+datalus@users.noreply.github.com> Date: Tue, 3 Mar 2020 09:57:11 -0600 Subject: [PATCH 07/15] Do not set the -fPIC flag for Windows targets when using clang for CXX builds (#481) --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 46f0b4da0..77c724507 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1374,7 +1374,7 @@ impl Build { // Disable generation of PIC on bare-metal for now: rust-lld doesn't support this yet if self .pic - .unwrap_or(!target.contains("windows-gnu") && !target.contains("-none-")) + .unwrap_or(!target.contains("windows") && !target.contains("-none-")) { cmd.push_cc_arg("-fPIC".into()); // PLT only applies if code is compiled with PIC support, From f139bce3aae34b91a470c3742a08fccd871b1982 Mon Sep 17 00:00:00 2001 From: datalus <2110472+datalus@users.noreply.github.com> Date: Tue, 3 Mar 2020 11:49:46 -0600 Subject: [PATCH 08/15] Use gnu -o flag for obj out path instead of -Fo when using clang & clang++ on Windows (#483) --- src/lib.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 77c724507..d77611c1e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -449,11 +449,13 @@ impl Build { let mut cmd = compiler.to_command(); let is_arm = target.contains("aarch64") || target.contains("arm"); + let clang = compiler.family == ToolFamily::Clang; command_add_output_file( &mut cmd, &obj, self.cuda, target.contains("msvc"), + clang, false, is_arm, ); @@ -1144,10 +1146,11 @@ impl Build { let is_asm = obj.src.extension().and_then(|s| s.to_str()) == Some("asm"); let target = self.get_target()?; let msvc = target.contains("msvc"); + let compiler = self.try_get_compiler()?; + let clang = compiler.family == ToolFamily::Clang; let (mut cmd, name) = if msvc && is_asm { self.msvc_macro_assembler()? } else { - let compiler = self.try_get_compiler()?; let mut cmd = compiler.to_command(); for &(ref a, ref b) in self.env.iter() { cmd.env(a, b); @@ -1163,7 +1166,7 @@ impl Build { ) }; let is_arm = target.contains("aarch64") || target.contains("arm"); - command_add_output_file(&mut cmd, &obj.dst, self.cuda, msvc, is_asm, is_arm); + command_add_output_file(&mut cmd, &obj.dst, self.cuda, msvc, clang, is_asm, is_arm); // armasm and armasm64 don't requrie -c option if !msvc || !is_asm || !is_arm { cmd.arg("-c"); @@ -2685,10 +2688,11 @@ fn command_add_output_file( dst: &Path, cuda: bool, msvc: bool, + clang: bool, is_asm: bool, is_arm: bool, ) { - if msvc && !cuda && !(is_asm && is_arm) { + if msvc && !clang && !cuda && !(is_asm && is_arm) { let mut s = OsString::from("-Fo"); s.push(&dst); cmd.arg(s); From a20cdff2e0030fabd382e6fecebf7b138102f85d Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 13 Mar 2020 19:33:52 +0100 Subject: [PATCH 09/15] Add tool autodetection for armv7a targets (#479) --- src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index d77611c1e..8981448c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1591,6 +1591,14 @@ impl Build { cmd.args.push("-mfloat-abi=soft".into()); } } + if target.starts_with("armv7a") { + cmd.args.push("-march=armv7-a".into()); + + if target.ends_with("eabihf") { + // lowest common denominator FPU + cmd.args.push("-mfpu=vfpv3-d16".into()); + } + } if target.starts_with("riscv32") || target.starts_with("riscv64") { // get the 32i/32imac/32imc/64gc/64imac/... part let mut parts = target.split('-'); @@ -2044,6 +2052,8 @@ impl Build { "sparc64-unknown-linux-gnu" => Some("sparc64-linux-gnu"), "sparc64-unknown-netbsd" => Some("sparc64--netbsd"), "sparcv9-sun-solaris" => Some("sparcv9-sun-solaris"), + "armv7a-none-eabi" => Some("arm-none-eabi"), + "armv7a-none-eabihf" => Some("arm-none-eabi"), "armebv7r-none-eabi" => Some("arm-none-eabi"), "armebv7r-none-eabihf" => Some("arm-none-eabi"), "armv7r-none-eabi" => Some("arm-none-eabi"), From 383f2dfe1f9c84a57478269b0bc4b39af029fdf9 Mon Sep 17 00:00:00 2001 From: "Joshua M. Clulow" Date: Sun, 19 Apr 2020 12:11:53 -0700 Subject: [PATCH 10/15] use "gcc" by default on illumos systems (#487) --- src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8981448c7..876533417 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1912,8 +1912,11 @@ impl Build { ("CC", "cl.exe", "gcc", "cc", "clang") }; - // On Solaris, c++/cc unlikely to exist or be correct. - let default = if host.contains("solaris") { + // On historical Solaris systems, "cc" may have been Sun Studio, which + // is not flag-compatible with "gcc". This history casts a long shadow, + // and many modern illumos distributions today ship GCC as "gcc" without + // also making it available as "cc". + let default = if host.contains("solaris") || host.contains("illumos") { gnu } else { traditional From 5bb26a660b3c58e53147471e7deafc6249d3e47c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Rouill=C3=A9?= Date: Wed, 22 Apr 2020 16:17:22 +0200 Subject: [PATCH 11/15] fix find_tool and find_vs_version might returns incompatible values (#488) On windows, I have both MSVC 15 and 16 and found out that find_vs_version returns MSVC 16 while find_tool returns MSVC 15 linker. --- src/windows_registry.rs | 50 +++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/src/windows_registry.rs b/src/windows_registry.rs index 5af3ff73b..c4349b12c 100644 --- a/src/windows_registry.rs +++ b/src/windows_registry.rs @@ -80,7 +80,7 @@ pub fn find_tool(target: &str, tool: &str) -> Option { // environment variables like `LIB`, `INCLUDE`, and `PATH` to ensure that // the tool is actually usable. - return impl_::find_msvc_15(tool, target) + return impl_::find_msvc_15plus(tool, target) .or_else(|| impl_::find_msvc_14(tool, target)) .or_else(|| impl_::find_msvc_12(tool, target)) .or_else(|| impl_::find_msvc_11(tool, target)); @@ -173,6 +173,7 @@ mod impl_ { use std::iter; use std::mem; use std::path::{Path, PathBuf}; + use std::str::FromStr; use crate::Tool; @@ -210,7 +211,7 @@ mod impl_ { #[allow(bare_trait_objects)] fn vs16_instances() -> Box> { - let instances = if let Some(instances) = vs15_instances() { + let instances = if let Some(instances) = vs15plus_instances() { instances } else { return Box::new(iter::empty()); @@ -253,24 +254,34 @@ mod impl_ { // Note that much of this logic can be found [online] wrt paths, COM, etc. // // [online]: https://blogs.msdn.microsoft.com/vcblog/2017/03/06/finding-the-visual-c-compiler-tools-in-visual-studio-2017/ - fn vs15_instances() -> Option { + // + // Returns MSVC 15+ instances (15, 16 right now), the order should be consider undefined. + fn vs15plus_instances() -> Option { com::initialize().ok()?; let config = SetupConfiguration::new().ok()?; config.enum_all_instances().ok() } - pub fn find_msvc_15(tool: &str, target: &str) -> Option { - let iter = vs15_instances()?; - for instance in iter { - let instance = instance.ok()?; - let tool = tool_from_vs15_instance(tool, target, &instance); - if tool.is_some() { - return tool; - } - } + // Inspired from official microsoft/vswhere ParseVersionString + // i.e. at most four u16 numbers separated by '.' + fn parse_version(version: &str) -> Option> { + version + .split('.') + .map(|chunk| u16::from_str(chunk).ok()) + .collect() + } - None + pub fn find_msvc_15plus(tool: &str, target: &str) -> Option { + let iter = vs15plus_instances()?; + iter.filter_map(|instance| { + let instance = instance.ok()?; + let version = parse_version(instance.installation_version().ok()?.to_str()?)?; + let tool = tool_from_vs15plus_instance(tool, target, &instance)?; + Some((version, tool)) + }) + .max_by(|(a_version, _), (b_version, _)| a_version.cmp(b_version)) + .map(|(_version, tool)| tool) } // While the paths to Visual Studio 2017's devenv and MSBuild could @@ -281,7 +292,7 @@ mod impl_ { // // [more reliable]: https://github.com/alexcrichton/cc-rs/pull/331 fn find_tool_in_vs15_path(tool: &str, target: &str) -> Option { - let mut path = match vs15_instances() { + let mut path = match vs15plus_instances() { Some(instances) => instances .filter_map(|instance| { instance @@ -312,8 +323,13 @@ mod impl_ { }) } - fn tool_from_vs15_instance(tool: &str, target: &str, instance: &SetupInstance) -> Option { - let (bin_path, host_dylib_path, lib_path, include_path) = vs15_vc_paths(target, instance)?; + fn tool_from_vs15plus_instance( + tool: &str, + target: &str, + instance: &SetupInstance, + ) -> Option { + let (bin_path, host_dylib_path, lib_path, include_path) = + vs15plus_vc_paths(target, instance)?; let tool_path = bin_path.join(tool); if !tool_path.exists() { return None; @@ -334,7 +350,7 @@ mod impl_ { Some(tool.into_tool()) } - fn vs15_vc_paths( + fn vs15plus_vc_paths( target: &str, instance: &SetupInstance, ) -> Option<(PathBuf, PathBuf, PathBuf, PathBuf)> { From 4c6e7c624d3c6560bd2ca4711ad3a10418065a84 Mon Sep 17 00:00:00 2001 From: Osspial Date: Wed, 22 Apr 2020 10:17:50 -0400 Subject: [PATCH 12/15] Fix Android clang compiler path when building with Windows host (#489) * Fix android clang compiler path when building with Windows host * Only use the cmd clang compiler if the exe clang doesn't exist --- src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 876533417..5324cb45b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1981,10 +1981,19 @@ impl Build { .replace("thumbv7", "arm"); let gnu_compiler = format!("{}-{}", target, gnu); let clang_compiler = format!("{}-{}", target, clang); + // On Windows, the Android clang compiler is provided as a `.cmd` file instead + // of a `.exe` file. `std::process::Command` won't run `.cmd` files unless the + // `.cmd` is explicitly appended to the command name, so we do that here. + let clang_compiler_cmd = format!("{}-{}.cmd", target, clang); + // Check if gnu compiler is present // if not, use clang if Command::new(&gnu_compiler).spawn().is_ok() { gnu_compiler + } else if host.contains("windows") + && Command::new(&clang_compiler).spawn().is_err() + { + clang_compiler_cmd } else { clang_compiler } From 4469060c5a3ae21aa7b3dccec6aaef65655f9b9d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 22 Apr 2020 07:18:29 -0700 Subject: [PATCH 13/15] Switch to `output()` from `spawn()` to avoid zombies --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5324cb45b..e6b4ed4a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1988,10 +1988,10 @@ impl Build { // Check if gnu compiler is present // if not, use clang - if Command::new(&gnu_compiler).spawn().is_ok() { + if Command::new(&gnu_compiler).output().is_ok() { gnu_compiler } else if host.contains("windows") - && Command::new(&clang_compiler).spawn().is_err() + && Command::new(&clang_compiler).output().is_ok() { clang_compiler_cmd } else { From 75446053a93f769abcf52e0ed63cbbee05a555c6 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 22 Apr 2020 07:18:46 -0700 Subject: [PATCH 14/15] Bump to 1.0.51 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 55da5b264..0c019af08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cc" -version = "1.0.50" +version = "1.0.51" authors = ["Alex Crichton "] license = "MIT/Apache-2.0" repository = "https://github.com/alexcrichton/cc-rs" From d1a7b8e4dcc0ead31b8e7db655a914fa0d472829 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 22 Apr 2020 12:51:02 -0700 Subject: [PATCH 15/15] Check for the right compiler we're testing --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0c019af08..db98772e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cc" -version = "1.0.51" +version = "1.0.52" authors = ["Alex Crichton "] license = "MIT/Apache-2.0" repository = "https://github.com/alexcrichton/cc-rs" diff --git a/src/lib.rs b/src/lib.rs index e6b4ed4a9..caf4f13e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1991,7 +1991,7 @@ impl Build { if Command::new(&gnu_compiler).output().is_ok() { gnu_compiler } else if host.contains("windows") - && Command::new(&clang_compiler).output().is_ok() + && Command::new(&clang_compiler_cmd).output().is_ok() { clang_compiler_cmd } else {