Skip to content

Commit

Permalink
Merge pull request #110 from rust-cross/fix-i686-windows
Browse files Browse the repository at this point in the history
Fix build on zig 0.11 with Rust nightly
  • Loading branch information
messense authored Mar 12, 2023
2 parents abbee31 + cae0eda commit f8bffa6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
- run: cargo build
- name: Install Rust targets
run: |
rustup target add aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu aarch64-apple-darwin x86_64-apple-darwin x86_64-pc-windows-gnu
rustup target add aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu aarch64-apple-darwin x86_64-apple-darwin x86_64-pc-windows-gnu i686-pc-windows-gnu
- name: Test bindgen
shell: bash
run: |
Expand Down Expand Up @@ -145,6 +145,8 @@ jobs:
run: |
cargo run zigbuild --target x86_64-pc-windows-gnu
cargo run zigbuild --target x86_64-pc-windows-gnu --manifest-path tests/hello-windows/Cargo.toml
cargo run zigbuild --target i686-pc-windows-gnu
cargo run zigbuild --target i686-pc-windows-gnu --manifest-path tests/hello-windows/Cargo.toml
- name: Windows - Test build curl
if: matrix.os == 'windows-latest'
run: |
Expand Down
21 changes: 18 additions & 3 deletions src/zig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,19 @@ impl Zig {
return Some("-lc++".to_string());
} else if arg == "-lwindows" || arg == "-l:libpthread.a" || arg == "-lgcc" {
return None;
} else if arg == "-Wl,--disable-auto-image-base" {
} else if arg == "-Wl,--disable-auto-image-base"
|| arg == "-Wl,--large-address-aware"
|| arg == "-Wl,--no-undefined-version"
{
// https://github.com/rust-lang/rust/blob/f0bc76ac41a0a832c9ee621e31aaf1f515d3d6a5/compiler/rustc_target/src/spec/windows_gnu_base.rs#L23
// zig doesn't support --disable-auto-image-base
// https://github.com/rust-lang/rust/blob/f0bc76ac41a0a832c9ee621e31aaf1f515d3d6a5/compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs#L16
// zig doesn't support --disable-auto-image-base, --large-address-aware
return None;
}
} else if arg == "-Wl,--no-undefined-version" {
// https://github.com/rust-lang/rust/blob/542ed2bf72b232b245ece058fc11aebb1ca507d7/compiler/rustc_codegen_ssa/src/back/linker.rs#L723
// zig doesn't support --no-undefined-version
return None;
}
if is_musl {
// Avoids duplicated symbols with both zig musl libc and the libc crate
Expand Down Expand Up @@ -713,7 +721,14 @@ pub fn prepare_zig_linker(target: &str) -> Result<ZigWrapper> {
}
OperatingSystem::Windows { .. } => {
let zig_arch = match arch.as_str() {
"i686" => "i386",
"i686" => {
let zig_version = Zig::zig_version()?;
if zig_version.major == 0 && zig_version.minor >= 11 {
"x86"
} else {
"i386"
}
}
arch => arch,
};
format!("-target {zig_arch}-windows-{target_env}{abi_suffix} {cc_args}",)
Expand Down

0 comments on commit f8bffa6

Please sign in to comment.