# Copyright 2023 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. # Provides per-crate and overall configuration options to gnrt. [resolve] # There is a virtual "sysroot" crate that includes all sysroot libraries as # dependencies. root = "sysroot" # Workaround for Cargo issue: hashbrown's Cargo.toml uses an unstable Cargo # feature that leads to incorrect `cargo metadata` output. # # TODO(https://github.com/rust-lang/cargo/issues/10801): remove workaround once # issue is fixed. remove_crates = ['allocator-api2'] [all-crates] # std crates should have metadata applied to them. This would avoid any symbol # conflicts between std dependencies and third_party/rust crates. # # However, we can't apply it yet. GN can't automatically clean old artifacts, # nor can we delete and rebuild the sysroot on every build. # # TODO(crbug.com/1245714): set up GN rules to rebuilt the sysroot only when # needed. Then set this metadata. # # rustc_metadata = "libstd" # force-unstable-if-unmarked prevents normal crates from inadvertently using # symbols from std-internal dependencies in the sysroot. This is normally passed # during an x.py build, but we have to do it manually. rustflags = ['-Zforce-unstable-if-unmarked'] # Override the GN output dir. We direct std targets to output directly to the # sysroot we'll use later. This must stay in sync with `local_rustc_sysroot` in # //build/rust/std/BUILD.gn output_dir = '$root_out_dir/local_rustc_sysroot/lib/rustlib/$rust_abi_target/lib/' # This target provides setup needed for building std. extra_gn_deps = [ '//build/rust/std:std_build_deps', '//build/rust/std:profiler_builtins_group', ] [crate.compiler_builtins] features = ['weak-intrinsics'] # Dependencies of profiler_builtins must have instrumentation disabled remove_library_configs = ['//build/config/coverage:default_coverage'] extra_gn_deps_to_ignore = ['//build/rust/std:profiler_builtins_group'] [crate.core] # Dependencies of profiler_builtins must have instrumentation disabled remove_library_configs = ['//build/config/coverage:default_coverage'] extra_gn_deps_to_ignore = ['//build/rust/std:profiler_builtins_group'] add_library_configs = ['//build/rust:panic_immediate_abort'] extra_src_roots = ['../../portable-simd/crates/core_simd', '../../stdarch/crates/core_arch'] extra_input_roots = ['../primitive_docs'] [crate.hashbrown] # Workaround for Cargo issue: hashbrown's Cargo.toml uses an unstable Cargo # feature that leads to incorrect `cargo metadata` output. # # TODO(https://github.com/rust-lang/cargo/issues/10801): remove workaround once # issue is fixed. remove_deps = ['allocator-api2'] [crate.libc] # The libc crate tries to link in the Windows CRT, but we specify the CRT # library ourselves in //build/config/win:dynamic_crt and # //build/config/win:static_crt because Rustc does not allow us to specify # using the debug CRT: https://github.com/rust-lang/rust/issues/39016 rustflags = ['-Zlink-directives=false'] # This target is #[no_core] when included by std, which is incompatible with # profiling. remove_library_configs = ['//build/config/coverage:default_coverage'] extra_gn_deps_to_ignore = ['//build/rust/std:profiler_builtins_group'] [crate.profiler_builtins] # The build script is used to compile a profiler-rt library, but we get # the profiler rt library from clang, so we skip this. skip_build_rs = true # profiler_builtins cannot depend on itself, which it would if build with # instrumentation. remove_library_configs = ['//build/config/coverage:default_coverage'] extra_gn_deps_to_ignore = ['//build/rust/std:profiler_builtins_group'] [crate.rustc-std-workspace-alloc] # This target is #[no_core] which is incompatible with profiling. remove_library_configs = ['//build/config/coverage:default_coverage'] extra_gn_deps_to_ignore = ['//build/rust/std:profiler_builtins_group'] [crate.rustc-std-workspace-core] # Dependencies of profiler_builtins must have instrumentation disabled remove_library_configs = ['//build/config/coverage:default_coverage'] extra_gn_deps_to_ignore = ['//build/rust/std:profiler_builtins_group'] [crate.std] # Requires: # * STD_ENV_ARCH is referenced in architecture-dependent code. Note this is the # target arch, and as such `$rust_target_arch` is passed literally to GN. This # variable is set at build time in build/config/rust.gni # # See https://github.com/rust-lang/rust/blob/master/library/std/build.rs # # TODO(crbug.com/1448880): Our cargo emulation should use `cargo:rustc-env` # to set the environment for the crate, then this goes away. cfg = ['backtrace_in_libstd'] env = ['STD_ENV_ARCH=$rust_target_arch'] add_library_configs = ['//build/rust:panic_immediate_abort'] extra_src_roots = ['../../backtrace/src', '../../portable-simd/crates/std_float/src'] extra_input_roots = ['../primitive_docs', '../../core/src', '../../portable-simd/crates/core_simd/src', '../../stdarch/crates/core_arch/src'] # Remove this from std. It will be depended on directly when needed. exclude_deps_in_gn = ['profiler_builtins'] [crate.test] # Requires: # * CFG_DISABLE_UNSTABLE_FEATURES=0 to match how it's built by x.py. env = ['CFG_DISABLE_UNSTABLE_FEATURES=0'] # test only depends on proc_macro as an internal detail of the Rust build, so # it's implicitly included with std/test. However, we list the std crates and # construct the sysroot explicitly. We don't need this, and we don't even want # it during cross-compiles (since we will only build host proc_macro crates). exclude_deps_in_gn = ['proc_macro'] [crate.unwind] # The build script is used to set up the link directives which we skip below. # It uses `cc` to run a compiler to do so, which we don't support in build # scripts. skip_build_rs = true # The unwind crate has #[link] directives to the native unwind library, but we # either get that automatically by linking with clang++, or build and link the # lib from //buildtools/third_party/libunsind explicitly. Disable -lfoo linker # flags from this crate. rustflags = ['-Zlink-directives=false']