1# Copyright 2023 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5# Provides per-crate and overall configuration options to gnrt. 6 7[resolve] 8# There is a virtual "sysroot" crate that includes all sysroot libraries as 9# dependencies. 10root = "sysroot" 11 12# Workaround for Cargo issue: hashbrown's Cargo.toml uses an unstable Cargo 13# feature that leads to incorrect `cargo metadata` output. 14# 15# TODO(https://github.com/rust-lang/cargo/issues/10801): remove workaround once 16# issue is fixed. 17remove_crates = ['allocator-api2'] 18 19[all-crates] 20# std crates should have metadata applied to them. This would avoid any symbol 21# conflicts between std dependencies and third_party/rust crates. 22# 23# However, we can't apply it yet. GN can't automatically clean old artifacts, 24# nor can we delete and rebuild the sysroot on every build. 25# 26# TODO(crbug.com/1245714): set up GN rules to rebuilt the sysroot only when 27# needed. Then set this metadata. 28# 29# rustc_metadata = "libstd" 30 31# force-unstable-if-unmarked prevents normal crates from inadvertently using 32# symbols from std-internal dependencies in the sysroot. This is normally passed 33# during an x.py build, but we have to do it manually. 34rustflags = ['-Zforce-unstable-if-unmarked'] 35 36# Override the GN output dir. We direct std targets to output directly to the 37# sysroot we'll use later. This must stay in sync with `local_rustc_sysroot` in 38# //build/rust/std/BUILD.gn 39output_dir = '$root_out_dir/local_rustc_sysroot/lib/rustlib/$rust_abi_target/lib/' 40 41# This target provides setup needed for building std. 42extra_gn_deps = [ 43 '//build/rust/std:std_build_deps', 44 '//build/rust/std:profiler_builtins_group', 45] 46 47[crate.compiler_builtins] 48features = ['weak-intrinsics'] 49# Dependencies of profiler_builtins must have instrumentation disabled 50remove_library_configs = ['//build/config/coverage:default_coverage'] 51extra_gn_deps_to_ignore = ['//build/rust/std:profiler_builtins_group'] 52 53[crate.core] 54# Dependencies of profiler_builtins must have instrumentation disabled 55remove_library_configs = ['//build/config/coverage:default_coverage'] 56extra_gn_deps_to_ignore = ['//build/rust/std:profiler_builtins_group'] 57add_library_configs = ['//build/rust:panic_immediate_abort'] 58extra_src_roots = ['../../portable-simd/crates/core_simd', '../../stdarch/crates/core_arch'] 59extra_input_roots = ['../primitive_docs'] 60 61[crate.hashbrown] 62# Workaround for Cargo issue: hashbrown's Cargo.toml uses an unstable Cargo 63# feature that leads to incorrect `cargo metadata` output. 64# 65# TODO(https://github.com/rust-lang/cargo/issues/10801): remove workaround once 66# issue is fixed. 67remove_deps = ['allocator-api2'] 68 69[crate.libc] 70# The libc crate tries to link in the Windows CRT, but we specify the CRT 71# library ourselves in //build/config/win:dynamic_crt and 72# //build/config/win:static_crt because Rustc does not allow us to specify 73# using the debug CRT: https://github.com/rust-lang/rust/issues/39016 74rustflags = ['-Zlink-directives=false'] 75 76# This target is #[no_core] when included by std, which is incompatible with 77# profiling. 78remove_library_configs = ['//build/config/coverage:default_coverage'] 79extra_gn_deps_to_ignore = ['//build/rust/std:profiler_builtins_group'] 80 81[crate.profiler_builtins] 82# The build script is used to compile a profiler-rt library, but we get 83# the profiler rt library from clang, so we skip this. 84skip_build_rs = true 85# profiler_builtins cannot depend on itself, which it would if build with 86# instrumentation. 87remove_library_configs = ['//build/config/coverage:default_coverage'] 88extra_gn_deps_to_ignore = ['//build/rust/std:profiler_builtins_group'] 89 90[crate.rustc-std-workspace-alloc] 91# This target is #[no_core] which is incompatible with profiling. 92remove_library_configs = ['//build/config/coverage:default_coverage'] 93extra_gn_deps_to_ignore = ['//build/rust/std:profiler_builtins_group'] 94 95[crate.rustc-std-workspace-core] 96# Dependencies of profiler_builtins must have instrumentation disabled 97remove_library_configs = ['//build/config/coverage:default_coverage'] 98extra_gn_deps_to_ignore = ['//build/rust/std:profiler_builtins_group'] 99 100[crate.std] 101# Requires: 102# * STD_ENV_ARCH is referenced in architecture-dependent code. Note this is the 103# target arch, and as such `$rust_target_arch` is passed literally to GN. This 104# variable is set at build time in build/config/rust.gni 105# 106# See https://github.com/rust-lang/rust/blob/master/library/std/build.rs 107# 108# TODO(crbug.com/1448880): Our cargo emulation should use `cargo:rustc-env` 109# to set the environment for the crate, then this goes away. 110cfg = ['backtrace_in_libstd'] 111env = ['STD_ENV_ARCH=$rust_target_arch'] 112add_library_configs = ['//build/rust:panic_immediate_abort'] 113extra_src_roots = ['../../backtrace/src', '../../portable-simd/crates/std_float/src'] 114extra_input_roots = ['../primitive_docs', '../../core/src', '../../portable-simd/crates/core_simd/src', '../../stdarch/crates/core_arch/src'] 115 116# Remove this from std. It will be depended on directly when needed. 117exclude_deps_in_gn = ['profiler_builtins'] 118 119[crate.test] 120# Requires: 121# * CFG_DISABLE_UNSTABLE_FEATURES=0 to match how it's built by x.py. 122env = ['CFG_DISABLE_UNSTABLE_FEATURES=0'] 123 124# test only depends on proc_macro as an internal detail of the Rust build, so 125# it's implicitly included with std/test. However, we list the std crates and 126# construct the sysroot explicitly. We don't need this, and we don't even want 127# it during cross-compiles (since we will only build host proc_macro crates). 128exclude_deps_in_gn = ['proc_macro'] 129 130[crate.unwind] 131# The build script is used to set up the link directives which we skip below. 132# It uses `cc` to run a compiler to do so, which we don't support in build 133# scripts. 134skip_build_rs = true 135# The unwind crate has #[link] directives to the native unwind library, but we 136# either get that automatically by linking with clang++, or build and link the 137# lib from //buildtools/third_party/libunsind explicitly. Disable -lfoo linker 138# flags from this crate. 139rustflags = ['-Zlink-directives=false'] 140