Bazel: Migrate to bzlmod (#1530)

This migrates the bazel integration to the new Bazel dependency system
"bzlmod". bzlmod is becoming mandatory this year (see second sentence
here: https://bazel.build/external/migration).

This is a backwards incompatible migration, directly removing the old
WORKSPACE based approach. Users will have to change how they depend on
bzlmod, however I assume pretty much every user will be happy about it,
because they are forced to use bzlmod anyway or add extra flags to
continue to build with newer Bazel versions. Given that users normally
depend on specific git commits in the old system, they won't be hit with
this until they decide to upgrade emsdk.

The basic principle here is simple: I took everything that WORKSPACE did
and searched an alternative in bzlmod. Some interesting bits:

- We have less worries about multiple versions and people depending on
emscripten multiple times in different ways. This is resolved by the new
system: Bazel first iterates through the MODULE.bazel files recursively,
then finds the minimum version needed for each module and then executes
the module extensions that define repos exactly once at that version. So
no more ifs needed to detect multiple inclusions.
- A bunch of nodejs stuff moves to MODULE.bazel, because that is how the
nodejs module works now. As their module extension gets executed only
once you need to declare everything that you could need before that in
the MODULE.bazel file. A side effect of that is that we have to make a
fake repository when emscripten doesn't have an arm64 binary for linux,
because we can't actually figure that out in MODULE.bazel, so we have to
declare that it always exists and then create one in all cases.

There is a bunch of autoformatter changes in here as well, I could try
to revert them if you prefer.

Closes #1509
This commit is contained in:
Conrad Burchert
2025-04-09 23:38:12 +02:00
committed by GitHub
parent 24fc909c0d
commit ed2035a3cc
28 changed files with 11776 additions and 595 deletions

View File

@@ -38,6 +38,39 @@ commands:
command: |
source emsdk_env.sh
test/test.py
test-bazel-linux:
steps:
- checkout
- run:
name: install bazelisk
command: |
wget https://github.com/bazelbuild/bazelisk/releases/download/v1.25.0/bazelisk-linux-amd64
chmod +x bazelisk-linux-amd64
mv bazelisk-linux-amd64 /usr/local/bin/bazel
- run: test/test_bazel.sh
test-bazel-mac:
steps:
- checkout
- run:
name: install bazelisk
command: |
brew install bazelisk
- run: test/test_bazel_mac.sh
test-bazel-windows:
steps:
- checkout
- run:
name: Download Bazelisk
shell: powershell.exe
command: |
$ProgressPreference = "SilentlyContinue"
Invoke-WebRequest -Uri https://github.com/bazelbuild/bazelisk/releases/download/v1.10.1/bazelisk-windows-amd64.exe -OutFile ( New-Item -Path "temp\bazel\bazel.exe" -Force )
- run:
name: Run Tests
shell: powershell.exe
command: |
$env:Path += ";C:\Python27amd64;$pwd\temp\bazel"
.\test\test_bazel.ps1
jobs:
flake8:
@@ -223,60 +256,52 @@ jobs:
docker login -u "$DOCKER_USER" -p "$DOCKER_PASS"
make -C ./docker version=${CIRCLE_TAG} alias=${CIRCLE_TAG}-arm64 only_alias=true push
test-bazel-linux:
test-bazel7-linux:
executor: ubuntu
environment:
USE_BAZEL_VERSION: "7.x"
steps:
- test-bazel-linux
test-bazel-latest-linux:
executor: ubuntu
steps:
- checkout
- run: apt-get install -q -y curl gnupg
- run: curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg
- run: mv bazel.gpg /etc/apt/trusted.gpg.d/
- run: echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list
- run:
name: install pip
command: |
apt-get update -q
apt-get install -q -y python3-pip
- run: pip3 install absl-py
- run:
name: install bazel
command: |
apt-get install -q -y bazel-7.4.1
- run: test/test_bazel.sh
- test-bazel-linux
test-bazel-mac-arm64:
test-bazel7-mac-arm64:
executor: mac_arm64
environment:
USE_BAZEL_VERSION: "7.4.1"
USE_BAZEL_VERSION: "7.x"
steps:
- checkout
- run:
name: install bazelisk
command: |
brew install bazelisk
- run: test/test_bazel_mac.sh
- test-bazel-mac
test-bazel-windows:
test-bazel-latest-mac-arm64:
executor: mac_arm64
steps:
- test-bazel-mac
test-bazel7-windows:
executor:
name: win/server-2019
shell: powershell.exe -ExecutionPolicy Bypass
environment:
PYTHONUNBUFFERED: "1"
EMSDK_NOTTY: "1"
USE_BAZEL_VERSION: "5.4.0"
# For some reason version resolution with "7.x" does not work on Windows,
# so we have to specify a full version.
USE_BAZEL_VERSION: "7.6.1"
steps:
- checkout
- run:
name: Download Bazelisk
shell: powershell.exe
command: |
$ProgressPreference = "SilentlyContinue"
Invoke-WebRequest -Uri https://github.com/bazelbuild/bazelisk/releases/download/v1.10.1/bazelisk-windows-amd64.exe -OutFile ( New-Item -Path "temp\bazel\bazel.exe" -Force )
- run:
name: Run Tests
shell: powershell.exe
command: |
$env:Path += ";C:\Python27amd64;$pwd\temp\bazel"
.\test\test_bazel.ps1
- test-bazel-windows
test-bazel-latest-windows:
executor:
name: win/server-2019
shell: powershell.exe -ExecutionPolicy Bypass
environment:
PYTHONUNBUFFERED: "1"
EMSDK_NOTTY: "1"
steps:
- test-bazel-windows
workflows:
flake8:
@@ -309,12 +334,21 @@ workflows:
ignore: /.*/
tags:
only: /.*/
test-bazel-linux:
test-bazel7-linux:
jobs:
- test-bazel-linux
test-bazel-mac-arm64:
- test-bazel7-linux
test-bazel-latest-linux:
jobs:
- test-bazel-mac-arm64
test-bazel-windows:
- test-bazel-latest-linux
test-bazel7-mac-arm64:
jobs:
- test-bazel-windows
- test-bazel7-mac-arm64
test-bazel-latest-mac-arm64:
jobs:
- test-bazel-latest-mac-arm64
test-bazel7-windows:
jobs:
- test-bazel7-windows
test-bazel-latest-windows:
jobs:
- test-bazel-latest-windows