diff --git a/.bazelrc b/.bazelrc index 81ee5fa9..3d3dbba4 100644 --- a/.bazelrc +++ b/.bazelrc @@ -6,6 +6,10 @@ common --enable_bzlmod common --noenable_workspace +# Auto-select build:linux / build:macos / build:windows based on the host OS, +# so platform-specific flags don't need manual --config= activation. +common --enable_platform_specific_config + # In Bazel 9, native C++ rules are no longer injected into the global namespace # by default. Two files in grpc 1.76.0 still use native.cc_*: # bazel/cython_library.bzl (native.cc_binary) @@ -15,3 +19,8 @@ build --incompatible_autoload_externally=+cc_library,+cc_binary build --conlyopt='-std=gnu11' --cxxopt='-std=c++17' build --host_cxxopt='-std=c++17' + +# Deployment target 10.13 is the minimum for C++17 aligned_alloc in libc++. +# host_macos_minimum_os covers host tool builds (e.g. protoc). +build:macos --macos_minimum_os=10.13 +build:macos --host_macos_minimum_os=10.13 diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml index 2caeb893..624b2f87 100644 --- a/.github/workflows/bazel.yml +++ b/.github/workflows/bazel.yml @@ -12,31 +12,47 @@ on: jobs: build: - runs-on: ubuntu-latest - env: - BAZEL: bazelisk-linux-amd64 - BUILDIFIER: buildifier-linux-amd64 + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v7 with: submodules: recursive + - name: Set platform environment variables + run: | + case "$(uname -s)" in + Linux*) OS=linux ;; + Darwin*) OS=darwin ;; + esac + case "$(uname -m)" in + x86_64) ARCH=amd64 ;; + arm64|aarch64) ARCH=arm64 ;; + esac + echo "OS=${OS}" >> $GITHUB_ENV + echo "ARCH=${ARCH}" >> $GITHUB_ENV + - name: Mount bazel cache uses: actions/cache@v6 with: + # Bazel's output root differs by OS: ~/.cache/bazel on Linux, ~/Library/Caches/bazel on macOS. # See https://docs.bazel.build/versions/master/output_directories.html - path: "~/.cache/bazel" + path: ${{ runner.os == 'macOS' && '~/Library/Caches/bazel' || '~/.cache/bazel' }} # Create a new cache entry whenever Bazel files change. # See https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows - key: bazel-${{ runner.os }}-build-${{ hashFiles('**/*.bzl', '**/*.bazel') }} + key: bazel-${{ runner.os }}-${{ runner.arch }}-build-${{ hashFiles('**/*.bzl', '**/*.bazel') }} restore-keys: | - bazel-${{ runner.os }}-build- + bazel-${{ runner.os }}-${{ runner.arch }}-build- - name: Install Buildifier run: | - curl -LO "https://github.com/bazelbuild/buildtools/releases/download/v8.5.1/$BUILDIFIER" - chmod +x $BUILDIFIER - sudo mv $BUILDIFIER /usr/local/bin/buildifier + BUILDIFIER="buildifier-${OS}-${ARCH}" + curl -LO "https://github.com/bazelbuild/buildtools/releases/download/v8.5.1/${BUILDIFIER}" + chmod +x "${BUILDIFIER}" + sudo mv "${BUILDIFIER}" /usr/local/bin/buildifier - name: Run Buildifier run: | @@ -53,9 +69,10 @@ jobs: - name: Install bazelisk run: | - curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.29.0/$BAZEL" - chmod +x $BAZEL - sudo mv $BAZEL /usr/local/bin/bazel + BAZEL="bazelisk-${OS}-${ARCH}" + curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.29.0/${BAZEL}" + chmod +x "${BAZEL}" + sudo mv "${BAZEL}" /usr/local/bin/bazel - name: Build run: bazel build //targets/simple_switch_grpc:simple_switch_grpc diff --git a/BUILD.bazel b/BUILD.bazel index de00349a..9f01abe5 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -28,8 +28,8 @@ expand_template( substitutions = { # disabled "#cmakedefine BM_DEBUG_ON @BM_DEBUG_ON@": "/* #undef BM_DEBUG_ON */", - "#cmakedefine BM_ELOG_ON @BM_ELOG_ON@": "/* #undef BM_ELOG_ON */", # enabled + "#cmakedefine BM_ELOG_ON @BM_ELOG_ON@": "#define BM_ELOG_ON 1", "#cmakedefine BM_ENABLE_MODULES @BM_ENABLE_MODULES@": "#define BM_ENABLE_MODULES 1", "#cmakedefine BM_HAVE_ALGORITHM @BM_HAVE_ALGORITHM@": "#define BM_HAVE_ALGORITHM 1", "#cmakedefine BM_HAVE_ARRAY @BM_HAVE_ARRAY@": "#define BM_HAVE_ARRAY 1",