| # Copyright 2026 The Fuchsia Authors. All rights reserved. | |
| # Use of this source code is governed by a BSD-style license that can be | |
| # found in the LICENSE file. | |
| load( | |
| "@fuchsia_rules_common//packages:resources.bzl", | |
| "resource", | |
| ) | |
| load( | |
| "//build/bazel/rules/components:fx_component.bzl", | |
| "fx_component", | |
| "fx_component_manifest", | |
| ) | |
| load( | |
| "//build/bazel/rules/components:structured_config.bzl", | |
| "fuchsia_structured_config_rust_lib", | |
| ) | |
| load( | |
| "//build/bazel/rules/packages:fx_package.bzl", | |
| "fx_package", | |
| ) | |
| load( | |
| "//build/bazel/rules/packages:fx_packaged_binary.bzl", | |
| "fx_packaged_binary", | |
| ) | |
| load("//build/bazel/rules/rust:rustc_binary.bzl", "rustc_binary") | |
| load("//build/bazel/rules/rust:rustc_test.bzl", "rustc_test") | |
| package(default_applicable_licenses = ["//:license"]) | |
| exports_files( | |
| ["meta/pkg-cache.bootstrap_shard.cml"], | |
| visibility = ["//bundles/assembly:__subpackages__"], | |
| ) | |
| # As this is a large binary that uses many resources to compile (and takes | |
| # minutes when LTO is enabled, shift it to the large RBE worker pool) | |
| # @bazel2gn:raw_attribute:visibility = [ ":*", "//src/sys/pkg/bin/grand-swd-binary:*" ] | |
| # @bazel2gn:raw_attribute:_concurrent_jobs = concurrent_jobs.link_highmem | |
| # @bazel2gn:raw_attribute:configs += _concurrent_jobs.configs | |
| # @bazel2gn:raw_attribute:forward_variables_from(_concurrent_jobs.vars, "*") | |
| rustc_binary( | |
| name = "bin", | |
| srcs = [ | |
| "src/base_package_resolver.rs", | |
| "src/blob_fetcher.rs", | |
| "src/blob_fetcher/retry.rs", | |
| "src/cache_service.rs", | |
| "src/cache_service/missing_blobs.rs", | |
| "src/compat.rs", | |
| "src/compat/pkgfs.rs", | |
| "src/compat/pkgfs/validation.rs", | |
| "src/component_resolver.rs", | |
| "src/executability.rs", | |
| "src/frozen_index.rs", | |
| "src/full_package_resolver.rs", | |
| "src/gc_service.rs", | |
| "src/index.rs", | |
| "src/index/package.rs", | |
| "src/index/retained.rs", | |
| "src/index/upgradable.rs", | |
| "src/index/writing.rs", | |
| "src/main.rs", | |
| "src/ota_downloader.rs", | |
| "src/ota_resolver.rs", | |
| "src/package_fetcher.rs", | |
| "src/required_blobs.rs", | |
| "src/retained_packages_service.rs", | |
| "src/root_dir.rs", | |
| "src/test_utils.rs", | |
| ], | |
| build_flags = ["//build/config/rust:bootfs"], | |
| crate_name = "pkg_cache", | |
| edition = "2024", | |
| lint_config = "//build/config/rust/lints:clippy_warn_all", | |
| tags = ["manual"], | |
| deps = [ | |
| ":config_lib", | |
| "//sdk/fidl/fuchsia.component.decl:fuchsia.component.decl_rust", | |
| "//sdk/fidl/fuchsia.component.resolution:fuchsia.component.resolution_rust", | |
| "//sdk/fidl/fuchsia.io:fuchsia.io_rust", | |
| "//sdk/fidl/fuchsia.mem:fuchsia.mem_rust", | |
| "//sdk/fidl/fuchsia.metrics:fuchsia.metrics_rust", | |
| "//sdk/fidl/fuchsia.pkg:fuchsia.pkg_rust", | |
| "//sdk/fidl/fuchsia.pkg.garbagecollector:fuchsia.pkg.garbagecollector_rust", | |
| "//sdk/fidl/fuchsia.pkg.http:fuchsia.pkg.http_rust", | |
| "//sdk/fidl/fuchsia.pkg.internal:fuchsia.pkg.internal_rust", | |
| "//sdk/fidl/fuchsia.pkg.resolution:fuchsia.pkg.resolution_rust", | |
| "//sdk/fidl/fuchsia.storage.block:fuchsia.storage.block_rust", | |
| "//sdk/fidl/fuchsia.update:fuchsia.update_rust", | |
| "//sdk/rust/zx", | |
| "//src/lib/cobalt/rust/builders", | |
| "//src/lib/collections/sorted-vec-map", | |
| "//src/lib/diagnostics/inspect/contrib/rust", | |
| "//src/lib/diagnostics/inspect/runtime/rust", | |
| "//src/lib/diagnostics/inspect/rust:fuchsia-inspect", # @bazel2gn:path_overwrite://src/lib/diagnostics/inspect/rust | |
| "//src/lib/fidl/rust/fidl", | |
| "//src/lib/fidl/rust/fidl-contrib", | |
| "//src/lib/fuchsia", | |
| "//src/lib/fuchsia-async", | |
| "//src/lib/fuchsia-component", | |
| "//src/lib/fuchsia-fs", | |
| "//src/lib/fuchsia-runtime", | |
| "//src/lib/fuchsia-sync", | |
| "//src/lib/fuchsia-url", | |
| "//src/lib/http-uri-ext", | |
| "//src/lib/trace/rust:trace", | |
| "//src/lib/trace/rust:trace-provider", | |
| "//src/lib/versioning/version-history/rust", | |
| "//src/storage/fidl/fuchsia.storage.mapping:fuchsia.storage.mapping_rust", | |
| "//src/storage/fxfs/fidl/fuchsia.fxfs:fuchsia.fxfs_rust", | |
| "//src/storage/lib/blob_pager_and_verifier", | |
| "//src/storage/lib/vfs/rust:vfs", | |
| "//src/sys/lib/fidl-connector", | |
| "//src/sys/lib/fidl-fuchsia-pkg-ext", | |
| "//src/sys/lib/fuchsia_backoff", | |
| "//src/sys/pkg/lib/blobfs", | |
| "//src/sys/pkg/lib/context-authenticator", | |
| "//src/sys/pkg/lib/fuchsia-hash", | |
| "//src/sys/pkg/lib/fuchsia-merkle", | |
| "//src/sys/pkg/lib/metrics:cobalt_sw_delivery_registry_rustlib", | |
| "//src/sys/pkg/lib/package-directory", | |
| "//src/sys/pkg/lib/system-image", | |
| "//src/sys/pkg/lib/work-queue", | |
| "//third_party/rust_crates/vendor:anyhow", | |
| "//third_party/rust_crates/vendor:async-lock", | |
| "//third_party/rust_crates/vendor:futures", | |
| "//third_party/rust_crates/vendor:http", | |
| "//third_party/rust_crates/vendor:itertools", | |
| "//third_party/rust_crates/vendor:log", | |
| "//third_party/rust_crates/vendor:rand", | |
| "//third_party/rust_crates/vendor:scopeguard", | |
| "//third_party/rust_crates/vendor:thiserror", | |
| "//third_party/rust_crates/vendor:typed-builder", | |
| ], | |
| ) | |
| # The binary is defined in BUILD.bazel. Its unit tests (`:bin_test`, | |
| # below) are defined here too, and bazel2gn generates their GN copy. Only | |
| # the test component and package (respectively | |
| # `:pkg-cache-test`, and `:pkg-cache-tests`) remain in GN above the sentinel | |
| # because `pkg-cache-tests` packages | |
| # `//src/storage/testing:storage_driver_test_realm` (which is GN-only). | |
| # `with_unit_tests` on `rustc_binary()` is not allowed in Bazel, so this is | |
| # a standalone `rustc_test()` keeping the output name that | |
| # `meta/pkg-cache-bin-test.cml` expects. | |
| # @bazel2gn:raw_attribute:_concurrent_jobs = concurrent_jobs.link_highmem | |
| # @bazel2gn:raw_attribute:configs += _concurrent_jobs.configs | |
| # @bazel2gn:raw_attribute:forward_variables_from(_concurrent_jobs.vars, "*") | |
| rustc_test( | |
| name = "bin_test", | |
| build_flags = ["//build/config/rust:bootfs"], | |
| crate = ":bin", | |
| crate_name = "pkg_cache_bin_test", | |
| edition = "2024", | |
| lint_config = "//build/config/rust/lints:clippy_warn_all", | |
| deps = [ | |
| "//src/lib/diagnostics/testing/diagnostics-assertions/rust:diagnostics-assertions", | |
| "//src/sys/pkg/lib/far/rust:fuchsia-archive", | |
| "//src/sys/pkg/lib/fuchsia-pkg", | |
| "//src/sys/pkg/lib/fuchsia-pkg-testing", | |
| "//src/sys/pkg/testing/blobfs-ramdisk", | |
| "//third_party/rust_crates/vendor:assert_matches", | |
| "//third_party/rust_crates/vendor:maplit", | |
| "//third_party/rust_crates/vendor:tempfile", | |
| "//third_party/rust_crates/vendor:test-case", | |
| ], | |
| ) | |
| # The Bazel build defines an equivalent `fx_component_manifest("manifest")` | |
| # target, so that `:config_lib` refers to the same label in both builds. | |
| fx_component_manifest( | |
| name = "manifest", | |
| component_name = "pkg-cache", | |
| includes = [ | |
| "//sdk/lib/inspect:client.shard", | |
| "//sdk/lib/syslog:client.shard", | |
| ], | |
| manifest = "meta/pkg-cache.cml", | |
| ) | |
| fuchsia_structured_config_rust_lib( | |
| name = "config_lib", | |
| cm_label = ":manifest", | |
| crate_name = "pkg_cache_config", | |
| ) | |
| fx_packaged_binary( | |
| name = "pkg_cache_packaged_bin", | |
| binary = ":bin", | |
| binary_name = "pkg_cache", | |
| ) | |
| fx_component( | |
| name = "component", | |
| compiled_manifest = ":manifest", | |
| visibility = [ | |
| "//src/sys/pkg/lib/isolated-swd:__pkg__", | |
| "//src/sys/pkg/tests/isolated-ota:__pkg__", | |
| "//src/sys/pkg/tests/pkg-cache:__pkg__", | |
| ], | |
| deps = [":pkg_cache_packaged_bin"], | |
| ) | |
| # If the file in this resource is included in the system_image package, then | |
| # pkg-cache will *not* enforce executability restrictions. | |
| # Used only by the Bazel `disable-executability-restrictions` fx_package. | |
| # @bazel2gn:skip | |
| resource( | |
| name = "disable-executability-restrictions-resource", | |
| src = "disable_executability_restrictions", | |
| dest = "data/pkgfs_disable_executability_restrictions", | |
| ) | |
| # The only consumer is the | |
| # //bundles/assembly:pkgfs_disable_executability_restrictions AIB, which sets | |
| # allowed_in = ["eng"], so assembly keeps it out of production builds. | |
| fx_package( | |
| name = "disable-executability-restrictions", | |
| resources = [":disable-executability-restrictions-resource"], | |
| visibility = ["//bundles/assembly:__subpackages__"], | |
| ) |