Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build on zig 0.11 with Rust nightly #110

Merged
merged 2 commits into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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" {
Copy link
Member Author

Choose a reason for hiding this comment

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

// 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