diff --git a/bazel/WASM.md b/bazel/WASM.md index 4f0f0f4179776..fa8c4385265c8 100644 --- a/bazel/WASM.md +++ b/bazel/WASM.md @@ -9,7 +9,7 @@ In order to update Cargo dependencies, please make sure that Rust and Cargo are installed, and run this tool: ``` -bash tools/update_crates.sh +bazel run //bazel/external/cargo:crates_vendor -- --repin ``` which will regenerate Bazel rules in `bazel/external/cargo/`. diff --git a/bazel/external/cargo/BUILD.bazel b/bazel/external/cargo/BUILD.bazel index 3eb88ebf5bfd9..928f6ff347a30 100644 --- a/bazel/external/cargo/BUILD.bazel +++ b/bazel/external/cargo/BUILD.bazel @@ -1,40 +1,21 @@ -""" -@generated -cargo-raze generated Bazel file. +load("@rules_rust//crate_universe:defs.bzl", "crates_vendor") -DO NOT EDIT! Replaced on runs of cargo-raze -""" - -package(default_visibility = ["//visibility:public"]) - -licenses([ - "notice", # See individual crates for specific licenses -]) - -# Aliased targets -alias( - name = "protobuf", - actual = "@raze__protobuf__2_24_1//:protobuf", - tags = [ - "cargo-raze", - "manual", - ], -) - -# Export file for Stardoc support exports_files( - glob([ - "**/*.bazel", - "**/*.bzl", - ]), - visibility = ["//visibility:public"], + [ + "Cargo.toml", + "Cargo.Bazel.lock", + ], ) -filegroup( - name = "srcs", - srcs = glob([ - "**/*.bazel", - "**/*.bzl", - ]), - visibility = ["//visibility:public"], +# Run this target to regenerate cargo_lockfile and vendor_path/*. +# $ bazelisk run bazel/external/cargo:crates_vendor -- --repin +crates_vendor( + name = "crates_vendor", + cargo_lockfile = ":Cargo.Bazel.lock", + generate_target_compatible_with = False, + manifests = [":Cargo.toml"], + mode = "remote", + repository_name = "cu", + tags = ["manual"], + vendor_path = "remote", ) diff --git a/bazel/external/cargo/Cargo.raze.lock b/bazel/external/cargo/Cargo.Bazel.lock similarity index 71% rename from bazel/external/cargo/Cargo.raze.lock rename to bazel/external/cargo/Cargo.Bazel.lock index c4c4b979f7cae..1afb989db4746 100644 --- a/bazel/external/cargo/Cargo.raze.lock +++ b/bazel/external/cargo/Cargo.Bazel.lock @@ -1,10 +1,12 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 4 + [[package]] name = "protobuf" -version = "2.24.1" +version = "2.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db50e77ae196458ccd3dc58a31ea1a90b0698ab1b7928d89f644c25d72070267" +checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" [[package]] name = "proxy-wasm-envoy-tests" diff --git a/bazel/external/cargo/Cargo.toml b/bazel/external/cargo/Cargo.toml index 1063b0a68b6c6..c06049b496353 100644 --- a/bazel/external/cargo/Cargo.toml +++ b/bazel/external/cargo/Cargo.toml @@ -13,11 +13,6 @@ lto = true opt-level = 3 panic = "abort" -[package.metadata.raze] -package_aliases_dir = "." -workspace_path = "//bazel/external/cargo" -genmode = "Remote" - [[example]] name = "grpc_call_rust" path = "../../../test/extensions/filters/http/wasm/test_data/grpc_call_rust.rs" diff --git a/bazel/external/cargo/crates.bzl b/bazel/external/cargo/crates.bzl deleted file mode 100644 index 1f16d74cb8ab6..0000000000000 --- a/bazel/external/cargo/crates.bzl +++ /dev/null @@ -1,22 +0,0 @@ -""" -@generated -cargo-raze generated Bazel file. - -DO NOT EDIT! Replaced on runs of cargo-raze -""" - -load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") # buildifier: disable=load -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") # buildifier: disable=load -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") # buildifier: disable=load - -def raze_fetch_remote_crates(): - """This function defines a collection of repos and should be called in a WORKSPACE file""" - maybe( - http_archive, - name = "raze__protobuf__2_24_1", - url = "https://static.crates.io/crates/protobuf/protobuf-2.24.1.crate", - type = "tar.gz", - sha256 = "db50e77ae196458ccd3dc58a31ea1a90b0698ab1b7928d89f644c25d72070267", - strip_prefix = "protobuf-2.24.1", - build_file = Label("//bazel/external/cargo/remote:BUILD.protobuf-2.24.1.bazel"), - ) diff --git a/bazel/external/cargo/remote/BUILD.bazel b/bazel/external/cargo/remote/BUILD.bazel index b49fb68667fcc..714fb0fbfd938 100644 --- a/bazel/external/cargo/remote/BUILD.bazel +++ b/bazel/external/cargo/remote/BUILD.bazel @@ -1,17 +1,44 @@ -# Export file for Stardoc support +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @//bazel/external/cargo:crates_vendor +############################################################################### + +package(default_visibility = ["//visibility:public"]) + exports_files( - glob([ - "**/*.bazel", - "**/*.bzl", - ]), - visibility = ["//visibility:public"], + [ + "cargo-bazel.json", + "crates.bzl", + "defs.bzl", + ] + glob( + include = ["*.bazel"], + allow_empty = True, + ), ) filegroup( name = "srcs", - srcs = glob([ - "**/*.bazel", - "**/*.bzl", - ]), - visibility = ["//visibility:public"], + srcs = glob( + include = [ + "*.bazel", + "*.bzl", + ], + allow_empty = True, + ), +) + +# Workspace Member Dependencies +alias( + name = "protobuf-2.28.0", + actual = "@cu__protobuf-2.28.0//:protobuf", + tags = ["manual"], +) + +alias( + name = "protobuf", + actual = "@cu__protobuf-2.28.0//:protobuf", + tags = ["manual"], ) diff --git a/bazel/external/cargo/remote/BUILD.protobuf-2.24.1.bazel b/bazel/external/cargo/remote/BUILD.protobuf-2.24.1.bazel deleted file mode 100644 index b818daadb7fdd..0000000000000 --- a/bazel/external/cargo/remote/BUILD.protobuf-2.24.1.bazel +++ /dev/null @@ -1,88 +0,0 @@ -""" -@generated -cargo-raze crate build file. - -DO NOT EDIT! Replaced on runs of cargo-raze -""" - -# buildifier: disable=load -load("@bazel_skylib//lib:selects.bzl", "selects") - -# buildifier: disable=load -load( - "@rules_rust//rust:defs.bzl", - "rust_binary", - "rust_library", - "rust_proc_macro", - "rust_test", -) - -package(default_visibility = [ - # Public for visibility by "@raze__crate__version//" targets. - # - # Prefer access through "//bazel/external/cargo", which limits external - # visibility to explicit Cargo.toml dependencies. - "//visibility:public", -]) - -licenses([ - "notice", # MIT from expression "MIT" -]) - -# Generated Targets -# buildifier: disable=out-of-order-load -# buildifier: disable=load-on-top -load( - "@rules_rust//cargo:defs.bzl", - "cargo_build_script", -) - -cargo_build_script( - name = "protobuf_build_script", - srcs = glob(["**/*.rs"]), - build_script_env = { - }, - crate_features = [ - ], - crate_root = "build.rs", - data = glob(["**"]), - edition = "2018", - rustc_flags = [ - "--cap-lints=allow", - ], - tags = [ - "cargo-raze", - "manual", - ], - version = "2.24.1", - visibility = ["//visibility:private"], - deps = [ - ], -) - -# Unsupported target "coded_input_stream" with type "bench" omitted - -# Unsupported target "coded_output_stream" with type "bench" omitted - -rust_library( - name = "protobuf", - srcs = glob(["**/*.rs"]), - crate_features = [ - ], - crate_root = "src/lib.rs", - data = [], - edition = "2018", - rustc_flags = [ - "--cap-lints=allow", - ], - tags = [ - "cargo-raze", - "crate-name=protobuf", - "manual", - ], - version = "2.24.1", - # buildifier: leave-alone - deps = [ - ":protobuf_build_script", - ], -) diff --git a/bazel/external/cargo/remote/BUILD.protobuf-2.28.0.bazel b/bazel/external/cargo/remote/BUILD.protobuf-2.28.0.bazel new file mode 100644 index 0000000000000..ed7c3de1c8b86 --- /dev/null +++ b/bazel/external/cargo/remote/BUILD.protobuf-2.28.0.bazel @@ -0,0 +1,118 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @//bazel/external/cargo:crates_vendor +############################################################################### + +load( + "@rules_rust//cargo:defs.bzl", + "cargo_build_script", + "cargo_toml_env_vars", +) +load("@rules_rust//rust:defs.bzl", "rust_library") + +package(default_visibility = ["//visibility:public"]) + +cargo_toml_env_vars( + name = "cargo_toml_env_vars", + src = "Cargo.toml", +) + +rust_library( + name = "protobuf", + srcs = glob( + include = ["**/*.rs"], + allow_empty = True, + ), + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_root = "src/lib.rs", + edition = "2018", + rustc_env_files = [ + ":cargo_toml_env_vars", + ], + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-bazel", + "crate-name=protobuf", + "manual", + "noclippy", + "norustfmt", + ], + version = "2.28.0", + deps = [ + "@cu__protobuf-2.28.0//:build_script_build", + ], +) + +cargo_build_script( + name = "_bs", + srcs = glob( + include = ["**/*.rs"], + allow_empty = True, + ), + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + "**/*.rs", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_name = "build_script_build", + crate_root = "build.rs", + data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + edition = "2018", + pkg_name = "protobuf", + rustc_env_files = [ + ":cargo_toml_env_vars", + ], + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-bazel", + "crate-name=protobuf", + "manual", + "noclippy", + "norustfmt", + ], + version = "2.28.0", + visibility = ["//visibility:private"], +) + +alias( + name = "build_script_build", + actual = ":_bs", + tags = ["manual"], +) diff --git a/bazel/external/cargo/remote/alias_rules.bzl b/bazel/external/cargo/remote/alias_rules.bzl new file mode 100644 index 0000000000000..14b04c12728a1 --- /dev/null +++ b/bazel/external/cargo/remote/alias_rules.bzl @@ -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") diff --git a/bazel/external/cargo/remote/crates.bzl b/bazel/external/cargo/remote/crates.bzl new file mode 100644 index 0000000000000..7c03826cbb76a --- /dev/null +++ b/bazel/external/cargo/remote/crates.bzl @@ -0,0 +1,32 @@ +############################################################################### +# @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""" + +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") + +# buildifier: disable=bzl-visibility +load("@envoy//bazel/external/cargo/remote:defs.bzl", _crate_repositories = "crate_repositories") + +# 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 = "cu", + build_file = Label("@envoy//bazel/external/cargo/remote:BUILD.bazel"), + defs_module = Label("@envoy//bazel/external/cargo/remote:defs.bzl"), + ) + + direct_deps = [struct(repo = "cu", is_dev_dep = False)] + direct_deps.extend(_crate_repositories()) + return direct_deps diff --git a/bazel/external/cargo/remote/defs.bzl b/bazel/external/cargo/remote/defs.bzl new file mode 100644 index 0000000000000..e6ceca1ba1d8a --- /dev/null +++ b/bazel/external/cargo/remote/defs.bzl @@ -0,0 +1,424 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @//bazel/external/cargo:crates_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 = { + "bazel/external/cargo": { + _COMMON_CONDITION: { + "protobuf": Label("@cu//:protobuf-2.28.0"), + }, + }, +} + +_NORMAL_ALIASES = { + "bazel/external/cargo": { + _COMMON_CONDITION: { + }, + }, +} + +_NORMAL_DEV_DEPENDENCIES = { + "bazel/external/cargo": { + }, +} + +_NORMAL_DEV_ALIASES = { + "bazel/external/cargo": { + }, +} + +_PROC_MACRO_DEPENDENCIES = { + "bazel/external/cargo": { + }, +} + +_PROC_MACRO_ALIASES = { + "bazel/external/cargo": { + }, +} + +_PROC_MACRO_DEV_DEPENDENCIES = { + "bazel/external/cargo": { + }, +} + +_PROC_MACRO_DEV_ALIASES = { + "bazel/external/cargo": { + }, +} + +_BUILD_DEPENDENCIES = { + "bazel/external/cargo": { + }, +} + +_BUILD_ALIASES = { + "bazel/external/cargo": { + }, +} + +_BUILD_PROC_MACRO_DEPENDENCIES = { + "bazel/external/cargo": { + }, +} + +_BUILD_PROC_MACRO_ALIASES = { + "bazel/external/cargo": { + }, +} + +_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-linux-android": ["@rules_rust//rust/platform:aarch64-linux-android"], + "aarch64-pc-windows-msvc": ["@rules_rust//rust/platform:aarch64-pc-windows-msvc"], + "aarch64-unknown-fuchsia": ["@rules_rust//rust/platform:aarch64-unknown-fuchsia"], + "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"], + "aarch64-unknown-uefi": ["@rules_rust//rust/platform:aarch64-unknown-uefi"], + "arm-unknown-linux-gnueabi": ["@rules_rust//rust/platform:arm-unknown-linux-gnueabi"], + "arm-unknown-linux-musleabi": ["@rules_rust//rust/platform:arm-unknown-linux-musleabi"], + "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-linux-gnu": ["@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu"], + "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-emscripten": ["@rules_rust//rust/platform:wasm32-unknown-emscripten"], + "wasm32-unknown-unknown": ["@rules_rust//rust/platform:wasm32-unknown-unknown"], + "wasm32-wasip1": ["@rules_rust//rust/platform:wasm32-wasip1"], + "wasm32-wasip1-threads": ["@rules_rust//rust/platform:wasm32-wasip1-threads"], + "wasm32-wasip2": ["@rules_rust//rust/platform:wasm32-wasip2"], + "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-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-fuchsia": ["@rules_rust//rust/platform:x86_64-unknown-fuchsia"], + "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"], + "x86_64-unknown-uefi": ["@rules_rust//rust/platform:x86_64-unknown-uefi"], +} + +############################################################################### + +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 = "cu__protobuf-2.28.0", + sha256 = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94", + type = "tar.gz", + urls = ["https://static.crates.io/crates/protobuf/2.28.0/download"], + strip_prefix = "protobuf-2.28.0", + build_file = Label("@envoy//bazel/external/cargo/remote:BUILD.protobuf-2.28.0.bazel"), + ) + + return [ + struct(repo = "cu__protobuf-2.28.0", is_dev_dep = False), + ] diff --git a/bazel/repositories_extra.bzl b/bazel/repositories_extra.bzl index 6e344551734b4..04c383dc7a3ab 100644 --- a/bazel/repositories_extra.bzl +++ b/bazel/repositories_extra.bzl @@ -3,12 +3,12 @@ load("@com_google_protobuf//bazel/private:proto_bazel_features.bzl", "proto_baze load("@emsdk//:deps.bzl", emsdk_deps = "deps") load("@envoy_toolshed//compile:libcxx_libs.bzl", "setup_libcxx_libs") load("@envoy_toolshed//sysroot:sysroot.bzl", "setup_sysroots") -load("@proxy_wasm_cpp_host//bazel/cargo/wasmtime/remote:crates.bzl", "crate_repositories") +load("@proxy_wasm_cpp_host//bazel/cargo/wasmtime/remote:crates.bzl", wasmtime_crate_repositories = "crate_repositories") load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo") load("@rules_java//java:rules_java_deps.bzl", java_compatibility_proxy_repo = "compatibility_proxy_repo") load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains") load("@toolchains_llvm//toolchain:deps.bzl", "bazel_toolchain_dependencies") -load("//bazel/external/cargo:crates.bzl", "raze_fetch_remote_crates") +load("//bazel/external/cargo/remote:crates.bzl", wasm_examples_crate_repositories = "crate_repositories") def _python_minor_version(python_version): return "_".join(python_version.split(".")[:-1]) @@ -30,8 +30,8 @@ def envoy_dependencies_extra( setup_libcxx_libs() setup_sysroots(glibc_version = glibc_version) emsdk_deps() - raze_fetch_remote_crates() - crate_repositories() + wasm_examples_crate_repositories() + wasmtime_crate_repositories() py_repositories() # Registers underscored Python minor version - eg `python3_10` diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 2aaf41505491c..7bda4d9a39143 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -638,7 +638,7 @@ REPOSITORY_LOCATIONS_SPEC = dict( ), # After updating you may need to run: # - # CARGO_BAZEL_REPIN=1 bazel sync --only=crate_index + # bazel run //bazel/external/cargo:crates_vendor -- --repin # rules_rust = dict( version = "0.69.0", diff --git a/test/extensions/filters/http/wasm/test_data/BUILD b/test/extensions/filters/http/wasm/test_data/BUILD index 6c6e3ac2a9783..142e72f118a8f 100644 --- a/test/extensions/filters/http/wasm/test_data/BUILD +++ b/test/extensions/filters/http/wasm/test_data/BUILD @@ -50,7 +50,7 @@ wasm_rust_binary( name = "grpc_call_rust.wasm", srcs = ["grpc_call_rust.rs"], deps = [ - "//bazel/external/cargo:protobuf", + "@cu//:protobuf", "@proxy_wasm_rust_sdk//:proxy_wasm", "@proxy_wasm_rust_sdk//bazel/cargo/remote:log", ], @@ -60,7 +60,7 @@ wasm_rust_binary( name = "grpc_stream_rust.wasm", srcs = ["grpc_stream_rust.rs"], deps = [ - "//bazel/external/cargo:protobuf", + "@cu//:protobuf", "@proxy_wasm_rust_sdk//:proxy_wasm", "@proxy_wasm_rust_sdk//bazel/cargo/remote:log", ], diff --git a/tools/code_format/config.yaml b/tools/code_format/config.yaml index 54b540a1d73d7..69baf02e4faf1 100644 --- a/tools/code_format/config.yaml +++ b/tools/code_format/config.yaml @@ -38,6 +38,7 @@ paths: excluded: - . - bazel/external/c-ares/ + - bazel/external/cargo/remote/ - bazel/external/http_parser/ - bazel/rbe/toolchains/configs/ - bazel- @@ -81,7 +82,7 @@ paths: include: - api/bazel/envoy_http_archive.bzl - api/bazel/repository_locations.bzl - - bazel/external/cargo/crates.bzl + - bazel/external/cargo/remote/defs.bzl - bazel/repository_locations.bzl - docs/bazel/repository_locations.bzl @@ -283,6 +284,7 @@ paths: - source/extensions/filters/http/grpc_field_extraction - source/extensions/filters/http/proto_message_extraction/extraction_util - test/extensions/bootstrap/wasm/test_data + - bazel/external/cargo/remote # Files that are allowed to use try without main thread assertion. raw_try: diff --git a/tools/dependency/validate.py b/tools/dependency/validate.py index b0cfdc770f310..af2f732fc9297 100755 --- a/tools/dependency/validate.py +++ b/tools/dependency/validate.py @@ -38,7 +38,7 @@ # docs/root/intro/arch_overview/security/external_deps.rst. def test_only_ignore(dep): # Rust - if dep.startswith('raze__'): + if dep.startswith('raze__') or dep.startswith('cu__') or dep == 'cu': return True # Java if dep.startswith('remotejdk'): diff --git a/tools/update_crates.sh b/tools/update_crates.sh deleted file mode 100755 index cd4d6fc2d91da..0000000000000 --- a/tools/update_crates.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -set -e - -ROOT="$(dirname "$(dirname "$(realpath "$0")")")" - -# Pin to a specific cargo-raze version, since the output might change between versions. -cargo install cargo-raze --version 0.12.0 - -# Regenerate BUILD files. -cd "${ROOT}"/bazel/external/cargo -cargo raze --generate-lockfile -git add .