| # 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") |
| import("//src/connectivity/network/unified_binary/network_unified_binary.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.net:fuchsia.net_rust", |
| "//sdk/fidl/fuchsia.net.debug:fuchsia.net.debug_rust", |
| "//sdk/fidl/fuchsia.net.dhcp:fuchsia.net.dhcp_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.multicast.admin:fuchsia.net.multicast.admin_rust", |
| "//sdk/fidl/fuchsia.net.name:fuchsia.net.name_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.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.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/diagnostics-traits", |
| "//src/connectivity/network/lib/explicit", |
| "//src/lib/async-utils", |
| "//src/lib/debug/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/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/packet", |
| "//src/lib/replace-with", |
| "//src/lib/trace/rust:trace-provider", |
| "//src/starnix/lib/ebpf", |
| "//src/starnix/lib/ebpf_api", |
| "//src/sys/pkg/fidl/fuchsia.update.verify:fuchsia.update.verify_rust", |
| "//third_party/rust_crates:anyhow", |
| "//third_party/rust_crates:assert_matches", |
| "//third_party/rust_crates:async-ringbuf", |
| "//third_party/rust_crates:bit-vec", |
| "//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:log", |
| "//third_party/rust_crates:once_cell", |
| "//third_party/rust_crates:rand", |
| "//third_party/rust_crates:scopeguard", |
| "//third_party/rust_crates:thiserror", |
| "//third_party/rust_crates:zerocopy", |
| |
| # TODO(https://fxbug.dev/42175119): re-enable check includes when the inspect/client.shard.cml |
| # stops exposing diagnostics from framework. |
| "//src/lib/diagnostics/inspect/runtime/rust:unchecked_includes", |
| ] |
| |
| common_test_deps = [ |
| ":ebpf_test_progs", |
| "core:netstack3-core-testutils", |
| "//src/connectivity/lib/ip-test-macro", |
| "//src/connectivity/lib/net-declare", |
| "//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/fuchsia", |
| "//src/lib/network/fidl_fuchsia_net_ext", |
| "//src/lib/proptest-support", |
| "//src/lib/testing/fixture", |
| "//src/starnix/lib/ebpf_loader", |
| "//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/multicast_admin.rs", |
| "src/bindings/name_worker.rs", |
| "src/bindings/ndp_watcher.rs", |
| "src/bindings/neighbor_worker.rs", |
| "src/bindings/netdevice_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/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/stack_fidl_worker.rs", |
| "src/bindings/time.rs", |
| "src/bindings/timers.rs", |
| "src/bindings/util.rs", |
| "src/bindings/util/data_available.rs", |
| "src/bindings/util/result_ext.rs", |
| "src/bindings/util/scope_ext.rs", |
| "src/bindings/waker.rs", |
| "src/main.rs", |
| ] |
| |
| network_unified_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 |
| |
| # Only add the netstack3 configs to the bin, not GUB because O3 in the default |
| # config causes binary size increases here. |
| bin_add_configs = [ |
| ":netstack3_configs", |
| ":netstack3_debug_configs", |
| ] |
| add_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 |
| add_configs += _concurrent_jobs.configs |
| build_job_vars = _concurrent_jobs.vars |
| |
| # Profile the binary and GUB library builds when requested. |
| if (netstack3_profile_rustc) { |
| add_configs += [ ":compiler_profile" ] |
| } |
| } |
| |
| # See netstack3_profile_rustc GN arg for details here. |
| config("compiler_profile") { |
| rustflags = [ |
| "-Ztime-passes", |
| "-Zllvm-time-trace", |
| "-Zself-profile", |
| ] |
| visibility = [ ":*" ] |
| } |
| |
| config("netstack3_configs") { |
| if (is_release && !is_host) { |
| configs = [ |
| # Always optimize speed, even if it increases size. |
| "//build/config:optimize_speed", |
| ] |
| |
| # Add thinlto config if lto variants are not used. |
| if (!is_lto_variant) { |
| # Allow cross-crate optimization since netstack3 is split between multiple |
| # crates. |
| configs += [ "//build/config/lto:thinlto" ] |
| } |
| } |
| } |
| |
| 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", |
| ] |
| |
| # Add thinlto config if lto variants are not used. |
| if (!is_lto_variant) { |
| # Allow cross-crate optimization since netstack3 is split between multiple |
| # crates. |
| configs += [ "//build/config/lto:thinlto" ] |
| } |
| } |
| } |
| |
| 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:allow_unused_results" ] |
| } |
| |
| fuchsia_component_manifest("component_manifest") { |
| component_name = "netstack3" |
| manifest = "meta/netstack3_prod.cml" |
| } |
| |
| network_unified_binary_regular_and_gub_components("component") { |
| cm_label = ":component_manifest" |
| component_name = "netstack3" |
| gub_deps = [ ":bin" ] |
| visibility = [ |
| ":*", |
| |
| # Only available to top level network for bubbling up into assembly. Use the |
| # test components everywhere else. |
| "//src/connectivity/network:*", |
| ] |
| } |
| |
| fuchsia_structured_config_rust_lib("config_lib") { |
| name = "ns3_config" |
| cm_label = ":component_manifest" |
| } |
| |
| resource("ebpf_test_progs") { |
| visibility = [ ":*" ] |
| sources = [ "tests/ebpf/ebpf_test_progs.o" ] |
| outputs = [ "data/ebpf_test_progs.o" ] |
| } |
| |
| template("ns3_test_component") { |
| _manifest_target = "${target_name}_manifest" |
| _config_target = "${target_name}_config" |
| fuchsia_component_manifest(_manifest_target) { |
| forward_variables_from(invoker, |
| [ |
| "component_name", |
| "manifest", |
| ]) |
| visibility = [ ":*" ] |
| } |
| |
| fuchsia_structured_config_values(_config_target) { |
| cm_label = ":${_manifest_target}" |
| values_source = invoker.config_values_source |
| visibility = [ ":*" ] |
| } |
| |
| fuchsia_component(target_name) { |
| forward_variables_from(invoker, [ "deps" ]) |
| cm_label = ":${_manifest_target}" |
| testonly = true |
| |
| # For ease of using embedded test component, we mark the configuration |
| # values as a component dependency directly. This suits the current needs |
| # with very basic configuration. If structured config grows to be used more |
| # richly this should be revisited. |
| deps += [ ":${_config_target}" ] |
| } |
| } |
| |
| # A stand-in for :component to use for tests. |
| ns3_test_component("component-for-tests") { |
| component_name = "netstack3" |
| manifest = "meta/netstack3_test.cml" |
| config_values_source = "config/test.json5" |
| deps = [ ":bin" ] |
| } |
| |
| # 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" |
| config_values_source = "config/test-debug.json5" |
| deps = [ ":bin-instrumented" ] |
| } |
| |
| # 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.cml" |
| config_values_source = "config/test.json5" |
| deps = [ ":bin-instrumented" ] |
| } |
| |
| # 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_debug.cml" |
| config_values_source = "config/test-conformance.json5" |
| deps = [ ":bin-instrumented" ] |
| } |
| |
| # Drop-in component with the name "netstack" rather than "netstack3." |
| ns3_test_component("component-dropin") { |
| component_name = "netstack" |
| manifest = "meta/netstack3_test.cml" |
| config_values_source = "config/test.json5" |
| deps = [ ":bin" ] |
| } |
| |
| ns3_test_component("component-debug-dropin") { |
| component_name = "netstack-debug" |
| manifest = "meta/netstack3_debug.cml" |
| config_values_source = "config/test-debug.json5" |
| deps = [ ":bin-instrumented" ] |
| } |
| |
| fuchsia_unittest_package("netstack3-bin_test") { |
| deps = [ |
| ":bin_test", |
| "//src/connectivity/network/testing/netemul/service:netemul-sandbox", |
| ] |
| } |
| |
| fuchsia_unittest_package("netstack3-bin-instrumented_test") { |
| deps = [ |
| ":bin-instrumented_test", |
| "//src/connectivity/network/testing/netemul/service:netemul-sandbox", |
| ] |
| } |
| |
| group("benchmarks") { |
| testonly = true |
| deps = [ "bench" ] |
| } |
| |
| group("tests") { |
| testonly = true |
| deps = [ |
| ":netstack3-bin-instrumented_test", |
| ":netstack3-bin_test", |
| "bench:tests", |
| "core:tests", |
| ] |
| } |