@bazel_tools//tools/build_defs/repo:http.bzl.
// Generated with Stardoc: http://skydoc.bazel.build
Rules for downloading files and archives over HTTP.
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 usehttp_archive:
use_repo_rule:
http_archive
"zip", "jar", "war", "aar", "tar",
"tar.gz", "tgz", "tar.xz", "txz", "tar.zst", "tzst", tar.bz2, "ar",
or "deb".
Examples:
Suppose the current repository contains the source code for a chat program,
rooted at the directory ~/chat-app. It needs to depend on an SSL library
which is available from http://example.com/openssl.zip. This .zip file
contains the following directory structure:
openssl.BUILD file which
contains the following target definition:
~/chat-app repository can depend on this target if the
following lines are added to ~/chat-app/WORKSPACE:
@my_ssl//:openssl-lib as a dependency.
ATTRIBUTES
name | Name; required A unique name for this repository. |
add_prefix | String; optional Destination directory relative to the repository directory.The archive will be unpacked into this directory, after applying |
auth_patterns | Dictionary: String -> String; optional An optional dict mapping host names to custom authorization patterns.If a URL’s host name is present in this dict the value will be used as a pattern when
generating the authorization header for the http request. This enables the use of custom
authorization schemes used in a lot of common cloud storage providers.The pattern currently supports 2 tokens: |
build_file | Label; optional The file to use as the BUILD file for this repository.This attribute is an absolute label (use ’@//’ for the main repo). The file does not need to be named BUILD, but can be (something like BUILD.new-repo-name may work well for distinguishing it from the repository’s actual BUILD files. Either build_file or build_file_content can be specified, but not both. |
build_file_content | String; optional The content for the BUILD file for this repository. Either build_file or build_file_content can be specified, but not both. |
canonical_id | String; optional A canonical ID of the file downloaded.If specified and non-empty, Bazel will not take the file from cache, unless it was added to the cache by a request with the same canonical ID.If unspecified or empty, Bazel by default uses the URLs of the file as the canonical ID. This helps catch the common mistake of updating the URLs without also updating the hash, resulting in builds that succeed locally but fail on machines without the file in the cache. This behavior can be disabled with —repo_env=BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID=0. |
files | Dictionary: String -> Label; optional A map of relative paths (key) to a file label (value) that overlaid on the repo as
a symlink. This is useful when you want to add REPO.bazel or BUILD.bazel files atop an existing
repository. Files are symlinked after remote files are downloaded and patches ( |
integrity | String; optional Expected checksum in Subresource Integrity format of the file downloaded.This must match the checksum of the file downloaded. It is a security risk
to omit the checksum as remote files can change. At best omitting this
field will make your build non-hermetic. It is optional to make development
easier but either this attribute or |
netrc | String; optional Location of the .netrc file to use for authentication |
patch_args | List of strings; optional The arguments given to the patch tool. Defaults to -p0 (see the |
patch_cmds | List of strings; optional Sequence of Bash commands to be applied on Linux/Macos after patches are applied. |
patch_cmds_win | List of strings; optional Sequence of Powershell commands to be applied on Windows after patches are applied. If this attribute is not set, patch_cmds will be executed on Windows, which requires Bash binary to exist. |
patch_strip | Integer; optional When set to |
patch_tool | String; optional The patch(1) utility to use. If this is specified, Bazel will use the specified patch tool instead of the Bazel-native patch implementation. |
patches | List of labels; optional A list of files that are to be applied as patches after extracting the archive. By default, it uses the Bazel-native patch implementation which doesn’t support fuzz match and binary patch, but Bazel will fall back to use patch command line tool if |
remote_file_integrity | Dictionary: String -> String; optional A map of file relative paths (key) to its integrity value (value). These relative paths should map to the files (key) in the |
remote_file_urls | Dictionary: String -> List of strings; optional A map of relative paths (key) to a list of URLs (value) that are to be downloaded
and made available as overlaid files on the repo. This is useful when you want to add REPO.bazel or
BUILD.bazel files atop an existing repository. The files are downloaded before |
remote_module_file_integrity | String; optional For internal use only. |
remote_module_file_urls | List of strings; optional For internal use only. |
remote_patch_strip | Integer; optional The number of leading slashes to be stripped from the file name in the remote patches. |
remote_patches | Dictionary: String -> String; optional A map of patch file URL to its integrity value, they are applied after extracting the archive and before applying patch files from the |
repo_mapping | Dictionary: String -> String; optional In |
sha256 | String; optional The expected SHA-256 of the file downloaded.This must match the SHA-256 of the file downloaded. It is a security risk
to omit the SHA-256 as remote files can change. At best omitting this
field will make your build non-hermetic. It is optional to make development
easier but either this attribute or |
strip_prefix | String; optional A directory prefix to strip from the extracted files.Many archives contain a top-level directory that contains all of the useful
files in archive. Instead of needing to specify this prefix over and over
in the |
type | String; optional The archive type of the downloaded file.By default, the archive type is determined from the file extension of the
URL. If the file has no extension, you can explicitly specify one of the
following: |
url | String; optional A URL to a file that will be made available to Bazel.This must be a file, http or https URL. Redirections are followed. Authentication is not supported.More flexibility can be achieved by the urls parameter that allows to specify alternative URLs to fetch from. |
urls | List of strings; optional A list of URLs to a file that will be made available to Bazel.Each entry must be a file, http or https URL. Redirections are followed. Authentication is not supported.URLs are tried in order until one succeeds, so you should list local mirrors first. If all downloads fail, the rule will fail. |
workspace_file | Label; optional No-op attribute; do not use. |
workspace_file_content | String; optional No-op attribute; do not use. |
BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID
http_file
@my_deb//file as a dependency to depend on this file.
ATTRIBUTES
name | Name; required A unique name for this repository. |
auth_patterns | Dictionary: String -> String; optional An optional dict mapping host names to custom authorization patterns.If a URL’s host name is present in this dict the value will be used as a pattern when
generating the authorization header for the http request. This enables the use of custom
authorization schemes used in a lot of common cloud storage providers.The pattern currently supports 2 tokens: |
canonical_id | String; optional A canonical ID of the file downloaded.If specified and non-empty, Bazel will not take the file from cache, unless it was added to the cache by a request with the same canonical ID.If unspecified or empty, Bazel by default uses the URLs of the file as the canonical ID. This helps catch the common mistake of updating the URLs without also updating the hash, resulting in builds that succeed locally but fail on machines without the file in the cache. This behavior can be disabled with —repo_env=BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID=0. |
downloaded_file_path | String; optional Path assigned to the file downloaded |
executable | Boolean; optional If the downloaded file should be made executable. |
integrity | String; optional Expected checksum in Subresource Integrity format of the file downloaded.This must match the checksum of the file downloaded. It is a security risk
to omit the checksum as remote files can change. At best omitting this
field will make your build non-hermetic. It is optional to make development
easier but either this attribute or |
netrc | String; optional Location of the .netrc file to use for authentication |
repo_mapping | Dictionary: String -> String; optional In |
sha256 | String; optional The expected SHA-256 of the file downloaded.This must match the SHA-256 of the file downloaded. It is a security risk to omit the SHA-256 as remote files can change. At best omitting this field will make your build non-hermetic. It is optional to make development easier but should be set before shipping. |
url | String; optional A URL to a file that will be made available to Bazel.This must be a file, http or https URL. Redirections are followed. Authentication is not supported.More flexibility can be achieved by the urls parameter that allows to specify alternative URLs to fetch from. |
urls | List of strings; optional A list of URLs to a file that will be made available to Bazel.Each entry must be a file, http or https URL. Redirections are followed. Authentication is not supported.URLs are tried in order until one succeeds, so you should list local mirrors first. If all downloads fail, the rule will fail. |
BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID
http_jar
~/chat-app. It needs to depend on an SSL library which is available from
http://example.com/openssl-0.2.jar.
Targets in the ~/chat-app repository can depend on this target if the following lines are
added to ~/chat-app/WORKSPACE:
@my_ssl//jar as a dependency to depend on this jar.
You may also reference files on the current system (localhost) by using “file:///path/to/file”
if you are on Unix-based systems. If you’re on Windows, use “file:///c:/path/to/file”. In both
examples, note the three slashes (/) — the first two slashes belong to file:// and the third
one belongs to the absolute path to the file.
ATTRIBUTES
name | Name; required A unique name for this repository. |
auth_patterns | Dictionary: String -> String; optional An optional dict mapping host names to custom authorization patterns.If a URL’s host name is present in this dict the value will be used as a pattern when
generating the authorization header for the http request. This enables the use of custom
authorization schemes used in a lot of common cloud storage providers.The pattern currently supports 2 tokens: |
canonical_id | String; optional A canonical ID of the file downloaded.If specified and non-empty, Bazel will not take the file from cache, unless it was added to the cache by a request with the same canonical ID.If unspecified or empty, Bazel by default uses the URLs of the file as the canonical ID. This helps catch the common mistake of updating the URLs without also updating the hash, resulting in builds that succeed locally but fail on machines without the file in the cache. This behavior can be disabled with —repo_env=BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID=0. |
downloaded_file_name | String; optional Filename assigned to the jar downloaded |
integrity | String; optional Expected checksum in Subresource Integrity format of the file downloaded.This must match the checksum of the file downloaded. It is a security risk
to omit the checksum as remote files can change. At best omitting this
field will make your build non-hermetic. It is optional to make development
easier but either this attribute or |
netrc | String; optional Location of the .netrc file to use for authentication |
repo_mapping | Dictionary: String -> String; optional In |
sha256 | String; optional The expected SHA-256 of the file downloaded.This must match the SHA-256 of the file downloaded. It is a security risk
to omit the SHA-256 as remote files can change. At best omitting this
field will make your build non-hermetic. It is optional to make development
easier but either this attribute or |
url | String; optional A URL to a file that will be made available to Bazel.This must be a file, http or https URL. Redirections are followed.
Authentication is not supported.More flexibility can be achieved by the urls parameter that allows
to specify alternative URLs to fetch from.The URL must end in |
urls | List of strings; optional A list of URLs to a file that will be made available to Bazel.Each entry must be a file, http or https URL. Redirections are followed.
Authentication is not supported.URLs are tried in order until one succeeds, so you should list local mirrors first.
If all downloads fail, the rule will fail.All URLs must end in |
BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID