Skip to content

Conversation

@bazel-io
Copy link
Member

The new flag allows users to specify additional mirrors for Bazel registry source URLs, taking precedence over those specified by registries. This provides a way to add mirrors without changing bazel_registry.json, the hash of which is stored in lockfiles.

RELNOTES: The new --module_mirrors flag accepts a comma-separated list of mirrors to use for source URLs provided by modules obtained from Bazel registries.

Closes #26832.

PiperOrigin-RevId: 800384242
Change-Id: I3b56eb5fe0405f460568d7563b2ad93f6b7461a5

Commit c3889fc

The new flag allows users to specify additional mirrors for Bazel registry source URLs, taking precedence over those specified by registries. This provides a way to add mirrors without changing `bazel_registry.json`, the hash of which is stored in lockfiles.

RELNOTES: The new `--module_mirrors` flag accepts a comma-separated list of mirrors to use for source URLs provided by modules obtained from Bazel registries.

Closes bazelbuild#26832.

PiperOrigin-RevId: 800384242
Change-Id: I3b56eb5fe0405f460568d7563b2ad93f6b7461a5
@bazel-io bazel-io added team-Configurability platforms, toolchains, cquery, select(), config transitions team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. awaiting-review PR is awaiting review from an assigned reviewer labels Aug 28, 2025
@bazel-io bazel-io requested a review from a team as a code owner August 28, 2025 10:04
@bazel-io bazel-io added team-Configurability platforms, toolchains, cquery, select(), config transitions team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. labels Aug 28, 2025
@bazel-io bazel-io requested a review from meteorcloudy August 28, 2025 10:04
@bazel-io bazel-io added the awaiting-review PR is awaiting review from an assigned reviewer label Aug 28, 2025
@bazel-io bazel-io requested a review from Wyverald August 28, 2025 10:04
@meteorcloudy
Copy link
Member

@fmeum Something weird with 8.4.0, can you take a look?

@fmeum
Copy link
Collaborator

fmeum commented Aug 28, 2025

@meteorcloudy Could you apply this patch?

diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionFunctionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionFunctionTest.java
index 0b44c3fad4..7bf0e83585 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BazelModuleResolutionFunctionTest.java
@@ -177,6 +177,7 @@ public class BazelModuleResolutionFunctionTest extends FoundationTestCase {
     PrecomputedValue.STARLARK_SEMANTICS.set(
         differencer,
         StarlarkSemantics.builder().setBool(BuildLanguageOptions.ENABLE_BZLMOD, true).build());
+    RegistryFunction.MODULE_MIRRORS.set(differencer, ImmutableSet.of());
     ModuleFileFunction.IGNORE_DEV_DEPS.set(differencer, false);
     ModuleFileFunction.INJECTED_REPOSITORIES.set(differencer, ImmutableMap.of());
     ModuleFileFunction.MODULE_OVERRIDES.set(differencer, ImmutableMap.of());
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BzlmodRepoRuleFunctionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BzlmodRepoRuleFunctionTest.java
index 8bf26610cf..175e0a8cd1 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BzlmodRepoRuleFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/BzlmodRepoRuleFunctionTest.java
@@ -154,6 +154,7 @@ public final class BzlmodRepoRuleFunctionTest extends FoundationTestCase {
 
     PrecomputedValue.STARLARK_SEMANTICS.set(differencer, StarlarkSemantics.DEFAULT);
     ModuleFileFunction.REGISTRIES.set(differencer, ImmutableSet.of());
+    RegistryFunction.MODULE_MIRRORS.set(differencer, ImmutableSet.of());
     ModuleFileFunction.IGNORE_DEV_DEPS.set(differencer, false);
     ModuleFileFunction.INJECTED_REPOSITORIES.set(differencer, ImmutableMap.of());
     ModuleFileFunction.MODULE_OVERRIDES.set(differencer, ImmutableMap.of());
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/DiscoveryTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/DiscoveryTest.java
index 439cee5530..9c595d8b13 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/DiscoveryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/DiscoveryTest.java
@@ -230,6 +230,7 @@ public class DiscoveryTest extends FoundationTestCase {
         differencer, Optional.empty());
     RepositoryDelegatorFunction.DISABLE_NATIVE_REPO_RULES.set(differencer, true);
     PrecomputedValue.REPO_ENV.set(differencer, ImmutableMap.of());
+    RegistryFunction.MODULE_MIRRORS.set(differencer, ImmutableSet.of());
     ModuleFileFunction.IGNORE_DEV_DEPS.set(differencer, false);
     ModuleFileFunction.INJECTED_REPOSITORIES.set(differencer, ImmutableMap.of());
     ModuleFileFunction.MODULE_OVERRIDES.set(differencer, ImmutableMap.of());
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java
index a5fbc11f62..7ddb510d50 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java
@@ -286,6 +286,7 @@ public class ModuleExtensionResolutionTest extends FoundationTestCase {
     ModuleFileFunction.MODULE_OVERRIDES.set(differencer, ImmutableMap.of());
     YankedVersionsUtil.ALLOWED_YANKED_VERSIONS.set(differencer, ImmutableList.of());
     ModuleFileFunction.REGISTRIES.set(differencer, ImmutableSet.of(registry.getUrl()));
+    RegistryFunction.MODULE_MIRRORS.set(differencer, ImmutableSet.of());
     BazelModuleResolutionFunction.CHECK_DIRECT_DEPENDENCIES.set(
         differencer, CheckDirectDepsMode.WARNING);
     BazelModuleResolutionFunction.BAZEL_COMPATIBILITY_MODE.set(
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java
index e1a45ab58c..3eb5b1cb5d 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java
@@ -210,6 +210,7 @@ public class ModuleFileFunctionTest extends FoundationTestCase {
     RepositoryDelegatorFunction.RESOLVED_FILE_INSTEAD_OF_WORKSPACE.set(
         differencer, Optional.empty());
     RepositoryDelegatorFunction.DISABLE_NATIVE_REPO_RULES.set(differencer, true);
+    RegistryFunction.MODULE_MIRRORS.set(differencer, ImmutableSet.of());
     PrecomputedValue.REPO_ENV.set(differencer, ImmutableMap.of());
     ModuleFileFunction.IGNORE_DEV_DEPS.set(differencer, false);
     ModuleFileFunction.INJECTED_REPOSITORIES.set(differencer, ImmutableMap.of());
diff --git a/src/test/java/com/google/devtools/build/lib/query2/testutil/SkyframeQueryHelper.java b/src/test/java/com/google/devtools/build/lib/query2/testutil/SkyframeQueryHelper.java
index 73e08a107d..dd662b96a3 100644
--- a/src/test/java/com/google/devtools/build/lib/query2/testutil/SkyframeQueryHelper.java
+++ b/src/test/java/com/google/devtools/build/lib/query2/testutil/SkyframeQueryHelper.java
@@ -30,6 +30,7 @@ import com.google.devtools.build.lib.bazel.bzlmod.BazelModuleResolutionFunction;
 import com.google.devtools.build.lib.bazel.bzlmod.FakeRegistry;
 import com.google.devtools.build.lib.bazel.bzlmod.ModuleFileFunction;
 import com.google.devtools.build.lib.bazel.bzlmod.ModuleKey;
+import com.google.devtools.build.lib.bazel.bzlmod.RegistryFunction;
 import com.google.devtools.build.lib.bazel.bzlmod.YankedVersionsUtil;
 import com.google.devtools.build.lib.bazel.repository.RepositoryOptions.BazelCompatibilityMode;
 import com.google.devtools.build.lib.bazel.repository.RepositoryOptions.CheckDirectDepsMode;
@@ -404,6 +405,7 @@ public abstract class SkyframeQueryHelper extends AbstractQueryHelper<Target> {
                         ModuleFileFunction.MODULE_OVERRIDES, ImmutableMap.of()),
                     PrecomputedValue.injected(
                         ModuleFileFunction.REGISTRIES, ImmutableSet.of(registry.getUrl())),
+                    PrecomputedValue.injected(RegistryFunction.MODULE_MIRRORS, ImmutableSet.of()),
                     PrecomputedValue.injected(ModuleFileFunction.IGNORE_DEV_DEPS, false),
                     PrecomputedValue.injected(
                         ModuleFileFunction.INJECTED_REPOSITORIES, ImmutableMap.of()),
@@ -443,6 +445,7 @@ public abstract class SkyframeQueryHelper extends AbstractQueryHelper<Target> {
                 RepositoryDelegatorFunction.VENDOR_DIRECTORY, Optional.empty()),
             PrecomputedValue.injected(
                 ModuleFileFunction.REGISTRIES, ImmutableSet.of(registry.getUrl())),
+            PrecomputedValue.injected(RegistryFunction.MODULE_MIRRORS, ImmutableSet.of()),
             PrecomputedValue.injected(ModuleFileFunction.IGNORE_DEV_DEPS, false),
             PrecomputedValue.injected(ModuleFileFunction.INJECTED_REPOSITORIES, ImmutableMap.of()),
             PrecomputedValue.injected(RepositoryDelegatorFunction.DISABLE_NATIVE_REPO_RULES, false),

@iancha1992
Copy link
Member

PrecomputedValue.injected(RegistryFunction.MODULE_MIRRORS, ImmutableSet.of()),

@fmeum Done

@iancha1992 iancha1992 enabled auto-merge August 28, 2025 17:51
@iancha1992
Copy link
Member

@fmeum The tests are still failing :(

@fmeum
Copy link
Collaborator

fmeum commented Aug 28, 2025

@iancha1992 One more patch:

diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java
index 437baa7f34..70a7083d17 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java
@@ -49,6 +49,7 @@ import com.google.devtools.build.lib.bazel.bzlmod.BazelLockFileFunction;
 import com.google.devtools.build.lib.bazel.bzlmod.BazelModuleResolutionFunction;
 import com.google.devtools.build.lib.bazel.bzlmod.FakeRegistry;
 import com.google.devtools.build.lib.bazel.bzlmod.ModuleFileFunction;
+import com.google.devtools.build.lib.bazel.bzlmod.RegistryFunction;
 import com.google.devtools.build.lib.bazel.bzlmod.YankedVersionsUtil;
 import com.google.devtools.build.lib.bazel.repository.RepositoryOptions.BazelCompatibilityMode;
 import com.google.devtools.build.lib.bazel.repository.RepositoryOptions.CheckDirectDepsMode;
@@ -239,6 +240,7 @@ public abstract class AnalysisTestCase extends FoundationTestCase {
                 ImmutableList.of(
                     PrecomputedValue.injected(
                         ModuleFileFunction.REGISTRIES, ImmutableSet.of(registry.getUrl())),
+                    PrecomputedValue.injected(RegistryFunction.MODULE_MIRRORS, ImmutableSet.of()),
                     PrecomputedValue.injected(ModuleFileFunction.IGNORE_DEV_DEPS, false),
                     PrecomputedValue.injected(
                         ModuleFileFunction.INJECTED_REPOSITORIES, ImmutableMap.of()),
@@ -301,6 +303,7 @@ public abstract class AnalysisTestCase extends FoundationTestCase {
                 RepositoryDelegatorFunction.VENDOR_DIRECTORY, Optional.empty()),
             PrecomputedValue.injected(
                 ModuleFileFunction.REGISTRIES, ImmutableSet.of(registry.getUrl())),
+            PrecomputedValue.injected(RegistryFunction.MODULE_MIRRORS, ImmutableSet.of()),
             PrecomputedValue.injected(ModuleFileFunction.IGNORE_DEV_DEPS, false),
             PrecomputedValue.injected(ModuleFileFunction.INJECTED_REPOSITORIES, ImmutableMap.of()),
             PrecomputedValue.injected(RepositoryDelegatorFunction.DISABLE_NATIVE_REPO_RULES, false),
diff --git a/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java b/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java
index 8a6435cf07..b6ad278357 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java
@@ -295,6 +295,7 @@ public class RepositoryDelegatorTest extends FoundationTestCase {
     BazelModuleResolutionFunction.BAZEL_COMPATIBILITY_MODE.set(
         differencer, BazelCompatibilityMode.ERROR);
     BazelLockFileFunction.LOCKFILE_MODE.set(differencer, LockfileMode.UPDATE);
+    RegistryFunction.MODULE_MIRRORS.set(differencer, ImmutableSet.of());
   }
 
   @Test

@iancha1992 iancha1992 added this pull request to the merge queue Aug 29, 2025
Merged via the queue into bazelbuild:release-8.4.0 with commit ba9a0fa Aug 29, 2025
46 checks passed
@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Aug 29, 2025
dd-mergequeue bot pushed a commit to DataDog/datadog-agent that referenced this pull request Nov 25, 2025
### Motivation
See:
- https://github.com/bazelbuild/bazel/releases/tag/8.4.0
- https://github.com/bazelbuild/bazel/releases/tag/8.4.1
- https://github.com/bazelbuild/bazel/releases/tag/8.4.2

(8.5.0 is due soon)

#### Cache & reliability
- 8.4.0 honors XDG_CACHE_HOME on macOS, which will definitely help ([ABLD-300](https://datadoghq.atlassian.net/browse/ABLD-300)): bazelbuild/bazel#26773
- 8.4.1 fixes a race condition affecting repository contents cache: bazelbuild/bazel#26950
- 8.4.0 fixes another race condition affecting workers: bazelbuild/bazel#26475

#### Modules
- 8.4.0 brings new `--module_mirrors` flag for fallback URLs when primary sources are slow/unavailable: bazelbuild/bazel#26850
- 8.4.0 avoids the need for dummy `MODULE.bazel` files with `git_repository`/`http_archive`: bazelbuild/bazel#26462
- 8.4.2 fixes a maintenance annoyance for `MODULE.bazel.lock` file: bazelbuild/bazel#27111

#### Platforms
- 8.4.0 allows to mitigate the long path issue with **MSVC on Windows**: bazelbuild/bazel#26532
- 8.4.2 fixes **macOS** compatibility issues: bazelbuild/bazel#27014

[ABLD-300]: https://datadoghq.atlassian.net/browse/ABLD-300?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

Co-authored-by: regis.desgroppes <[email protected]>
chouquette pushed a commit to DataDog/datadog-agent that referenced this pull request Nov 27, 2025
### Motivation
See:
- https://github.com/bazelbuild/bazel/releases/tag/8.4.0
- https://github.com/bazelbuild/bazel/releases/tag/8.4.1
- https://github.com/bazelbuild/bazel/releases/tag/8.4.2

(8.5.0 is due soon)

#### Cache & reliability
- 8.4.0 honors XDG_CACHE_HOME on macOS, which will definitely help ([ABLD-300](https://datadoghq.atlassian.net/browse/ABLD-300)): bazelbuild/bazel#26773
- 8.4.1 fixes a race condition affecting repository contents cache: bazelbuild/bazel#26950
- 8.4.0 fixes another race condition affecting workers: bazelbuild/bazel#26475

#### Modules
- 8.4.0 brings new `--module_mirrors` flag for fallback URLs when primary sources are slow/unavailable: bazelbuild/bazel#26850
- 8.4.0 avoids the need for dummy `MODULE.bazel` files with `git_repository`/`http_archive`: bazelbuild/bazel#26462
- 8.4.2 fixes a maintenance annoyance for `MODULE.bazel.lock` file: bazelbuild/bazel#27111

#### Platforms
- 8.4.0 allows to mitigate the long path issue with **MSVC on Windows**: bazelbuild/bazel#26532
- 8.4.2 fixes **macOS** compatibility issues: bazelbuild/bazel#27014

[ABLD-300]: https://datadoghq.atlassian.net/browse/ABLD-300?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

Co-authored-by: regis.desgroppes <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-Configurability platforms, toolchains, cquery, select(), config transitions team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants