Skip to content

Commit

Permalink
Pass -Zforce-unstable-if-unmarked to std build crates
Browse files Browse the repository at this point in the history
This flag is important: it prevents regular crates from accidentally
requesting symbols from std-internal deps. We will likely need to
provide custom metadata at some point too, since this fixes only the
rustc side and not the linking side.

The option is passed via a new gnrt_config.toml section.

Bug: 1368806
Change-Id: If2a843216a0fb39d9263a27ca05597a012c6eb2d

Cq-Include-Trybots: luci.chromium.try:android-rust-arm32-rel,android-rust-arm64-dbg,android-rust-arm64-rel,linux-rust-x64-dbg,linux-rust-x64-rel
Change-Id: If2a843216a0fb39d9263a27ca05597a012c6eb2d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4351043
Auto-Submit: Collin Baker <collinbaker@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1120050}
  • Loading branch information
chbaker0 authored and Chromium LUCI CQ committed Mar 21, 2023
1 parent a1a555b commit 81e6574
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 96 deletions.
14 changes: 11 additions & 3 deletions build/rust/std/gnrt_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

[libc]
# Provides per-crate and overall configuration options to gnrt.

[all]
# 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']

[crate.libc]
# Requires:
# * cfg(libc_align) for new enough rustc, which is normally provided by build.rs
# but we don't run build scripts for std crates.
Expand All @@ -12,7 +20,7 @@
# See https://github.com/rust-lang/libc/blob/master/build.rs
cfg = ['libc_align', 'libc_priv_mod_use', 'libc_core_cvoid']

[std]
[crate.std]
# Requires:
# * cfg(backtrace_in_libstd) because it directly includes .rs files from the
# backtrace code rather than including it as a dependency. backtrace's
Expand All @@ -25,7 +33,7 @@ cfg = ['libc_align', 'libc_priv_mod_use', 'libc_core_cvoid']
cfg = ['backtrace_in_libstd']
env = ['STD_ENV_ARCH=$rust_target_arch']

[test]
[crate.test]
# Requires:
# * CFG_DISABLE_UNSTABLE_FEATURES=0 to match how it's built by x.py.
env = ['CFG_DISABLE_UNSTABLE_FEATURES=0']
32 changes: 30 additions & 2 deletions build/rust/std/rules/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ cargo_crate("addr2line") {
"core",
"rustc-dep-of-std",
]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("adler") {
crate_type = "rlib"
Expand Down Expand Up @@ -68,6 +69,7 @@ cargo_crate("adler") {
"core",
"rustc-dep-of-std",
]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("alloc") {
crate_type = "rlib"
Expand All @@ -89,6 +91,7 @@ cargo_crate("alloc") {
":compiler_builtins",
":core",
]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("cc") {
crate_type = "rlib"
Expand All @@ -107,6 +110,7 @@ cargo_crate("cc") {
library_configs += [ "//build/config/compiler:no_chromium_code" ]
executable_configs -= [ "//build/config/compiler:chromium_code" ]
executable_configs += [ "//build/config/compiler:no_chromium_code" ]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("cfg_if") {
crate_type = "rlib"
Expand Down Expand Up @@ -137,6 +141,7 @@ cargo_crate("cfg_if") {
"core",
"rustc-dep-of-std",
]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("compiler_builtins") {
crate_type = "rlib"
Expand Down Expand Up @@ -164,6 +169,7 @@ cargo_crate("compiler_builtins") {
"core",
"rustc-dep-of-std",
]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("core") {
crate_type = "rlib"
Expand All @@ -183,6 +189,7 @@ cargo_crate("core") {
library_configs += [ "//build/config/compiler:no_chromium_code" ]
executable_configs -= [ "//build/config/compiler:chromium_code" ]
executable_configs += [ "//build/config/compiler:no_chromium_code" ]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("getopts") {
crate_type = "rlib"
Expand Down Expand Up @@ -215,6 +222,7 @@ cargo_crate("getopts") {
"rustc-dep-of-std",
"std",
]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("gimli") {
crate_type = "rlib"
Expand Down Expand Up @@ -250,6 +258,7 @@ cargo_crate("gimli") {
"read-core",
"rustc-dep-of-std",
]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("hashbrown") {
crate_type = "rlib"
Expand Down Expand Up @@ -285,6 +294,7 @@ cargo_crate("hashbrown") {
"rustc-dep-of-std",
"rustc-internal-api",
]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("libc") {
crate_type = "rlib"
Expand Down Expand Up @@ -313,6 +323,7 @@ cargo_crate("libc") {
"--cfg=libc_align",
"--cfg=libc_priv_mod_use",
"--cfg=libc_core_cvoid",
"-Zforce-unstable-if-unmarked",
]
}
cargo_crate("memchr") {
Expand Down Expand Up @@ -344,6 +355,7 @@ cargo_crate("memchr") {
"core",
"rustc-dep-of-std",
]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("miniz_oxide") {
crate_type = "rlib"
Expand Down Expand Up @@ -378,6 +390,7 @@ cargo_crate("miniz_oxide") {
"core",
"rustc-dep-of-std",
]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("object") {
crate_type = "rlib"
Expand Down Expand Up @@ -419,6 +432,7 @@ cargo_crate("object") {
"rustc-dep-of-std",
"unaligned",
]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("panic_abort") {
crate_type = "rlib"
Expand All @@ -443,6 +457,7 @@ cargo_crate("panic_abort") {
":core",
":libc",
]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("panic_unwind") {
crate_type = "rlib"
Expand All @@ -468,6 +483,7 @@ cargo_crate("panic_unwind") {
":libc",
":unwind",
]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("proc_macro") {
crate_type = "rlib"
Expand All @@ -488,6 +504,7 @@ cargo_crate("proc_macro") {
":core",
":std",
]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("profiler_builtins") {
crate_type = "rlib"
Expand All @@ -509,6 +526,7 @@ cargo_crate("profiler_builtins") {
":core",
]
build_deps = [ ":cc" ]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("rustc_demangle") {
crate_type = "rlib"
Expand Down Expand Up @@ -539,6 +557,7 @@ cargo_crate("rustc_demangle") {
"core",
"rustc-dep-of-std",
]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("rustc_std_workspace_alloc") {
crate_type = "rlib"
Expand All @@ -557,6 +576,7 @@ cargo_crate("rustc_std_workspace_alloc") {
executable_configs -= [ "//build/config/compiler:chromium_code" ]
executable_configs += [ "//build/config/compiler:no_chromium_code" ]
deps = [ ":alloc" ]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("rustc_std_workspace_core") {
crate_type = "rlib"
Expand All @@ -575,6 +595,7 @@ cargo_crate("rustc_std_workspace_core") {
executable_configs -= [ "//build/config/compiler:chromium_code" ]
executable_configs += [ "//build/config/compiler:no_chromium_code" ]
deps = [ ":core" ]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("rustc_std_workspace_std") {
crate_type = "rlib"
Expand All @@ -593,6 +614,7 @@ cargo_crate("rustc_std_workspace_std") {
executable_configs -= [ "//build/config/compiler:chromium_code" ]
executable_configs += [ "//build/config/compiler:no_chromium_code" ]
deps = [ ":std" ]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("std") {
crate_type = "rlib"
Expand Down Expand Up @@ -642,8 +664,11 @@ cargo_crate("std") {
"std_detect_dlsym_getauxval",
"std_detect_file_io",
]
rustflags = [ "--cfg=backtrace_in_libstd" ]
rustenv = [ "STD_ENV_ARCH=$rust_target_arch" ]
rustflags = [
"--cfg=backtrace_in_libstd",
"-Zforce-unstable-if-unmarked",
]
}
cargo_crate("std_detect") {
crate_type = "rlib"
Expand Down Expand Up @@ -683,6 +708,7 @@ cargo_crate("std_detect") {
"std_detect_dlsym_getauxval",
"std_detect_file_io",
]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("test") {
crate_type = "rlib"
Expand All @@ -709,8 +735,8 @@ cargo_crate("test") {
":proc_macro",
":std",
]

rustenv = [ "CFG_DISABLE_UNSTABLE_FEATURES=0" ]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("unicode_width") {
crate_type = "rlib"
Expand Down Expand Up @@ -745,6 +771,7 @@ cargo_crate("unicode_width") {
"rustc-dep-of-std",
"std",
]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
cargo_crate("unwind") {
crate_type = "rlib"
Expand All @@ -768,4 +795,5 @@ cargo_crate("unwind") {
":libc",
]
build_deps = [ ":cc" ]
rustflags = [ "-Zforce-unstable-if-unmarked" ]
}
2 changes: 1 addition & 1 deletion third_party/rust/which/v4/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cargo_crate("lib") {
cargo_pkg_version = "4.3.0"
cargo_pkg_authors = "Harry Fei <tiziyuanfang@gmail.com>"
cargo_pkg_name = "which"
cargo_pkg_description = "A Rust equivalent of Unix command 'which'. Locate installed executable in cross platforms."
cargo_pkg_description = "A Rust equivalent of Unix command \"which\". Locate installed executable in cross platforms."
library_configs -= [ "//build/config/compiler:chromium_code" ]
library_configs += [ "//build/config/compiler:no_chromium_code" ]
executable_configs -= [ "//build/config/compiler:chromium_code" ]
Expand Down
25 changes: 16 additions & 9 deletions tools/crates/gnrt/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,27 @@ use std::collections::BTreeMap;

use serde::Deserialize;

/// Extra GN configuration for targets. Contains one entry for each crate with
/// custom config.
/// Customizes GN output for a session.
#[derive(Clone, Debug, Deserialize)]
pub struct ConfigFile {
#[serde(flatten)]
pub per_lib_config: BTreeMap<String, PerLibConfig>,
pub struct BuildConfig {
/// Configuration that applies to all crates
#[serde(default, rename = "all")]
pub all_config: CrateConfig,
/// Additional configuration options for specific crates. Keyed by crate
/// name. Config is additive with `all_config`.
#[serde(rename = "crate")]
pub per_crate_config: BTreeMap<String, CrateConfig>,
}

#[derive(Clone, Debug, Deserialize)]
pub struct PerLibConfig {
/// List of `cfg(...)` options for building this crate.
#[derive(Clone, Debug, Default, Deserialize)]
pub struct CrateConfig {
/// `cfg(...)` options for building this crate.
#[serde(default)]
pub cfg: Vec<String>,
/// List of compile-time environment variables for this crate.
/// Compile-time environment variables for this crate.
#[serde(default)]
pub env: Vec<String>,
/// Extra rustc flags.
#[serde(default)]
pub rustflags: Vec<String>,
}
Loading

0 comments on commit 81e6574

Please sign in to comment.