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

Add -mcpu option for arm* targets #58

Merged
merged 1 commit into from
Sep 11, 2022
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 @@ -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