Skip to content

Commit

Permalink
Marked various extensions as reproducible to reduce bzlmod lock size (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre authored Jan 8, 2025
1 parent b6c9468 commit f329c0c
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 30 deletions.
10 changes: 9 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ use_repo(
"cargo_bazel.buildifier-linux-arm64",
"cargo_bazel.buildifier-linux-s390x",
"cargo_bazel.buildifier-windows-amd64.exe",
"cargo_bazel_bootstrap",
"cui",
"cui__anyhow-1.0.89",
"cui__camino-1.1.9",
Expand Down Expand Up @@ -162,6 +161,15 @@ use_repo(
"cui__walkdir-2.5.0",
)

crate_universe_internal_non_repro_deps = use_extension(
"//crate_universe/private:internal_extensions.bzl",
"cu_nr",
)
use_repo(
crate_universe_internal_non_repro_deps,
"cargo_bazel_bootstrap",
)

crate_universe_internal_dev_deps = use_extension(
"//crate_universe/private:internal_extensions.bzl",
"cu_dev",
Expand Down
32 changes: 29 additions & 3 deletions crate_universe/private/internal_extensions.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Bzlmod module extensions that are only used internally"""

load("@bazel_features//:features.bzl", "bazel_features")
load("//crate_universe:deps_bootstrap.bzl", "cargo_bazel_bootstrap")
load("//crate_universe:repositories.bzl", "crate_universe_dependencies")
load("//crate_universe/tools/cross_installer:cross_installer_deps.bzl", "cross_installer_deps")
Expand All @@ -8,6 +9,31 @@ def _internal_deps_impl(module_ctx):
direct_deps = []

direct_deps.extend(crate_universe_dependencies())

# is_dev_dep is ignored here. It's not relevant for internal_deps, as dev
# dependencies are only relevant for module extensions that can be used
# by other MODULES.
metadata_kwargs = {
"root_module_direct_deps": [repo.repo for repo in direct_deps],
"root_module_direct_dev_deps": [],
}

if bazel_features.external_deps.extension_metadata_has_reproducible:
metadata_kwargs["reproducible"] = True

return module_ctx.extension_metadata(**metadata_kwargs)

# This is named a single character to reduce the size of path names when running build scripts, to reduce the chance
# of hitting the 260 character windows path name limit.
# TODO: https://github.com/bazelbuild/rules_rust/issues/1120
cu = module_extension(
doc = "Dependencies for crate_universe.",
implementation = _internal_deps_impl,
)

def _internal_non_reproducible_deps_impl(module_ctx):
direct_deps = []

direct_deps.extend(cargo_bazel_bootstrap(
rust_toolchain_cargo_template = "@rust_host_tools//:bin/{tool}",
rust_toolchain_rustc_template = "@rust_host_tools//:bin/{tool}",
Expand All @@ -25,9 +51,9 @@ def _internal_deps_impl(module_ctx):
# This is named a single character to reduce the size of path names when running build scripts, to reduce the chance
# of hitting the 260 character windows path name limit.
# TODO: https://github.com/bazelbuild/rules_rust/issues/1120
cu = module_extension(
doc = "Dependencies for crate_universe.",
implementation = _internal_deps_impl,
cu_nr = module_extension(
doc = "Dependencies for crate_universe (non reproducible).",
implementation = _internal_non_reproducible_deps_impl,
)

def _internal_dev_deps_impl(module_ctx):
Expand Down
5 changes: 5 additions & 0 deletions extensions/bindgen/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ bazel_dep(
name = "rules_rust",
version = "0.56.0",
)
bazel_dep(
name = "bazel_features",
version = "1.21.0",
)
bazel_dep(
name = "bazel_skylib",
version = "1.7.1",
Expand All @@ -30,6 +34,7 @@ rust_ext = use_extension("//:extensions.bzl", "rust_ext")
use_repo(
rust_ext,
"rules_rust_bindgen__bindgen-cli-0.70.1",
"rules_rust_bindgen_deps",
"rules_rust_bindgen_deps__bindgen-0.70.1",
"rules_rust_bindgen_deps__clang-sys-1.8.1",
"rules_rust_bindgen_deps__clap-4.5.17",
Expand Down
14 changes: 10 additions & 4 deletions extensions/bindgen/extensions.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Bzlmod module extensions"""

load("@bazel_features//:features.bzl", "bazel_features")
load("//:repositories.bzl", "rust_bindgen_dependencies")

def _rust_ext_impl(module_ctx):
Expand All @@ -12,10 +13,15 @@ def _rust_ext_impl(module_ctx):
# is_dev_dep is ignored here. It's not relevant for internal_deps, as dev
# dependencies are only relevant for module extensions that can be used
# by other MODULES.
return module_ctx.extension_metadata(
root_module_direct_deps = [repo.repo for repo in direct_deps],
root_module_direct_dev_deps = [],
)
metadata_kwargs = {
"root_module_direct_deps": [repo.repo for repo in direct_deps],
"root_module_direct_dev_deps": [],
}

if bazel_features.external_deps.extension_metadata_has_reproducible:
metadata_kwargs["reproducible"] = True

return module_ctx.extension_metadata(**metadata_kwargs)

rust_ext = module_extension(
doc = "Dependencies for the rules_rust_bindgen extension.",
Expand Down
2 changes: 1 addition & 1 deletion extensions/bindgen/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//3rdparty/crates:defs.bzl", "crate_repositories")
load("//3rdparty/crates:crates.bzl", "crate_repositories")

BINDGEN_VERSION = "0.70.1"

Expand Down
4 changes: 4 additions & 0 deletions extensions/mdbook/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ bazel_dep(
name = "rules_cc",
version = "0.0.17",
)
bazel_dep(
name = "bazel_features",
version = "1.21.0",
)
bazel_dep(
name = "bazel_skylib",
version = "1.7.1",
Expand Down
14 changes: 10 additions & 4 deletions extensions/mdbook/extensions.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Bzlmod module extensions"""

load("@bazel_features//:features.bzl", "bazel_features")
load("//:repositories.bzl", "mdbook_register_toolchains")
load("//private/3rdparty/crates:crates.bzl", "crate_repositories")

Expand All @@ -14,10 +15,15 @@ def _rust_ext_impl(module_ctx):
# is_dev_dep is ignored here. It's not relevant for internal_deps, as dev
# dependencies are only relevant for module extensions that can be used
# by other MODULES.
return module_ctx.extension_metadata(
root_module_direct_deps = [repo.repo for repo in direct_deps],
root_module_direct_dev_deps = [],
)
metadata_kwargs = {
"root_module_direct_deps": [repo.repo for repo in direct_deps],
"root_module_direct_dev_deps": [],
}

if bazel_features.external_deps.extension_metadata_has_reproducible:
metadata_kwargs["reproducible"] = True

return module_ctx.extension_metadata(**metadata_kwargs)

rust_ext = module_extension(
doc = "Dependencies for the rules_rust mdbook extension.",
Expand Down
4 changes: 4 additions & 0 deletions extensions/prost/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ bazel_dep(
name = "platforms",
version = "0.0.10",
)
bazel_dep(
name = "bazel_features",
version = "1.21.0",
)
bazel_dep(
name = "bazel_skylib",
version = "1.7.1",
Expand Down
14 changes: 10 additions & 4 deletions extensions/prost/extensions.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Bzlmod module extensions"""

load("@bazel_features//:features.bzl", "bazel_features")
load("//:repositories.bzl", "rust_prost_dependencies")

def _rust_ext_impl(module_ctx):
Expand All @@ -12,10 +13,15 @@ def _rust_ext_impl(module_ctx):
# is_dev_dep is ignored here. It's not relevant for internal_deps, as dev
# dependencies are only relevant for module extensions that can be used
# by other MODULES.
return module_ctx.extension_metadata(
root_module_direct_deps = [repo.repo for repo in direct_deps],
root_module_direct_dev_deps = [],
)
metadata_kwargs = {
"root_module_direct_deps": [repo.repo for repo in direct_deps],
"root_module_direct_dev_deps": [],
}

if bazel_features.external_deps.extension_metadata_has_reproducible:
metadata_kwargs["reproducible"] = True

return module_ctx.extension_metadata(**metadata_kwargs)

rust_ext = module_extension(
doc = "Dependencies for the rules_rust prost extension.",
Expand Down
5 changes: 5 additions & 0 deletions extensions/protobuf/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ bazel_dep(
name = "rules_rust",
version = "0.56.0",
)
bazel_dep(
name = "bazel_features",
version = "1.21.0",
)
bazel_dep(
name = "bazel_skylib",
version = "1.7.1",
Expand Down Expand Up @@ -40,6 +44,7 @@ bazel_dep(
rust_ext = use_extension("//:extensions.bzl", "rust_ext")
use_repo(
rust_ext,
"rules_rust_protobuf_deps",
"rules_rust_protobuf_deps__grpc-0.6.2",
"rules_rust_protobuf_deps__grpc-compiler-0.6.2",
"rules_rust_protobuf_deps__log-0.4.17",
Expand Down
14 changes: 10 additions & 4 deletions extensions/protobuf/extensions.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Bzlmod module extensions"""

load("@bazel_features//:features.bzl", "bazel_features")
load("//:repositories.bzl", "rust_proto_protobuf_dependencies")

def _rust_ext_impl(module_ctx):
Expand All @@ -12,10 +13,15 @@ def _rust_ext_impl(module_ctx):
# is_dev_dep is ignored here. It's not relevant for internal_deps, as dev
# dependencies are only relevant for module extensions that can be used
# by other MODULES.
return module_ctx.extension_metadata(
root_module_direct_deps = [repo.repo for repo in direct_deps],
root_module_direct_dev_deps = [],
)
metadata_kwargs = {
"root_module_direct_deps": [repo.repo for repo in direct_deps],
"root_module_direct_dev_deps": [],
}

if bazel_features.external_deps.extension_metadata_has_reproducible:
metadata_kwargs["reproducible"] = True

return module_ctx.extension_metadata(**metadata_kwargs)

rust_ext = module_extension(
doc = "Dependencies for the rules_rust protobuf extension.",
Expand Down
2 changes: 1 addition & 1 deletion extensions/protobuf/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//3rdparty/crates:defs.bzl", "crate_repositories")
load("//3rdparty/crates:crates.bzl", "crate_repositories")

def rust_proto_protobuf_dependencies(bzlmod = False):
"""Sets up dependencies for rules_rust's proto support.
Expand Down
4 changes: 4 additions & 0 deletions extensions/wasm_bindgen/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ bazel_dep(
name = "rules_rust",
version = "0.56.0",
)
bazel_dep(
name = "bazel_features",
version = "1.21.0",
)
bazel_dep(
name = "bazel_skylib",
version = "1.7.1",
Expand Down
14 changes: 10 additions & 4 deletions extensions/wasm_bindgen/extensions.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Bzlmod module extensions"""

load("@bazel_features//:features.bzl", "bazel_features")
load("//:repositories.bzl", "rust_wasm_bindgen_dependencies")

def _rust_ext_impl(module_ctx):
Expand All @@ -12,10 +13,15 @@ def _rust_ext_impl(module_ctx):
# is_dev_dep is ignored here. It's not relevant for internal_deps, as dev
# dependencies are only relevant for module extensions that can be used
# by other MODULES.
return module_ctx.extension_metadata(
root_module_direct_deps = [repo.repo for repo in direct_deps],
root_module_direct_dev_deps = [],
)
metadata_kwargs = {
"root_module_direct_deps": [repo.repo for repo in direct_deps],
"root_module_direct_dev_deps": [],
}

if bazel_features.external_deps.extension_metadata_has_reproducible:
metadata_kwargs["reproducible"] = True

return module_ctx.extension_metadata(**metadata_kwargs)

rust_ext = module_extension(
doc = "Dependencies for the rules_rust wasm_bindgen extension.",
Expand Down
14 changes: 10 additions & 4 deletions rust/private/internal_extensions.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Bzlmod module extensions that are only used internally"""

load("@bazel_features//:features.bzl", "bazel_features")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//rust/private:repository_utils.bzl", "TINYJSON_KWARGS")
load("//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies")
Expand All @@ -18,10 +19,15 @@ def _internal_deps_impl(module_ctx):
# is_dev_dep is ignored here. It's not relevant for internal_deps, as dev
# dependencies are only relevant for module extensions that can be used
# by other MODULES.
return module_ctx.extension_metadata(
root_module_direct_deps = [repo.repo for repo in direct_deps],
root_module_direct_dev_deps = [],
)
metadata_kwargs = {
"root_module_direct_deps": [repo.repo for repo in direct_deps],
"root_module_direct_dev_deps": [],
}

if bazel_features.external_deps.extension_metadata_has_reproducible:
metadata_kwargs["reproducible"] = True

return module_ctx.extension_metadata(**metadata_kwargs)

# This is named a single character to reduce the size of path names when running build scripts, to reduce the chance
# of hitting the 260 character windows path name limit.
Expand Down

0 comments on commit f329c0c

Please sign in to comment.