From 56323239916af48811e70dfa9ea6ebf507e04873 Mon Sep 17 00:00:00 2001 From: Matthieu Felix Date: Mon, 16 Dec 2024 18:07:43 -0500 Subject: [PATCH] MacOS: Set `as` options to cross-compile for x86_64 This works on Apple silicon systems, and the resulting binary can be transparently run with Rosetta. --- .github/workflows/test.yml | 4 ++-- src/main.rs | 27 +++++++++++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0d8c10d..db70a31 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,8 +6,8 @@ jobs: test: strategy: matrix: - # have to use macos-13 because newer versions are arm-based - os: [ubuntu-latest, macos-13] + # check on macos-13 (x86) and macos-latest (ARM through Rosetta) + os: [ubuntu-latest, macos-13, macos-latest] runs-on: ${{ matrix.os }} diff --git a/src/main.rs b/src/main.rs index 50fe72f..73cbc1d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,12 +96,27 @@ fn output_path( fn assemble(options: &CliOptions, file: &Path, asm_file: OutFile) -> Result { let output_path = output_path(file, &options.output_path, options.no_link, "o"); - let output = Command::new("as") - .arg(asm_file.get()) - .arg("-o") - .arg(output_path.get()) - .output() - .map_err(|_| WreccError::Sys("could not invoke assembler 'as'".to_string()))?; + let output = match std::env::consts::OS { + "linux" => { + Command::new("as") + .arg(asm_file.get()) + .arg("-o") + .arg(output_path.get()) + .output() + .map_err(|_| WreccError::Sys("could not invoke assembler 'as'".to_string()))? + } + "macos" => { + Command::new("as") + .arg(asm_file.get()) + .arg("-o") + .arg(output_path.get()) + .arg("-arch") + .arg("x86_64") + .output() + .map_err(|_| WreccError::Sys("could not invoke assembler 'as'".to_string()))? + } + _ => return Err(WreccError::Sys(String::from("only supports linux and macos"))), + }; if output.status.success() { Ok(output_path)