Skip to content

Commit 72417d8

Browse files
committed
Auto merge of rust-lang#73504 - RalfJung:rollup-iy8hsvl, r=RalfJung
Rollup of 10 pull requests Successful merges: - rust-lang#72280 (Fix up autoderef when reborrowing) - rust-lang#72785 (linker: MSVC supports linking static libraries as a whole archive) - rust-lang#73011 (first stage of implementing LLVM code coverage) - rust-lang#73044 (compiletest: Add directives to detect sanitizer support) - rust-lang#73054 (memory access sanity checks: abort instead of panic) - rust-lang#73136 (Change how compiler-builtins gets many CGUs) - rust-lang#73280 (Add E0763) - rust-lang#73317 (bootstrap: read config from $RUST_BOOTSTRAP_CONFIG) - rust-lang#73350 (bootstrap/install.rs: support a nonexistent `prefix` in `x.py install`) - rust-lang#73352 (Speed up bootstrap a little.) Failed merges: r? @ghost
2 parents 63b441a + 61c8925 commit 72417d8

File tree

75 files changed

+1086
-604
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1086
-604
lines changed

Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ debug-assertions = false
4242
debug = false
4343
debug-assertions = false
4444

45+
[profile.release.package.compiler_builtins]
46+
# For compiler-builtins we always use a high number of codegen units.
47+
# The goal here is to place every single intrinsic into its own object
48+
# file to avoid symbol clashes with the system libgcc if possible. Note
49+
# that this number doesn't actually produce this many object files, we
50+
# just don't create more than this number of object files.
51+
#
52+
# It's a bit of a bummer that we have to pass this here, unfortunately.
53+
# Ideally this would be specified through an env var to Cargo so Cargo
54+
# knows how many CGUs are for this specific crate, but for now
55+
# per-crate configuration isn't specifiable in the environment.
56+
codegen-units = 10000
57+
4558
# We want the RLS to use the version of Cargo that we've got vendored in this
4659
# repository to ensure that the same exact version of Cargo is used by both the
4760
# RLS and the Cargo binary itself. The RLS depends on Cargo as a git repository

config.toml.example

+2-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@
209209
# Build the sanitizer runtimes
210210
#sanitizers = false
211211

212-
# Build the profiler runtime
212+
# Build the profiler runtime (required when compiling with options that depend
213+
# on this runtime, such as `-C profile-generate` or `-Z instrument-coverage`).
213214
#profiler = false
214215

215216
# Indicates whether the native libraries linked into Cargo will be statically

src/bootstrap/bootstrap.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ def bootstrap(help_triggered):
894894
build.clean = args.clean
895895

896896
try:
897-
toml_path = args.config or 'config.toml'
897+
toml_path = os.getenv('RUST_BOOTSTRAP_CONFIG') or args.config or 'config.toml'
898898
if not os.path.exists(toml_path):
899899
toml_path = os.path.join(build.rust_root, toml_path)
900900

@@ -947,6 +947,7 @@ def bootstrap(help_triggered):
947947
env["SRC"] = build.rust_root
948948
env["BOOTSTRAP_PARENT_ID"] = str(os.getpid())
949949
env["BOOTSTRAP_PYTHON"] = sys.executable
950+
env["BOOTSTRAP_CONFIG"] = toml_path
950951
env["BUILD_DIR"] = build.build_dir
951952
env["RUSTC_BOOTSTRAP"] = '1'
952953
env["CARGO"] = build.cargo()

src/bootstrap/builder.rs

+41-11
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,21 @@ struct StepDescription {
9999
name: &'static str,
100100
}
101101

102+
/// Collection of paths used to match a task rule.
102103
#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq)]
103104
pub enum PathSet {
105+
/// A collection of individual paths.
106+
///
107+
/// These are generally matched as a path suffix. For example, a
108+
/// command-line value of `libstd` will match if `src/libstd` is in the
109+
/// set.
104110
Set(BTreeSet<PathBuf>),
111+
/// A "suite" of paths.
112+
///
113+
/// These can match as a path suffix (like `Set`), or as a prefix. For
114+
/// example, a command-line value of `src/test/ui/abi/variadic-ffi.rs`
115+
/// will match `src/test/ui`. A command-line value of `ui` would also
116+
/// match `src/test/ui`.
105117
Suite(PathBuf),
106118
}
107119

@@ -251,21 +263,33 @@ impl<'a> ShouldRun<'a> {
251263
self
252264
}
253265

254-
// Unlike `krate` this will create just one pathset. As such, it probably shouldn't actually
255-
// ever be used, but as we transition to having all rules properly handle passing krate(...) by
256-
// actually doing something different for every crate passed.
266+
/// Indicates it should run if the command-line selects the given crate or
267+
/// any of its (local) dependencies.
268+
///
269+
/// Compared to `krate`, this treats the dependencies as aliases for the
270+
/// same job. Generally it is preferred to use `krate`, and treat each
271+
/// individual path separately. For example `./x.py test src/liballoc`
272+
/// (which uses `krate`) will test just `liballoc`. However, `./x.py check
273+
/// src/liballoc` (which uses `all_krates`) will check all of `libtest`.
274+
/// `all_krates` should probably be removed at some point.
257275
pub fn all_krates(mut self, name: &str) -> Self {
258276
let mut set = BTreeSet::new();
259277
for krate in self.builder.in_tree_crates(name) {
260-
set.insert(PathBuf::from(&krate.path));
278+
let path = krate.local_path(self.builder);
279+
set.insert(path);
261280
}
262281
self.paths.insert(PathSet::Set(set));
263282
self
264283
}
265284

285+
/// Indicates it should run if the command-line selects the given crate or
286+
/// any of its (local) dependencies.
287+
///
288+
/// `make_run` will be called separately for each matching command-line path.
266289
pub fn krate(mut self, name: &str) -> Self {
267290
for krate in self.builder.in_tree_crates(name) {
268-
self.paths.insert(PathSet::one(&krate.path));
291+
let path = krate.local_path(self.builder);
292+
self.paths.insert(PathSet::one(path));
269293
}
270294
self
271295
}
@@ -488,13 +512,19 @@ impl<'a> Builder<'a> {
488512
should_run = (desc.should_run)(should_run);
489513
}
490514
let mut help = String::from("Available paths:\n");
515+
let mut add_path = |path: &Path| {
516+
help.push_str(&format!(" ./x.py {} {}\n", subcommand, path.display()));
517+
};
491518
for pathset in should_run.paths {
492-
if let PathSet::Set(set) = pathset {
493-
set.iter().for_each(|path| {
494-
help.push_str(
495-
format!(" ./x.py {} {}\n", subcommand, path.display()).as_str(),
496-
)
497-
})
519+
match pathset {
520+
PathSet::Set(set) => {
521+
for path in set {
522+
add_path(&path);
523+
}
524+
}
525+
PathSet::Suite(path) => {
526+
add_path(&path.join("..."));
527+
}
498528
}
499529
}
500530
Some(help)

src/bootstrap/doc.rs

+2-18
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ impl Step for Rustc {
548548
// Find dependencies for top level crates.
549549
let mut compiler_crates = HashSet::new();
550550
for root_crate in &["rustc_driver", "rustc_codegen_llvm", "rustc_codegen_ssa"] {
551-
let interned_root_crate = INTERNER.intern_str(root_crate);
552-
find_compiler_crates(builder, &interned_root_crate, &mut compiler_crates);
551+
compiler_crates
552+
.extend(builder.in_tree_crates(root_crate).into_iter().map(|krate| krate.name));
553553
}
554554

555555
for krate in &compiler_crates {
@@ -564,22 +564,6 @@ impl Step for Rustc {
564564
}
565565
}
566566

567-
fn find_compiler_crates(
568-
builder: &Builder<'_>,
569-
name: &Interned<String>,
570-
crates: &mut HashSet<Interned<String>>,
571-
) {
572-
// Add current crate.
573-
crates.insert(*name);
574-
575-
// Look for dependencies.
576-
for dep in builder.crates.get(name).unwrap().deps.iter() {
577-
if builder.crates.get(dep).unwrap().is_local(builder) {
578-
find_compiler_crates(builder, dep, crates);
579-
}
580-
}
581-
}
582-
583567
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
584568
pub struct Rustdoc {
585569
stage: u32,

src/bootstrap/flags.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@
33
//! This module implements the command-line parsing of the build system which
44
//! has various flags to configure how it's run.
55
6-
use std::fs;
6+
use std::env;
77
use std::path::PathBuf;
88
use std::process;
99

1010
use getopts::Options;
1111

1212
use crate::builder::Builder;
13+
use crate::cache::{Interned, INTERNER};
1314
use crate::config::Config;
14-
use crate::metadata;
1515
use crate::{Build, DocTests};
1616

17-
use crate::cache::{Interned, INTERNER};
18-
1917
/// Deserialized version of all flags for this compile.
2018
pub struct Flags {
2119
pub verbose: usize, // number of -v args; each extra -v after the first is passed to Cargo
@@ -438,19 +436,12 @@ Arguments:
438436
// Get any optional paths which occur after the subcommand
439437
let paths = matches.free[1..].iter().map(|p| p.into()).collect::<Vec<PathBuf>>();
440438

441-
let cfg_file = matches.opt_str("config").map(PathBuf::from).or_else(|| {
442-
if fs::metadata("config.toml").is_ok() {
443-
Some(PathBuf::from("config.toml"))
444-
} else {
445-
None
446-
}
447-
});
439+
let cfg_file = env::var_os("BOOTSTRAP_CONFIG").map(PathBuf::from);
448440

449441
// All subcommands except `clean` can have an optional "Available paths" section
450442
if matches.opt_present("verbose") {
451443
let config = Config::parse(&["build".to_string()]);
452-
let mut build = Build::new(config);
453-
metadata::build(&mut build);
444+
let build = Build::new(config);
454445

455446
let maybe_rules_help = Builder::get_help(&build, subcommand.as_str());
456447
extra_help.push_str(maybe_rules_help.unwrap_or_default().as_str());

src/bootstrap/install.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ fn install_sh(
7070
let libdir_default = PathBuf::from("lib");
7171
let mandir_default = datadir_default.join("man");
7272
let prefix = builder.config.prefix.as_ref().map_or(prefix_default, |p| {
73-
fs::canonicalize(p).unwrap_or_else(|_| panic!("could not canonicalize {}", p.display()))
73+
fs::create_dir_all(p)
74+
.unwrap_or_else(|err| panic!("could not create {}: {}", p.display(), err));
75+
fs::canonicalize(p)
76+
.unwrap_or_else(|err| panic!("could not canonicalize {}: {}", p.display(), err))
7477
});
7578
let sysconfdir = builder.config.sysconfdir.as_ref().unwrap_or(&sysconfdir_default);
7679
let datadir = builder.config.datadir.as_ref().unwrap_or(&datadir_default);

src/bootstrap/lib.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,7 @@ struct Crate {
270270
}
271271

272272
impl Crate {
273-
fn is_local(&self, build: &Build) -> bool {
274-
self.path.starts_with(&build.config.src) && !self.path.to_string_lossy().ends_with("_shim")
275-
}
276-
277273
fn local_path(&self, build: &Build) -> PathBuf {
278-
assert!(self.is_local(build));
279274
self.path.strip_prefix(&build.config.src).unwrap().into()
280275
}
281276
}
@@ -1090,17 +1085,29 @@ impl Build {
10901085
}
10911086
}
10921087

1088+
/// Returns a Vec of all the dependencies of the given root crate,
1089+
/// including transitive dependencies and the root itself. Only includes
1090+
/// "local" crates (those in the local source tree, not from a registry).
10931091
fn in_tree_crates(&self, root: &str) -> Vec<&Crate> {
10941092
let mut ret = Vec::new();
10951093
let mut list = vec![INTERNER.intern_str(root)];
10961094
let mut visited = HashSet::new();
10971095
while let Some(krate) = list.pop() {
10981096
let krate = &self.crates[&krate];
1099-
if krate.is_local(self) {
1100-
ret.push(krate);
1101-
}
1097+
ret.push(krate);
11021098
for dep in &krate.deps {
1103-
if visited.insert(dep) && dep != "build_helper" {
1099+
// Don't include optional deps if their features are not
1100+
// enabled. Ideally this would be computed from `cargo
1101+
// metadata --features …`, but that is somewhat slow. Just
1102+
// skip `build_helper` since there aren't any operations we
1103+
// want to perform on it. In the future, we may want to
1104+
// consider just filtering all build and dev dependencies in
1105+
// metadata::build.
1106+
if visited.insert(dep)
1107+
&& dep != "build_helper"
1108+
&& (dep != "profiler_builtins" || self.config.profiler)
1109+
&& (dep != "rustc_codegen_llvm" || self.config.llvm_enabled())
1110+
{
11041111
list.push(*dep);
11051112
}
11061113
}

src/bootstrap/metadata.rs

+13-49
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::collections::HashMap;
2-
use std::collections::HashSet;
31
use std::path::PathBuf;
42
use std::process::Command;
53

@@ -12,7 +10,6 @@ use crate::{Build, Crate};
1210
#[derive(Deserialize)]
1311
struct Output {
1412
packages: Vec<Package>,
15-
resolve: Resolve,
1613
}
1714

1815
#[derive(Deserialize)]
@@ -21,72 +18,39 @@ struct Package {
2118
name: String,
2219
source: Option<String>,
2320
manifest_path: String,
21+
dependencies: Vec<Dependency>,
2422
}
2523

2624
#[derive(Deserialize)]
27-
struct Resolve {
28-
nodes: Vec<ResolveNode>,
29-
}
30-
31-
#[derive(Deserialize)]
32-
struct ResolveNode {
33-
id: String,
34-
dependencies: Vec<String>,
25+
struct Dependency {
26+
name: String,
27+
source: Option<String>,
3528
}
3629

3730
pub fn build(build: &mut Build) {
38-
let mut resolves = Vec::new();
39-
build_krate(&build.std_features(), build, &mut resolves, "src/libstd");
40-
build_krate("", build, &mut resolves, "src/libtest");
41-
build_krate(&build.rustc_features(), build, &mut resolves, "src/rustc");
42-
43-
let mut id2name = HashMap::with_capacity(build.crates.len());
44-
for (name, krate) in build.crates.iter() {
45-
id2name.insert(krate.id.clone(), name.clone());
46-
}
47-
48-
for node in resolves {
49-
let name = match id2name.get(&node.id) {
50-
Some(name) => name,
51-
None => continue,
52-
};
53-
54-
let krate = build.crates.get_mut(name).unwrap();
55-
for dep in node.dependencies.iter() {
56-
let dep = match id2name.get(dep) {
57-
Some(dep) => dep,
58-
None => continue,
59-
};
60-
krate.deps.insert(*dep);
61-
}
62-
}
63-
}
64-
65-
fn build_krate(features: &str, build: &mut Build, resolves: &mut Vec<ResolveNode>, krate: &str) {
6631
// Run `cargo metadata` to figure out what crates we're testing.
67-
//
68-
// Down below we're going to call `cargo test`, but to test the right set
69-
// of packages we're going to have to know what `-p` arguments to pass it
70-
// to know what crates to test. Here we run `cargo metadata` to learn about
71-
// the dependency graph and what `-p` arguments there are.
7232
let mut cargo = Command::new(&build.initial_cargo);
7333
cargo
7434
.arg("metadata")
7535
.arg("--format-version")
7636
.arg("1")
77-
.arg("--features")
78-
.arg(features)
37+
.arg("--no-deps")
7938
.arg("--manifest-path")
80-
.arg(build.src.join(krate).join("Cargo.toml"));
39+
.arg(build.src.join("Cargo.toml"));
8140
let output = output(&mut cargo);
8241
let output: Output = serde_json::from_str(&output).unwrap();
8342
for package in output.packages {
8443
if package.source.is_none() {
8544
let name = INTERNER.intern_string(package.name);
8645
let mut path = PathBuf::from(package.manifest_path);
8746
path.pop();
88-
build.crates.insert(name, Crate { name, id: package.id, deps: HashSet::new(), path });
47+
let deps = package
48+
.dependencies
49+
.into_iter()
50+
.filter(|dep| dep.source.is_none())
51+
.map(|dep| INTERNER.intern_string(dep.name))
52+
.collect();
53+
build.crates.insert(name, Crate { name, id: package.id, deps, path });
8954
}
9055
}
91-
resolves.extend(output.resolve.nodes);
9256
}

src/bootstrap/test.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1648,14 +1648,8 @@ impl Step for Crate {
16481648
type Output = ();
16491649
const DEFAULT: bool = true;
16501650

1651-
fn should_run(mut run: ShouldRun<'_>) -> ShouldRun<'_> {
1652-
let builder = run.builder;
1653-
for krate in run.builder.in_tree_crates("test") {
1654-
if !(krate.name.starts_with("rustc_") && krate.name.ends_with("san")) {
1655-
run = run.path(krate.local_path(&builder).to_str().unwrap());
1656-
}
1657-
}
1658-
run
1651+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1652+
run.krate("test")
16591653
}
16601654

16611655
fn make_run(run: RunConfig<'_>) {

0 commit comments

Comments
 (0)