From 88ce420b001f79bbc337be07aceb54cee838a558 Mon Sep 17 00:00:00 2001 From: David Gonzalez Martin Date: Mon, 22 Apr 2024 14:57:08 -0600 Subject: [PATCH] Enable MacOS CI --- .github/workflows/ci.yml | 16 ++++++++++++++-- build.zig | 4 ++-- build/test_runner.zig | 7 ++++++- ...thub_ubuntu_runner.sh => linux_gnu_runner.sh} | 0 ci/macos_runner.sh | 5 +++++ test/cc_macos/c_asm/.gitignore | 2 ++ test/cc_macos/c_asm/CMakeLists.txt | 3 +++ test/cc_macos/c_asm/assembly.S | 4 ++++ test/cc_macos/c_asm/main.c | 7 +++++++ 9 files changed, 43 insertions(+), 5 deletions(-) rename ci/{github_ubuntu_runner.sh => linux_gnu_runner.sh} (100%) create mode 100644 ci/macos_runner.sh create mode 100644 test/cc_macos/c_asm/.gitignore create mode 100644 test/cc_macos/c_asm/CMakeLists.txt create mode 100644 test/cc_macos/c_asm/assembly.S create mode 100644 test/cc_macos/c_asm/main.c diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9105a78..471f1f0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ on: - cron: "0 0 * * *" jobs: - build_and_test: + linux-gnu: runs-on: ubuntu-latest timeout-minutes: 15 steps: @@ -20,4 +20,16 @@ jobs: with: version: master - name: Build and test - run: sh ci/github_ubuntu_runner.sh + run: sh ci/linux_gnu_runner.sh + macos: + runs-on: macos-latest + timeout-minutes: 15 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Zig + uses: davidgm94/setup-zig@foo + with: + version: master + - name: Build and test + run: sh ci/macos_runner.sh diff --git a/build.zig b/build.zig index bd68abc..bbf3dc3 100644 --- a/build.zig +++ b/build.zig @@ -30,7 +30,7 @@ pub fn build(b: *std.Build) !void { const static = b.option(bool, "static", "This option enables the compiler to be built statically") orelse switch (@import("builtin").os.tag) { else => use_debug, .windows => true, - .macos => true, + // .macos => true, }; const compiler_options = b.addOptions(); compiler_options.addOption(bool, "print_stack_trace", print_stack_trace); @@ -481,7 +481,7 @@ pub fn build(b: *std.Build) !void { .macos => { compiler.linkLibCpp(); - if (discover_brew_prefix(b, "llvm")) |llvm_prefix| { + if (discover_brew_prefix(b, "llvm@17")) |llvm_prefix| { const llvm_include_path = try std.mem.concat(b.allocator, u8, &.{ llvm_prefix, "/include" }); const llvm_lib_path = try std.mem.concat(b.allocator, u8, &.{ llvm_prefix, "/lib" }); compiler.addIncludePath(.{ .cwd_relative = llvm_include_path }); diff --git a/build/test_runner.zig b/build/test_runner.zig index ead7ff9..5744178 100644 --- a/build/test_runner.zig +++ b/build/test_runner.zig @@ -523,7 +523,12 @@ fn run_test_suite(allocator: Allocator, args: struct { }; switch (@import("builtin").os.tag) { - .macos => {}, + .macos => runCmakeTests(allocator, .{ + .dir_path = "test/cc_macos", + .compiler_path = args.compiler_path, + }) catch { + errors = true; + }, .windows => {}, .linux => switch (@import("builtin").abi) { .gnu => runCmakeTests(allocator, .{ diff --git a/ci/github_ubuntu_runner.sh b/ci/linux_gnu_runner.sh similarity index 100% rename from ci/github_ubuntu_runner.sh rename to ci/linux_gnu_runner.sh diff --git a/ci/macos_runner.sh b/ci/macos_runner.sh new file mode 100644 index 0000000..b6a6362 --- /dev/null +++ b/ci/macos_runner.sh @@ -0,0 +1,5 @@ +#!/bin/sh +set -ex +brew update +brew install llvm@17 ninja +zig build test -Dthird_party_ci diff --git a/test/cc_macos/c_asm/.gitignore b/test/cc_macos/c_asm/.gitignore new file mode 100644 index 0000000..8326e08 --- /dev/null +++ b/test/cc_macos/c_asm/.gitignore @@ -0,0 +1,2 @@ +*.o +build/ diff --git a/test/cc_macos/c_asm/CMakeLists.txt b/test/cc_macos/c_asm/CMakeLists.txt new file mode 100644 index 0000000..5294827 --- /dev/null +++ b/test/cc_macos/c_asm/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.15) +project(c_asm C ASM) +add_executable(c_asm main.c assembly.S) diff --git a/test/cc_macos/c_asm/assembly.S b/test/cc_macos/c_asm/assembly.S new file mode 100644 index 0000000..34b90dc --- /dev/null +++ b/test/cc_macos/c_asm/assembly.S @@ -0,0 +1,4 @@ +.global _foo +_foo: + mov w0, #42 + ret diff --git a/test/cc_macos/c_asm/main.c b/test/cc_macos/c_asm/main.c new file mode 100644 index 0000000..cfa19e8 --- /dev/null +++ b/test/cc_macos/c_asm/main.c @@ -0,0 +1,7 @@ +extern int foo(); +#include +int main() +{ + assert(foo() == 42); + return 0; +}