| # Copyright 2021 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. |
| |
| import("//build/components.gni") |
| import("//build/rust/rustc_binary.gni") |
| import("//build/rust/rustc_macro.gni") |
| import("//build/rust/rustc_test.gni") |
| import("//src/starnix/kernel/starnix.gni") |
| import("//tools/protobuf/rust_proto_library.gni") |
| |
| declare_args() { |
| # Whether or not logging is disabled globally. |
| starnix_disable_logging = false |
| |
| # Whether or not tracing is enabled globally. |
| starnix_enable_tracing = false |
| |
| # Compiles-in trace and debug logging in release builds. By default, these |
| # logs are compiled-out for performance reasons. For more information, see |
| # https://fuchsia-review.googlesource.com/c/fuchsia/+/929995. |
| starnix_enable_trace_and_debug_logs_in_release = false |
| |
| # Whether or not syscall status inspect is enabled globally. |
| starnix_syscall_stats = false |
| } |
| |
| rust_proto_library("perfetto_consumer_proto") { |
| sources = [ |
| "//third_party/perfetto/protos/perfetto/ipc/consumer_port.proto", |
| "//third_party/perfetto/protos/perfetto/ipc/wire_protocol.proto", |
| ] |
| packages = [ "perfetto.protos" ] |
| include_dirs = [ "//third_party/perfetto" ] |
| } |
| |
| group("kernel") { |
| deps = [ ":starnix_kernel_package" ] |
| } |
| |
| group("tests") { |
| testonly = true |
| |
| deps = [ ":starnix-tests" ] |
| } |
| |
| static_library("restricted_trampoline") { |
| sources = [ "execution/trampoline_${current_cpu}.S" ] |
| } |
| |
| rustc_binary("starnix_kernel_bin") { |
| name = "starnix_kernel" |
| edition = "2021" |
| with_unit_tests = true |
| |
| # TODO(fxbug.dev/107698): Re-enable starnix in these environments. |
| exclude_toolchain_tags = [ |
| "asan", |
| "hwasan", |
| ] |
| |
| source_root = "main.rs" |
| deps = [ |
| ":perfetto_consumer_proto", |
| ":starnix_kernel_config", |
| ":vdso-data($target_linux_toolchain)", |
| "//sdk/fidl/fuchsia.buildinfo:fuchsia.buildinfo_rust", |
| "//sdk/fidl/fuchsia.component:fuchsia.component_rust", |
| "//sdk/fidl/fuchsia.component.runner:fuchsia.component.runner_rust", |
| "//sdk/fidl/fuchsia.element:fuchsia.element_rust", |
| "//sdk/fidl/fuchsia.fs:fuchsia.fs_rust", |
| "//sdk/fidl/fuchsia.hardware.power.statecontrol:fuchsia.hardware.power.statecontrol_rust", |
| "//sdk/fidl/fuchsia.input:fuchsia.input_rust", |
| "//sdk/fidl/fuchsia.io:fuchsia.io_rust", |
| "//sdk/fidl/fuchsia.kernel:fuchsia.kernel_rust", |
| "//sdk/fidl/fuchsia.logger:fuchsia.logger_rust", |
| "//sdk/fidl/fuchsia.math:fuchsia.math_rust", |
| "//sdk/fidl/fuchsia.posix:fuchsia.posix_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.process:fuchsia.process_rust", |
| "//sdk/fidl/fuchsia.process.lifecycle:fuchsia.process.lifecycle_rust", |
| "//sdk/fidl/fuchsia.starnix.binder:fuchsia.starnix.binder_rust", |
| "//sdk/fidl/fuchsia.starnix.container:fuchsia.starnix.container_rust", |
| "//sdk/fidl/fuchsia.sysinfo:fuchsia.sysinfo_rust", |
| "//sdk/fidl/fuchsia.sysmem:fuchsia.sysmem_rust", |
| "//sdk/fidl/fuchsia.ui.app:fuchsia.ui.app_rust", |
| "//sdk/fidl/fuchsia.ui.composition:fuchsia.ui.composition_rust", |
| "//sdk/fidl/fuchsia.ui.display.singleton:fuchsia.ui.display.singleton_rust", |
| "//sdk/fidl/fuchsia.ui.input:fuchsia.ui.input_rust", |
| "//sdk/fidl/fuchsia.ui.input3:fuchsia.ui.input3_rust", |
| "//sdk/fidl/fuchsia.ui.pointer:fuchsia.ui.pointer_rust", |
| "//sdk/fidl/fuchsia.ui.policy:fuchsia.ui.policy_rust", |
| "//sdk/fidl/fuchsia.ui.views:fuchsia.ui.views_rust", |
| "//src/connectivity/lib/net-types", |
| "//src/connectivity/network/netlink", |
| "//src/connectivity/wlan/wlanix:fuchsia.wlan.wlanix_rust", |
| "//src/graphics/lib/magma/src/libmagma", |
| "//src/lib/debug/rust", |
| "//src/lib/dense-map", |
| "//src/lib/diagnostics/inspect/contrib/rust", |
| "//src/lib/diagnostics/inspect/runtime/rust", |
| "//src/lib/diagnostics/inspect/rust", |
| "//src/lib/fdio/rust:fdio", |
| "//src/lib/fidl/rust/fidl", |
| "//src/lib/fuchsia", |
| "//src/lib/fuchsia-async", |
| "//src/lib/fuchsia-component", |
| "//src/lib/fuchsia-fs", |
| "//src/lib/fuchsia-image-format", |
| "//src/lib/fuchsia-runtime", |
| "//src/lib/mundane", |
| "//src/lib/process_builder", |
| "//src/lib/trace/rust:trace", |
| "//src/lib/trace/rust:trace-observer", |
| "//src/lib/trace/rust:trace-provider", |
| "//src/lib/ui/flatland-frame-scheduling:flatland-frame-scheduling-lib", |
| "//src/lib/ui/fuchsia-framebuffer", |
| "//src/lib/ui/fuchsia-scenic", |
| "//src/lib/ui/fuchsia-vulkan", |
| "//src/lib/vulkan", |
| "//src/lib/zircon/rust:fuchsia-zircon", |
| "//src/starnix/lib/extended_pstate:lib", |
| "//src/starnix/lib/filter_methods_macro", |
| "//src/starnix/lib/kill_job_on_panic", |
| "//src/starnix/lib/linux_uapi", |
| "//src/starnix/lib/lock-sequence", |
| "//src/starnix/lib/magma", |
| "//src/starnix/lib/range_map", |
| "//src/starnix/lib/selinux", |
| "//src/starnix/lib/starnix-lock", |
| "//src/starnix/lib/starnix-sync", |
| "//src/starnix/lib/syncio", |
| "//src/starnix/lib/ubpf", |
| "//src/storage/ext4/lib/metadata", |
| "//src/storage/ext4/read-only:ext4-read-only", |
| "//src/storage/lib/vfs/rust:vfs", |
| "//src/sys/lib/runner", |
| "//third_party/rust_crates:anyhow", |
| "//third_party/rust_crates:assert_matches", |
| "//third_party/rust_crates:async-lock", |
| "//third_party/rust_crates:async-trait", |
| "//third_party/rust_crates:bit-vec", |
| "//third_party/rust_crates:bitflags", |
| "//third_party/rust_crates:bstr", |
| "//third_party/rust_crates:derivative", |
| "//third_party/rust_crates:dyn-clone", |
| "//third_party/rust_crates:futures", |
| "//third_party/rust_crates:itertools", |
| "//third_party/rust_crates:linked-hash-map", |
| "//third_party/rust_crates:lock_api", |
| "//third_party/rust_crates:macro_rules_attribute", |
| "//third_party/rust_crates:maplit", |
| "//third_party/rust_crates:memchr", |
| "//third_party/rust_crates:memoffset", |
| "//third_party/rust_crates:netlink-packet-core", |
| "//third_party/rust_crates:netlink-packet-generic", |
| "//third_party/rust_crates:netlink-packet-route", |
| "//third_party/rust_crates:netlink-packet-utils", |
| "//third_party/rust_crates:num-derive", |
| "//third_party/rust_crates:num-traits", |
| "//third_party/rust_crates:once_cell", |
| "//third_party/rust_crates:paste", |
| "//third_party/rust_crates:prost", |
| "//third_party/rust_crates:rand", |
| "//third_party/rust_crates:ref-cast", |
| "//third_party/rust_crates:regex", |
| "//third_party/rust_crates:scopeguard", |
| "//third_party/rust_crates:slab", |
| "//third_party/rust_crates:smallvec", |
| "//third_party/rust_crates:static_assertions", |
| "//third_party/rust_crates:tracing", |
| "//third_party/rust_crates:utf8parse", |
| "//third_party/rust_crates:vk-sys", |
| "//third_party/rust_crates:zerocopy", |
| ] |
| |
| if (is_debug) { |
| deps += [ "//third_party/rust_crates:tracing-mutex" ] |
| } |
| |
| if (current_cpu == "arm64") { |
| deps += [ ":vdso-helpers-arm" ] |
| } |
| |
| test_deps = [ |
| "//src/lib/diagnostics/testing/diagnostics-assertions/rust:diagnostics-assertions", |
| "//src/lib/fuchsia-fs", |
| "//src/lib/test_util", |
| "//src/storage/ext4/tests:test_img", |
| "//src/storage/fxfs/platform:fxfs-testing", |
| "//third_party/rust_crates:rand", |
| "//third_party/rust_crates:test-case", |
| "//third_party/rust_crates:tracing-mutex", |
| ] |
| |
| non_rust_deps = [ ":restricted_trampoline" ] |
| |
| sources = [ |
| "arch/${current_cpu}/execution.rs", |
| "arch/${current_cpu}/loader.rs", |
| "arch/${current_cpu}/mod.rs", |
| "arch/${current_cpu}/registers.rs", |
| "arch/${current_cpu}/signal_handling.rs", |
| "arch/${current_cpu}/syscalls.rs", |
| "arch/${current_cpu}/task.rs", |
| "arch/${current_cpu}/uapi.rs", |
| "arch/${current_cpu}/vdso.rs", |
| "arch/mod.rs", |
| "auth.rs", |
| "bpf.rs", |
| "device/binder.rs", |
| "device/common.rs", |
| "device/features.rs", |
| "device/framebuffer.rs", |
| "device/framebuffer_server.rs", |
| "device/input.rs", |
| "device/loop_device.rs", |
| "device/magma/ffi.rs", |
| "device/magma/file.rs", |
| "device/magma/magma.rs", |
| "device/magma/mod.rs", |
| "device/mem.rs", |
| "device/misc.rs", |
| "device/mod.rs", |
| "device/perfetto_consumer.rs", |
| "device/registry.rs", |
| "device/remote_binder.rs", |
| "device/starnix.rs", |
| "device/sync_file.rs", |
| "device/terminal.rs", |
| "device/uinput.rs", |
| "device/wayland/image_file.rs", |
| "device/wayland/mod.rs", |
| "device/wayland/vulkan.rs", |
| "diagnostics/mod.rs", |
| "drop_notifier.rs", |
| "dynamic_thread_spawner.rs", |
| "execution/component_runner.rs", |
| "execution/container.rs", |
| "execution/mod.rs", |
| "execution/restricted_executor.rs", |
| "execution/serve_protocols.rs", |
| "execution/shared.rs", |
| "fs/anon_node.rs", |
| "fs/buffers/io_buffers.rs", |
| "fs/buffers/message_queue.rs", |
| "fs/buffers/message_types.rs", |
| "fs/buffers/mod.rs", |
| "fs/cgroup.rs", |
| "fs/devpts.rs", |
| "fs/devtmpfs.rs", |
| "fs/dir_entry.rs", |
| "fs/directory_file.rs", |
| "fs/dirent_sink.rs", |
| "fs/dynamic_file.rs", |
| "fs/epoll.rs", |
| "fs/eventfd.rs", |
| "fs/ext4.rs", |
| "fs/ext4/pager.rs", |
| "fs/fd_events.rs", |
| "fs/fd_number.rs", |
| "fs/fd_table.rs", |
| "fs/file_object.rs", |
| "fs/file_server.rs", |
| "fs/file_system.rs", |
| "fs/file_write_guard.rs", |
| "fs/fs_args.rs", |
| "fs/fs_context.rs", |
| "fs/fs_node.rs", |
| "fs/fsverity.rs", |
| "fs/fuchsia/mod.rs", |
| "fs/fuchsia/remote.rs", |
| "fs/fuchsia/remote_bundle.rs", |
| "fs/fuchsia/syslog.rs", |
| "fs/fuchsia/timer.rs", |
| "fs/fuse.rs", |
| "fs/inotify.rs", |
| "fs/inotify_mask.rs", |
| "fs/kobject.rs", |
| "fs/layeredfs.rs", |
| "fs/mod.rs", |
| "fs/namespace.rs", |
| "fs/overlayfs.rs", |
| "fs/path.rs", |
| "fs/pidfd.rs", |
| "fs/pipe.rs", |
| "fs/proc/fs.rs", |
| "fs/proc/mod.rs", |
| "fs/proc/pid_directory.rs", |
| "fs/proc/proc_directory.rs", |
| "fs/proc/sysctl.rs", |
| "fs/record_locks.rs", |
| "fs/rw_queue.rs", |
| "fs/simple_file.rs", |
| "fs/socket/mod.rs", |
| "fs/socket/socket.rs", |
| "fs/socket/socket_backed_by_zxio.rs", |
| "fs/socket/socket_file.rs", |
| "fs/socket/socket_fs.rs", |
| "fs/socket/socket_generic_netlink/messages.rs", |
| "fs/socket/socket_generic_netlink/mod.rs", |
| "fs/socket/socket_generic_netlink/nl80211.rs", |
| "fs/socket/socket_netlink.rs", |
| "fs/socket/socket_types.rs", |
| "fs/socket/socket_unix.rs", |
| "fs/socket/socket_vsock.rs", |
| "fs/socket/syscalls.rs", |
| "fs/splice.rs", |
| "fs/static_directory.rs", |
| "fs/symlink_node.rs", |
| "fs/syscalls.rs", |
| "fs/sysfs/cpu_class_directory.rs", |
| "fs/sysfs/device_directory.rs", |
| "fs/sysfs/fs.rs", |
| "fs/sysfs/mod.rs", |
| "fs/sysfs/power_directory.rs", |
| "fs/sysfs/sys_fs_directory.rs", |
| "fs/tmpfs.rs", |
| "fs/tracefs/fs.rs", |
| "fs/tracefs/mod.rs", |
| "fs/tracefs/tracing_directory.rs", |
| "fs/vec_directory.rs", |
| "fs/vmo_file.rs", |
| "fs/wd_number.rs", |
| "fs/xattr.rs", |
| "fs/zxio.rs", |
| "loader.rs", |
| "lock_ordering.rs", |
| "logging.rs", |
| "main.rs", |
| "mm/futex_table.rs", |
| "mm/memory_manager.rs", |
| "mm/mod.rs", |
| "mm/syscalls.rs", |
| "mm/vmo.rs", |
| "mutable_state.rs", |
| "power/manager.rs", |
| "power/mod.rs", |
| "power/state.rs", |
| "power/suspend_stats.rs", |
| "power/wakeup_count.rs", |
| "selinux/fs.rs", |
| "selinux/mod.rs", |
| "signals/mod.rs", |
| "signals/signal_handling.rs", |
| "signals/signalfd.rs", |
| "signals/syscalls.rs", |
| "signals/types.rs", |
| "syscalls/decls.rs", |
| "syscalls/misc.rs", |
| "syscalls/mod.rs", |
| "syscalls/syscall_arg.rs", |
| "syscalls/syscall_result.rs", |
| "syscalls/table.rs", |
| "syscalls/time.rs", |
| "task/abstract_socket_namespace.rs", |
| "task/interval_timer.rs", |
| "task/iptables.rs", |
| "task/kernel.rs", |
| "task/kernel_threads.rs", |
| "task/mod.rs", |
| "task/net.rs", |
| "task/pid_table.rs", |
| "task/process_group.rs", |
| "task/ptrace.rs", |
| "task/scheduler.rs", |
| "task/seccomp.rs", |
| "task/session.rs", |
| "task/syscalls.rs", |
| "task/task.rs", |
| "task/thread_group.rs", |
| "task/timers.rs", |
| "task/uts_namespace.rs", |
| "task/waiter.rs", |
| "testing.rs", |
| "time/mod.rs", |
| "time/utc.rs", |
| "trace.rs", |
| "types/arc_key.rs", |
| "types/as_any.rs", |
| "types/auth.rs", |
| "types/device_type.rs", |
| "types/errno.rs", |
| "types/file_mode.rs", |
| "types/kcmp.rs", |
| "types/mod.rs", |
| "types/mount_flags.rs", |
| "types/open_flags.rs", |
| "types/ownership.rs", |
| "types/personality.rs", |
| "types/range_ext.rs", |
| "types/resource_limits.rs", |
| "types/seal_flags.rs", |
| "types/signals.rs", |
| "types/stats.rs", |
| "types/time.rs", |
| "types/uapi.rs", |
| "types/union.rs", |
| "types/user_address.rs", |
| "types/user_buffer.rs", |
| "vdso/mod.rs", |
| "vdso/vdso_loader.rs", |
| "vmex_resource.rs", |
| ] |
| |
| features = [] |
| if (starnix_disable_logging) { |
| features = [ "disable_logging" ] |
| } |
| if (starnix_enable_tracing) { |
| features += [ "tracing" ] |
| } |
| if (starnix_enable_trace_and_debug_logs_in_release) { |
| features += [ "trace_and_debug_logs_in_release" ] |
| } |
| if (starnix_syscall_stats) { |
| features += [ "syscall_stats" ] |
| } |
| |
| configs += [ "//build/config/rust/lints:clippy_warn_all" ] |
| |
| disable_rustdoc = false |
| } |
| |
| # The starnix kernel manifest, used by all containers. |
| fuchsia_component_manifest("starnix_kernel_manifest") { |
| manifest = "meta/starnix_kernel.cml" |
| component_name = "starnix_kernel" |
| } |
| |
| # The starnix kernel configuration library, used by the Rust binary to parse configuration. |
| fuchsia_structured_config_rust_lib("starnix_kernel_config") { |
| cm_label = ":starnix_kernel_manifest" |
| } |
| |
| resource("starnix-test-files") { |
| sources = [ |
| "data/testfile.txt", |
| "data/testfile2.txt", |
| ] |
| outputs = [ "data/{{source_file_part}}" ] |
| } |
| |
| fuchsia_unittest_package("starnix-tests") { |
| manifest = "meta/starnix-tests.cml" |
| deps = [ |
| ":starnix-test-files", |
| ":starnix_kernel_bin_test", |
| "//src/starnix/examples/hello_starnix:bin", |
| ] |
| test_specs = { |
| log_settings = { |
| # Tests exercise failure cases, so ERROR logs are expected. |
| max_severity = "ERROR" |
| } |
| } |
| test_type = "system" |
| } |
| |
| config("vdso_config") { |
| cflags = [ "-fPIC" ] |
| ldflags = [ |
| "-shared", |
| |
| # Make sure libc is not linked into the vDSO. Header-only use is OK. |
| "-nostdlib", |
| ] |
| |
| # Force LTO so that functions are inlined when appropriate even across |
| # different compilation units. |
| if (!is_debug) { |
| configs = [ "//build/config/lto:thinlto" ] |
| } |
| |
| # Use a custom linker script to ensure only one PT_LOAD header. |
| vdso_linker_script = "vdso/vdso.ld" |
| vdso_version_script = "vdso/vdso-${current_cpu}.map" |
| ldflags += [ |
| "-Wl,-T," + rebase_path(vdso_linker_script, root_build_dir), |
| "-Wl,--version-script," + rebase_path(vdso_version_script, root_build_dir), |
| ] |
| } |
| |
| source_set("vdso-calculate-utc") { |
| sources = [ "vdso/vdso-calculate-utc.cc" ] |
| deps = [ |
| "//zircon/system/public", |
| "//zircon/system/ulib/affine", |
| ] |
| configs += [ ":vdso_config" ] |
| } |
| |
| if (current_cpu == "arm64") { |
| static_library("vdso-helpers-arm") { |
| sources = [ "vdso/get_raw_ticks_arm.cc" ] |
| deps = [ "//zircon/system/public" ] |
| } |
| } |
| |
| loadable_module("vdso") { |
| sources = [ |
| "vdso/vdso-${current_cpu}.cc", |
| "vdso/vdso-common.cc", |
| ] |
| deps = [ |
| ":vdso-calculate-utc", |
| "//zircon/system/public", |
| "//zircon/system/ulib/affine", |
| ] |
| |
| if (current_cpu == "arm64") { |
| deps += [ ":vdso-helpers-arm" ] |
| } |
| |
| output_name = "libvdso" |
| configs += [ ":vdso_config" ] |
| if (is_linux) { |
| # By default, Linux host libraries statically link libc++. Since this library specifies nostdlib |
| # this option is unused and generates a warning. |
| configs -= [ "//build/config/linux:implicit-host-libs" ] |
| } |
| |
| exclude_toolchain_tags = [ "instrumented" ] |
| } |
| |
| resource("vdso-data") { |
| sources = [ "$root_out_dir/libvdso.so" ] |
| outputs = [ "data/libvdso.so" ] |
| deps = [ ":vdso" ] |
| } |
| |
| fuchsia_component("starnix_kernel") { |
| cm_label = ":starnix_kernel_manifest" |
| deps = [ ":starnix_kernel_bin" ] |
| } |
| |
| fuchsia_structured_config_values("kernel_config") { |
| cm_label = ":starnix_kernel_manifest" |
| values_source = "//src/starnix/kernel/meta/config.json5" |
| } |
| |
| fuchsia_package("starnix_kernel_package") { |
| package_name = "starnix_kernel" |
| deps = [ |
| ":kernel_config", |
| ":starnix_kernel", |
| ":starnix_kernel_manifest", |
| "//src/starnix/containers:default_init", |
| ] |
| } |