From 2a3ef547013cf4eb9d34d4051f57d42ab1d8514e Mon Sep 17 00:00:00 2001 From: Mizux Date: Wed, 30 Aug 2023 17:17:34 +0200 Subject: [PATCH] ci: Add amd64 macos bazel workflow (#324) * ci: Add amd64 MacOS Bazel job * bazel: Fix MacOS build * add amd64_macos_bazel badge --- .github/workflows/amd64_macos_bazel.yml | 35 +++++++++++++++++++++++++ BUILD.bazel | 13 ++++++++- README.md | 4 ++- bazel/platforms.bzl | 3 +++ scripts/generate_badges.d | 3 ++- 5 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/amd64_macos_bazel.yml diff --git a/.github/workflows/amd64_macos_bazel.yml b/.github/workflows/amd64_macos_bazel.yml new file mode 100644 index 0000000..fd1bc5a --- /dev/null +++ b/.github/workflows/amd64_macos_bazel.yml @@ -0,0 +1,35 @@ +name: amd64 MacOS Bazel + +on: + push: + pull_request: + schedule: + # min hours day(month) month day(week) + - cron: '0 0 7,22 * *' + +jobs: + # Building using the github runner environement directly. + bazel: + runs-on: macos-latest + steps: + - name: Check out repository code + uses: actions/checkout@v3 + - name: Install Bazel + run: | + brew update + brew unlink bazelisk + brew install bazel + - name: Check Bazel + run: bazel version + - name: Build + run: > + bazel build + -c opt + --subcommands=true + ... + - name: Test + run: > + bazel test + -c opt + --test_output=errors + ... diff --git a/BUILD.bazel b/BUILD.bazel index b6e4b9f..6925944 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -2,6 +2,7 @@ load("@bazel_skylib//lib:selects.bzl", "selects") load("//:bazel/platforms.bzl", "PLATFORM_CPU_ARM", "PLATFORM_CPU_ARM64", "PLATFORM_CPU_MIPS", "PLATFORM_CPU_PPC", "PLATFORM_CPU_RISCV32", "PLATFORM_CPU_RISCV64", "PLATFORM_CPU_X86_64") +load("//:bazel/platforms.bzl", "PLATFORM_OS_MACOS") package( default_visibility = ["//visibility:public"], @@ -170,7 +171,10 @@ cc_library( name = "hwcaps", srcs = ["src/hwcaps.c"], copts = C99_FLAGS, - defines = ["HAVE_STRONG_GETAUXVAL"], + defines = selects.with_or({ + PLATFORM_OS_MACOS: ["HAVE_DLFCN_H"], + "//conditions:default": ["HAVE_STRONG_GETAUXVAL"], + }), includes = INCLUDES, textual_hdrs = ["include/internal/hwcaps.h"], deps = [ @@ -237,6 +241,10 @@ cc_library( PLATFORM_CPU_RISCV64: ["include/cpuinfo_riscv.h"], }), copts = C99_FLAGS, + defines = selects.with_or({ + PLATFORM_OS_MACOS: ["HAVE_SYSCTLBYNAME"], + "//conditions:default": [], + }), includes = INCLUDES, textual_hdrs = selects.with_or({ PLATFORM_CPU_X86_64: ["src/impl_x86__base_implementation.inl"], @@ -296,6 +304,9 @@ cc_library( defines = selects.with_or({ PLATFORM_CPU_X86_64: ["CPU_FEATURES_MOCK_CPUID_X86"], "//conditions:default": [], + }) + selects.with_or({ + PLATFORM_OS_MACOS: ["HAVE_SYSCTLBYNAME"], + "//conditions:default": [], }), includes = INCLUDES, textual_hdrs = selects.with_or({ diff --git a/README.md b/README.md index 8cb272d..0221a80 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ instructions) at runtime. | | Linux | FreeBSD | MacOS | Windows | | :-- | --: | --: | --: | --: | -| amd64 | [![][i1a0]][l1a0]
[![][i1a1]][l1a1] | [![][i2a0]][l2a0]
![][d1] | [![][i3a0]][l3a0]
![][d1] | [![][i4a0]][l4a0]
![][d1] | +| amd64 | [![][i1a0]][l1a0]
[![][i1a1]][l1a1] | [![][i2a0]][l2a0]
![][d1] | [![][i3a0]][l3a0]
[![][i3a1]][l3a1] | [![][i4a0]][l4a0]
![][d1] | | AArch64 | [![][i1b0]][l1b0]
[![][i1b1]][l1b1] | ![][d0]
![][d1] | ![][d0]
![][d1] | ![][d0]
![][d1] | | ARM | [![][i1c0]][l1c0]
![][d1] | ![][d0]
![][d1] | ![][d0]
![][d1] | ![][d0]
![][d1] | | MIPS | [![][i1d0]][l1d0]
![][d1] | ![][d0]
![][d1] | ![][d0]
![][d1] | ![][d0]
![][d1] | @@ -31,6 +31,7 @@ instructions) at runtime. [i1h0]: https://img.shields.io/github/actions/workflow/status/google/cpu_features/s390x_linux_cmake.yml?branch=main&event=push&label=&logo=cmake [i2a0]: https://img.shields.io/github/actions/workflow/status/google/cpu_features/amd64_freebsd_cmake.yml?branch=main&event=push&label=&logo=cmake [i3a0]: https://img.shields.io/github/actions/workflow/status/google/cpu_features/amd64_macos_cmake.yml?branch=main&event=push&label=&logo=cmake +[i3a1]: https://img.shields.io/github/actions/workflow/status/google/cpu_features/amd64_macos_bazel.yml?branch=main&event=push&label=&logo=data:image/svg%2bxml;base64,PHN2ZyByb2xlPSJpbWciIHZpZXdCb3g9IjAgMCAyNCAyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNNiAuMTZsNS43ODYgNS43ODZMNiAxMS43MzIuMjE0IDUuOTQ2IDYgLjE2MXpNMCA2LjIxNFYxMmw1Ljc4NiA1Ljc4NlYxMkwwIDYuMjE0ek0xOCAuMTZsNS43ODYgNS43ODZMMTggMTEuNzMybC01Ljc4Ni01Ljc4NkwxOCAuMTYxek0yNCA2LjIxNFYxMmwtNS43ODYgNS43ODZWMTJMMjQgNi4yMTR6TTEyIDYuMTZsNS43ODYgNS43ODZMMTIgMTcuNzMybC01Ljc4Ni01Ljc4NkwxMiA2LjE2MXpNMTEuODQgMTguMDU0djUuNzg1bC01Ljc4Ni01Ljc4NXYtNS43ODZsNS43ODUgNS43ODZ6TTEyLjE2IDE4LjA1NGw1Ljc4Ni01Ljc4NnY1Ljc4NmwtNS43ODUgNS43ODV2LTUuNzg1eiIgc3Ryb2tlPSJ0cmFuc3BhcmVudCIgZmlsbD0id2hpdGUiLz48L3N2Zz4= [i4a0]: https://img.shields.io/github/actions/workflow/status/google/cpu_features/amd64_windows_cmake.yml?branch=main&event=push&label=&logo=cmake [l1a0]: https://github.com/google/cpu_features/actions/workflows/amd64_linux_cmake.yml [l1a1]: https://github.com/google/cpu_features/actions/workflows/amd64_linux_bazel.yml @@ -43,6 +44,7 @@ instructions) at runtime. [l1h0]: https://github.com/google/cpu_features/actions/workflows/s390x_linux_cmake.yml [l2a0]: https://github.com/google/cpu_features/actions/workflows/amd64_freebsd_cmake.yml [l3a0]: https://github.com/google/cpu_features/actions/workflows/amd64_macos_cmake.yml +[l3a1]: https://github.com/google/cpu_features/actions/workflows/amd64_macos_bazel.yml [l4a0]: https://github.com/google/cpu_features/actions/workflows/amd64_windows_cmake.yml ## Table of Contents diff --git a/bazel/platforms.bzl b/bazel/platforms.bzl index 20ed79d..eb025ce 100644 --- a/bazel/platforms.bzl +++ b/bazel/platforms.bzl @@ -13,3 +13,6 @@ PLATFORM_CPU_PPC = ("@platforms//cpu:ppc") PLATFORM_CPU_RISCV32 = ("@platforms//cpu:riscv32") PLATFORM_CPU_RISCV64 = ("@platforms//cpu:riscv64") + + +PLATFORM_OS_MACOS = ("@platforms//os:macos") diff --git a/scripts/generate_badges.d b/scripts/generate_badges.d index f62b2e9..e69e2d5 100644 --- a/scripts/generate_badges.d +++ b/scripts/generate_badges.d @@ -78,7 +78,8 @@ const: case BuildSystem.CMake: return os == Os.Linux || cpu == Cpu.amd64; case BuildSystem.Bazel: - return os == Os.Linux && (cpu == Cpu.amd64 || cpu == Cpu.AArch64); + return (os == Os.Linux && (cpu == Cpu.amd64 || cpu == Cpu.AArch64)) + || (os == Os.MacOS && cpu == Cpu.amd64); } }