Skip to content

Commit b95133c

Browse files
authored
Merge pull request #121 from rust-cross/fix-120
Use `x86-linux-*` for i585/i686 Rust targets on zig 0.11+
2 parents f2c70a1 + ecb93c3 commit b95133c

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

.github/workflows/CI.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,17 @@ jobs:
5959
- run: zig version
6060
- run: cargo build
6161
- name: Install Rust targets
62+
shell: bash
6263
run: |
63-
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
64+
rustup target add aarch64-unknown-linux-gnu \
65+
x86_64-unknown-linux-gnu \
66+
i686-unknown-linux-gnu \
67+
arm-unknown-linux-gnueabihf \
68+
armv7-unknown-linux-gnueabihf \
69+
aarch64-apple-darwin \
70+
x86_64-apple-darwin \
71+
x86_64-pc-windows-gnu \
72+
i686-pc-windows-gnu
6473
- name: Test bindgen
6574
shell: bash
6675
run: |
@@ -108,15 +117,14 @@ jobs:
108117
./target/x86_64-unknown-linux-gnu/debug/cargo-zigbuild --help
109118
- name: Linux - Test glibc build
110119
run: |
111-
rustup target add arm-unknown-linux-gnueabihf
112-
rustup target add armv7-unknown-linux-gnueabihf
113120
cargo run zigbuild --target aarch64-unknown-linux-gnu
114121
cargo run zigbuild --target aarch64-unknown-linux-gnu.2.17
115122
116123
cargo run zigbuild --target aarch64-unknown-linux-gnu --manifest-path tests/hello-cmake/Cargo.toml
117124
cargo run zigbuild --target aarch64-unknown-linux-gnu --manifest-path tests/hello-rustls/Cargo.toml
118125
cargo run zigbuild --target armv7-unknown-linux-gnueabihf --manifest-path tests/hello-rustls/Cargo.toml
119126
cargo run zigbuild --target arm-unknown-linux-gnueabihf --manifest-path tests/hello-rustls/Cargo.toml
127+
cargo run zigbuild --target i686-unknown-linux-gnu --manifest-path tests/hello-rustls/Cargo.toml
120128
121129
# Test building shared library
122130
cargo run zigbuild --target aarch64-unknown-linux-gnu --manifest-path tests/libhello/Cargo.toml

src/zig.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ impl Zig {
102102
} else if arg == "-lwindows" || arg == "-l:libpthread.a" || arg == "-lgcc" {
103103
return None;
104104
} else if arg == "-Wl,--disable-auto-image-base"
105+
|| arg == "-Wl,--dynamicbase"
105106
|| arg == "-Wl,--large-address-aware"
106107
{
107108
// https://github.com/rust-lang/rust/blob/f0bc76ac41a0a832c9ee621e31aaf1f515d3d6a5/compiler/rustc_target/src/spec/windows_gnu_base.rs#L23
109+
// https://github.com/rust-lang/rust/blob/2fb0e8d162a021f8a795fb603f5d8c0017855160/compiler/rustc_target/src/spec/windows_gnu_base.rs#L22
108110
// https://github.com/rust-lang/rust/blob/f0bc76ac41a0a832c9ee621e31aaf1f515d3d6a5/compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs#L16
109-
// zig doesn't support --disable-auto-image-base, --large-address-aware
111+
// zig doesn't support --disable-auto-image-base, --dynamicbase, and --large-address-aware
110112
return None;
111113
}
112114
} else if arg == "-Wl,--no-undefined-version" {
@@ -710,8 +712,20 @@ pub fn prepare_zig_linker(target: &str) -> Result<ZigWrapper> {
710712
},
711713
"armv5te" => ("arm", "-mcpu=generic+soft_float+strict_align"),
712714
"armv7" => ("arm", "-mcpu=generic+v7a+vfp3-d32+thumb2-neon"),
713-
"i586" => ("i386", "-mcpu=pentium"),
714-
"i686" => ("i386", "-mcpu=pentium4"),
715+
arch_str @ ("i586" | "i686") => {
716+
let cpu_arg = if arch_str == "i586" {
717+
"-mcpu=pentium"
718+
} else {
719+
"-mcpu=pentium4"
720+
};
721+
let zig_version = Zig::zig_version()?;
722+
let zig_arch = if zig_version.major == 0 && zig_version.minor >= 11 {
723+
"x86"
724+
} else {
725+
"i386"
726+
};
727+
(zig_arch, cpu_arg)
728+
}
715729
"riscv64gc" => ("riscv64", "-mcpu=generic_rv64+m+a+f+d+c"),
716730
"s390x" => ("s390x", "-mcpu=z10-vector"),
717731
_ => (arch.as_str(), ""),

0 commit comments

Comments
 (0)