Skip to content

Commit

Permalink
Merge pull request #58 from messense/armv7
Browse files Browse the repository at this point in the history
Add `-mcpu` option for arm* targets
  • Loading branch information
messense authored Sep 11, 2022
2 parents d5c2834 + e89afeb commit 9148798
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ jobs:
run: |
rustup target add aarch64-unknown-linux-gnu
rustup target add arm-unknown-linux-gnueabihf
rustup target add armv7-unknown-linux-gnueabihf
cargo run zigbuild --target aarch64-unknown-linux-gnu
cargo run zigbuild --target aarch64-unknown-linux-gnu.2.17
cargo run zigbuild --target arm-unknown-linux-gnueabihf
cargo run zigbuild --target aarch64-unknown-linux-gnu --manifest-path tests/hello-rustls/Cargo.toml
cargo run zigbuild --target armv7-unknown-linux-gnueabihf --manifest-path tests/hello-rustls/Cargo.toml
cargo run zigbuild --target arm-unknown-linux-gnueabihf --manifest-path tests/hello-rustls/Cargo.toml
# Test building shared library
cargo run zigbuild --target aarch64-unknown-linux-gnu --manifest-path tests/libhello/Cargo.toml
Expand Down
31 changes: 26 additions & 5 deletions src/zig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Zig {
let is_windows_msvc = target
.map(|x| x.contains("windows-msvc"))
.unwrap_or_default();
let is_arm = target.map(|x| x.contains("arm")).unwrap_or_default();
let is_arm = target.map(|x| x.starts_with("arm")).unwrap_or_default();
let is_macos = target.map(|x| x.contains("macos")).unwrap_or_default();

let rustc_ver = rustc_version::version()?;
Expand Down Expand Up @@ -115,6 +115,10 @@ impl Zig {
return None;
}
}
// Ignore `-march` option for arm* targets, we use `generic` + cpu features instead
if is_arm && arg.starts_with("-march=") {
return None;
}
Some(arg.to_string())
};
let has_undefined_dynamic_lookup = |args: &[String]| {
Expand Down Expand Up @@ -546,10 +550,27 @@ pub fn prepare_zig_linker(target: &str) -> Result<ZigWrapper> {
let zig_cxx = format!("zigcxx-{}.{}", file_target, file_ext);
let cc_args = "-g"; // prevent stripping
let mut cc_args = match triple.operating_system {
OperatingSystem::Linux => format!(
"-target {}-linux-{}{} {}",
arch, target_env, abi_suffix, cc_args,
),
OperatingSystem::Linux => {
let (zig_arch, zig_cpu) = match arch.as_str() {
// zig uses _ instead of - in cpu features
"arm" => match target_env {
Environment::Gnueabi | Environment::Musleabi => {
("arm", "-mcpu=generic+v6+strict_align")
}
Environment::Gnueabihf | Environment::Musleabihf => {
("arm", "-mcpu=generic+v6+strict_align+vfp2-d32")
}
_ => ("arm", ""),
},
"armv5te" => ("arm", "-mcpu=generic+soft_float+strict_align"),
"armv7" => ("arm", "-mcpu=generic+v7a+vfp3-d32+thumb2-neon"),
_ => (arch.as_str(), ""),
};
format!(
"-target {}-linux-{}{} {} {}",
zig_arch, target_env, abi_suffix, zig_cpu, cc_args,
)
}
OperatingSystem::MacOSX { .. } | OperatingSystem::Darwin => {
let zig_version = Zig::zig_version()?;
// Zig 0.10.0 switched macOS ABI to none
Expand Down

0 comments on commit 9148798

Please sign in to comment.