Skip to content

Latest commit

 

History

History
executable file
·
114 lines (80 loc) · 14.6 KB

repository_rules_overview.md

File metadata and controls

executable file
·
114 lines (80 loc) · 14.6 KB

Repository Rules

The rules described below are used to build Swift packages and make their products and targets available as Bazel targets.

On this page:

local_swift_package

load("@rules_swift_package_manager//swiftpkg:defs.bzl", "local_swift_package")

local_swift_package(name, bazel_package_name, dependencies_index, env, path, repo_mapping)

Used to build a local Swift package.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this repository. Name required
bazel_package_name The short name for the Swift package's Bazel repository. String optional ""
dependencies_index A JSON file that contains a mapping of Swift products and Swift modules. Label optional None
env Environment variables that will be passed to the execution environments for this repository rule. (e.g. SPM version check, SPM dependency resolution, SPM package description generation) Dictionary: String -> String optional {}
path The path to the local Swift package directory. This can be an absolute path or a relative path to the workspace root. String required
repo_mapping In WORKSPACE context only: 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).

This attribute is not supported in MODULE.bazel context (when invoking a repository rule inside a module extension's implementation function).
Dictionary: String -> String optional

registry_swift_package

load("@rules_swift_package_manager//swiftpkg:defs.bzl", "registry_swift_package")

registry_swift_package(name, bazel_package_name, dependencies_index, env, id, registries,
                       replace_scm_with_registry, repo_mapping, resolved, version)

Used to download and build an external Swift package from a registry.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this repository. Name required
bazel_package_name The short name for the Swift package's Bazel repository. String optional ""
dependencies_index A JSON file that contains a mapping of Swift products and Swift modules. Label optional None
env Environment variables that will be passed to the execution environments for this repository rule. (e.g. SPM version check, SPM dependency resolution, SPM package description generation) Dictionary: String -> String optional {}
id The package identifier. String required
registries A registries.json file that defines the configured Swift package registries.

The registries.json file is used when resolving Swift packages from a Swift package registry. It is created by Swift Package Manager when using the swift package-registry commands.

When using the swift_package_tool rules, this file is symlinked to the config_path directory defined in the configure_swift_package tag. If not using the swift_package_tool rules, the file must be in one of Swift Package Manager's search paths or in the manually specified --config-path directory.
Label optional None
replace_scm_with_registry When enabled replaces SCM identities in dependencies package description with identities from the registries.

Using this option requires that the registries provide repositoryURLs as metadata for the package.

When True the equivalent --replace-scm-with-registry option must be used with the Swift Package Manager CLI (or swift_package rule) so that the resolved file includes the version and identity information from the registry.

For more information see the Swift Package Manager documentation.
Boolean optional False
repo_mapping In WORKSPACE context only: 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).

This attribute is not supported in MODULE.bazel context (when invoking a repository rule inside a module extension's implementation function).
Dictionary: String -> String optional
resolved A Package.resolved, used to de-duplicate dependency identities when use_registry_identity_for_scm or replace_scm_with_registry is enabled. Label optional None
version The package version. String required

swift_package

load("@rules_swift_package_manager//swiftpkg:defs.bzl", "swift_package")

swift_package(name, bazel_package_name, branch, commit, dependencies_index, env, init_submodules,
              patch_args, patch_cmds, patch_cmds_win, patch_tool, patches,
              publicly_expose_all_targets, recursive_init_submodules, registries, remote,
              replace_scm_with_registry, repo_mapping, shallow_since, tag, verbose, version)

Used to download and build an external Swift package.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this repository. Name required
bazel_package_name The short name for the Swift package's Bazel repository. String optional ""
branch branch in the remote repository to checked out. Precisely one of branch, tag, or commit must be specified. String optional ""
commit The commit or revision to download from version control. String required
dependencies_index A JSON file that contains a mapping of Swift products and Swift modules. Label optional None
env Environment variables that will be passed to the execution environments for this repository rule. (e.g. SPM version check, SPM dependency resolution, SPM package description generation) Dictionary: String -> String optional {}
init_submodules Whether to clone submodules in the repository. Boolean optional False
patch_args The arguments given to the patch tool. Defaults to -p0, however -p1 will usually be needed for patches generated by git. If multiple -p arguments are specified, the last one will take effect.If arguments other than -p are specified, Bazel will fall back to use patch command line tool instead of the Bazel-native patch implementation. When falling back to patch command line tool and patch_tool attribute is not specified, patch will be used. List of strings optional ["-p0"]
patch_cmds Sequence of Bash commands to be applied on Linux/Macos after patches are applied. List of strings optional []
patch_cmds_win 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. List of strings optional []
patch_tool The patch(1) utility to use. If this is specified, Bazel will use the specified patch tool instead of the Bazel-native patch implementation. String optional ""
patches 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 patch_tool attribute is specified or there are arguments other than -p in patch_args attribute. List of labels optional []
publicly_expose_all_targets Allows to expose internal build targets required for package compilation. The structure and labels of exposed targets may change in future releases without requiring a major version bump. Boolean optional False
recursive_init_submodules Whether to clone submodules recursively in the repository. Boolean optional True
registries The registries JSON file for the package if using Swift Package Registries. Label optional None
remote The version control location from where the repository should be downloaded. String required
replace_scm_with_registry Whether to replace SCM references with registry references. Only used if registries is provided. Boolean optional False
repo_mapping In WORKSPACE context only: 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).

This attribute is not supported in MODULE.bazel context (when invoking a repository rule inside a module extension's implementation function).
Dictionary: String -> String optional
shallow_since an optional date, not after the specified commit; the argument is not allowed if a tag is specified (which allows cloning with depth 1). Setting such a date close to the specified commit allows for a more shallow clone of the repository, saving bandwidth and wall-clock time. String optional ""
tag tag in the remote repository to checked out. Precisely one of branch, tag, or commit must be specified. String optional ""
verbose - Boolean optional False
version The resolved version of the package. String optional ""