Skip to content

Commit e89afeb

Browse files
committed
Add -mcpu option for arm* targets
1 parent d5c2834 commit e89afeb

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

.github/workflows/CI.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ jobs:
118118
run: |
119119
rustup target add aarch64-unknown-linux-gnu
120120
rustup target add arm-unknown-linux-gnueabihf
121+
rustup target add armv7-unknown-linux-gnueabihf
121122
cargo run zigbuild --target aarch64-unknown-linux-gnu
122123
cargo run zigbuild --target aarch64-unknown-linux-gnu.2.17
123-
cargo run zigbuild --target arm-unknown-linux-gnueabihf
124124
125125
cargo run zigbuild --target aarch64-unknown-linux-gnu --manifest-path tests/hello-rustls/Cargo.toml
126+
cargo run zigbuild --target armv7-unknown-linux-gnueabihf --manifest-path tests/hello-rustls/Cargo.toml
127+
cargo run zigbuild --target arm-unknown-linux-gnueabihf --manifest-path tests/hello-rustls/Cargo.toml
126128
127129
# Test building shared library
128130
cargo run zigbuild --target aarch64-unknown-linux-gnu --manifest-path tests/libhello/Cargo.toml

src/zig.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl Zig {
7474
let is_windows_msvc = target
7575
.map(|x| x.contains("windows-msvc"))
7676
.unwrap_or_default();
77-
let is_arm = target.map(|x| x.contains("arm")).unwrap_or_default();
77+
let is_arm = target.map(|x| x.starts_with("arm")).unwrap_or_default();
7878
let is_macos = target.map(|x| x.contains("macos")).unwrap_or_default();
7979

8080
let rustc_ver = rustc_version::version()?;
@@ -115,6 +115,10 @@ impl Zig {
115115
return None;
116116
}
117117
}
118+
// Ignore `-march` option for arm* targets, we use `generic` + cpu features instead
119+
if is_arm && arg.starts_with("-march=") {
120+
return None;
121+
}
118122
Some(arg.to_string())
119123
};
120124
let has_undefined_dynamic_lookup = |args: &[String]| {
@@ -546,10 +550,27 @@ pub fn prepare_zig_linker(target: &str) -> Result<ZigWrapper> {
546550
let zig_cxx = format!("zigcxx-{}.{}", file_target, file_ext);
547551
let cc_args = "-g"; // prevent stripping
548552
let mut cc_args = match triple.operating_system {
549-
OperatingSystem::Linux => format!(
550-
"-target {}-linux-{}{} {}",
551-
arch, target_env, abi_suffix, cc_args,
552-
),
553+
OperatingSystem::Linux => {
554+
let (zig_arch, zig_cpu) = match arch.as_str() {
555+
// zig uses _ instead of - in cpu features
556+
"arm" => match target_env {
557+
Environment::Gnueabi | Environment::Musleabi => {
558+
("arm", "-mcpu=generic+v6+strict_align")
559+
}
560+
Environment::Gnueabihf | Environment::Musleabihf => {
561+
("arm", "-mcpu=generic+v6+strict_align+vfp2-d32")
562+
}
563+
_ => ("arm", ""),
564+
},
565+
"armv5te" => ("arm", "-mcpu=generic+soft_float+strict_align"),
566+
"armv7" => ("arm", "-mcpu=generic+v7a+vfp3-d32+thumb2-neon"),
567+
_ => (arch.as_str(), ""),
568+
};
569+
format!(
570+
"-target {}-linux-{}{} {} {}",
571+
zig_arch, target_env, abi_suffix, zig_cpu, cc_args,
572+
)
573+
}
553574
OperatingSystem::MacOSX { .. } | OperatingSystem::Darwin => {
554575
let zig_version = Zig::zig_version()?;
555576
// Zig 0.10.0 switched macOS ABI to none

0 commit comments

Comments
 (0)