Enable Bzlmod for Bazel
This PR enables Bzlmod as the default external dependencies system for Bazel.
Changes included:
- Enable bzlmod by default in `.bazelrc`.
- Renamed `io_bazel` to `_main` at necessary locations.
- Added lockfile `MODULE.bazel.lock`. We should enable `--lockfile_mode=error` on CI and `--lockfile_mode=update` for local builds after fixing some issues in the lock file feature, probably with 6.4.0.
- Replaced distdir with repository cache (http artifact cache) in the offline bootstrap build. This will eventually be replaced by vendoring and packaging dependencies.
- Replaced `--override_repository` hack with repository cache (http artifact cache) for running integration tests without network access. This will eventually be replaced by a true shared repository cache.
- Only keep `--experimental_repository_cache_hardlinks` for macOS inside integration tests. On Linux, it'll trigger `invalid cross-device link` error because the file system of the sandbox dir is different from the repo cache dir inside docker container.
- Moved common CI flags to .bazelrc for better maintenance.
- Added all Maven coords in MODULE.bazel, patched rules_jvm_external to fix some Bzlmod issues.
Next step:
- Remove WORKSPACE and clean up distdir_deps, distdir.bzl.
- Enable `--lockfile_mode=error` on CI and `--lockfile_mode=update` for local builds
Closes https://github.com/bazelbuild/bazel/pull/19087
Fixes https://github.com/bazelbuild/bazel/issues/18957
PiperOrigin-RevId: 563825184
Change-Id: Ibf06418688bd568b38fd4aa73ad8328acfbaa13c
diff --git a/.bazelrc b/.bazelrc
index 5d76405..010a828 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -39,6 +39,7 @@
common:bzlmod --enable_bzlmod
common:bzlmod --check_direct_dependencies=error
common:bzlmod --experimental_downloader_config=bazel_downloader.cfg
+common --config=bzlmod
# Enable Java 11 language features (https://github.com/bazelbuild/bazel/issues/14592)
build --java_language_version=11
@@ -57,3 +58,28 @@
try-import %workspace%/user.bazelrc
build:docs --workspace_status_command=scripts/docs/get_workspace_status.sh
+
+# Flags for CI builds
+## For Linux
+build:ci-linux --repository_cache=/var/lib/buildkite-agent/bazeltest/repo_cache
+test:ci-linux --test_env=TEST_INSTALL_BASE=/var/lib/buildkite-agent/bazeltest/install_base
+test:ci-linux --test_env=REPOSITORY_CACHE=/var/lib/buildkite-agent/bazeltest/repo_cache
+test:ci-linux --test_env=REMOTE_NETWORK_ADDRESS=bazel.build:80
+test:ci-linux --sandbox_writable_path=/var/lib/buildkite-agent/bazeltest
+test:ci-linux --sandbox_default_allow_network=false
+
+## For macOS
+build:ci-macos --repository_cache=/Users/buildkite/bazeltest/repo_cache
+test:ci-macos --test_env=TEST_INSTALL_BASE=/Users/buildkite/bazeltest/install_base
+test:ci-macos --test_env=REPOSITORY_CACHE=/Users/buildkite/bazeltest/repo_cache
+test:ci-macos --test_env=REMOTE_NETWORK_ADDRESS=bazel.build:80
+test:ci-macos --sandbox_writable_path=/Users/buildkite/bazeltest
+test:ci-macos --sandbox_default_allow_network=false
+
+## For Windows
+build:ci-windows --repository_cache=C:/b/bazeltest_repo_cache
+test:ci-windows --test_env=BAZEL_VC
+test:ci-windows --test_env=JAVA_HOME
+test:ci-windows --test_env=TEST_INSTALL_BASE=C:/b/bazeltest_install_base
+test:ci-windows --test_env=REPOSITORY_CACHE=C:/b/bazeltest_repo_cache
+test:ci-windows --test_tag_filters=-no_windows,-slow