Just enough changes to compile on M1

This commit is contained in:
Shritesh Bhattarai 2021-10-20 20:07:33 -04:00
parent 95e38a36b6
commit be9d817830
3 changed files with 54 additions and 36 deletions

View file

@ -42,7 +42,7 @@ quickcheck = "0.8"
quickcheck_macros = "0.8"
[features]
default = ["llvm", "target-webassembly"]
default = ["llvm", "target-webassembly", "target-aarch64"]
target-arm = []
target-aarch64 = []
target-webassembly = []

View file

@ -36,7 +36,6 @@ pub fn link(
..
} => link_linux(target, output_path, input_paths, link_type),
Triple {
architecture: Architecture::X86_64,
operating_system: OperatingSystem::Darwin,
..
} => link_macos(target, output_path, input_paths, link_type),
@ -724,10 +723,14 @@ fn link_macos(
String::from("-lSystem")
};
Ok((
let arch = match target.architecture {
Architecture::Aarch64(_) => "arm64".to_string(),
_ => target.architecture.to_string(),
};
let mut ld_child = Command::new("ld")
// NOTE: order of arguments to `ld` matters here!
// The `-l` flags should go after the `.o` arguments
Command::new("ld")
// Don't allow LD_ env vars to affect this
.env_clear()
.args(&[
@ -738,7 +741,7 @@ fn link_macos(
// "--gc-sections",
link_type_arg,
"-arch",
target.architecture.to_string().as_str(),
&arch,
])
.args(input_paths)
.args(&[
@ -757,9 +760,19 @@ fn link_macos(
"-o",
output_path.to_str().unwrap(), // app
])
.spawn()?,
output_path,
))
.spawn()?;
match target.architecture {
Architecture::Aarch64(_) => {
ld_child.wait()?;
let child = Command::new("codesign")
.args(&["-s", "-", output_path.to_str().unwrap()])
.spawn()?;
Ok((child, output_path))
}
_ => Ok((ld_child, output_path)),
}
}
fn link_wasm32(

View file

@ -31,6 +31,11 @@ pub fn target_triple_str(target: &Triple) -> &'static str {
operating_system: OperatingSystem::Linux,
..
} => "aarch64-unknown-linux-gnu",
Triple {
architecture: Architecture::Aarch64(_),
operating_system: OperatingSystem::Darwin,
..
} => "aarch64-apple-darwin",
Triple {
architecture: Architecture::X86_64,
operating_system: OperatingSystem::Darwin,