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" quickcheck_macros = "0.8"
[features] [features]
default = ["llvm", "target-webassembly"] default = ["llvm", "target-webassembly", "target-aarch64"]
target-arm = [] target-arm = []
target-aarch64 = [] target-aarch64 = []
target-webassembly = [] target-webassembly = []

View file

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

View file

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