blob: 786f5744fe8f38a8c1f935a01c14dc8fc7ea8e7b [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(
"@fuchsia_build_info//:args.bzl",
"compilation_mode",
"starnix_enable_trace_and_debug_logs_in_release",
)
load(
"@fuchsia_rules_common//packages:resources.bzl",
"fuchsia_package_resource_group",
)
load("//build/bazel/rbe:rbe.bzl", "RBE_USE_LARGE_WORKER")
load(
"//build/bazel/rules/components:fx_component.bzl",
"fx_component_manifest",
"fx_test_component",
)
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_library.bzl", "rustc_library")
load("//build/bazel/rules/rust:rustc_test.bzl", "rustc_test")
load("//build/bazel/rules/testing:fx_test.bzl", "fx_test")
package(default_applicable_licenses = ["//:license"])
# In GN, //src/starnix/kernel/vdso is a resource() group (built with the
# GN-only bionic toolchain) that propagates data/libvdso.so to dependent GN
# packages through deps. In Bazel, rustc_library deps only accept Rust crates
# (package resources are listed on fx_component / fx_package instead).
# Allows binaries that depend on this library to link.
# @bazel2gn:raw_attribute:deps += [ "//src/starnix/kernel/vdso" ]
# @bazel2gn:raw_attribute:public_configs = [ "//build/config/fuchsia:dynamic_cpp_standard_library" ]
rustc_library(
name = "core",
srcs = [
"arch/mod.rs",
"bpf/attachments.rs",
"bpf/context.rs",
"bpf/fs.rs",
"bpf/map.rs",
"bpf/mod.rs",
"bpf/program.rs",
"bpf/syscalls.rs",
"device/block.rs",
"device/kobject.rs",
"device/kobject_store.rs",
"device/mem.rs",
"device/mod.rs",
"device/power_stats.rs",
"device/registry.rs",
"device/remote_block_device.rs",
"device/service_watcher.rs",
"device/terminal.rs",
"execution/crash_reporter.rs",
"execution/executor.rs",
"execution/loop_entry.rs",
"execution/mod.rs",
"execution/task_creation.rs",
"fs/devtmpfs.rs",
"fs/mod.rs",
"fs/sysfs/cpu_class_directory.rs",
"fs/sysfs/device_directory.rs",
"fs/sysfs/fs.rs",
"fs/sysfs/kernel_directory.rs",
"fs/sysfs/mod.rs",
"fs/sysfs/power_directory.rs",
"fs/tmpfs.rs",
"lib.rs",
"mm/barrier.rs",
"mm/debugger.rs",
"mm/futex_table.rs",
"mm/map_info_cache.rs",
"mm/mapping.rs",
"mm/memory.rs",
"mm/memory_accessor.rs",
"mm/memory_manager.rs",
"mm/mlock.rs",
"mm/mod.rs",
"mm/prefetch_pool.rs",
"mm/private_anonymous_memory_manager.rs",
"mm/protection_flags.rs",
"mm/syscalls.rs",
"mm/userfault.rs",
"mm/vmex_resource.rs",
"mm/vmsplice.rs",
"mutable_state.rs",
"perf/event.rs",
"perf/mod.rs",
"power/manager.rs",
"power/mod.rs",
"power/state.rs",
"power/suspend_stats.rs",
"power/sync_on_suspend.rs",
"power/wake_lock.rs",
"power/wakeup_count.rs",
"ptrace/event.rs",
"ptrace/hooks.rs",
"ptrace/mod.rs",
"ptrace/ptrace.rs",
"ptrace/stop_state.rs",
"security/audit.rs",
"security/common_cap.rs",
"security/hooks.rs",
"security/mod.rs",
"security/non_private.rs",
"security/selinux_hooks/audit.rs",
"security/selinux_hooks/binder.rs",
"security/selinux_hooks/bpf.rs",
"security/selinux_hooks/file.rs",
"security/selinux_hooks/fs_node.rs",
"security/selinux_hooks/mod.rs",
"security/selinux_hooks/netlink_socket.rs",
"security/selinux_hooks/perf_event.rs",
"security/selinux_hooks/selinuxfs.rs",
"security/selinux_hooks/socket.rs",
"security/selinux_hooks/superblock.rs",
"security/selinux_hooks/task.rs",
"security/selinux_hooks/testing.rs",
"security/yama.rs",
"signals/mod.rs",
"signals/signal_handling.rs",
"signals/signalfd.rs",
"signals/syscalls.rs",
"signals/types.rs",
"syscalls/mod.rs",
"syscalls/time.rs",
"task/abstract_socket_namespace.rs",
"task/cgroup.rs",
"task/container_namespace.rs",
"task/current_task.rs",
"task/delayed_release.rs",
"task/dynamic_thread_spawner.rs",
"task/exit_status.rs",
"task/idr.rs",
"task/iptables.rs",
"task/kernel.rs",
"task/kernel_stats.rs",
"task/kernel_threads.rs",
"task/limits.rs",
"task/loader.rs",
"task/memory_attribution.rs",
"task/mod.rs",
"task/net.rs",
"task/pid_table.rs",
"task/run_state.rs",
"task/scheduler/manager.rs",
"task/scheduler/mod.rs",
"task/scheduler/role_overrides.rs",
"task/seccomp.rs",
"task/syscall_trace.rs",
"task/syscalls.rs",
"task/syslog.rs",
"task/task.rs",
"task/task_running_state.rs",
"task/thread_group.rs",
"task/thread_lockup_detector.rs",
"task/thread_state.rs",
"task/tracing.rs",
"task/uts_namespace.rs",
"task/waiter.rs",
"task/zombie.rs",
"testing.rs",
"time/hr_timer_manager.rs",
"time/interval_timer.rs",
"time/mod.rs",
"time/timeline.rs",
"time/timers.rs",
"time/utc.rs",
"vdso/mod.rs",
"vdso/vdso_loader.rs",
"vfs/access_check.rs",
"vfs/aio.rs",
"vfs/anon_node.rs",
"vfs/buffers/io_buffers.rs",
"vfs/buffers/message_queue.rs",
"vfs/buffers/message_types.rs",
"vfs/buffers/mod.rs",
"vfs/dir_entry.rs",
"vfs/dirent_sink.rs",
"vfs/epoll.rs",
"vfs/eventfd.rs",
"vfs/fd_number.rs",
"vfs/fd_table.rs",
"vfs/file_object.rs",
"vfs/file_server.rs",
"vfs/file_system.rs",
"vfs/file_write_guard.rs",
"vfs/fs_args.rs",
"vfs/fs_context.rs",
"vfs/fs_node.rs",
"vfs/fs_node_cache.rs",
"vfs/fs_registry.rs",
"vfs/fsverity.rs",
"vfs/inotify_hook.rs",
"vfs/memory_directory.rs",
"vfs/memory_regular.rs",
"vfs/mod.rs",
"vfs/namespace.rs",
"vfs/path.rs",
"vfs/pidfd.rs",
"vfs/pipe.rs",
"vfs/pseudo/dynamic_file.rs",
"vfs/pseudo/mod.rs",
"vfs/pseudo/simple_directory.rs",
"vfs/pseudo/simple_file.rs",
"vfs/pseudo/stub_bytes_file.rs",
"vfs/pseudo/stub_empty_file.rs",
"vfs/pseudo/vec_directory.rs",
"vfs/record_locks.rs",
"vfs/rw_queue.rs",
"vfs/socket/iptables_utils.rs",
"vfs/socket/mod.rs",
"vfs/socket/netlink_ioctl.rs",
"vfs/socket/socket.rs",
"vfs/socket/socket_backed_by_zxio.rs",
"vfs/socket/socket_file.rs",
"vfs/socket/socket_fs.rs",
"vfs/socket/socket_generic_netlink/messages.rs",
"vfs/socket/socket_generic_netlink/mod.rs",
"vfs/socket/socket_generic_netlink/nl80211.rs",
"vfs/socket/socket_generic_netlink/taskstats.rs",
"vfs/socket/socket_netlink.rs",
"vfs/socket/socket_qipcrtr.rs",
"vfs/socket/socket_types.rs",
"vfs/socket/socket_unix.rs",
"vfs/socket/socket_vsock.rs",
"vfs/socket/syscalls.rs",
"vfs/splice.rs",
"vfs/symlink_node.rs",
"vfs/syscalls.rs",
"vfs/timer.rs",
"vfs/wd_number.rs",
"vfs/xattr.rs",
"//src/starnix/kernel/core/fs/fuchsia:mod.rs",
"//src/starnix/kernel/core/fs/fuchsia:remote.rs",
"//src/starnix/kernel/core/fs/fuchsia:remote_bundle.rs",
"//src/starnix/kernel/core/fs/fuchsia:remote_unix_domain_socket.rs",
"//src/starnix/kernel/core/fs/fuchsia:remote_volume.rs",
"//src/starnix/kernel/core/fs/fuchsia:sync_file.rs",
"//src/starnix/kernel/core/fs/fuchsia:syslog.rs",
"//src/starnix/kernel/core/fs/fuchsia:timer.rs",
"//src/starnix/kernel/core/fs/fuchsia:zxio.rs",
] + select({
"@platforms//cpu:arm64": [
"arch/arm64/execution.rs",
"arch/arm64/mod.rs",
"arch/arm64/signal_handling.rs",
"arch/arm64/syscalls.rs",
"arch/arm64/task.rs",
"arch/arm64/vdso.rs",
],
"@platforms//cpu:riscv64": [
"arch/riscv64/execution.rs",
"arch/riscv64/mod.rs",
"arch/riscv64/signal_handling.rs",
"arch/riscv64/syscalls.rs",
"arch/riscv64/task.rs",
"arch/riscv64/vdso.rs",
],
"@platforms//cpu:x86_64": [
"arch/x64/execution.rs",
"arch/x64/mod.rs",
"arch/x64/signal_handling.rs",
"arch/x64/syscalls.rs",
"arch/x64/task.rs",
"arch/x64/vdso.rs",
],
}),
compile_data = [
"//src/starnix/lib/selinux:testdata/composite_policies/compiled/bounded_transition_policy",
"//src/starnix/lib/selinux:testdata/micro_policies/hooks_tests_policy",
],
# This is normally controlled on the starnix_logging crate, but controlling the
# features here also allows the kernel to store debug-log-only information on
# structs without paying any overhead in release.
crate_features = ["debug_and_trace_logs_enabled"] if (
compilation_mode != "release" or
starnix_enable_trace_and_debug_logs_in_release
) else [],
crate_name = "starnix_core",
crate_root = "lib.rs",
edition = "2024",
lint_config = "//src/starnix/build:kernel_library_config",
proc_macro_deps = [
"//src/starnix/lib/filter_methods_macro",
"//third_party/rust_crates/vendor:async-trait",
"//third_party/rust_crates/vendor:derivative",
"//third_party/rust_crates/vendor:num-derive",
"//third_party/rust_crates/vendor:paste",
],
visibility = [
"//src/starnix/kernel:__subpackages__",
"//src/starnix/modules:__subpackages__",
"//src/starnix/runner/lib/kernel_manager:__pkg__",
"//src/starnix/tests/kernel_core_bench:__pkg__",
"//src/starnix/tests/selinux/bench:__pkg__",
],
deps = [
"//sdk/fidl/fuchsia.component.runner:fuchsia.component.runner_rust",
"//sdk/fidl/fuchsia.cpu.profiler:fuchsia.cpu.profiler_rust",
"//sdk/fidl/fuchsia.diagnostics:fuchsia.diagnostics_rust",
"//sdk/fidl/fuchsia.ebpf:fuchsia.ebpf_rust",
"//sdk/fidl/fuchsia.feedback:fuchsia.feedback_rust",
"//sdk/fidl/fuchsia.fs:fuchsia.fs_rust",
"//sdk/fidl/fuchsia.fshost:fuchsia.fshost_rust",
"//sdk/fidl/fuchsia.hardware.cpu.ctrl:fuchsia.hardware.cpu.ctrl_rust",
"//sdk/fidl/fuchsia.hardware.inlineencryption:fuchsia.hardware.inlineencryption_rust",
"//sdk/fidl/fuchsia.hardware.power.stats:fuchsia.hardware.power.stats_rust",
"//sdk/fidl/fuchsia.hardware.qualcomm.router:fuchsia.hardware.qualcomm.router_rust",
"//sdk/fidl/fuchsia.io:fuchsia.io_rust",
"//sdk/fidl/fuchsia.kernel:fuchsia.kernel_rust",
"//sdk/fidl/fuchsia.memory.attribution:fuchsia.memory.attribution_rust",
"//sdk/fidl/fuchsia.net.filter:fuchsia.net.filter_rust",
"//sdk/fidl/fuchsia.net:fuchsia.net_rust",
"//sdk/fidl/fuchsia.net.power:fuchsia.net.power_rust",
"//sdk/fidl/fuchsia.net.resources:fuchsia.net.resources_rust",
"//sdk/fidl/fuchsia.posix.socket:fuchsia.posix.socket_rust",
"//sdk/fidl/fuchsia.posix.socket.packet:fuchsia.posix.socket.packet_rust",
"//sdk/fidl/fuchsia.posix.socket.raw:fuchsia.posix.socket.raw_rust",
"//sdk/fidl/fuchsia.power.broker:fuchsia.power.broker_rust",
"//sdk/fidl/fuchsia.power.cpu:fuchsia.power.cpu_rust",
"//sdk/fidl/fuchsia.power.observability:fuchsia.power.observability_rust",
"//sdk/fidl/fuchsia.scheduler:fuchsia.scheduler_rust",
"//sdk/fidl/fuchsia.session.power:fuchsia.session.power_rust",
"//sdk/fidl/fuchsia.starnix.binder:fuchsia.starnix.binder_rust",
"//sdk/fidl/fuchsia.starnix.runner:fuchsia.starnix.runner_rust",
"//sdk/fidl/fuchsia.storage.block:fuchsia.storage.block_rust",
"//sdk/fidl/fuchsia.time.alarms:fuchsia.time.alarms_rust",
"//sdk/fidl/fuchsia.time.external:fuchsia.time.external_rust",
"//sdk/fidl/fuchsia.time:fuchsia.time_rust",
"//sdk/fidl/fuchsia.unknown:fuchsia.unknown_rust",
"//sdk/lib/c/rust",
"//sdk/lib/scheduler/rust",
"//sdk/rust/zx",
"//src/connectivity/lib/net-types",
"//src/connectivity/network/netlink",
"//src/connectivity/wlan/wlanix:fuchsia.wlan.wlanix_rust",
"//src/lib/debug/rust",
"//src/lib/diagnostics/data/rust",
"//src/lib/diagnostics/inspect/rust:fuchsia-inspect",
"//src/lib/diagnostics/log/encoding/rust",
"//src/lib/diagnostics/log/message/rust",
"//src/lib/elf_parse",
"//src/lib/fdio/rust:fdio",
"//src/lib/fidl/rust/fidl",
"//src/lib/fuchsia-async",
"//src/lib/fuchsia-component",
"//src/lib/fuchsia-fs",
"//src/lib/fuchsia-rcu",
"//src/lib/fuchsia-rcu-collections",
"//src/lib/fuchsia-runtime",
"//src/lib/fuchsia-sync",
"//src/lib/mapped-clock:lib",
"//src/lib/mundane",
"//src/lib/network/fidl_fuchsia_net_filter_ext",
"//src/lib/network/fidl_fuchsia_net_matchers_ext",
"//src/lib/process_builder",
"//src/lib/replace-with",
"//src/lib/trace/rust:trace",
"//src/lib/trace/rust:trace-observer",
"//src/performance/lib/fxt/rust",
"//src/performance/memory/attribution/server",
"//src/starnix/lib/atomic_bitflags",
"//src/starnix/lib/crash_throttling",
"//src/starnix/lib/devicetree",
"//src/starnix/lib/ebpf",
"//src/starnix/lib/ebpf_api",
"//src/starnix/lib/estimate_timeline",
"//src/starnix/lib/expando",
"//src/starnix/lib/extended_pstate:lib",
"//src/starnix/lib/line_discipline",
"//src/starnix/lib/linux_uapi",
"//src/starnix/lib/memory_pinning",
"//src/starnix/lib/page_buf",
"//src/starnix/lib/paged_ring_buffer",
"//src/starnix/lib/range_map",
"//src/starnix/lib/selinux",
"//src/starnix/lib/seq_lock",
"//src/starnix/lib/split_enum_storage",
"//src/starnix/lib/starnix_crypto",
"//src/starnix/lib/starnix_lifecycle",
"//src/starnix/lib/starnix_logging",
"//src/starnix/lib/starnix_rcu",
"//src/starnix/lib/starnix_registers",
"//src/starnix/lib/starnix_sync",
"//src/starnix/lib/starnix_syscalls",
"//src/starnix/lib/starnix_task_command",
"//src/starnix/lib/starnix_types",
"//src/starnix/lib/starnix_uapi",
"//src/starnix/lib/syncio",
"//src/starnix/lib/third_party/rust_netlink/netlink_packet_core",
"//src/starnix/lib/third_party/rust_netlink/netlink_packet_generic",
"//src/starnix/lib/third_party/rust_netlink/netlink_packet_route",
"//src/starnix/lib/third_party/rust_netlink/netlink_packet_sock_diag",
"//src/starnix/lib/third_party/rust_netlink/netlink_packet_utils",
"//src/starnix/lib/thread_create_vmars",
"//src/starnix/lib/usercopy",
"//src/storage/crypt/starnix:lib",
"//src/storage/ext4/lib/metadata",
"//src/storage/fxfs/fidl/fuchsia.fxfs:fuchsia.fxfs_rust",
"//src/storage/fxfs/unicode",
"//src/storage/lib/block_client/rust:block-client",
"//src/storage/lib/sync_io_client",
"//src/storage/lib/vfs/rust:vfs",
"//src/sys/lib/moniker",
"//src/sys/time/timekeeper/pretty:time_pretty",
"//third_party/rust_crates/vendor:anyhow",
"//third_party/rust_crates/vendor:assert_matches",
"//third_party/rust_crates/vendor:bitflags",
"//third_party/rust_crates/vendor:bstr",
"//third_party/rust_crates/vendor:byteorder",
"//third_party/rust_crates/vendor:crossbeam",
"//third_party/rust_crates/vendor:dyn-clone",
"//third_party/rust_crates/vendor:flyweights",
"//third_party/rust_crates/vendor:fragile",
"//third_party/rust_crates/vendor:futures",
"//third_party/rust_crates/vendor:hex",
"//third_party/rust_crates/vendor:indexmap",
"//third_party/rust_crates/vendor:itertools",
"//third_party/rust_crates/vendor:linked-hash-map",
"//third_party/rust_crates/vendor:lock_api",
"//third_party/rust_crates/vendor:macro_rules_attribute",
"//third_party/rust_crates/vendor:memchr",
"//third_party/rust_crates/vendor:memoffset",
"//third_party/rust_crates/vendor:nom",
"//third_party/rust_crates/vendor:num-traits",
"//third_party/rust_crates/vendor:once_cell",
"//third_party/rust_crates/vendor:pin-project",
"//third_party/rust_crates/vendor:rand",
"//third_party/rust_crates/vendor:ref-cast",
"//third_party/rust_crates/vendor:regex-lite",
"//third_party/rust_crates/vendor:rustc-hash",
"//third_party/rust_crates/vendor:scopeguard",
"//third_party/rust_crates/vendor:serde",
"//third_party/rust_crates/vendor:slab",
"//third_party/rust_crates/vendor:smallvec",
"//third_party/rust_crates/vendor:static_assertions",
"//third_party/rust_crates/vendor:strum",
"//third_party/rust_crates/vendor:thiserror",
"//third_party/rust_crates/vendor:tracing-mutex",
"//third_party/rust_crates/vendor:zerocopy",
],
)
# In GN, //src/starnix/kernel/vdso and //src/storage/ext4/tests:test_img are
# resource() targets propagated to starnix_core_tests through deps.
# @bazel2gn:raw_attribute:deps += [ "//src/starnix/kernel/vdso", "//src/storage/ext4/tests:test_img" ]
rustc_test(
name = "starnix_core_test",
crate = ":core",
crate_features = ["debug_and_trace_logs_enabled"] if (
compilation_mode != "release" or
starnix_enable_trace_and_debug_logs_in_release
) else [],
crate_name = "starnix_core_lib_test",
edition = "2024",
# Linking the lib tests requires a lot of memory.
# Notes: if (is_asan || target_cpu == "riscv64"), linking is known to
# OOM on n2-standard-2.
# For other configurations, building on n2-standard-8 is significantly
# faster due to the memory usage.
exec_properties = RBE_USE_LARGE_WORKER,
link_deps = ["//src/starnix/kernel/syscall_loop:module_changes_breakpoint"],
lint_config = "//src/starnix/config:starnix_clippy_lints_test",
# TODO(https://fxbug.dev/42059075): Re-enable starnix in these environments.
tags = [
"exclude_toolchain_tags=asan",
"exclude_toolchain_tags=hwasan",
],
deps = [
"//src/connectivity/lib/net-declare",
"//src/lib/diagnostics/testing/diagnostics-assertions/rust:diagnostics-assertions",
"//src/lib/fuchsia",
"//src/lib/test_util",
"//src/storage/fxfs/platform:fxfs-testing",
"//src/storage/lib/block_server/vmo_backed",
"//src/storage/lib/storage_device",
"//src/sys/time/testing/fake-wake-alarms:lib",
"//src/testing/fidl:placeholders_rust",
"//third_party/rust_crates/vendor:maplit",
"//third_party/rust_crates/vendor:test-case",
],
)
# LINT.IfChange
# Hand-maintained in BUILD.gn above the sentinel while GN consumers remain.
# @bazel2gn:skip
fuchsia_package_resource_group(
name = "test_files",
testonly = True,
srcs = [
"test_data/testfile.txt",
"test_data/testfile2.txt",
],
basename_only = True,
dest = "data",
)
fx_packaged_binary(
name = "starnix_core_test_packaged_bin",
testonly = True,
binary = ":starnix_core_test",
binary_name = "starnix_core_lib_test",
)
fx_component_manifest(
name = "starnix_core_tests-manifest",
testonly = True,
component_name = "starnix_core_tests",
includes = [
"//sdk/lib/inspect:client.shard",
"//sdk/lib/syslog:client.shard",
"//src/sys/test_runners/starnix:unit_test.shard.cml",
],
manifest = "meta/starnix_core_tests.cml",
)
fx_test_component(
name = "starnix_core_tests-component",
compiled_manifest = ":starnix_core_tests-manifest",
test_type = "starnix",
deps = [
":starnix_core_test_packaged_bin",
":test_files",
"//src/starnix/examples/hello_starnix:hello_starnix_bin",
"//src/starnix/kernel/vdso",
"//src/storage/ext4/tests:test_img",
],
)
fx_package(
name = "starnix_core_tests-package",
package_name = "starnix_core_tests",
test_components = [":starnix_core_tests-component"],
)
fx_test(
name = "starnix_core_tests",
# Tests exercise failure cases, so ERROR logs are expected.
max_log_severity = "ERROR",
package = ":starnix_core_tests-package",
)
# LINT.ThenChange(BUILD.gn)