blob: 372cd72680546dfa14d537a9f398fe1f2d8cc363 [file]
# 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(
"//build/bazel/rules/components:fx_component.bzl",
"fx_component",
"fx_component_manifest",
)
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")
load(
"//build/bazel/rules/testing:fx_unittest_package.bzl",
"fx_unittest_package",
)
load("//tools/protobuf:rust_proto_library.bzl", "rust_proto_library")
package(default_applicable_licenses = ["//:license"])
exports_files(
["meta/memory_sampler.core_shard.cml"],
visibility = ["//bundles/assembly:__subpackages__"],
)
rust_proto_library(
name = "profile_rust_proto",
srcs = [
# @fuchsia_perfetto_protos exposes //third_party/perfetto as an external Bazel repo.
"@fuchsia_perfetto_protos//:protos/third_party/pprof/profile.proto", # @bazel2gn:path_overwrite://third_party/perfetto/protos/third_party/pprof/profile.proto
],
packages = ["perfetto.third_party.perftools.profiles"],
)
rustc_binary(
name = "bin",
srcs = [
"src/crash_reporter.rs",
"src/main.rs",
"src/pprof.rs",
"src/profile_builder.rs",
"src/sampler_service.rs",
],
binary_name = "memory_sampler",
edition = "2024",
deps = [
":profile_rust_proto",
"//sdk/fidl/fuchsia.feedback:fuchsia.feedback_rust",
"//sdk/fidl/fuchsia.mem:fuchsia.mem_rust",
"//sdk/fidl/fuchsia.memory.sampler:fuchsia.memory.sampler_rust",
"//sdk/rust/zx",
"//src/lib/fidl/rust/fidl",
"//src/lib/fuchsia",
"//src/lib/fuchsia-async",
"//src/lib/fuchsia-component",
"//third_party/rust_crates/vendor:anyhow",
"//third_party/rust_crates/vendor:flate2",
"//third_party/rust_crates/vendor:futures",
"//third_party/rust_crates/vendor:hex",
"//third_party/rust_crates/vendor:log",
"//third_party/rust_crates/vendor:prost",
"//third_party/rust_crates/vendor:tar",
],
)
rustc_test(
name = "bin_test",
crate = ":bin",
# Preserves the GN test binary name from `rustc_binary(name = "bin", with_unit_tests = true)`.
crate_name = "memory_sampler_bin_test",
tags = ["manual"],
target_compatible_with = ["@platforms//os:fuchsia"],
deps = ["//third_party/rust_crates/vendor:itertools"],
)
fx_unittest_package(
name = "memory_sampler_tests",
unit_tests = [":bin_test"],
)
fx_packaged_binary(
name = "bin_packaged",
binary = ":bin",
binary_name = "memory_sampler",
)
fx_component_manifest(
name = "memory_sampler_manifest",
component_name = "memory_sampler",
includes = ["//sdk/lib/syslog:client.shard"],
manifest = "meta/memory_sampler.cml",
)
fx_component(
name = "component",
compiled_manifest = ":memory_sampler_manifest",
deps = [":bin_packaged"],
)