Expose crates_vendor deps to bzlmod (#2372)

Without this, I have been unable to update
https://github.com/dtolnay/cxx to bzlmod. When I run `bazel run
//third-party:vendor` ([this
rule](3c1bcc012f/third-party/BUILD (L3-L11)))
it failed with **"unknown repo 'cargo_bazel.buildifier-linux-amd64'
requested from @@rules_rust~0.35.0"**:

```console
ERROR: no such package '@@[unknown repo 'cargo_bazel.buildifier-linux-amd64' requested from @@rules_rust~0.35.0]//file': The repository '@@[unknown repo 'cargo_bazel.buildifier-linux-amd64' requested from @@rules_rust~0.35.0]' could not be resolved: No repository visible as '@cargo_bazel.buildifier-linux-amd64' from repository '@@rules_rust~0.35.0'
ERROR: ~/.cache/bazel/_bazel_david/ebce1d0721fb68dda9c70c0dd1405803/external/rules_rust~0.35.0/crate_universe/private/vendor/BUILD.bazel:3:27: no such package '@@[unknown repo 'cargo_bazel.buildifier-linux-amd64' requested from @@rules_rust~0.35.0]//file': The repository '@@[unknown repo 'cargo_bazel.buildifier-linux-amd64' requested from @@rules_rust~0.35.0]' could not be resolved: No repository visible as '@cargo_bazel.buildifier-linux-amd64' from repository '@@rules_rust~0.35.0' and referenced by '@@rules_rust~0.35.0//crate_universe/private/vendor:buildifier'
ERROR: Analysis of target '//third-party:vendor' failed; build aborted: Analysis failed
```

After this change, it works. My MODULE.bazel can be seen in
https://github.com/dtolnay/cxx/pull/1294.
This commit is contained in:
David Tolnay 2023-12-28 10:53:57 -08:00 committed by GitHub
parent 0d77db7e7c
commit 5001ff6804
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 745 additions and 14838 deletions

View File

@ -630,12 +630,16 @@ tasks:
name: bzlmod BCR presubmit
platform: ubuntu2004
working_directory: examples/bzlmod/hello_world
run_targets:
- "//third-party:vendor"
test_targets:
- "//..."
macos_bzlmod_bcr:
name: bzlmod BCR presubmit
platform: macos
working_directory: examples/bzlmod/hello_world
run_targets:
- "//third-party:vendor"
test_targets:
- "//..."

View File

@ -7,5 +7,7 @@ bcr_test_module:
working_directory: examples/bzlmod/hello_world
name: "Run test module"
platform: ${{ platform }}
run_targets:
- "//third-party:vendor"
test_targets:
- "//..."

1
.gitattributes vendored
View File

@ -3,6 +3,7 @@
bindgen/3rdparty/crates/** linguist-generated
crate_universe/3rdparty/crates/** linguist-generated
crate_universe/test_data/metadata/*/metadata.json linguist-generated
examples/bzlmod/hello_world/third-party/crates/** linguist-generated
examples/crate_universe/vendor_external/crates/** linguist-generated
examples/crate_universe/vendor_local_manifests/crates/** linguist-generated
examples/crate_universe/vendor_local_pkgs/crates/** linguist-generated

View File

@ -36,6 +36,11 @@ internal_deps = use_extension("//rust/private:extensions.bzl", "internal_deps")
use_repo(
internal_deps,
"bazelci_rules",
"cargo_bazel.buildifier-darwin-amd64",
"cargo_bazel.buildifier-darwin-arm64",
"cargo_bazel.buildifier-linux-amd64",
"cargo_bazel.buildifier-linux-arm64",
"cargo_bazel.buildifier-windows-amd64.exe",
"com_google_googleapis",
"cui",
"cui__anyhow-1.0.75",

View File

@ -14,10 +14,18 @@ _BUILDIFIER_SHA256S = {
}
def crates_vendor_deps():
"""Define dependencies of the `crates_vendor` rule
Returns:
list[struct(repo=str, is_dev_dep=bool)]: List of the dependency repositories.
"""
direct_deps = []
for bin, sha256 in _BUILDIFIER_SHA256S.items():
repo = "cargo_bazel.{}".format(bin)
maybe(
http_file,
name = "cargo_bazel.{}".format(bin),
name = repo,
urls = [_BUILDIFIER_URL_TEMPLATE.format(
bin = bin,
version = _BUILDIFIER_VERSION,
@ -26,6 +34,9 @@ def crates_vendor_deps():
downloaded_file_path = "buildifier.exe",
executable = True,
)
direct_deps.append(struct(repo = repo, is_dev_dep = False))
return direct_deps
# buildifier: disable=unnamed-macro
def crates_vendor_deps_targets():

View File

@ -25,7 +25,6 @@ def crate_universe_dependencies(rust_version = rust_common.default_version, boot
cargo_bazel_bootstrap(rust_version = rust_version, **kwargs)
direct_deps = _vendor_crate_repositories()
crates_vendor_deps()
direct_deps.extend(crates_vendor_deps())
cross_installer_deps()
return direct_deps

View File

@ -0,0 +1,2 @@
/bazel-*
/MODULE.bazel.lock

View File

@ -5,6 +5,9 @@ package(default_visibility = ["//visibility:public"])
rust_binary(
name = "hello_world",
srcs = ["src/main.rs"],
deps = [
"//third-party/crates:anyhow",
],
)
rust_doc(

View File

@ -5,6 +5,7 @@ module(
version = "0.0.0",
)
bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "rules_rust", version = "0.0.0")
local_path_override(
module_name = "rules_rust",
@ -19,3 +20,6 @@ use_repo(
)
register_toolchains("@rust_toolchains//:all")
crate_repositories = use_extension("//third-party:extension.bzl", "crate_repositories")
use_repo(crate_repositories, "vendor__anyhow-1.0.77")

File diff suppressed because it is too large Load Diff

View File

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
fn main() {
fn main() -> anyhow::Result<()> {
println!("Hello, world!");
Ok(())
}

View File

@ -0,0 +1,10 @@
load("@rules_rust//crate_universe:defs.bzl", "crates_vendor")
crates_vendor(
name = "vendor",
cargo_lockfile = "//third-party:Cargo.lock",
generate_build_scripts = True,
manifests = ["//third-party:Cargo.toml"],
mode = "remote",
tags = ["manual"],
)

16
examples/bzlmod/hello_world/third-party/Cargo.lock generated vendored Normal file
View File

@ -0,0 +1,16 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "anyhow"
version = "1.0.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9d19de80eff169429ac1e9f48fffb163916b448a44e8e046186232046d9e1f9"
[[package]]
name = "third-party"
version = "0.0.0"
dependencies = [
"anyhow",
]

View File

@ -0,0 +1,12 @@
[workspace]
[package]
name = "third-party"
version = "0.0.0"
edition = "2021"
publish = false
[lib]
path = "/dev/null"
[dependencies]
anyhow = "1.0.77"

View File

@ -0,0 +1,130 @@
###############################################################################
# @generated
# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To
# regenerate this file, run the following:
#
# bazel run @@//third-party:vendor
###############################################################################
load("@rules_rust//cargo:defs.bzl", "cargo_build_script")
load("@rules_rust//rust:defs.bzl", "rust_library")
package(default_visibility = ["//visibility:public"])
# licenses([
# "TODO", # MIT OR Apache-2.0
# ])
rust_library(
name = "anyhow",
srcs = glob(["**/*.rs"]),
compile_data = glob(
include = ["**"],
exclude = [
"**/* *",
".tmp_git_root/**/*",
"BUILD",
"BUILD.bazel",
"WORKSPACE",
"WORKSPACE.bazel",
],
),
crate_features = [
"default",
"std",
],
crate_root = "src/lib.rs",
edition = "2018",
rustc_flags = [
"--cap-lints=allow",
],
tags = [
"cargo-bazel",
"crate-name=anyhow",
"manual",
"noclippy",
"norustfmt",
],
target_compatible_with = select({
"@rules_rust//rust/platform:aarch64-apple-darwin": [],
"@rules_rust//rust/platform:aarch64-apple-ios": [],
"@rules_rust//rust/platform:aarch64-apple-ios-sim": [],
"@rules_rust//rust/platform:aarch64-fuchsia": [],
"@rules_rust//rust/platform:aarch64-linux-android": [],
"@rules_rust//rust/platform:aarch64-pc-windows-msvc": [],
"@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [],
"@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [],
"@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [],
"@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [],
"@rules_rust//rust/platform:armv7-linux-androideabi": [],
"@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [],
"@rules_rust//rust/platform:i686-apple-darwin": [],
"@rules_rust//rust/platform:i686-linux-android": [],
"@rules_rust//rust/platform:i686-pc-windows-msvc": [],
"@rules_rust//rust/platform:i686-unknown-freebsd": [],
"@rules_rust//rust/platform:i686-unknown-linux-gnu": [],
"@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [],
"@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [],
"@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [],
"@rules_rust//rust/platform:s390x-unknown-linux-gnu": [],
"@rules_rust//rust/platform:thumbv7em-none-eabi": [],
"@rules_rust//rust/platform:thumbv8m.main-none-eabi": [],
"@rules_rust//rust/platform:wasm32-unknown-unknown": [],
"@rules_rust//rust/platform:wasm32-wasi": [],
"@rules_rust//rust/platform:x86_64-apple-darwin": [],
"@rules_rust//rust/platform:x86_64-apple-ios": [],
"@rules_rust//rust/platform:x86_64-fuchsia": [],
"@rules_rust//rust/platform:x86_64-linux-android": [],
"@rules_rust//rust/platform:x86_64-pc-windows-msvc": [],
"@rules_rust//rust/platform:x86_64-unknown-freebsd": [],
"@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [],
"@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [],
"@rules_rust//rust/platform:x86_64-unknown-none": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
version = "1.0.77",
deps = [
"@vendor__anyhow-1.0.77//:build_script_build",
],
)
cargo_build_script(
name = "anyhow_build_script",
srcs = glob(["**/*.rs"]),
crate_features = [
"default",
"std",
],
crate_name = "build_script_build",
crate_root = "build.rs",
data = glob(
include = ["**"],
exclude = [
"**/* *",
".tmp_git_root/**/*",
"BUILD",
"BUILD.bazel",
"WORKSPACE",
"WORKSPACE.bazel",
],
),
edition = "2018",
rustc_flags = [
"--cap-lints=allow",
],
tags = [
"cargo-bazel",
"crate-name=anyhow",
"manual",
"noclippy",
"norustfmt",
],
version = "1.0.77",
visibility = ["//visibility:private"],
)
alias(
name = "build_script_build",
actual = "anyhow_build_script",
tags = ["manual"],
)

View File

@ -0,0 +1,32 @@
###############################################################################
# @generated
# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To
# regenerate this file, run the following:
#
# bazel run @@//third-party:vendor
###############################################################################
package(default_visibility = ["//visibility:public"])
exports_files(
[
"cargo-bazel.json",
"crates.bzl",
"defs.bzl",
] + glob(["*.bazel"]),
)
filegroup(
name = "srcs",
srcs = glob([
"*.bazel",
"*.bzl",
]),
)
# Workspace Member Dependencies
alias(
name = "anyhow",
actual = "@vendor__anyhow-1.0.77//:anyhow",
tags = ["manual"],
)

View File

@ -0,0 +1,47 @@
"""Alias that transitions its target to `compilation_mode=opt`. Use `transition_alias="opt"` to enable."""
load("@rules_cc//cc:defs.bzl", "CcInfo")
load("@rules_rust//rust:rust_common.bzl", "COMMON_PROVIDERS")
def _transition_alias_impl(ctx):
# `ctx.attr.actual` is a list of 1 item due to the transition
providers = [ctx.attr.actual[0][provider] for provider in COMMON_PROVIDERS]
if CcInfo in ctx.attr.actual[0]:
providers.append(ctx.attr.actual[0][CcInfo])
return providers
def _change_compilation_mode(compilation_mode):
def _change_compilation_mode_impl(_settings, _attr):
return {
"//command_line_option:compilation_mode": compilation_mode,
}
return transition(
implementation = _change_compilation_mode_impl,
inputs = [],
outputs = [
"//command_line_option:compilation_mode",
],
)
def _transition_alias_rule(compilation_mode):
return rule(
implementation = _transition_alias_impl,
provides = COMMON_PROVIDERS,
attrs = {
"actual": attr.label(
mandatory = True,
doc = "`rust_library()` target to transition to `compilation_mode=opt`.",
providers = COMMON_PROVIDERS,
cfg = _change_compilation_mode(compilation_mode),
),
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
},
doc = "Transitions a Rust library crate to the `compilation_mode=opt`.",
)
transition_alias_dbg = _transition_alias_rule("dbg")
transition_alias_fastbuild = _transition_alias_rule("fastbuild")
transition_alias_opt = _transition_alias_rule("opt")

View File

@ -0,0 +1,31 @@
###############################################################################
# @generated
# This file is auto-generated by the cargo-bazel tool.
#
# DO NOT MODIFY: Local changes may be replaced in future executions.
###############################################################################
"""Rules for defining repositories for remote `crates_vendor` repositories"""
# buildifier: disable=bzl-visibility
load("@//third-party/crates:defs.bzl", _crate_repositories = "crate_repositories")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
# buildifier: disable=bzl-visibility
load("@rules_rust//crate_universe/private:crates_vendor.bzl", "crates_vendor_remote_repository")
def crate_repositories():
"""Generates repositories for vendored crates.
Returns:
A list of repos visible to the module through the module extension.
"""
maybe(
crates_vendor_remote_repository,
name = "vendor",
build_file = Label("@//third-party/crates:BUILD.bazel"),
defs_module = Label("@//third-party/crates:defs.bzl"),
)
direct_deps = [struct(repo = "vendor", is_dev_dep = False)]
direct_deps.extend(_crate_repositories())
return direct_deps

417
examples/bzlmod/hello_world/third-party/crates/defs.bzl generated vendored Normal file
View File

@ -0,0 +1,417 @@
###############################################################################
# @generated
# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To
# regenerate this file, run the following:
#
# bazel run @@//third-party:vendor
###############################################################################
"""
# `crates_repository` API
- [aliases](#aliases)
- [crate_deps](#crate_deps)
- [all_crate_deps](#all_crate_deps)
- [crate_repositories](#crate_repositories)
"""
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
###############################################################################
# MACROS API
###############################################################################
# An identifier that represent common dependencies (unconditional).
_COMMON_CONDITION = ""
def _flatten_dependency_maps(all_dependency_maps):
"""Flatten a list of dependency maps into one dictionary.
Dependency maps have the following structure:
```python
DEPENDENCIES_MAP = {
# The first key in the map is a Bazel package
# name of the workspace this file is defined in.
"workspace_member_package": {
# Not all dependencies are supported for all platforms.
# the condition key is the condition required to be true
# on the host platform.
"condition": {
# An alias to a crate target. # The label of the crate target the
# Aliases are only crate names. # package name refers to.
"package_name": "@full//:label",
}
}
}
```
Args:
all_dependency_maps (list): A list of dicts as described above
Returns:
dict: A dictionary as described above
"""
dependencies = {}
for workspace_deps_map in all_dependency_maps:
for pkg_name, conditional_deps_map in workspace_deps_map.items():
if pkg_name not in dependencies:
non_frozen_map = dict()
for key, values in conditional_deps_map.items():
non_frozen_map.update({key: dict(values.items())})
dependencies.setdefault(pkg_name, non_frozen_map)
continue
for condition, deps_map in conditional_deps_map.items():
# If the condition has not been recorded, do so and continue
if condition not in dependencies[pkg_name]:
dependencies[pkg_name].setdefault(condition, dict(deps_map.items()))
continue
# Alert on any miss-matched dependencies
inconsistent_entries = []
for crate_name, crate_label in deps_map.items():
existing = dependencies[pkg_name][condition].get(crate_name)
if existing and existing != crate_label:
inconsistent_entries.append((crate_name, existing, crate_label))
dependencies[pkg_name][condition].update({crate_name: crate_label})
return dependencies
def crate_deps(deps, package_name = None):
"""Finds the fully qualified label of the requested crates for the package where this macro is called.
Args:
deps (list): The desired list of crate targets.
package_name (str, optional): The package name of the set of dependencies to look up.
Defaults to `native.package_name()`.
Returns:
list: A list of labels to generated rust targets (str)
"""
if not deps:
return []
if package_name == None:
package_name = native.package_name()
# Join both sets of dependencies
dependencies = _flatten_dependency_maps([
_NORMAL_DEPENDENCIES,
_NORMAL_DEV_DEPENDENCIES,
_PROC_MACRO_DEPENDENCIES,
_PROC_MACRO_DEV_DEPENDENCIES,
_BUILD_DEPENDENCIES,
_BUILD_PROC_MACRO_DEPENDENCIES,
]).pop(package_name, {})
# Combine all conditional packages so we can easily index over a flat list
# TODO: Perhaps this should actually return select statements and maintain
# the conditionals of the dependencies
flat_deps = {}
for deps_set in dependencies.values():
for crate_name, crate_label in deps_set.items():
flat_deps.update({crate_name: crate_label})
missing_crates = []
crate_targets = []
for crate_target in deps:
if crate_target not in flat_deps:
missing_crates.append(crate_target)
else:
crate_targets.append(flat_deps[crate_target])
if missing_crates:
fail("Could not find crates `{}` among dependencies of `{}`. Available dependencies were `{}`".format(
missing_crates,
package_name,
dependencies,
))
return crate_targets
def all_crate_deps(
normal = False,
normal_dev = False,
proc_macro = False,
proc_macro_dev = False,
build = False,
build_proc_macro = False,
package_name = None):
"""Finds the fully qualified label of all requested direct crate dependencies \
for the package where this macro is called.
If no parameters are set, all normal dependencies are returned. Setting any one flag will
otherwise impact the contents of the returned list.
Args:
normal (bool, optional): If True, normal dependencies are included in the
output list.
normal_dev (bool, optional): If True, normal dev dependencies will be
included in the output list..
proc_macro (bool, optional): If True, proc_macro dependencies are included
in the output list.
proc_macro_dev (bool, optional): If True, dev proc_macro dependencies are
included in the output list.
build (bool, optional): If True, build dependencies are included
in the output list.
build_proc_macro (bool, optional): If True, build proc_macro dependencies are
included in the output list.
package_name (str, optional): The package name of the set of dependencies to look up.
Defaults to `native.package_name()` when unset.
Returns:
list: A list of labels to generated rust targets (str)
"""
if package_name == None:
package_name = native.package_name()
# Determine the relevant maps to use
all_dependency_maps = []
if normal:
all_dependency_maps.append(_NORMAL_DEPENDENCIES)
if normal_dev:
all_dependency_maps.append(_NORMAL_DEV_DEPENDENCIES)
if proc_macro:
all_dependency_maps.append(_PROC_MACRO_DEPENDENCIES)
if proc_macro_dev:
all_dependency_maps.append(_PROC_MACRO_DEV_DEPENDENCIES)
if build:
all_dependency_maps.append(_BUILD_DEPENDENCIES)
if build_proc_macro:
all_dependency_maps.append(_BUILD_PROC_MACRO_DEPENDENCIES)
# Default to always using normal dependencies
if not all_dependency_maps:
all_dependency_maps.append(_NORMAL_DEPENDENCIES)
dependencies = _flatten_dependency_maps(all_dependency_maps).pop(package_name, None)
if not dependencies:
if dependencies == None:
fail("Tried to get all_crate_deps for package " + package_name + " but that package had no Cargo.toml file")
else:
return []
crate_deps = list(dependencies.pop(_COMMON_CONDITION, {}).values())
for condition, deps in dependencies.items():
crate_deps += selects.with_or({
tuple(_CONDITIONS[condition]): deps.values(),
"//conditions:default": [],
})
return crate_deps
def aliases(
normal = False,
normal_dev = False,
proc_macro = False,
proc_macro_dev = False,
build = False,
build_proc_macro = False,
package_name = None):
"""Produces a map of Crate alias names to their original label
If no dependency kinds are specified, `normal` and `proc_macro` are used by default.
Setting any one flag will otherwise determine the contents of the returned dict.
Args:
normal (bool, optional): If True, normal dependencies are included in the
output list.
normal_dev (bool, optional): If True, normal dev dependencies will be
included in the output list..
proc_macro (bool, optional): If True, proc_macro dependencies are included
in the output list.
proc_macro_dev (bool, optional): If True, dev proc_macro dependencies are
included in the output list.
build (bool, optional): If True, build dependencies are included
in the output list.
build_proc_macro (bool, optional): If True, build proc_macro dependencies are
included in the output list.
package_name (str, optional): The package name of the set of dependencies to look up.
Defaults to `native.package_name()` when unset.
Returns:
dict: The aliases of all associated packages
"""
if package_name == None:
package_name = native.package_name()
# Determine the relevant maps to use
all_aliases_maps = []
if normal:
all_aliases_maps.append(_NORMAL_ALIASES)
if normal_dev:
all_aliases_maps.append(_NORMAL_DEV_ALIASES)
if proc_macro:
all_aliases_maps.append(_PROC_MACRO_ALIASES)
if proc_macro_dev:
all_aliases_maps.append(_PROC_MACRO_DEV_ALIASES)
if build:
all_aliases_maps.append(_BUILD_ALIASES)
if build_proc_macro:
all_aliases_maps.append(_BUILD_PROC_MACRO_ALIASES)
# Default to always using normal aliases
if not all_aliases_maps:
all_aliases_maps.append(_NORMAL_ALIASES)
all_aliases_maps.append(_PROC_MACRO_ALIASES)
aliases = _flatten_dependency_maps(all_aliases_maps).pop(package_name, None)
if not aliases:
return dict()
common_items = aliases.pop(_COMMON_CONDITION, {}).items()
# If there are only common items in the dictionary, immediately return them
if not len(aliases.keys()) == 1:
return dict(common_items)
# Build a single select statement where each conditional has accounted for the
# common set of aliases.
crate_aliases = {"//conditions:default": dict(common_items)}
for condition, deps in aliases.items():
condition_triples = _CONDITIONS[condition]
for triple in condition_triples:
if triple in crate_aliases:
crate_aliases[triple].update(deps)
else:
crate_aliases.update({triple: dict(deps.items() + common_items)})
return select(crate_aliases)
###############################################################################
# WORKSPACE MEMBER DEPS AND ALIASES
###############################################################################
_NORMAL_DEPENDENCIES = {
"third-party": {
_COMMON_CONDITION: {
"anyhow": "@vendor__anyhow-1.0.77//:anyhow",
},
},
}
_NORMAL_ALIASES = {
"third-party": {
_COMMON_CONDITION: {
},
},
}
_NORMAL_DEV_DEPENDENCIES = {
"third-party": {
},
}
_NORMAL_DEV_ALIASES = {
"third-party": {
},
}
_PROC_MACRO_DEPENDENCIES = {
"third-party": {
},
}
_PROC_MACRO_ALIASES = {
"third-party": {
},
}
_PROC_MACRO_DEV_DEPENDENCIES = {
"third-party": {
},
}
_PROC_MACRO_DEV_ALIASES = {
"third-party": {
},
}
_BUILD_DEPENDENCIES = {
"third-party": {
},
}
_BUILD_ALIASES = {
"third-party": {
},
}
_BUILD_PROC_MACRO_DEPENDENCIES = {
"third-party": {
},
}
_BUILD_PROC_MACRO_ALIASES = {
"third-party": {
},
}
_CONDITIONS = {
"aarch64-apple-darwin": ["@rules_rust//rust/platform:aarch64-apple-darwin"],
"aarch64-apple-ios": ["@rules_rust//rust/platform:aarch64-apple-ios"],
"aarch64-apple-ios-sim": ["@rules_rust//rust/platform:aarch64-apple-ios-sim"],
"aarch64-fuchsia": ["@rules_rust//rust/platform:aarch64-fuchsia"],
"aarch64-linux-android": ["@rules_rust//rust/platform:aarch64-linux-android"],
"aarch64-pc-windows-msvc": ["@rules_rust//rust/platform:aarch64-pc-windows-msvc"],
"aarch64-unknown-linux-gnu": ["@rules_rust//rust/platform:aarch64-unknown-linux-gnu"],
"aarch64-unknown-nixos-gnu": ["@rules_rust//rust/platform:aarch64-unknown-nixos-gnu"],
"aarch64-unknown-nto-qnx710": ["@rules_rust//rust/platform:aarch64-unknown-nto-qnx710"],
"arm-unknown-linux-gnueabi": ["@rules_rust//rust/platform:arm-unknown-linux-gnueabi"],
"armv7-linux-androideabi": ["@rules_rust//rust/platform:armv7-linux-androideabi"],
"armv7-unknown-linux-gnueabi": ["@rules_rust//rust/platform:armv7-unknown-linux-gnueabi"],
"i686-apple-darwin": ["@rules_rust//rust/platform:i686-apple-darwin"],
"i686-linux-android": ["@rules_rust//rust/platform:i686-linux-android"],
"i686-pc-windows-msvc": ["@rules_rust//rust/platform:i686-pc-windows-msvc"],
"i686-unknown-freebsd": ["@rules_rust//rust/platform:i686-unknown-freebsd"],
"i686-unknown-linux-gnu": ["@rules_rust//rust/platform:i686-unknown-linux-gnu"],
"powerpc-unknown-linux-gnu": ["@rules_rust//rust/platform:powerpc-unknown-linux-gnu"],
"riscv32imc-unknown-none-elf": ["@rules_rust//rust/platform:riscv32imc-unknown-none-elf"],
"riscv64gc-unknown-none-elf": ["@rules_rust//rust/platform:riscv64gc-unknown-none-elf"],
"s390x-unknown-linux-gnu": ["@rules_rust//rust/platform:s390x-unknown-linux-gnu"],
"thumbv7em-none-eabi": ["@rules_rust//rust/platform:thumbv7em-none-eabi"],
"thumbv8m.main-none-eabi": ["@rules_rust//rust/platform:thumbv8m.main-none-eabi"],
"wasm32-unknown-unknown": ["@rules_rust//rust/platform:wasm32-unknown-unknown"],
"wasm32-wasi": ["@rules_rust//rust/platform:wasm32-wasi"],
"x86_64-apple-darwin": ["@rules_rust//rust/platform:x86_64-apple-darwin"],
"x86_64-apple-ios": ["@rules_rust//rust/platform:x86_64-apple-ios"],
"x86_64-fuchsia": ["@rules_rust//rust/platform:x86_64-fuchsia"],
"x86_64-linux-android": ["@rules_rust//rust/platform:x86_64-linux-android"],
"x86_64-pc-windows-msvc": ["@rules_rust//rust/platform:x86_64-pc-windows-msvc"],
"x86_64-unknown-freebsd": ["@rules_rust//rust/platform:x86_64-unknown-freebsd"],
"x86_64-unknown-linux-gnu": ["@rules_rust//rust/platform:x86_64-unknown-linux-gnu"],
"x86_64-unknown-nixos-gnu": ["@rules_rust//rust/platform:x86_64-unknown-nixos-gnu"],
"x86_64-unknown-none": ["@rules_rust//rust/platform:x86_64-unknown-none"],
}
###############################################################################
def crate_repositories():
"""A macro for defining repositories for all generated crates.
Returns:
A list of repos visible to the module through the module extension.
"""
maybe(
http_archive,
name = "vendor__anyhow-1.0.77",
sha256 = "c9d19de80eff169429ac1e9f48fffb163916b448a44e8e046186232046d9e1f9",
type = "tar.gz",
urls = ["https://crates.io/api/v1/crates/anyhow/1.0.77/download"],
strip_prefix = "anyhow-1.0.77",
build_file = Label("@//third-party/crates:BUILD.anyhow-1.0.77.bazel"),
)
return [
struct(repo = "vendor__anyhow-1.0.77", is_dev_dep = False),
]

View File

@ -0,0 +1,14 @@
"""Module extensions for using vendored crates with bzlmod"""
load("//third-party/crates:defs.bzl", _crate_repositories = "crate_repositories")
def _crate_repositories_impl(module_ctx):
direct_deps = _crate_repositories()
return module_ctx.extension_metadata(
root_module_direct_deps = [repo.repo for repo in direct_deps],
root_module_direct_dev_deps = [],
)
crate_repositories = module_extension(
implementation = _crate_repositories_impl,
)