From 34251f84db8d2ec23576e67cda2a035cbbc82b84 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 1 Oct 2020 22:42:40 -0400 Subject: [PATCH] Link macOS hosts --- compiler/build/src/link.rs | 39 +++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/compiler/build/src/link.rs b/compiler/build/src/link.rs index 705ffdee19..b9c44e1ff8 100644 --- a/compiler/build/src/link.rs +++ b/compiler/build/src/link.rs @@ -15,23 +15,18 @@ pub fn link( architecture: Architecture::X86_64, operating_system: OperatingSystem::Linux, .. - } => link_linux( - arch_str(target), - binary_path, - host_input_path, - dest_filename, - ), + } => link_linux(target, binary_path, host_input_path, dest_filename), Triple { architecture: Architecture::X86_64, operating_system: OperatingSystem::Darwin, .. - } => todo!("link macos"), + } => link_macos(target, binary_path, host_input_path, dest_filename), _ => panic!("TODO gracefully handle unsupported target: {:?}", target), } } fn link_linux( - arch: &str, + target: &Triple, binary_path: &Path, host_input_path: &Path, dest_filename: &Path, @@ -39,7 +34,7 @@ fn link_linux( Command::new("ld") .args(&[ "-arch", - arch, + arch_str(target), "/usr/lib/x86_64-linux-gnu/crti.o", "/usr/lib/x86_64-linux-gnu/crtn.o", "/usr/lib/x86_64-linux-gnu/Scrt1.o", @@ -64,3 +59,29 @@ fn link_linux( ]) .spawn() } + +fn link_macos( + target: &Triple, + binary_path: &Path, + host_input_path: &Path, + dest_filename: &Path, +) -> io::Result { + Command::new("ld") + .args(&[ + "-arch", + target.architecture.to_string().as_str(), + // Libraries - see https://github.com/rtfeldman/roc/pull/554#discussion_r496392274 + // for discussion and further references + "-lSystem", + // "-lrt", // TODO shouldn't we need this? + // "-lc_nonshared", // TODO sho + // "-lc++", // TODO shouldn't we need this? + // "-lgcc", // TODO will eventually need compiler_rt from gcc or something - see https://github.com/rtfeldman/roc/pull/554#discussion_r496370840 + // "-lunwind", // TODO will eventually need this, see https://github.com/rtfeldman/roc/pull/554#discussion_r496370840 + "-o", + binary_path.to_str().unwrap(), // app + host_input_path.to_str().unwrap(), // host.o + dest_filename.to_str().unwrap(), // roc_app.o + ]) + .spawn() +}