| # Copyright 2018 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. | |
| declare_args() { | |
| # Adds compilation flags to emit rustc self-profiling when building netstack3 | |
| # targets. That helps us track down where time is spent and memory | |
| # consumption to play nice with RBE. | |
| netstack3_profile_rustc = false | |
| } | |
| import("//build/components.gni") | |
| import("//build/rust/rustc_binary.gni") | |
| import("//build/toolchain/concurrent_jobs.gni") | |
| common_deps = [ | |
| ":config_lib", | |
| "fidl:fuchsia.netstack.persistence_rust", | |
| "//sdk/fidl/fuchsia.ebpf:fuchsia.ebpf_rust", | |
| "//sdk/fidl/fuchsia.hardware.network:fuchsia.hardware.network_rust", | |
| "//sdk/fidl/fuchsia.io:fuchsia.io_rust", | |
| "//sdk/fidl/fuchsia.net:fuchsia.net_rust", | |
| "//sdk/fidl/fuchsia.net.debug:fuchsia.net.debug_rust", | |
| "//sdk/fidl/fuchsia.net.filter:fuchsia.net.filter_rust", | |
| "//sdk/fidl/fuchsia.net.interfaces:fuchsia.net.interfaces_rust", | |
| "//sdk/fidl/fuchsia.net.interfaces.admin:fuchsia.net.interfaces.admin_rust", | |
| "//sdk/fidl/fuchsia.net.matchers:fuchsia.net.matchers_rust", | |
| "//sdk/fidl/fuchsia.net.multicast.admin:fuchsia.net.multicast.admin_rust", | |
| "//sdk/fidl/fuchsia.net.ndp:fuchsia.net.ndp_rust", | |
| "//sdk/fidl/fuchsia.net.neighbor:fuchsia.net.neighbor_rust", | |
| "//sdk/fidl/fuchsia.net.power:fuchsia.net.power_rust", | |
| "//sdk/fidl/fuchsia.net.resources:fuchsia.net.resources_rust", | |
| "//sdk/fidl/fuchsia.net.root:fuchsia.net.root_rust", | |
| "//sdk/fidl/fuchsia.net.routes:fuchsia.net.routes_rust", | |
| "//sdk/fidl/fuchsia.net.routes.admin:fuchsia.net.routes.admin_rust", | |
| "//sdk/fidl/fuchsia.net.settings:fuchsia.net.settings_rust", | |
| "//sdk/fidl/fuchsia.net.sockets:fuchsia.net.sockets_rust", | |
| "//sdk/fidl/fuchsia.net.stack:fuchsia.net.stack_rust", | |
| "//sdk/fidl/fuchsia.net.tcp:fuchsia.net.tcp_rust", | |
| "//sdk/fidl/fuchsia.net.udp:fuchsia.net.udp_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.power.broker:fuchsia.power.broker_rust", | |
| "//sdk/fidl/fuchsia.power.system:fuchsia.power.system_rust", | |
| "//sdk/fidl/fuchsia.process.lifecycle:fuchsia.process.lifecycle_rust", | |
| "//sdk/rust/zx", | |
| "//src/connectivity/lib/fidl_fuchsia_net_neighbor_ext", | |
| "//src/connectivity/lib/net-declare", | |
| "//src/connectivity/lib/net-types", | |
| "//src/connectivity/lib/network-device/rust", | |
| "//src/connectivity/lib/packet-formats", | |
| "//src/connectivity/network/lib/chunked_ringbuf", | |
| "//src/connectivity/network/lib/diagnostics-traits", | |
| "//src/connectivity/network/lib/explicit", | |
| "//src/connectivity/network/lib/pcap", | |
| "//src/diagnostics/lib/redactor_client", | |
| "//src/lib/async-utils", | |
| "//src/lib/debug/rust", | |
| "//src/lib/diagnostics/inspect/runtime/rust", | |
| "//src/lib/diagnostics/inspect/rust", | |
| "//src/lib/diagnostics/log/rust", | |
| "//src/lib/fidl/rust/fidl", | |
| "//src/lib/fidl_table_validation", | |
| "//src/lib/fuchsia-async", | |
| "//src/lib/fuchsia-component", | |
| "//src/lib/fuchsia-runtime", | |
| "//src/lib/fuchsia-sync", | |
| "//src/lib/network/fidl_fuchsia_net_ext", | |
| "//src/lib/network/fidl_fuchsia_net_filter_ext", | |
| "//src/lib/network/fidl_fuchsia_net_interfaces_ext", | |
| "//src/lib/network/fidl_fuchsia_net_matchers_ext", | |
| "//src/lib/network/fidl_fuchsia_net_multicast_ext", | |
| "//src/lib/network/fidl_fuchsia_net_ndp_ext", | |
| "//src/lib/network/fidl_fuchsia_net_routes_ext", | |
| "//src/lib/network/fidl_fuchsia_net_sockets_ext", | |
| "//src/lib/network/packet", | |
| "//src/lib/replace-with", | |
| "//src/lib/trace/rust:trace-provider", | |
| "//src/lib/windowed-stats", | |
| "//src/starnix/lib/ebpf", | |
| "//src/starnix/lib/ebpf_api", | |
| "//src/storage/lib/vfs/rust:vfs", | |
| "//src/sys/pkg/fidl/fuchsia.update.verify:fuchsia.update.verify_rust", | |
| "//third_party/rust_crates:anyhow", | |
| "//third_party/rust_crates:arc-swap", | |
| "//third_party/rust_crates:assert_matches", | |
| "//third_party/rust_crates:async-ringbuf", | |
| "//third_party/rust_crates:bit-vec", | |
| "//third_party/rust_crates:bitflags", | |
| "//third_party/rust_crates:derivative", | |
| "//third_party/rust_crates:either", | |
| "//third_party/rust_crates:event-listener", | |
| "//third_party/rust_crates:futures", | |
| "//third_party/rust_crates:itertools", | |
| "//third_party/rust_crates:libc", | |
| "//third_party/rust_crates:log", | |
| "//third_party/rust_crates:once_cell", | |
| "//third_party/rust_crates:pin-project", | |
| "//third_party/rust_crates:rand", | |
| "//third_party/rust_crates:scopeguard", | |
| "//third_party/rust_crates:smallvec", | |
| "//third_party/rust_crates:thiserror", | |
| "//third_party/rust_crates:zerocopy", | |
| ] | |
| common_test_deps = [ | |
| "core:netstack3-core-testutils", | |
| "//src/connectivity/lib/ip-test-macro", | |
| "//src/connectivity/lib/net-declare", | |
| "//src/connectivity/network/testing/ebpf_test_util", | |
| "//src/connectivity/network/testing/netemul/network-context/fidl:network_rust", | |
| "//src/connectivity/network/testing/netemul/rust:lib", | |
| "//src/lib/diagnostics/hierarchy/rust", | |
| "//src/lib/diagnostics/testing/diagnostics-assertions/rust:diagnostics-assertions", | |
| "//src/lib/fdio/rust:fdio", | |
| "//src/lib/fuchsia", | |
| "//src/lib/network/fidl_fuchsia_net_ext", | |
| "//src/lib/proptest-support", | |
| "//src/lib/testing/fixture", | |
| "//third_party/rust_crates:futures-lite", | |
| "//third_party/rust_crates:itertools", | |
| "//third_party/rust_crates:log", | |
| "//third_party/rust_crates:proptest", | |
| "//third_party/rust_crates:test-case", | |
| ] | |
| common_sources = [ | |
| "src/bindings.rs", | |
| "src/bindings/bpf.rs", | |
| "src/bindings/counters.rs", | |
| "src/bindings/debug_fidl_worker.rs", | |
| "src/bindings/devices.rs", | |
| "src/bindings/errno.rs", | |
| "src/bindings/error.rs", | |
| "src/bindings/filter.rs", | |
| "src/bindings/filter/controller.rs", | |
| "src/bindings/filter/conversion.rs", | |
| "src/bindings/filter/conversion/actions.rs", | |
| "src/bindings/filter/conversion/matchers.rs", | |
| "src/bindings/filter/socket_filters.rs", | |
| "src/bindings/health_check_worker.rs", | |
| "src/bindings/inspect.rs", | |
| "src/bindings/integration_tests.rs", | |
| "src/bindings/interface_config.rs", | |
| "src/bindings/interfaces_admin.rs", | |
| "src/bindings/interfaces_watcher.rs", | |
| "src/bindings/matchers.rs", | |
| "src/bindings/multicast_admin.rs", | |
| "src/bindings/ndp_watcher.rs", | |
| "src/bindings/neighbor_worker.rs", | |
| "src/bindings/netdevice_worker.rs", | |
| "src/bindings/packet_capture_worker.rs", | |
| "src/bindings/persistence.rs", | |
| "src/bindings/power.rs", | |
| "src/bindings/power/element.rs", | |
| "src/bindings/power/suspension_block.rs", | |
| "src/bindings/power/transmit_suspension_handler.rs", | |
| "src/bindings/reference_notifier.rs", | |
| "src/bindings/resource_removal.rs", | |
| "src/bindings/root_fidl_worker.rs", | |
| "src/bindings/routes.rs", | |
| "src/bindings/routes/admin.rs", | |
| "src/bindings/routes/interface_local.rs", | |
| "src/bindings/routes/rules_admin.rs", | |
| "src/bindings/routes/rules_state.rs", | |
| "src/bindings/routes/state.rs", | |
| "src/bindings/routes/watcher.rs", | |
| "src/bindings/routes/witness.rs", | |
| "src/bindings/settings.rs", | |
| "src/bindings/socket.rs", | |
| "src/bindings/socket/datagram.rs", | |
| "src/bindings/socket/datagram/sndbuf.rs", | |
| "src/bindings/socket/event_pair.rs", | |
| "src/bindings/socket/packet.rs", | |
| "src/bindings/socket/queue.rs", | |
| "src/bindings/socket/raw.rs", | |
| "src/bindings/socket/stream.rs", | |
| "src/bindings/socket/stream/buffer.rs", | |
| "src/bindings/socket/worker.rs", | |
| "src/bindings/sockets_fidl.rs", | |
| "src/bindings/stack_fidl_worker.rs", | |
| "src/bindings/stats_sampler.rs", | |
| "src/bindings/sync.rs", | |
| "src/bindings/time.rs", | |
| "src/bindings/timers.rs", | |
| "src/bindings/util.rs", | |
| "src/bindings/util/data_available.rs", | |
| "src/bindings/util/rcu.rs", | |
| "src/bindings/util/result_ext.rs", | |
| "src/bindings/util/scope_ext.rs", | |
| "src/bindings/waker.rs", | |
| "src/main.rs", | |
| ] | |
| rustc_binary("bin") { | |
| name = "netstack3" | |
| edition = "2024" | |
| with_unit_tests = true | |
| check_cfgs = [ | |
| "test", | |
| "feature, values(\"instrumented\")", | |
| ] | |
| deps = common_deps | |
| non_test_deps = [ "core:netstack3-core" ] | |
| test_deps = common_test_deps | |
| sources = common_sources | |
| configs += [ | |
| "//build/config/rust/lints:deny_unused_results", | |
| ":netstack3_configs", | |
| ":netstack3_debug_configs", | |
| ] | |
| # Both debug and release NS3 builds take a long while to run because of | |
| # optimizations. Build these on the larger build machines to prevent build | |
| # times from becoming unreasonably large. | |
| _concurrent_jobs = concurrent_jobs.rust_highmem | |
| configs += _concurrent_jobs.configs | |
| forward_variables_from(_concurrent_jobs.vars, "*") | |
| # Profile the binary build when requested. | |
| if (netstack3_profile_rustc) { | |
| configs += [ ":compiler_profile" ] | |
| } | |
| } | |
| # See netstack3_profile_rustc GN arg for details here. | |
| config("compiler_profile") { | |
| rustflags = [ | |
| "-Ztime-passes", | |
| "-Zllvm-time-trace", | |
| "-Zself-profile", | |
| ] | |
| visibility = [ ":*" ] | |
| } | |
| # LINT.IfChange(netstack3_configs) | |
| config("netstack3_configs") { | |
| if (is_release && !is_host) { | |
| configs = [ | |
| # Always optimize speed, even if it increases size. | |
| "//build/config:optimize_speed", | |
| ] | |
| } | |
| visibility = [ | |
| "//src/connectivity/lib/packet-formats/benchmarks:*", | |
| "//src/connectivity/network/*", | |
| ] | |
| } | |
| # LINT.ThenChange(BUILD.bazel:netstack3_configs) | |
| config("netstack3_debug_configs") { | |
| if (is_debug) { | |
| configs = [ | |
| # Minor optimizations that remove a lot of indirection and make zero-cost | |
| # closer to zero-cost. | |
| "//build/config:optimize_debug", | |
| ] | |
| # Enable ThinLTO to allow cross-crate optimization, as netstack3 is | |
| # distributed across multiple crates. | |
| configs += [ "//build/config/lto:thinlto-if-compatible" ] | |
| } | |
| } | |
| rustc_binary("bin-instrumented") { | |
| name = "netstack3-instrumented" | |
| edition = "2024" | |
| with_unit_tests = true | |
| deps = common_deps | |
| non_test_deps = [ "core:netstack3-core-instrumented" ] | |
| test_deps = common_test_deps | |
| features = [ "instrumented" ] | |
| sources = common_sources | |
| configs += [ "//build/config/rust/lints:deny_unused_results" ] | |
| # This target needs more memory to build remotely, see b/484091776. | |
| _concurrent_jobs = concurrent_jobs.rust_highmem | |
| configs += _concurrent_jobs.configs | |
| forward_variables_from(_concurrent_jobs.vars, "*") | |
| } | |
| fuchsia_component_manifest("component_manifest") { | |
| component_name = "netstack3" | |
| manifest = "meta/netstack3_prod.cml" | |
| visibility = [ ":*" ] | |
| } | |
| fuchsia_component("component") { | |
| cm_label = ":component_manifest" | |
| component_name = "netstack3" | |
| deps = [ ":bin" ] | |
| visibility = [ ":*" ] | |
| } | |
| fuchsia_package("netstack3") { | |
| package_name = "netstack3" | |
| deps = [ ":component" ] | |
| visibility = [ | |
| ":*", | |
| "//bundles/assembly/*", | |
| ] | |
| } | |
| fuchsia_structured_config_rust_lib("config_lib") { | |
| name = "ns3_config" | |
| cm_label = ":component_manifest" | |
| } | |
| template("ns3_test_component") { | |
| _manifest_target = "${target_name}_manifest" | |
| fuchsia_component_manifest(_manifest_target) { | |
| forward_variables_from(invoker, | |
| [ | |
| "component_name", | |
| "manifest", | |
| ]) | |
| visibility = [ ":*" ] | |
| } | |
| fuchsia_component(target_name) { | |
| forward_variables_from(invoker, [ "deps" ]) | |
| cm_label = ":${_manifest_target}" | |
| testonly = true | |
| visibility = [ ":*" ] | |
| } | |
| } | |
| # A stand-in for :component to use for tests. | |
| ns3_test_component("component-for-tests") { | |
| component_name = "netstack3" | |
| manifest = "meta/netstack3_test.cml" | |
| deps = [ ":bin" ] | |
| } | |
| # A stand-in for :netstack3 to use as a subpackage in tests. | |
| fuchsia_package("package-for-tests") { | |
| testonly = true | |
| package_name = "netstack" | |
| deps = [ ":component-for-tests" ] | |
| } | |
| # Component with debugging instrumentation enabled. This should be used for | |
| # tests but not benchmarks. | |
| ns3_test_component("component-debug") { | |
| component_name = "netstack3-debug" | |
| manifest = "meta/netstack3_debug.cml" | |
| deps = [ ":bin-instrumented" ] | |
| } | |
| # Package with debugging instrumentation enabled. This should be used as a | |
| # subpackage in tests, not benchmarks. | |
| fuchsia_package("package-debug") { | |
| testonly = true | |
| package_name = "netstack-debug" | |
| deps = [ ":component-debug" ] | |
| } | |
| # A stand-in for :component-debug to use for tests that need to avoid logging as | |
| # verbosely to avoid timing out in infra. | |
| ns3_test_component("component-debug-less-logs") { | |
| component_name = "netstack3-debug" | |
| manifest = "meta/netstack3_debug_less_logs.cml" | |
| deps = [ ":bin-instrumented" ] | |
| } | |
| # A stand-in for :package-debug for tests that need reduced logging verbosity. | |
| fuchsia_package("package-debug-less-logs") { | |
| testonly = true | |
| package_name = "netstack-debug" | |
| deps = [ ":component-debug-less-logs" ] | |
| } | |
| # Component with debugging instrumentation enabled and opaque IIDs disabled for | |
| # convenience in conformance testing. | |
| ns3_test_component("component-conformance") { | |
| component_name = "netstack3-conformance" | |
| manifest = "meta/netstack3_conformance.cml" | |
| deps = [ ":bin-instrumented" ] | |
| } | |
| # Package with debugging instrumentation enabled and opaque IIDs disabled for | |
| # convenience in conformance testing. | |
| fuchsia_package("package-conformance") { | |
| testonly = true | |
| package_name = "netstack-conformance" | |
| deps = [ ":component-conformance" ] | |
| } | |
| fuchsia_unittest_package("netstack3-bin_test") { | |
| deps = [ ":bin_test" ] | |
| subpackages = [ "//src/connectivity/network/testing/netemul/service:package" ] | |
| } | |
| fuchsia_unittest_package("netstack3-bin-instrumented_test") { | |
| deps = [ ":bin-instrumented_test" ] | |
| subpackages = [ "//src/connectivity/network/testing/netemul/service:package" ] | |
| } | |
| group("benchmarks") { | |
| testonly = true | |
| deps = [ "bench" ] | |
| } | |
| group("tests") { | |
| testonly = true | |
| deps = [ | |
| ":netstack3-bin-instrumented_test", | |
| ":netstack3-bin_test", | |
| "bench:tests", | |
| "core:tests", | |
| ] | |
| } |