From 829e054d6768e43b59025ccf3b96561b13a720ca Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Mon, 18 Mar 2024 20:14:00 -0600 Subject: [PATCH 01/32] fix llvm-ar as archiver for msvc targets this is somewhat a nasty hack here, but it does work. when (cross) compiling for msvc and you use llvm-ar as the archiver, then you need to use gnu-style flags. currently it attemps to run llvm-ar like: ``` running: "/usr/bin/llvm-ar" "-out:/workspaces/ars/build_windows_clang_x86_64_relnoopt/./cargo/build/x86_64-pc-windows-msvc/release/build/link-cplusplus-b04e59fc086748c2/out/liblink-cplusplus.a" "-nologo" "/workspaces/ars/build_windows_clang_x86_64_relnoopt/./cargo/build/x86_64-pc-windows-msvc/release/build/link-cplusplus-b04e59fc086748c2/out/0466faf07398e270-dummy.o" ``` which doesn't work, as llvm-ar takes in GNU-style ar flags. i'm definitely open to a more robust way to get the archiver "Family" (maybe something similar to how we detect compiler family? idk) if that would be better --- src/lib.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b37105196..1ee4fd1e5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2398,7 +2398,8 @@ impl Build { } let target = self.get_target()?; - if target.contains("msvc") { + let (mut ar, cmd, _any_flags) = self.get_ar()?; + if target.contains("msvc") && ! ar.get_program().to_str().unwrap().contains("llvm-") { // The Rust compiler will look for libfoo.a and foo.lib, but the // MSVC linker will also be passed foo.lib, so be sure that both // exist for now. @@ -2421,7 +2422,6 @@ impl Build { // Non-msvc targets (those using `ar`) need a separate step to add // the symbol table to archives since our construction command of // `cq` doesn't add it for us. - let (mut ar, cmd, _any_flags) = self.get_ar()?; // NOTE: We add `s` even if flags were passed using $ARFLAGS/ar_flag, because `s` // here represents a _mode_, not an arbitrary flag. Further discussion of this choice @@ -2435,8 +2435,8 @@ impl Build { fn assemble_progressive(&self, dst: &Path, objs: &[&Path]) -> Result<(), Error> { let target = self.get_target()?; - if target.contains("msvc") { - let (mut cmd, program, any_flags) = self.get_ar()?; + let (mut cmd, program, any_flags) = self.get_ar()?; + if target.contains("msvc") && !cmd.get_program().to_str().unwrap().contains("llvm-") { // NOTE: -out: here is an I/O flag, and so must be included even if $ARFLAGS/ar_flag is // in use. -nologo on the other hand is just a regular flag, and one that we'll skip if // the caller has explicitly dictated the flags they want. See @@ -2455,8 +2455,6 @@ impl Build { cmd.args(objs); run(&mut cmd, &program, &self.cargo_output)?; } else { - let (mut ar, cmd, _any_flags) = self.get_ar()?; - // Set an environment variable to tell the OSX archiver to ensure // that all dates listed in the archive are zero, improving // determinism of builds. AFAIK there's not really official @@ -2479,12 +2477,12 @@ impl Build { // // In any case if this doesn't end up getting read, it shouldn't // cause that many issues! - ar.env("ZERO_AR_DATE", "1"); + cmd.env("ZERO_AR_DATE", "1"); // NOTE: We add cq here regardless of whether $ARFLAGS/ar_flag have been used because // it dictates the _mode_ ar runs in, which the setter of $ARFLAGS/ar_flag can't // dictate. See https://github.com/rust-lang/cc-rs/pull/763 for further discussion. - run(ar.arg("cq").arg(dst).args(objs), &cmd, &self.cargo_output)?; + run(cmd.arg("cq").arg(dst).args(objs), &program, &self.cargo_output)?; } Ok(()) From 094d4069a58997c85382fadb6f582c16f9f2ae25 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Mon, 18 Mar 2024 20:24:39 -0600 Subject: [PATCH 02/32] fix usage of get_command --- src/lib.rs | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1ee4fd1e5..330e6e1bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2399,7 +2399,7 @@ impl Build { let target = self.get_target()?; let (mut ar, cmd, _any_flags) = self.get_ar()?; - if target.contains("msvc") && ! ar.get_program().to_str().unwrap().contains("llvm-") { + if target.contains("msvc") && ! cmd.to_str().unwrap().contains("llvm-") { // The Rust compiler will look for libfoo.a and foo.lib, but the // MSVC linker will also be passed foo.lib, so be sure that both // exist for now. @@ -2436,7 +2436,7 @@ impl Build { let target = self.get_target()?; let (mut cmd, program, any_flags) = self.get_ar()?; - if target.contains("msvc") && !cmd.get_program().to_str().unwrap().contains("llvm-") { + if target.contains("msvc") && !program.to_str().unwrap().contains("llvm-") { // NOTE: -out: here is an I/O flag, and so must be included even if $ARFLAGS/ar_flag is // in use. -nologo on the other hand is just a regular flag, and one that we'll skip if // the caller has explicitly dictated the flags they want. See @@ -3122,12 +3122,13 @@ impl Build { Ok(self.get_base_archiver_variant("RANLIB", "ranlib")?.0) } - fn get_base_archiver_variant(&self, env: &str, tool: &str) -> Result<(Command, String), Error> { + fn get_base_archiver_variant(&self, env: &str, tool: &str) -> Result<(Command, PathBuf), Error> { let target = self.get_target()?; - let mut name = String::new(); + let mut name = PathBuf::new(); let tool_opt: Option = self .env_tool(env) .map(|(tool, _wrapper, args)| { + name = tool.clone(); let mut cmd = self.cmd(tool); cmd.args(args); cmd @@ -3137,11 +3138,11 @@ impl Build { // Windows use bat files so we have to be a bit more specific if cfg!(windows) { let mut cmd = self.cmd("cmd"); - name = format!("em{}.bat", tool); + name = format!("em{}.bat", tool).into(); cmd.arg("/c").arg(&name); Some(cmd) } else { - name = format!("em{}", tool); + name = format!("em{}", tool).into(); Some(self.cmd(&name)) } } else if target.starts_with("wasm32") { @@ -3152,7 +3153,7 @@ impl Build { // of "llvm-ar"... let compiler = self.get_base_compiler().ok()?; if compiler.is_like_clang() { - name = format!("llvm-{}", tool); + name = format!("llvm-{}", tool).into(); search_programs(&mut self.cmd(&compiler.path), &name, &self.cargo_output) .map(|name| self.cmd(name)) } else { @@ -3168,10 +3169,10 @@ impl Build { Some(t) => t, None => { if target.contains("android") { - name = format!("llvm-{}", tool); + name = format!("llvm-{}", tool).into(); match Command::new(&name).arg("--version").status() { Ok(status) if status.success() => (), - _ => name = format!("{}-{}", target.replace("armv7", "arm"), tool), + _ => name = format!("{}-{}", target.replace("armv7", "arm"), tool).into(), } self.cmd(&name) } else if target.contains("msvc") { @@ -3198,7 +3199,7 @@ impl Build { } if lib.is_empty() { - name = String::from("lib.exe"); + name = PathBuf::from("lib.exe"); let mut cmd = match windows_registry::find(&target, "lib.exe") { Some(t) => t, None => self.cmd("lib.exe"), @@ -3208,7 +3209,7 @@ impl Build { } cmd } else { - name = lib; + name = lib.into(); self.cmd(&name) } } else if target.contains("illumos") { @@ -3216,7 +3217,7 @@ impl Build { // but the OS comes bundled with a GNU-compatible variant. // // Use the GNU-variant to match other Unix systems. - name = format!("g{}", tool); + name = format!("g{}", tool).into(); self.cmd(&name) } else if self.get_host()? != target { match self.prefix_for_target(&target) { @@ -3236,16 +3237,16 @@ impl Build { break; } } - name = chosen; + name = chosen.into(); self.cmd(&name) } None => { - name = default; + name = default.into(); self.cmd(&name) } } } else { - name = default; + name = default.into(); self.cmd(&name) } } @@ -3937,7 +3938,7 @@ fn which(tool: &Path, path_entries: Option) -> Option { } // search for |prog| on 'programs' path in '|cc| -print-search-dirs' output -fn search_programs(cc: &mut Command, prog: &str, cargo_output: &CargoOutput) -> Option { +fn search_programs(cc: &mut Command, prog: &Path, cargo_output: &CargoOutput) -> Option { let search_dirs = run_output( cc.arg("-print-search-dirs"), "cc", @@ -3950,7 +3951,7 @@ fn search_programs(cc: &mut Command, prog: &str, cargo_output: &CargoOutput) -> let search_dirs = std::str::from_utf8(&search_dirs).ok()?; for dirs in search_dirs.split(|c| c == '\r' || c == '\n') { if let Some(path) = dirs.strip_prefix("programs: =") { - return which(Path::new(prog), Some(OsString::from(path))); + return which(prog, Some(OsString::from(path))); } } None From d388cb80ddc2e3ae49254f86ed50284810313de6 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Mon, 18 Mar 2024 20:26:23 -0600 Subject: [PATCH 03/32] fmt --- src/lib.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 330e6e1bc..b2c58f79e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2399,7 +2399,7 @@ impl Build { let target = self.get_target()?; let (mut ar, cmd, _any_flags) = self.get_ar()?; - if target.contains("msvc") && ! cmd.to_str().unwrap().contains("llvm-") { + if target.contains("msvc") && !cmd.to_str().unwrap().contains("llvm-") { // The Rust compiler will look for libfoo.a and foo.lib, but the // MSVC linker will also be passed foo.lib, so be sure that both // exist for now. @@ -2482,7 +2482,11 @@ impl Build { // NOTE: We add cq here regardless of whether $ARFLAGS/ar_flag have been used because // it dictates the _mode_ ar runs in, which the setter of $ARFLAGS/ar_flag can't // dictate. See https://github.com/rust-lang/cc-rs/pull/763 for further discussion. - run(cmd.arg("cq").arg(dst).args(objs), &program, &self.cargo_output)?; + run( + cmd.arg("cq").arg(dst).args(objs), + &program, + &self.cargo_output, + )?; } Ok(()) @@ -3122,7 +3126,11 @@ impl Build { Ok(self.get_base_archiver_variant("RANLIB", "ranlib")?.0) } - fn get_base_archiver_variant(&self, env: &str, tool: &str) -> Result<(Command, PathBuf), Error> { + fn get_base_archiver_variant( + &self, + env: &str, + tool: &str, + ) -> Result<(Command, PathBuf), Error> { let target = self.get_target()?; let mut name = PathBuf::new(); let tool_opt: Option = self From d737de14d1622a31855653ce34a836a86dda130f Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Tue, 19 Mar 2024 08:29:51 -0600 Subject: [PATCH 04/32] initial attempt at clang windows CI --- .github/workflows/main.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ee2551ce5..399d51234 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -72,6 +72,11 @@ jobs: os: windows-2019 rust: stable-x86_64 target: x86_64-pc-windows-msvc + - build: windows-clang + os: windows-2019 + rust: stable + target: x86_64-pc-windows-msvc + env: AR=llvm-ar CC=clang CXX=clang++ RUSTFLAGS=-Clinker=lld-link steps: - uses: actions/checkout@v4 - name: Install Rust (rustup) @@ -92,9 +97,9 @@ jobs: sudo apt-get install g++-multilib if: matrix.build == 'linux32' - uses: Swatinem/rust-cache@v2 - - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} - - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release - - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel + - run: ${{ matrix.env }} cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} + - run: ${{ matrix.env }} cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release + - run: ${{ matrix.env }} cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel # This is separate from the matrix above because there is no prebuilt rust-std component for these targets. check-tvos: From 9eff7532cca2e15f7341f96de300b8b8b8ba1a07 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Tue, 19 Mar 2024 08:31:09 -0600 Subject: [PATCH 05/32] apply suggestion --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b2c58f79e..75c9215c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2399,7 +2399,7 @@ impl Build { let target = self.get_target()?; let (mut ar, cmd, _any_flags) = self.get_ar()?; - if target.contains("msvc") && !cmd.to_str().unwrap().contains("llvm-") { + if target.contains("msvc") && !cmd.to_string_lossy().contains("llvm-") { // The Rust compiler will look for libfoo.a and foo.lib, but the // MSVC linker will also be passed foo.lib, so be sure that both // exist for now. @@ -2436,7 +2436,7 @@ impl Build { let target = self.get_target()?; let (mut cmd, program, any_flags) = self.get_ar()?; - if target.contains("msvc") && !program.to_str().unwrap().contains("llvm-") { + if target.contains("msvc") && !program.to_string_lossy().contains("llvm-") { // NOTE: -out: here is an I/O flag, and so must be included even if $ARFLAGS/ar_flag is // in use. -nologo on the other hand is just a regular flag, and one that we'll skip if // the caller has explicitly dictated the flags they want. See From 7c20d23cafa68679bf8939886981e019334ab4df Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Tue, 19 Mar 2024 08:37:08 -0600 Subject: [PATCH 06/32] hopefully get clang in path --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 399d51234..1ec25ee5b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -96,6 +96,9 @@ jobs: sudo apt-get update sudo apt-get install g++-multilib if: matrix.build == 'linux32' + - name: add clang to path + run: $Env:PATH += ";C:\msys64\mingw64\bin" + if: matrix.build == 'windows-clang' - uses: Swatinem/rust-cache@v2 - run: ${{ matrix.env }} cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} - run: ${{ matrix.env }} cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release From 3da03c7f680ab004860fc5f752ed9bb8ac86db75 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Tue, 19 Mar 2024 08:40:47 -0600 Subject: [PATCH 07/32] oops this is powershell --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1ec25ee5b..b06a3604c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -76,7 +76,7 @@ jobs: os: windows-2019 rust: stable target: x86_64-pc-windows-msvc - env: AR=llvm-ar CC=clang CXX=clang++ RUSTFLAGS=-Clinker=lld-link + env: $Env:AR="llvm-ar" ; $Env:CC="clang" ; $Env:CXX="clang++" ; $Env:RUSTFLAGS="-Clinker=lld-link" ; steps: - uses: actions/checkout@v4 - name: Install Rust (rustup) From 0571f2ac6bf1b9fd98056a4412b41cd70a4ef352 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Tue, 19 Mar 2024 20:46:40 -0600 Subject: [PATCH 08/32] use -? to detect cl-style frontends --- src/detect_compiler_family.c | 4 ---- src/tool.rs | 16 +++++++++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/detect_compiler_family.c b/src/detect_compiler_family.c index 290d2fc72..e66dcc044 100644 --- a/src/detect_compiler_family.c +++ b/src/detect_compiler_family.c @@ -5,7 +5,3 @@ #ifdef __GNUC__ #pragma message "gcc" #endif - -#ifdef _MSC_VER -#pragma message "msvc" -#endif diff --git a/src/tool.rs b/src/tool.rs index 7a2ad4da1..850065800 100644 --- a/src/tool.rs +++ b/src/tool.rs @@ -5,12 +5,13 @@ use std::{ ffi::{OsStr, OsString}, io::Write, path::{Path, PathBuf}, - process::Command, + process::{Command, Stdio}, sync::Mutex, }; use crate::{ command_helpers::{run_output, CargoOutput}, + run, tempfile::NamedTempfile, Error, ErrorKind, }; @@ -135,11 +136,20 @@ impl Tool { cargo_output.print_debug(&stdout); + // https://gitlab.kitware.com/cmake/cmake/-/blob/69a2eeb9dff5b60f2f1e5b425002a0fd45b7cadb/Modules/CMakeDetermineCompilerId.cmake#L267-271 + let accepts_cl_style_flags = + run(Command::new(path).arg("-?").stdout(Stdio::null()), path, &{ + // the errors are not errors! + let mut cargo_output = cargo_output.clone(); + cargo_output.warnings = cargo_output.debug; + cargo_output + }) + .is_ok(); + let clang = stdout.contains(r#""clang""#); - let msvc = stdout.contains(r#""msvc""#); let gcc = stdout.contains(r#""gcc""#); - match (clang, msvc, gcc) { + match (clang, accepts_cl_style_flags, gcc) { (clang_cl, true, _) => Ok(ToolFamily::Msvc { clang_cl }), (true, false, _) => Ok(ToolFamily::Clang { zig_cc: is_zig_cc(path, cargo_output), From 4581b2667c56d6631da5453268321d8913970cd3 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Wed, 20 Mar 2024 23:17:54 -0600 Subject: [PATCH 09/32] use output flag directly for assembler type --- src/lib.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 75c9215c2..f7f82ac63 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1579,8 +1579,6 @@ impl Build { let target = self.get_target()?; let msvc = target.contains("msvc"); let compiler = self.try_get_compiler()?; - let clang = compiler.is_like_clang(); - let gnu = compiler.family == ToolFamily::Gnu; let is_assembler_msvc = msvc && asm_ext == Some(AsmFileExt::DotAsm); let (mut cmd, name) = if is_assembler_msvc { @@ -1602,9 +1600,12 @@ impl Build { ) }; let is_arm = target.contains("aarch64") || target.contains("arm"); - command_add_output_file( - &mut cmd, &obj.dst, self.cuda, msvc, clang, gnu, is_asm, is_arm, - ); + if is_assembler_msvc { + cmd.arg("/Fo"); + } else { + cmd.arg("-o"); + } + cmd.arg(&obj.dst); // armasm and armasm64 don't requrie -c option if !is_assembler_msvc || !is_arm { cmd.arg("-c"); From c5c7562b6fc1a30dceebdb4f5a8f9cc60ad3cd0f Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Wed, 20 Mar 2024 23:18:03 -0600 Subject: [PATCH 10/32] apply ci suggestion --- .github/workflows/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b06a3604c..7c65d18c4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -76,7 +76,7 @@ jobs: os: windows-2019 rust: stable target: x86_64-pc-windows-msvc - env: $Env:AR="llvm-ar" ; $Env:CC="clang" ; $Env:CXX="clang++" ; $Env:RUSTFLAGS="-Clinker=lld-link" ; + env: AR=llvm-ar CC=clang CXX=clang++ RUSTFLAGS=-Clinker=lld-link steps: - uses: actions/checkout@v4 - name: Install Rust (rustup) @@ -99,6 +99,8 @@ jobs: - name: add clang to path run: $Env:PATH += ";C:\msys64\mingw64\bin" if: matrix.build == 'windows-clang' + - run : echo ${{ matrix.env }} >> $GITHUB_ENV + shell: bash - uses: Swatinem/rust-cache@v2 - run: ${{ matrix.env }} cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} - run: ${{ matrix.env }} cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release From ea91a79c3ffebfd1fe334773c87bcd471153ee0b Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Wed, 20 Mar 2024 23:18:33 -0600 Subject: [PATCH 11/32] add windows clang-cl ci --- .github/workflows/main.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7c65d18c4..c70f94cff 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -77,6 +77,11 @@ jobs: rust: stable target: x86_64-pc-windows-msvc env: AR=llvm-ar CC=clang CXX=clang++ RUSTFLAGS=-Clinker=lld-link + - build: windows-clang-cl + os: windows-2019 + rust: stable + target: x86_64-pc-windows-msvc + env: AR=llvm-ar CC=clang-cl CXX=clang-cl RUSTFLAGS=-Clinker=lld-link steps: - uses: actions/checkout@v4 - name: Install Rust (rustup) From 0ec9ca3d0416c582a42235f9383a580b4eff1296 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Wed, 20 Mar 2024 23:20:12 -0600 Subject: [PATCH 12/32] remove duplicate env --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c70f94cff..7ba1699d1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -107,9 +107,9 @@ jobs: - run : echo ${{ matrix.env }} >> $GITHUB_ENV shell: bash - uses: Swatinem/rust-cache@v2 - - run: ${{ matrix.env }} cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} - - run: ${{ matrix.env }} cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release - - run: ${{ matrix.env }} cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel + - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} + - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release + - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel # This is separate from the matrix above because there is no prebuilt rust-std component for these targets. check-tvos: From d44e7333ee6343956f9a65ba02ee483636f2b4f8 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Wed, 20 Mar 2024 23:23:08 -0600 Subject: [PATCH 13/32] make sure output arg is in same arg --- src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f7f82ac63..9cfdac6d4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1601,11 +1601,12 @@ impl Build { }; let is_arm = target.contains("aarch64") || target.contains("arm"); if is_assembler_msvc { - cmd.arg("/Fo"); + let mut out_arg = PathBuf::from("/Fo"); + out_arg.push(&obj.dst); + cmd.arg(out_arg); } else { - cmd.arg("-o"); + cmd.arg("-o").arg(&obj.dst); } - cmd.arg(&obj.dst); // armasm and armasm64 don't requrie -c option if !is_assembler_msvc || !is_arm { cmd.arg("-c"); From 8b7ed60e40e59df9b38bf36128fd69c2ccbedfd6 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Wed, 20 Mar 2024 23:29:07 -0600 Subject: [PATCH 14/32] fix creation of output arg --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 9cfdac6d4..e71be6022 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1601,7 +1601,7 @@ impl Build { }; let is_arm = target.contains("aarch64") || target.contains("arm"); if is_assembler_msvc { - let mut out_arg = PathBuf::from("/Fo"); + let mut out_arg = OsString::from("/Fo"); out_arg.push(&obj.dst); cmd.arg(out_arg); } else { From e0226791747795664a314b5d096b7a4cb0d4b388 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Wed, 20 Mar 2024 23:59:44 -0600 Subject: [PATCH 15/32] use msvc-style args for msvc --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index e71be6022..94567fb24 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1600,7 +1600,7 @@ impl Build { ) }; let is_arm = target.contains("aarch64") || target.contains("arm"); - if is_assembler_msvc { + if is_assembler_msvc || compiler.is_like_msvc() { let mut out_arg = OsString::from("/Fo"); out_arg.push(&obj.dst); cmd.arg(out_arg); From 4c5260ae679f590fbd4e0de578b337f292cec2aa Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Thu, 21 Mar 2024 00:06:40 -0600 Subject: [PATCH 16/32] hopefully fix env --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7ba1699d1..3a42e7f1c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -103,8 +103,8 @@ jobs: if: matrix.build == 'linux32' - name: add clang to path run: $Env:PATH += ";C:\msys64\mingw64\bin" - if: matrix.build == 'windows-clang' - - run : echo ${{ matrix.env }} >> $GITHUB_ENV + if: startsWith(matrix.build, 'windows-clang') + - run : echo ${{ matrix.env }} | xargs -I{} -n1 -- bash -c "echo {} >> $GITHUB_ENV" shell: bash - uses: Swatinem/rust-cache@v2 - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} From 9d35dcda369f65fed198ed9e30bd23f22b4c263a Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Thu, 21 Mar 2024 00:21:06 -0600 Subject: [PATCH 17/32] add test env command --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3a42e7f1c..646391ae2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -106,6 +106,8 @@ jobs: if: startsWith(matrix.build, 'windows-clang') - run : echo ${{ matrix.env }} | xargs -I{} -n1 -- bash -c "echo {} >> $GITHUB_ENV" shell: bash + - run: env + shell: bash - uses: Swatinem/rust-cache@v2 - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release From ba42c16ddc1268690025b6d061a28e1cd21e2017 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Thu, 21 Mar 2024 00:33:18 -0600 Subject: [PATCH 18/32] go back to previous env method --- .github/workflows/main.yml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 646391ae2..69d45a683 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -76,12 +76,12 @@ jobs: os: windows-2019 rust: stable target: x86_64-pc-windows-msvc - env: AR=llvm-ar CC=clang CXX=clang++ RUSTFLAGS=-Clinker=lld-link + env: $Env:AR="llvm-ar" ; $Env:CC="clang" ; $Env:CXX="clang++" ; $Env:RUSTFLAGS="-Clinker=lld-link" ; - build: windows-clang-cl os: windows-2019 rust: stable target: x86_64-pc-windows-msvc - env: AR=llvm-ar CC=clang-cl CXX=clang-cl RUSTFLAGS=-Clinker=lld-link + env: $Env:AR="llvm-ar" ; $Env:CC="clang-cl" ; $Env:CXX="clang-cl" ; $Env:RUSTFLAGS="-Clinker=lld-link" ; steps: - uses: actions/checkout@v4 - name: Install Rust (rustup) @@ -104,14 +104,10 @@ jobs: - name: add clang to path run: $Env:PATH += ";C:\msys64\mingw64\bin" if: startsWith(matrix.build, 'windows-clang') - - run : echo ${{ matrix.env }} | xargs -I{} -n1 -- bash -c "echo {} >> $GITHUB_ENV" - shell: bash - - run: env - shell: bash - uses: Swatinem/rust-cache@v2 - - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} - - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release - - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel + - run: ${{ matrix.env }} cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} + - run: ${{ matrix.env }} cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release + - run: ${{ matrix.env }} cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel # This is separate from the matrix above because there is no prebuilt rust-std component for these targets. check-tvos: From d69c416689610aae3dd62b8a8dab96a9675f7e00 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Thu, 21 Mar 2024 00:40:18 -0600 Subject: [PATCH 19/32] maybe? --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 94567fb24..a3591006b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -216,7 +216,7 @@ //! ``` #![doc(html_root_url = "https://docs.rs/cc/1.0")] -#![cfg_attr(test, deny(warnings))] +// #![cfg_attr(test, deny(warnings))] #![allow(deprecated)] #![deny(missing_docs)] @@ -1601,7 +1601,7 @@ impl Build { }; let is_arm = target.contains("aarch64") || target.contains("arm"); if is_assembler_msvc || compiler.is_like_msvc() { - let mut out_arg = OsString::from("/Fo"); + let mut out_arg = OsString::from("-Fo"); out_arg.push(&obj.dst); cmd.arg(out_arg); } else { From 975a9d7f77afce9557f38df0a79d92d7a2e3865b Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sat, 30 Mar 2024 21:35:53 +1100 Subject: [PATCH 20/32] FIx CI Signed-off-by: Jiahao XU --- .github/workflows/main.yml | 188 +++++++++++++++++++++---------------- 1 file changed, 105 insertions(+), 83 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 69d45a683..716965568 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,7 +12,21 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - build: [stable, beta, nightly, linux32, macos, aarch64-macos, aarch64-ios, win32, win64, mingw32, mingw64, windows-2019] + build: + [ + stable, + beta, + nightly, + linux32, + macos, + aarch64-macos, + aarch64-ios, + win32, + win64, + mingw32, + mingw64, + windows-2019, + ] include: - build: stable os: ubuntu-latest @@ -76,38 +90,46 @@ jobs: os: windows-2019 rust: stable target: x86_64-pc-windows-msvc - env: $Env:AR="llvm-ar" ; $Env:CC="clang" ; $Env:CXX="clang++" ; $Env:RUSTFLAGS="-Clinker=lld-link" ; + CC: clang + CXX: clang++ - build: windows-clang-cl os: windows-2019 rust: stable target: x86_64-pc-windows-msvc - env: $Env:AR="llvm-ar" ; $Env:CC="clang-cl" ; $Env:CXX="clang-cl" ; $Env:RUSTFLAGS="-Clinker=lld-link" ; + CC: clang-cl + CXX: clang-cl steps: - - uses: actions/checkout@v4 - - name: Install Rust (rustup) - run: | - set -euxo pipefail - rustup toolchain install ${{ matrix.rust }} --no-self-update --profile minimal --target ${{ matrix.target }} - rustup default ${{ matrix.rust }} - shell: bash - - name: Install g++-multilib - run: | - set -e - # Remove the ubuntu-toolchain-r/test PPA, which is added by default. - # Some packages were removed, and this is causing the g++multilib - # install to fail. Similar issue: - # https://github.com/scikit-learn/scikit-learn/issues/13928. - sudo add-apt-repository --remove ppa:ubuntu-toolchain-r/test - sudo apt-get update - sudo apt-get install g++-multilib - if: matrix.build == 'linux32' - - name: add clang to path - run: $Env:PATH += ";C:\msys64\mingw64\bin" - if: startsWith(matrix.build, 'windows-clang') - - uses: Swatinem/rust-cache@v2 - - run: ${{ matrix.env }} cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} - - run: ${{ matrix.env }} cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release - - run: ${{ matrix.env }} cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel + - uses: actions/checkout@v4 + - name: Install Rust (rustup) + run: | + set -euxo pipefail + rustup toolchain install ${{ matrix.rust }} --no-self-update --profile minimal --target ${{ matrix.target }} + rustup default ${{ matrix.rust }} + shell: bash + - name: Install g++-multilib + run: | + set -e + # Remove the ubuntu-toolchain-r/test PPA, which is added by default. + # Some packages were removed, and this is causing the g++multilib + # install to fail. Similar issue: + # https://github.com/scikit-learn/scikit-learn/issues/13928. + sudo add-apt-repository --remove ppa:ubuntu-toolchain-r/test + sudo apt-get update + sudo apt-get install g++-multilib + if: matrix.build == 'linux32' + - name: add clang to path + if: startsWith(matrix.build, 'windows-clang') + run: | + echo "C:\msys64\mingw64\bin" >> "$GITHUB_PATH" + echo -e "AR=llvm-ar\nRUSTFLAGS=-Clinker=lld-link\nCC=${CC}\nCXX=${CXX}" >> "$GITHUB_ENV" + shell: bash + env: + CC: ${{ matrix.CC }} + CXX: ${{ matrix.CXX }} + - uses: Swatinem/rust-cache@v2 + - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} + - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release + - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel # This is separate from the matrix above because there is no prebuilt rust-std component for these targets. check-tvos: @@ -133,37 +155,37 @@ jobs: target: x86_64-apple-tvos no_run: --no-run steps: - - uses: actions/checkout@v4 - - name: Install Rust (rustup) - run: | - set -euxo pipefail - rustup toolchain install ${{ matrix.rust }} --no-self-update --profile minimal - rustup component add rust-src --toolchain ${{ matrix.rust }} - rustup default ${{ matrix.rust }} - shell: bash - - uses: Swatinem/rust-cache@v2 - - run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} - - run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release - - run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel + - uses: actions/checkout@v4 + - name: Install Rust (rustup) + run: | + set -euxo pipefail + rustup toolchain install ${{ matrix.rust }} --no-self-update --profile minimal + rustup component add rust-src --toolchain ${{ matrix.rust }} + rustup default ${{ matrix.rust }} + shell: bash + - uses: Swatinem/rust-cache@v2 + - run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} + - run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release + - run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel cuda: name: Test CUDA support runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v4 - - name: Install cuda-minimal-build-11-8 - shell: bash - run: | - # https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=deb_network - wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb - sudo dpkg -i cuda-keyring_1.0-1_all.deb - sudo apt-get update - sudo apt-get -y install cuda-minimal-build-11-8 - - uses: Swatinem/rust-cache@v2 - - name: Test 'cudart' feature - shell: bash - run: | - PATH="/usr/local/cuda/bin:$PATH" cargo test --manifest-path dev-tools/cc-test/Cargo.toml --features test_cuda + - uses: actions/checkout@v4 + - name: Install cuda-minimal-build-11-8 + shell: bash + run: | + # https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=deb_network + wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb + sudo dpkg -i cuda-keyring_1.0-1_all.deb + sudo apt-get update + sudo apt-get -y install cuda-minimal-build-11-8 + - uses: Swatinem/rust-cache@v2 + - name: Test 'cudart' feature + shell: bash + run: | + PATH="/usr/local/cuda/bin:$PATH" cargo test --manifest-path dev-tools/cc-test/Cargo.toml --features test_cuda msrv: name: MSRV @@ -173,42 +195,42 @@ jobs: matrix: os: [ubuntu-latest, windows-latest] steps: - - uses: actions/checkout@v4 - - name: Install Rust - run: | - rustup toolchain install 1.53.0 --no-self-update --profile minimal - rustup toolchain install nightly --no-self-update --profile minimal - rustup default 1.53.0 - shell: bash - - name: Create Cargo.lock with minimal version - run: cargo +nightly update -Zminimal-versions - - name: Cache downloaded crates since 1.53 is really slow in fetching - uses: Swatinem/rust-cache@v2 - - run: cargo check --lib -p cc --locked - - run: cargo check --lib -p cc --locked --all-features + - uses: actions/checkout@v4 + - name: Install Rust + run: | + rustup toolchain install 1.53.0 --no-self-update --profile minimal + rustup toolchain install nightly --no-self-update --profile minimal + rustup default 1.53.0 + shell: bash + - name: Create Cargo.lock with minimal version + run: cargo +nightly update -Zminimal-versions + - name: Cache downloaded crates since 1.53 is really slow in fetching + uses: Swatinem/rust-cache@v2 + - run: cargo check --lib -p cc --locked + - run: cargo check --lib -p cc --locked --all-features clippy: name: Clippy runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Install Rust - run: | - rustup toolchain install stable --no-self-update --profile minimal --component rustfmt - rustup default stable - shell: bash - - uses: Swatinem/rust-cache@v2 - - run: cargo clippy + - uses: actions/checkout@v4 + - name: Install Rust + run: | + rustup toolchain install stable --no-self-update --profile minimal --component rustfmt + rustup default stable + shell: bash + - uses: Swatinem/rust-cache@v2 + - run: cargo clippy rustfmt: name: Rustfmt runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Install Rust - run: | - rustup toolchain install stable --no-self-update --profile minimal --component rustfmt - rustup default stable - shell: bash - - uses: Swatinem/rust-cache@v2 - - run: cargo fmt -- --check + - uses: actions/checkout@v4 + - name: Install Rust + run: | + rustup toolchain install stable --no-self-update --profile minimal --component rustfmt + rustup default stable + shell: bash + - uses: Swatinem/rust-cache@v2 + - run: cargo fmt -- --check From 6237e2e76d90399cb97f5e9d3798e1b74a55638c Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sat, 30 Mar 2024 21:57:43 +1100 Subject: [PATCH 21/32] Re-enable warnings-as-error when compiling tests Signed-off-by: Jiahao XU --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index a3591006b..3f66acfea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -216,7 +216,7 @@ //! ``` #![doc(html_root_url = "https://docs.rs/cc/1.0")] -// #![cfg_attr(test, deny(warnings))] +#![cfg_attr(test, deny(warnings))] #![allow(deprecated)] #![deny(missing_docs)] From f573a66791782a70a747c6cc03383c1b39147d0e Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sat, 30 Mar 2024 22:06:47 +1100 Subject: [PATCH 22/32] Fix `create_compile_object_cmd` Signed-off-by: Jiahao XU --- src/lib.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3f66acfea..25c4f1fff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1579,6 +1579,8 @@ impl Build { let target = self.get_target()?; let msvc = target.contains("msvc"); let compiler = self.try_get_compiler()?; + let clang = compiler.is_like_clang(); + let gnu = compiler.family == ToolFamily::Gnu; let is_assembler_msvc = msvc && asm_ext == Some(AsmFileExt::DotAsm); let (mut cmd, name) = if is_assembler_msvc { @@ -1600,13 +1602,16 @@ impl Build { ) }; let is_arm = target.contains("aarch64") || target.contains("arm"); - if is_assembler_msvc || compiler.is_like_msvc() { - let mut out_arg = OsString::from("-Fo"); - out_arg.push(&obj.dst); - cmd.arg(out_arg); - } else { - cmd.arg("-o").arg(&obj.dst); - } + command_add_output_file( + &mut cmd, + &obj.dst, + self.cuda, + is_assembler_msvc || compiler.is_like_msvc(), + clang, + gnu, + is_asm, + is_arm, + ); // armasm and armasm64 don't requrie -c option if !is_assembler_msvc || !is_arm { cmd.arg("-c"); From 6e72ff56ee6e3cf1b53cecfc997365cd6b2f6b61 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sat, 30 Mar 2024 22:42:21 +1100 Subject: [PATCH 23/32] Fix `is_flag_supported` and `create_compile_object_cmd` Signed-off-by: Jiahao XU --- src/command_helpers.rs | 25 ++++++++++++++----------- src/lib.rs | 30 ++++++++++++++++++------------ 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/command_helpers.rs b/src/command_helpers.rs index 10dafeb1c..fe919a523 100644 --- a/src/command_helpers.rs +++ b/src/command_helpers.rs @@ -385,17 +385,20 @@ for help)" } } -pub(crate) fn command_add_output_file( - cmd: &mut Command, - dst: &Path, - cuda: bool, - msvc: bool, - clang: bool, - gnu: bool, - is_asm: bool, - is_arm: bool, -) { - if msvc && !clang && !gnu && !cuda && !(is_asm && is_arm) { +pub(crate) struct CmdAddOutputFileArgs { + pub(crate) cuda: bool, + pub(crate) is_assembler_msvc: bool, + pub(crate) msvc: bool, + pub(crate) clang: bool, + pub(crate) gnu: bool, + pub(crate) is_asm: bool, + pub(crate) is_arm: bool, +} + +pub(crate) fn command_add_output_file(cmd: &mut Command, dst: &Path, args: CmdAddOutputFileArgs) { + if args.is_assembler_msvc + || (args.msvc && !args.clang && !args.gnu && !args.cuda && !(args.is_asm && args.is_arm)) + { let mut s = OsString::from("-Fo"); s.push(dst); cmd.arg(s); diff --git a/src/lib.rs b/src/lib.rs index 25c4f1fff..dce0b22f9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -637,12 +637,15 @@ impl Build { command_add_output_file( &mut cmd, &obj, - self.cuda, - target.contains("msvc"), - clang, - gnu, - false, - is_arm, + CmdAddOutputFileArgs { + cuda: self.cuda, + is_assembler_msvc: false, + msvc: compiler.is_like_msvc(), + clang, + gnu, + is_asm: false, + is_arm, + }, ); // Checking for compiler flags does not require linking @@ -1605,12 +1608,15 @@ impl Build { command_add_output_file( &mut cmd, &obj.dst, - self.cuda, - is_assembler_msvc || compiler.is_like_msvc(), - clang, - gnu, - is_asm, - is_arm, + CmdAddOutputFileArgs { + cuda: self.cuda, + is_assembler_msvc, + msvc: compiler.is_like_msvc(), + clang, + gnu, + is_asm, + is_arm, + }, ); // armasm and armasm64 don't requrie -c option if !is_assembler_msvc || !is_arm { From ad8d07271ffa2d3ef298b5cc6ae6be33fca835a9 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Sun, 31 Mar 2024 14:12:40 -0600 Subject: [PATCH 24/32] another ci attempt --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 716965568..974057f0d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -126,6 +126,9 @@ jobs: env: CC: ${{ matrix.CC }} CXX: ${{ matrix.CXX }} + - name: setup dev environment + uses: ilammy/msvc-dev-cmd@v1 + if: startsWith(matrix.build, 'windows-clang') - uses: Swatinem/rust-cache@v2 - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release From 940bc3e7349c88249b23d57fd3d9cc665135186e Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Sun, 31 Mar 2024 15:15:58 -0600 Subject: [PATCH 25/32] generalize NMakefile to allow clang flags --- .github/workflows/main.yml | 3 --- dev-tools/cc-test/build.rs | 21 ++++++++++++++++++--- dev-tools/cc-test/src/NMakefile | 14 ++++++++++---- src/lib.rs | 2 +- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 974057f0d..716965568 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -126,9 +126,6 @@ jobs: env: CC: ${{ matrix.CC }} CXX: ${{ matrix.CXX }} - - name: setup dev environment - uses: ilammy/msvc-dev-cmd@v1 - if: startsWith(matrix.build, 'windows-clang') - uses: Swatinem/rust-cache@v2 - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release diff --git a/dev-tools/cc-test/build.rs b/dev-tools/cc-test/build.rs index 7ebeeab22..fe1c70955 100644 --- a/dev-tools/cc-test/build.rs +++ b/dev-tools/cc-test/build.rs @@ -30,14 +30,16 @@ fn main() { run_forked_capture_output(&out, "warnings-on"); } - cc::Build::new() - .file("src/foo.c") + let mut build = cc::Build::new(); + build.file("src/foo.c") .flag_if_supported("-Wall") .flag_if_supported("-Wfoo-bar-this-flag-does-not-exist") .define("FOO", None) .define("BAR", "1") .compile("foo"); + let compiler = build.get_compiler(); + cc::Build::new() .file("src/bar1.c") .file("src/bar2.c") @@ -84,6 +86,14 @@ fn main() { // nmake which runs vanilla cl, and then also test it after we remove all // the relevant env vars from our own process. if target.contains("msvc") { + let cc_frontend = if compiler.is_like_msvc() { + "MSVC" + } else if compiler.is_like_clang() { + "CLANG" + } else { + unimplemented!("Unknown compiler that targets msvc but isn't clang-link or msvc-like") + }; + let out = out.join("tmp"); fs::create_dir(&out).unwrap(); println!("nmake 1"); @@ -92,6 +102,7 @@ fn main() { .env_remove("MAKEFLAGS") .arg("/fsrc/NMakefile") .env("OUT_DIR", &out) + .env("CC_FRONTEND", cc_frontend) .status() .unwrap(); assert!(status.success()); @@ -99,7 +110,10 @@ fn main() { fs::remove_dir_all(&out).unwrap(); fs::create_dir(&out).unwrap(); - env::remove_var("PATH"); + // windows registry won't find clang in path + if compiler.is_like_msvc() { + env::remove_var("PATH"); + } env::remove_var("VCINSTALLDIR"); env::remove_var("INCLUDE"); env::remove_var("LIB"); @@ -109,6 +123,7 @@ fn main() { .env_remove("MAKEFLAGS") .arg("/fsrc/NMakefile") .env("OUT_DIR", &out) + .env("CC_FRONTEND", cc_frontend) .status() .unwrap(); assert!(status.success()); diff --git a/dev-tools/cc-test/src/NMakefile b/dev-tools/cc-test/src/NMakefile index 03c73dff0..fab088ad9 100644 --- a/dev-tools/cc-test/src/NMakefile +++ b/dev-tools/cc-test/src/NMakefile @@ -1,14 +1,20 @@ all: $(OUT_DIR)/msvc.lib $(OUT_DIR)/msvc.exe +!IF "$(CC_FRONTEND)" == "MSVC" +EXTRA_CFLAGS=-nologo +CFLAG_OUTPUT=-Fo: +!ELSE +CFLAG_OUTPUT=-o +!ENDIF + $(OUT_DIR)/msvc.lib: $(OUT_DIR)/msvc.o lib -nologo -out:$(OUT_DIR)/msvc.lib $(OUT_DIR)/msvc.o - rc -h $(OUT_DIR)/msvc.o: src/msvc.c - $(CC) -nologo -c -Fo:$@ src/msvc.c -MD + $(CC) $(EXTRA_CFLAGS) -c $(CFLAG_OUTPUT)$@ src/msvc.c -MD $(OUT_DIR)/msvc.exe: $(OUT_DIR)/msvc2.o - $(CC) -nologo -Fo:$@ $(OUT_DIR)/msvc2.o + $(CC) $(EXTRA_CFLAGS) $(CFLAG_OUTPUT)$@ $(OUT_DIR)/msvc2.o $(OUT_DIR)/msvc2.o: src/msvc.c - $(CC) -nologo -c -Fo:$@ src/msvc.c -DMAIN -MD + $(CC) $(EXTRA_CFLAGS) -c $(CFLAG_OUTPUT)$@ src/msvc.c -DMAIN -MD diff --git a/src/lib.rs b/src/lib.rs index dce0b22f9..c7ca245ed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2412,7 +2412,7 @@ impl Build { let target = self.get_target()?; let (mut ar, cmd, _any_flags) = self.get_ar()?; - if target.contains("msvc") && !cmd.to_string_lossy().contains("llvm-") { + if target.contains("msvc") { // The Rust compiler will look for libfoo.a and foo.lib, but the // MSVC linker will also be passed foo.lib, so be sure that both // exist for now. From 2c41d81b9836b3f113d844a24b6c30f457261037 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Sun, 31 Mar 2024 15:17:26 -0600 Subject: [PATCH 26/32] fmt --- dev-tools/cc-test/build.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dev-tools/cc-test/build.rs b/dev-tools/cc-test/build.rs index fe1c70955..3ca7956a3 100644 --- a/dev-tools/cc-test/build.rs +++ b/dev-tools/cc-test/build.rs @@ -31,7 +31,8 @@ fn main() { } let mut build = cc::Build::new(); - build.file("src/foo.c") + build + .file("src/foo.c") .flag_if_supported("-Wall") .flag_if_supported("-Wfoo-bar-this-flag-does-not-exist") .define("FOO", None) From ff0f7af1fd2c1e20331500ec829975be28e10e1d Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Sun, 31 Mar 2024 15:23:57 -0600 Subject: [PATCH 27/32] try re-adding devenv --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 716965568..974057f0d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -126,6 +126,9 @@ jobs: env: CC: ${{ matrix.CC }} CXX: ${{ matrix.CXX }} + - name: setup dev environment + uses: ilammy/msvc-dev-cmd@v1 + if: startsWith(matrix.build, 'windows-clang') - uses: Swatinem/rust-cache@v2 - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} - run: cargo test ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release From fe5ae81449f7cbf1789d3999b7b4f19c0e90ad3e Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Sun, 31 Mar 2024 15:43:25 -0600 Subject: [PATCH 28/32] fix env vars in commandline tests --- tests/support/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/support/mod.rs b/tests/support/mod.rs index a17fe43f4..5b9f3b5c0 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -34,6 +34,11 @@ impl Test { // lesser of the two evils. env::remove_var("RUSTC_WRAPPER"); + // cc-rs prefers these env vars to the wrappers. We set these in some tests, so unset them so the wrappers get used + env::remove_var("CC"); + env::remove_var("CXX"); + env::remove_var("AR"); + let mut gcc = env::current_exe().unwrap(); gcc.pop(); if gcc.ends_with("deps") { From fd6b59a5dca3038c14ab269ec704f4704f342857 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Sun, 31 Mar 2024 15:49:47 -0600 Subject: [PATCH 29/32] apparently clang-cl doesn't accept -Fo: --- dev-tools/cc-test/src/NMakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-tools/cc-test/src/NMakefile b/dev-tools/cc-test/src/NMakefile index fab088ad9..e310a4f36 100644 --- a/dev-tools/cc-test/src/NMakefile +++ b/dev-tools/cc-test/src/NMakefile @@ -2,7 +2,7 @@ all: $(OUT_DIR)/msvc.lib $(OUT_DIR)/msvc.exe !IF "$(CC_FRONTEND)" == "MSVC" EXTRA_CFLAGS=-nologo -CFLAG_OUTPUT=-Fo: +CFLAG_OUTPUT=-Fo !ELSE CFLAG_OUTPUT=-o !ENDIF From 80a2f819fb03ea885f63a6554de8aff93fb35b48 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Sun, 31 Mar 2024 15:55:49 -0600 Subject: [PATCH 30/32] better check for if compiler is clang --- dev-tools/cc-test/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-tools/cc-test/build.rs b/dev-tools/cc-test/build.rs index 3ca7956a3..b7d66da0a 100644 --- a/dev-tools/cc-test/build.rs +++ b/dev-tools/cc-test/build.rs @@ -112,7 +112,7 @@ fn main() { fs::create_dir(&out).unwrap(); // windows registry won't find clang in path - if compiler.is_like_msvc() { + if !compiler.path().to_string_lossy().starts_with("clang-") { env::remove_var("PATH"); } env::remove_var("VCINSTALLDIR"); From 006ac81c3e268783657e59d2d40e9c86e6e417bc Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Sun, 31 Mar 2024 16:15:06 -0600 Subject: [PATCH 31/32] fix clang not being detected as clang --- dev-tools/cc-test/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-tools/cc-test/build.rs b/dev-tools/cc-test/build.rs index b7d66da0a..5b40ca686 100644 --- a/dev-tools/cc-test/build.rs +++ b/dev-tools/cc-test/build.rs @@ -112,7 +112,7 @@ fn main() { fs::create_dir(&out).unwrap(); // windows registry won't find clang in path - if !compiler.path().to_string_lossy().starts_with("clang-") { + if !compiler.path().to_string_lossy().starts_with("clang") { env::remove_var("PATH"); } env::remove_var("VCINSTALLDIR"); From eed65b49dc6ee2752b1e73b75e35f1743183b8a3 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Sun, 31 Mar 2024 16:23:59 -0600 Subject: [PATCH 32/32] fix typo, minor cleanup --- dev-tools/cc-test/build.rs | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-tools/cc-test/build.rs b/dev-tools/cc-test/build.rs index 5b40ca686..f26cbbb68 100644 --- a/dev-tools/cc-test/build.rs +++ b/dev-tools/cc-test/build.rs @@ -92,7 +92,7 @@ fn main() { } else if compiler.is_like_clang() { "CLANG" } else { - unimplemented!("Unknown compiler that targets msvc but isn't clang-link or msvc-like") + unimplemented!("Unknown compiler that targets msvc but isn't clang-like or msvc-like") }; let out = out.join("tmp"); diff --git a/src/lib.rs b/src/lib.rs index c7ca245ed..e0318765c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2411,7 +2411,6 @@ impl Build { } let target = self.get_target()?; - let (mut ar, cmd, _any_flags) = self.get_ar()?; if target.contains("msvc") { // The Rust compiler will look for libfoo.a and foo.lib, but the // MSVC linker will also be passed foo.lib, so be sure that both @@ -2435,6 +2434,7 @@ impl Build { // Non-msvc targets (those using `ar`) need a separate step to add // the symbol table to archives since our construction command of // `cq` doesn't add it for us. + let (mut ar, cmd, _any_flags) = self.get_ar()?; // NOTE: We add `s` even if flags were passed using $ARFLAGS/ar_flag, because `s` // here represents a _mode_, not an arbitrary flag. Further discussion of this choice