| # 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. |
| |
| # ________ _________ ________ ________ |
| # |\ ____\|\___ ___\\ __ \|\ __ \ |
| # \ \ \___|\|___ \ \_\ \ \|\ \ \ \|\ \ |
| # \ \_____ \ \ \ \ \ \ \\\ \ \ ____\ |
| # \|____|\ \ \ \ \ \ \ \\\ \ \ \___| |
| # ____\_\ \ \ \__\ \ \_______\ \__\ |
| # |\_________\ \|__| \|_______|\|__| |
| # \|_________| |
| # |
| # Here to enable an unstable feature? All unstable features require special |
| # approval because they create risk and may have stable alternatives that better |
| # fit our needs. See the "Unstable features" section for more information. |
| |
| import("//build/images/filesystem_limits.gni") |
| import("//build/rust/config.gni") |
| import("//build/toolchain/rbe.gni") |
| |
| declare_args() { |
| # Controls whether the rust compiler uses v0 symbol mangling scheme |
| # (see https://github.com/rust-lang/rfcs/blob/HEAD/text/2603-rust-symbol-name-mangling-v0.md). |
| # The v0 symbol mangling scheme requires upstream LLVM support when demangling, |
| # so it is not on by default. |
| # TODO(fxbug.dev/57302): Enable v0 mangling by default. |
| rust_v0_symbol_mangling = false |
| |
| # Enable incremental rust compilation. Takes a path to the directory to use |
| # as the cache. |
| rust_incremental = "" |
| } |
| |
| # Defines a Rust cfg flag with the value of the rust_panic build arg. |
| # Useful for changing behavior of code based on panic behavior. |
| config("panic_cfg") { |
| rustflags = [ "--cfg=rust_panic=\"${rust_panic}\"" ] |
| } |
| |
| # Turns on the rust compilation analysis generator. This will produce a |
| # directory $OUT/save-analysis-temp, which will dump all the source analysis |
| # that the compiler collected while analyzing the source. This config is |
| # included conditionally, see //build/config/BUILDCONFIG.gn for details. |
| config("analysis") { |
| rustflags = [ "-Zsave-analysis" ] |
| } |
| |
| config("edition_2021") { |
| rustflags = [ "--edition=2021" ] |
| } |
| |
| config("edition_2018") { |
| rustflags = [ "--edition=2018" ] |
| } |
| |
| config("edition_2015") { |
| rustflags = [ "--edition=2015" ] |
| } |
| |
| config("no_features") { |
| rustflags = [ "-Zallow-features=" ] |
| } |
| |
| config("incremental") { |
| if (rust_incremental != "") { |
| rustflags = [ "-Cincremental=" + rust_incremental ] |
| } |
| } |
| |
| config("one_codegen_unit") { |
| # Disable codegen parallelism. |
| # Trades incremental rebuild speed for smaller code size. |
| # See: fxbug.dev/74435, fxbug.dev/80514 |
| if (rust_incremental == "") { |
| rustflags = [ "-Ccodegen-units=1" ] |
| } |
| } |
| |
| config("codegen_units_16") { |
| # Enable default codegen parallelism (rustc default). |
| # This will increase code size over `:one_codegen_unit` above. |
| # |
| # Used without any lto option, this will also enable thin-local lto. |
| # https://doc.rust-lang.org/rustc/codegen-options/index.html#lto |
| if (rust_incremental == "") { |
| rustflags = [ "-Ccodegen-units=16" ] |
| } |
| } |
| |
| config("lto_disabled") { |
| # Fully disable lto. |
| # |
| # This is the default when -Ccodegen_units=1 or when optimizations are off |
| # (-Copt-level=0) |
| rustflags = [ "-Clto=off" ] |
| } |
| |
| config("lto_thin") { |
| # Enable "thin" lto across all crates being linked |
| rustflags = [ "-Clto=thin" ] |
| } |
| |
| # Best practices for Rust binaries that go into size-constrained bootfs. |
| config("bootfs") { |
| # Optimize for size. |
| # TODO(fxbug.dev/63313): use "z" when resolved. |
| rustflags = [ "-Copt-level=s" ] |
| |
| if (is_debug && # Debug builds produce large Rust binaries |
| max_fuchsia_zbi_size > 0) { # So large they might not fit in the ZBI |
| # Force ThinLTO to squeeze Rust binaries further. |
| # See: fxbug.dev/80514 |
| # See: fxbug.dev/91325 |
| configs = [ "//build/config/lto:thinlto" ] |
| } |
| |
| # Can't dynamically link libstd and libtest for ZBI binaries. |
| # TODO(fxbug.dev/83081): reconsider this. |
| rustflags += [ "-Cprefer-dynamic=no" ] |
| } |
| |
| config("proc_macro_test") { |
| rustflags = [ |
| "--extern", |
| "proc_macro", |
| ] |
| } |
| |
| config("2018_idioms") { |
| rustflags = [ "-Wrust-2018-idioms" ] |
| } |
| |
| config("target") { |
| rustflags = [ |
| "--target", |
| rust_target, |
| "--cap-lints=$rust_cap_lints", |
| ] |
| } |
| |
| config("panic_abort") { |
| rustflags = [ |
| "-Cpanic=abort", |
| "-Cforce-unwind-tables=yes", |
| "-Zpanic_abort_tests", |
| ] |
| } |
| |
| config("v0_symbol_mangling") { |
| if (rust_v0_symbol_mangling) { |
| rustflags = [ "-Csymbol-mangling-version=v0" ] |
| } |
| } |
| |
| config("allow_unknown_lints") { |
| rustflags = [ "-Aunknown-lints" ] |
| } |
| |
| # TODO(fxbug.dev/67118) remove this allowance |
| config("allow_redundant_semicolons") { |
| rustflags = [ "-Aredundant-semicolons" ] |
| } |
| |
| # TODO(fxbug.dev/69442) remove this allowance |
| config("allow_legacy_derive_helpers") { |
| rustflags = [ "-Alegacy-derive-helpers" ] |
| } |
| |
| config("deny_unused_results") { |
| rustflags = [ "-Dunused_results" ] |
| } |
| |
| config("allow_unused_results") { |
| rustflags = [ "-Aunused_results" ] |
| |
| # This visibility list allows for targets to opt out of allowing unused results. |
| # |
| # There is currently no platform mandate to adopt the unused_results lint and it's opt-in for |
| # developers that want to use it. See https://fxbug.dev/73468 for more context. |
| # |
| # To adopt the lint, add the following to your rust target: |
| # configs -= ["//build/config/rust:allow_unused_results"] |
| # The visibility list below can be used to enforce the list on certain areas of the tree while |
| # we evaluate wider adoption. |
| # |
| # To update this list run: |
| # $ scripts/gn/gen_visibility_globs.py \ |
| # --all=//build/config/rust:deny_unused_results \ |
| # --allow=//build/config/rust:allow_unused_results \ |
| # --ignore-suffix=-rustc,_banjo_rust |
| visibility = [ |
| "//build/*", |
| "//examples/*", |
| "//garnet/*", |
| "//sdk/*", |
| "//src/bringup/*", |
| "//src/camera/*", |
| "//src/cobalt/*", |
| "//src/connectivity/bluetooth/lib/bt-a2dp:*", |
| "//src/connectivity/location/*", |
| "//src/connectivity/lowpan/*", |
| "//src/connectivity/network/net-cli/ffx:*", |
| "//src/connectivity/network/netstack:networking_metrics_rustlib", |
| "//src/connectivity/network/testing/network-test-realm/ffx:*", |
| "//src/connectivity/openthread/*", |
| "//src/connectivity/overnet/*", |
| "//src/connectivity/ppp/*", |
| "//src/connectivity/telephony/*", |
| "//src/connectivity/weave/*", |
| "//src/connectivity/wlan/*", |
| "//src/developer/*", |
| "//src/devices/*", |
| "//src/diagnostics/*", |
| "//src/experiences/*", |
| "//src/factory/*", |
| "//src/fonts/*", |
| "//src/graphics/*", |
| "//src/hwinfo/*", |
| "//src/identity/*", |
| "//src/intl/*", |
| "//src/lib/*", |
| "//src/media/*", |
| "//src/modular/*", |
| "//src/power/*", |
| "//src/proc/*", |
| "//src/recovery/*", |
| "//src/security/*", |
| "//src/session/*", |
| "//src/settings/*", |
| "//src/storage/*", |
| "//src/sys/*", |
| "//src/testing/*", |
| "//src/tests/*", |
| "//src/ui/*", |
| "//src/virtualization/*", |
| "//src/zircon/*", |
| "//third_party/*", |
| "//tools/*", |
| "//vendor/*", |
| "//zircon/*", |
| ] |
| } |
| |
| config("coverage") { |
| rustflags = [ "-Cinstrument-coverage" ] |
| } |
| |
| # TODO(fxbug.dev/94355): Eliminate or identify all sources of output dir leaks. |
| # This option makes it explicit that a particular build action is sensitive |
| # to the output dir path, and informs remote execution to refrain from |
| # normalizing the output dir, which improves caching. |
| # As a goal, we should aim to minimize the need for this config. |
| config("output_dir_sensitive") { |
| if (rust_rbe_enable) { |
| # --remote-flag=* is a pseudo flag that is intercepted by |
| # build/rbe/rustc-remote-wrapper.sh and forwarded to rewrapper (reclient). |
| rustflags = [ "--remote-flag=--canonicalize_working_dir=false" ] |
| } |
| } |
| |
| # Unstable features |
| # |
| # These configs enable unstable Rust features. Configs that enable unstable |
| # features must go through an approval process before they may be added. See: |
| # https://fuchsia.dev/fuchsia-src/development/languages/rust/unstable#the_process |
| # |
| # When adding a new config, make sure to add a TODO with a link to the tracking |
| # issue. |
| |
| # TODO(fxbug.dev/98399) |
| config("netstack3_only_specialization_feature") { |
| rustflags = [ |
| "-Zallow-features=min_specialization,specialization", |
| "-Aincomplete-features", |
| ] |
| } |
| |
| # TODO(fxbug.dev/94237) |
| config("allow_simd") { |
| rustflags = [ "-Zallow-features=stdsimd,aarch64_target_feature" ] |
| } |
| |
| # TODO(fxbug.dev/103193) |
| config("allow_non_exhaustive_omitted_patterns_lint") { |
| rustflags = [ "-Zallow-features=non_exhaustive_omitted_patterns_lint" ] |
| visibility = |
| [ "//src/connectivity/network/netstack3/core/specialize-ip-macro:*" ] |
| } |