Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
829e054
fix llvm-ar as archiver for msvc targets
russelltg Mar 19, 2024
094d406
fix usage of get_command
russelltg Mar 19, 2024
d388cb8
fmt
russelltg Mar 19, 2024
d737de1
initial attempt at clang windows CI
russelltg Mar 19, 2024
9eff753
apply suggestion
russelltg Mar 19, 2024
7c20d23
hopefully get clang in path
russelltg Mar 19, 2024
3da03c7
oops this is powershell
russelltg Mar 19, 2024
0571f2a
use -? to detect cl-style frontends
russelltg Mar 20, 2024
4581b26
use output flag directly for assembler type
russelltg Mar 21, 2024
c5c7562
apply ci suggestion
russelltg Mar 21, 2024
ea91a79
add windows clang-cl ci
russelltg Mar 21, 2024
0ec9ca3
remove duplicate env
russelltg Mar 21, 2024
d44e733
make sure output arg is in same arg
russelltg Mar 21, 2024
8b7ed60
fix creation of output arg
russelltg Mar 21, 2024
e022679
use msvc-style args for msvc
russelltg Mar 21, 2024
4c5260a
hopefully fix env
russelltg Mar 21, 2024
9d35dcd
add test env command
russelltg Mar 21, 2024
ba42c16
go back to previous env method
russelltg Mar 21, 2024
d69c416
maybe?
russelltg Mar 21, 2024
975a9d7
FIx CI
NobodyXu Mar 30, 2024
6237e2e
Re-enable warnings-as-error when compiling tests
NobodyXu Mar 30, 2024
f573a66
Fix `create_compile_object_cmd`
NobodyXu Mar 30, 2024
6e72ff5
Fix `is_flag_supported` and `create_compile_object_cmd`
NobodyXu Mar 30, 2024
ad8d072
another ci attempt
russelltg Mar 31, 2024
940bc3e
generalize NMakefile to allow clang flags
russelltg Mar 31, 2024
2c41d81
fmt
russelltg Mar 31, 2024
ff0f7af
try re-adding devenv
russelltg Mar 31, 2024
fe5ae81
fix env vars in commandline tests
russelltg Mar 31, 2024
fd6b59a
apparently clang-cl doesn't accept -Fo:
russelltg Mar 31, 2024
80a2f81
better check for if compiler is clang
russelltg Mar 31, 2024
006ac81
fix clang not being detected as clang
russelltg Mar 31, 2024
eed65b4
fix typo, minor cleanup
russelltg Mar 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: $Env:AR="llvm-ar" ; $Env:CC="clang" ; $Env:CXX="clang++" ; $Env:RUSTFLAGS="-Clinker=lld-link" ;
steps:
- uses: actions/checkout@v4
- name: Install Rust (rustup)
Expand All @@ -91,10 +96,13 @@ 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: 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:
Expand Down
53 changes: 30 additions & 23 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") && !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.
Expand All @@ -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
Expand All @@ -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") && !program.to_string_lossy().contains("llvm-") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will probably need adjusting but for now is fine.

// 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
Expand All @@ -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
Expand All @@ -2479,12 +2477,16 @@ 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(())
Expand Down Expand Up @@ -3124,12 +3126,17 @@ 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<Command> = self
.env_tool(env)
.map(|(tool, _wrapper, args)| {
name = tool.clone();
let mut cmd = self.cmd(tool);
cmd.args(args);
cmd
Expand All @@ -3139,11 +3146,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") {
Expand All @@ -3154,7 +3161,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 {
Expand All @@ -3170,10 +3177,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") {
Expand All @@ -3200,7 +3207,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"),
Expand All @@ -3210,15 +3217,15 @@ impl Build {
}
cmd
} else {
name = lib;
name = lib.into();
self.cmd(&name)
}
} else if target.contains("illumos") {
// The default 'ar' on illumos uses a non-standard flags,
// 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) {
Expand All @@ -3238,16 +3245,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)
}
}
Expand Down Expand Up @@ -3939,7 +3946,7 @@ fn which(tool: &Path, path_entries: Option<OsString>) -> Option<PathBuf> {
}

// search for |prog| on 'programs' path in '|cc| -print-search-dirs' output
fn search_programs(cc: &mut Command, prog: &str, cargo_output: &CargoOutput) -> Option<PathBuf> {
fn search_programs(cc: &mut Command, prog: &Path, cargo_output: &CargoOutput) -> Option<PathBuf> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally the change to use &Path would be in a different pr. But I'm not about to hold this up for that, since it is a good change.

let search_dirs = run_output(
cc.arg("-print-search-dirs"),
"cc",
Expand All @@ -3952,7 +3959,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
Expand Down