Auto merge of #134865 - clubby789:proc-macro-tls, r=onur-ozkan
bootstrap: Don't apply -Ztls-model=initial-exec to deps of proc-macros Fixes #134863 1. Checks if a crate name is in a static list before applying the flag 2. Adds a tidy check that gathers transitive deps of proc macros and ensures the list is up to date cc `@bjorn3` - the issue specifies `rustc_fluent_macro` but I assume this applies to all proc macro crates.
This commit is contained in:
commit
c1566141b6
6 changed files with 171 additions and 12 deletions
28
Cargo.lock
28
Cargo.lock
|
@ -367,7 +367,7 @@ dependencies = [
|
||||||
name = "cargo-miri"
|
name = "cargo-miri"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo_metadata",
|
"cargo_metadata 0.18.1",
|
||||||
"directories",
|
"directories",
|
||||||
"rustc-build-sysroot",
|
"rustc-build-sysroot",
|
||||||
"rustc_tools_util",
|
"rustc_tools_util",
|
||||||
|
@ -399,6 +399,20 @@ dependencies = [
|
||||||
"thiserror 1.0.69",
|
"thiserror 1.0.69",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cargo_metadata"
|
||||||
|
version = "0.19.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8769706aad5d996120af43197bf46ef6ad0fda35216b4505f926a365a232d924"
|
||||||
|
dependencies = [
|
||||||
|
"camino",
|
||||||
|
"cargo-platform",
|
||||||
|
"semver",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"thiserror 2.0.9",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cargotest2"
|
name = "cargotest2"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -533,7 +547,7 @@ name = "clippy"
|
||||||
version = "0.1.85"
|
version = "0.1.85"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstream",
|
"anstream",
|
||||||
"cargo_metadata",
|
"cargo_metadata 0.18.1",
|
||||||
"clippy_config",
|
"clippy_config",
|
||||||
"clippy_lints",
|
"clippy_lints",
|
||||||
"clippy_utils",
|
"clippy_utils",
|
||||||
|
@ -589,7 +603,7 @@ name = "clippy_lints"
|
||||||
version = "0.1.85"
|
version = "0.1.85"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
"cargo_metadata",
|
"cargo_metadata 0.18.1",
|
||||||
"clippy_config",
|
"clippy_config",
|
||||||
"clippy_utils",
|
"clippy_utils",
|
||||||
"itertools",
|
"itertools",
|
||||||
|
@ -1389,7 +1403,7 @@ name = "generate-copyright"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cargo_metadata",
|
"cargo_metadata 0.18.1",
|
||||||
"rinja",
|
"rinja",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
@ -4750,7 +4764,7 @@ dependencies = [
|
||||||
"annotate-snippets 0.9.2",
|
"annotate-snippets 0.9.2",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bytecount",
|
"bytecount",
|
||||||
"cargo_metadata",
|
"cargo_metadata 0.18.1",
|
||||||
"clap",
|
"clap",
|
||||||
"clap-cargo",
|
"clap-cargo",
|
||||||
"diff",
|
"diff",
|
||||||
|
@ -5344,7 +5358,7 @@ name = "tidy"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"build_helper",
|
"build_helper",
|
||||||
"cargo_metadata",
|
"cargo_metadata 0.19.1",
|
||||||
"fluent-syntax",
|
"fluent-syntax",
|
||||||
"ignore",
|
"ignore",
|
||||||
"miropt-test-tools",
|
"miropt-test-tools",
|
||||||
|
@ -5622,7 +5636,7 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bstr",
|
"bstr",
|
||||||
"cargo-platform",
|
"cargo-platform",
|
||||||
"cargo_metadata",
|
"cargo_metadata 0.18.1",
|
||||||
"color-eyre",
|
"color-eyre",
|
||||||
"colored",
|
"colored",
|
||||||
"comma",
|
"comma",
|
||||||
|
|
|
@ -28,6 +28,9 @@ use shared_helpers::{
|
||||||
#[path = "../utils/shared_helpers.rs"]
|
#[path = "../utils/shared_helpers.rs"]
|
||||||
mod shared_helpers;
|
mod shared_helpers;
|
||||||
|
|
||||||
|
#[path = "../utils/proc_macro_deps.rs"]
|
||||||
|
mod proc_macro_deps;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let orig_args = env::args_os().skip(1).collect::<Vec<_>>();
|
let orig_args = env::args_os().skip(1).collect::<Vec<_>>();
|
||||||
let mut args = orig_args.clone();
|
let mut args = orig_args.clone();
|
||||||
|
@ -167,7 +170,7 @@ fn main() {
|
||||||
// issue https://github.com/rust-lang/rust/issues/100530
|
// issue https://github.com/rust-lang/rust/issues/100530
|
||||||
if env::var("RUSTC_TLS_MODEL_INITIAL_EXEC").is_ok()
|
if env::var("RUSTC_TLS_MODEL_INITIAL_EXEC").is_ok()
|
||||||
&& crate_type != Some("proc-macro")
|
&& crate_type != Some("proc-macro")
|
||||||
&& !matches!(crate_name, Some("proc_macro2" | "quote" | "syn" | "synstructure"))
|
&& proc_macro_deps::CRATES.binary_search(&crate_name.unwrap_or_default()).is_err()
|
||||||
{
|
{
|
||||||
cmd.arg("-Ztls-model=initial-exec");
|
cmd.arg("-Ztls-model=initial-exec");
|
||||||
}
|
}
|
||||||
|
|
71
src/bootstrap/src/utils/proc_macro_deps.rs
Normal file
71
src/bootstrap/src/utils/proc_macro_deps.rs
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
/// Do not update manually - use `./x.py test tidy --bless`
|
||||||
|
/// Holds all direct and indirect dependencies of proc-macro crates in tree.
|
||||||
|
/// See <https://github.com/rust-lang/rust/issues/134863>
|
||||||
|
pub static CRATES: &[&str] = &[
|
||||||
|
// tidy-alphabetical-start
|
||||||
|
"annotate-snippets",
|
||||||
|
"anstyle",
|
||||||
|
"basic-toml",
|
||||||
|
"block-buffer",
|
||||||
|
"bumpalo",
|
||||||
|
"cfg-if",
|
||||||
|
"cpufeatures",
|
||||||
|
"crypto-common",
|
||||||
|
"darling",
|
||||||
|
"darling_core",
|
||||||
|
"derive_builder_core",
|
||||||
|
"digest",
|
||||||
|
"fluent-bundle",
|
||||||
|
"fluent-langneg",
|
||||||
|
"fluent-syntax",
|
||||||
|
"fnv",
|
||||||
|
"generic-array",
|
||||||
|
"heck",
|
||||||
|
"ident_case",
|
||||||
|
"intl-memoizer",
|
||||||
|
"intl_pluralrules",
|
||||||
|
"libc",
|
||||||
|
"log",
|
||||||
|
"memchr",
|
||||||
|
"mime",
|
||||||
|
"mime_guess",
|
||||||
|
"minimal-lexical",
|
||||||
|
"nom",
|
||||||
|
"num-conv",
|
||||||
|
"once_cell",
|
||||||
|
"pest",
|
||||||
|
"pest_generator",
|
||||||
|
"pest_meta",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"rinja_parser",
|
||||||
|
"rustc-hash",
|
||||||
|
"self_cell",
|
||||||
|
"serde",
|
||||||
|
"sha2",
|
||||||
|
"smallvec",
|
||||||
|
"stable_deref_trait",
|
||||||
|
"strsim",
|
||||||
|
"syn",
|
||||||
|
"synstructure",
|
||||||
|
"thiserror",
|
||||||
|
"time-core",
|
||||||
|
"tinystr",
|
||||||
|
"type-map",
|
||||||
|
"typenum",
|
||||||
|
"ucd-trie",
|
||||||
|
"unic-langid",
|
||||||
|
"unic-langid-impl",
|
||||||
|
"unic-langid-macros",
|
||||||
|
"unicase",
|
||||||
|
"unicode-ident",
|
||||||
|
"unicode-width",
|
||||||
|
"version_check",
|
||||||
|
"wasm-bindgen-backend",
|
||||||
|
"wasm-bindgen-macro-support",
|
||||||
|
"wasm-bindgen-shared",
|
||||||
|
"yoke",
|
||||||
|
"zerofrom",
|
||||||
|
"zerovec",
|
||||||
|
// tidy-alphabetical-end
|
||||||
|
];
|
|
@ -6,7 +6,7 @@ autobins = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
build_helper = { path = "../../build_helper" }
|
build_helper = { path = "../../build_helper" }
|
||||||
cargo_metadata = "0.18"
|
cargo_metadata = "0.19"
|
||||||
regex = "1"
|
regex = "1"
|
||||||
miropt-test-tools = { path = "../miropt-test-tools" }
|
miropt-test-tools = { path = "../miropt-test-tools" }
|
||||||
walkdir = "2"
|
walkdir = "2"
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
//! Checks the licenses of third-party dependencies.
|
//! Checks the licenses of third-party dependencies.
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::fs::read_dir;
|
use std::fs::{File, read_dir};
|
||||||
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use build_helper::ci::CiEnv;
|
use build_helper::ci::CiEnv;
|
||||||
use cargo_metadata::{Metadata, Package, PackageId};
|
use cargo_metadata::{Metadata, Package, PackageId};
|
||||||
|
|
||||||
|
#[path = "../../../bootstrap/src/utils/proc_macro_deps.rs"]
|
||||||
|
mod proc_macro_deps;
|
||||||
|
|
||||||
/// These are licenses that are allowed for all crates, including the runtime,
|
/// These are licenses that are allowed for all crates, including the runtime,
|
||||||
/// rustc, tools, etc.
|
/// rustc, tools, etc.
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
|
@ -564,9 +568,11 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[
|
||||||
///
|
///
|
||||||
/// `root` is path to the directory with the root `Cargo.toml` (for the workspace). `cargo` is path
|
/// `root` is path to the directory with the root `Cargo.toml` (for the workspace). `cargo` is path
|
||||||
/// to the cargo executable.
|
/// to the cargo executable.
|
||||||
pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
|
pub fn check(root: &Path, cargo: &Path, bless: bool, bad: &mut bool) {
|
||||||
let mut checked_runtime_licenses = false;
|
let mut checked_runtime_licenses = false;
|
||||||
|
|
||||||
|
check_proc_macro_dep_list(root, cargo, bless, bad);
|
||||||
|
|
||||||
for &(workspace, exceptions, permitted_deps, submodules) in WORKSPACES {
|
for &(workspace, exceptions, permitted_deps, submodules) in WORKSPACES {
|
||||||
if has_missing_submodule(root, submodules) {
|
if has_missing_submodule(root, submodules) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -600,6 +606,71 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
|
||||||
assert!(checked_runtime_licenses);
|
assert!(checked_runtime_licenses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Ensure the list of proc-macro crate transitive dependencies is up to date
|
||||||
|
fn check_proc_macro_dep_list(root: &Path, cargo: &Path, bless: bool, bad: &mut bool) {
|
||||||
|
let mut cmd = cargo_metadata::MetadataCommand::new();
|
||||||
|
cmd.cargo_path(cargo)
|
||||||
|
.manifest_path(root.join("Cargo.toml"))
|
||||||
|
.features(cargo_metadata::CargoOpt::AllFeatures)
|
||||||
|
.other_options(vec!["--locked".to_owned()]);
|
||||||
|
let metadata = t!(cmd.exec());
|
||||||
|
let is_proc_macro_pkg = |pkg: &Package| pkg.targets.iter().any(|target| target.is_proc_macro());
|
||||||
|
|
||||||
|
let mut proc_macro_deps = HashSet::new();
|
||||||
|
for pkg in metadata.packages.iter().filter(|pkg| is_proc_macro_pkg(*pkg)) {
|
||||||
|
deps_of(&metadata, &pkg.id, &mut proc_macro_deps);
|
||||||
|
}
|
||||||
|
// Remove the proc-macro crates themselves
|
||||||
|
proc_macro_deps.retain(|pkg| !is_proc_macro_pkg(&metadata[pkg]));
|
||||||
|
let proc_macro_deps_iter = proc_macro_deps.into_iter().map(|dep| metadata[dep].name.clone());
|
||||||
|
|
||||||
|
if bless {
|
||||||
|
let mut proc_macro_deps: Vec<_> = proc_macro_deps_iter.collect();
|
||||||
|
proc_macro_deps.sort();
|
||||||
|
proc_macro_deps.dedup();
|
||||||
|
let mut file = File::create(root.join("src/bootstrap/src/utils/proc_macro_deps.rs"))
|
||||||
|
.expect("`proc_macro_deps` should exist");
|
||||||
|
writeln!(
|
||||||
|
&mut file,
|
||||||
|
"/// Do not update manually - use `./x.py test tidy --bless`
|
||||||
|
/// Holds all direct and indirect dependencies of proc-macro crates in tree.
|
||||||
|
/// See <https://github.com/rust-lang/rust/issues/134863>
|
||||||
|
pub static CRATES: &[&str] = &[
|
||||||
|
// tidy-alphabetical-start"
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
for dep in proc_macro_deps {
|
||||||
|
writeln!(&mut file, " {dep:?},").unwrap();
|
||||||
|
}
|
||||||
|
writeln!(
|
||||||
|
&mut file,
|
||||||
|
" // tidy-alphabetical-end
|
||||||
|
];"
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
} else {
|
||||||
|
let proc_macro_deps: HashSet<_> = proc_macro_deps_iter.collect();
|
||||||
|
let expected =
|
||||||
|
proc_macro_deps::CRATES.iter().map(|s| s.to_string()).collect::<HashSet<_>>();
|
||||||
|
let old_bad = *bad;
|
||||||
|
for missing in proc_macro_deps.difference(&expected) {
|
||||||
|
tidy_error!(
|
||||||
|
bad,
|
||||||
|
"proc-macro crate dependency `{missing}` is not registered in `src/bootstrap/src/utils/proc_macro_deps.rs`",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for extra in expected.difference(&proc_macro_deps) {
|
||||||
|
tidy_error!(
|
||||||
|
bad,
|
||||||
|
"`{extra}` is not registered in `src/bootstrap/src/utils/proc_macro_deps.rs`, but is not a proc-macro crate dependency",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if *bad != old_bad {
|
||||||
|
eprintln!("Run `./x.py test tidy --bless` to regenerate the list");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Used to skip a check if a submodule is not checked out, and not in a CI environment.
|
/// Used to skip a check if a submodule is not checked out, and not in a CI environment.
|
||||||
///
|
///
|
||||||
/// This helps prevent enforcing developers to fetch submodules for tidy.
|
/// This helps prevent enforcing developers to fetch submodules for tidy.
|
||||||
|
|
|
@ -95,7 +95,7 @@ fn main() {
|
||||||
check!(target_specific_tests, &tests_path);
|
check!(target_specific_tests, &tests_path);
|
||||||
|
|
||||||
// Checks that are done on the cargo workspace.
|
// Checks that are done on the cargo workspace.
|
||||||
check!(deps, &root_path, &cargo);
|
check!(deps, &root_path, &cargo, bless);
|
||||||
check!(extdeps, &root_path);
|
check!(extdeps, &root_path);
|
||||||
|
|
||||||
// Checks over tests.
|
// Checks over tests.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue