Skip to content

Commit

Permalink
Fix i686-pc-windows-gnu build on zig 0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Mar 12, 2023
1 parent abbee31 commit 56a29bd
Show file tree
Hide file tree
Showing 2 changed files with 15 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
15 changes: 12 additions & 3 deletions src/zig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ 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"
{
// 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
// zig doesn't support --disable-auto-image-base, --large-address-aware
return None;
}
}
Expand Down Expand Up @@ -713,7 +715,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 >= semver::Version::new(0, 11, 0) {
"x86"
} else {
"i386"
}
}
arch => arch,
};
format!("-target {zig_arch}-windows-{target_env}{abi_suffix} {cc_args}",)
Expand Down

0 comments on commit 56a29bd

Please sign in to comment.