Skip to main content
The following functions can be loaded from @bazel_tools//tools/build_defs/repo:local.bzl. Rules for making directories in the local filesystem available as repos.

Setup

To use these rules in a module extension, load them in your .bzl file and then call them from your extension’s implementation function. For example, to use local_repository:
Alternatively, you can directly call these repo rules in your MODULE.bazel file with use_repo_rule:

local_repository

local_repository(name, path, repo_mapping)
Makes a local directory that already contains Bazel files available as a repo. This directory should contain Bazel BUILD files and a repo boundary file already. If it doesn’t contain these files, consider using <a href=“#new_local_repository”><code>new_local_repository</code></a> instead.

Attributes

nameName; required

A unique name for this repository.

pathString; required

The path to the directory to make available as a repo.

The path can be either absolute, or relative to the workspace root.

repo_mappingDictionary: String -> String; required

A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.

For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target).

new_local_repository

new_local_repository(name, build_file, build_file_content, path, repo_mapping)
Makes a local directory that doesn’t contain Bazel files available as a repo. This directory need not contain Bazel BUILD files or a repo boundary file; they will be created by this repo rule. If the directory already contains Bazel files, consider using <a href=“#local_repository”><code>local_repository</code></a> instead.

Attributes

nameName; required

A unique name for this repository.

build_fileLabel; optional

A file to use as a BUILD file for this repo.

Exactly one of build_file and build_file_content must be specified.

The file addressed by this label does not need to be named BUILD, but can be. Something like BUILD.new-repo-name may work well to distinguish it from actual BUILD files.

build_file_contentString; optional

The content of the BUILD file to be created for this repo.

Exactly one of build_file and build_file_content must be specified.

pathString; required

The path to the directory to make available as a repo.

The path can be either absolute, or relative to the workspace root.

repo_mappingDictionary: String -> String; required

A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.

For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target).