Skip to content

Commit

Permalink
chore: remove rustc-workspace-hack
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Schafer <[email protected]>
Co-authored-by: Eric Huss <[email protected]>
  • Loading branch information
3 people committed Apr 16, 2023
1 parent 1cfaa34 commit befa5c9
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 191 deletions.
8 changes: 2 additions & 6 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2773,7 +2773,6 @@ dependencies = [
name = "rls"
version = "2.0.0"
dependencies = [
"rustc-workspace-hack",
"serde",
"serde_json",
]
Expand Down Expand Up @@ -2885,11 +2884,8 @@ dependencies = [
[[package]]
name = "rustc-workspace-hack"
version = "1.0.0"
dependencies = [
"libc",
"regex",
"serde_json",
]
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc71d2faa173b74b232dedc235e3ee1696581bb132fc116fa3626d6151a1a8fb"

[[package]]
name = "rustc_abi"
Expand Down
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ miniz_oxide.debug = 0
object.debug = 0

[patch.crates-io]
# See comments in `src/tools/rustc-workspace-hack/README.md` for what's going on
# here
rustc-workspace-hack = { path = 'src/tools/rustc-workspace-hack' }

# See comments in `library/rustc-std-workspace-core/README.md` for what's going on
# here
rustc-std-workspace-core = { path = 'library/rustc-std-workspace-core' }
Expand Down
3 changes: 0 additions & 3 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ pub struct Build {
ci_env: CiEnv,
delayed_failures: RefCell<Vec<String>>,
prerelease_version: Cell<Option<u32>>,
tool_artifacts:
RefCell<HashMap<TargetSelection, HashMap<String, (&'static str, PathBuf, Vec<String>)>>>,

#[cfg(feature = "build-metrics")]
metrics: metrics::BuildMetrics,
Expand Down Expand Up @@ -458,7 +456,6 @@ impl Build {
ci_env: CiEnv::current(),
delayed_failures: RefCell::new(Vec::new()),
prerelease_version: Cell::new(None),
tool_artifacts: Default::default(),

#[cfg(feature = "build-metrics")]
metrics: metrics::BuildMetrics::init(),
Expand Down
131 changes: 2 additions & 129 deletions src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::HashSet;
use std::env;
use std::fs;
use std::path::PathBuf;
Expand Down Expand Up @@ -120,136 +119,10 @@ impl Step for ToolBuild {
&self.target,
);
builder.info(&msg);
let mut duplicates = Vec::new();
let is_expected = compile::stream_cargo(builder, cargo, vec![], &mut |msg| {
// Only care about big things like the RLS/Cargo for now
match tool {
"rls" | "clippy-driver" | "miri" | "rustfmt" => {}

_ => return,
}
let (id, features, filenames) = match msg {
compile::CargoMessage::CompilerArtifact {
package_id,
features,
filenames,
target: _,
} => (package_id, features, filenames),
_ => return,
};
let features = features.iter().map(|s| s.to_string()).collect::<Vec<_>>();

for path in filenames {
let val = (tool, PathBuf::from(&*path), features.clone());
// we're only interested in deduplicating rlibs for now
if val.1.extension().and_then(|s| s.to_str()) != Some("rlib") {
continue;
}

// Don't worry about compiles that turn out to be host
// dependencies or build scripts. To skip these we look for
// anything that goes in `.../release/deps` but *doesn't* go in
// `$target/release/deps`. This ensure that outputs in
// `$target/release` are still considered candidates for
// deduplication.
if let Some(parent) = val.1.parent() {
if parent.ends_with("release/deps") {
let maybe_target = parent
.parent()
.and_then(|p| p.parent())
.and_then(|p| p.file_name())
.and_then(|p| p.to_str())
.unwrap();
if maybe_target != &*target.triple {
continue;
}
}
}

// Record that we've built an artifact for `id`, and if one was
// already listed then we need to see if we reused the same
// artifact or produced a duplicate.
let mut artifacts = builder.tool_artifacts.borrow_mut();
let prev_artifacts = artifacts.entry(target).or_default();
let prev = match prev_artifacts.get(&*id) {
Some(prev) => prev,
None => {
prev_artifacts.insert(id.to_string(), val);
continue;
}
};
if prev.1 == val.1 {
return; // same path, same artifact
}

// If the paths are different and one of them *isn't* inside of
// `release/deps`, then it means it's probably in
// `$target/release`, or it's some final artifact like
// `libcargo.rlib`. In these situations Cargo probably just
// copied it up from `$target/release/deps/libcargo-xxxx.rlib`,
// so if the features are equal we can just skip it.
let prev_no_hash = prev.1.parent().unwrap().ends_with("release/deps");
let val_no_hash = val.1.parent().unwrap().ends_with("release/deps");
if prev.2 == val.2 || !prev_no_hash || !val_no_hash {
return;
}

// ... and otherwise this looks like we duplicated some sort of
// compilation, so record it to generate an error later.
duplicates.push((id.to_string(), val, prev.clone()));
}
let is_expected = compile::stream_cargo(builder, cargo, vec![], &mut |_msg| {
return;
});

if is_expected && !duplicates.is_empty() {
eprintln!(
"duplicate artifacts found when compiling a tool, this \
typically means that something was recompiled because \
a transitive dependency has different features activated \
than in a previous build:\n"
);
let (same, different): (Vec<_>, Vec<_>) =
duplicates.into_iter().partition(|(_, cur, prev)| cur.2 == prev.2);
if !same.is_empty() {
eprintln!(
"the following dependencies are duplicated although they \
have the same features enabled:"
);
for (id, cur, prev) in same {
eprintln!(" {}", id);
// same features
eprintln!(" `{}` ({:?})\n `{}` ({:?})", cur.0, cur.1, prev.0, prev.1);
}
}
if !different.is_empty() {
eprintln!("the following dependencies have different features:");
for (id, cur, prev) in different {
eprintln!(" {}", id);
let cur_features: HashSet<_> = cur.2.into_iter().collect();
let prev_features: HashSet<_> = prev.2.into_iter().collect();
eprintln!(
" `{}` additionally enabled features {:?} at {:?}",
cur.0,
&cur_features - &prev_features,
cur.1
);
eprintln!(
" `{}` additionally enabled features {:?} at {:?}",
prev.0,
&prev_features - &cur_features,
prev.1
);
}
}
eprintln!();
eprintln!(
"to fix this you will probably want to edit the local \
src/tools/rustc-workspace-hack/Cargo.toml crate, as \
that will update the dependency graph to ensure that \
these crates all share the same feature set"
);
panic!("tools should not compile multiple copies of the same crate");
}

builder.save_toolstate(
tool,
if is_expected { ToolState::TestFail } else { ToolState::BuildFail },
Expand Down
4 changes: 0 additions & 4 deletions src/tools/rls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,3 @@ license = "Apache-2.0/MIT"
[dependencies]
serde = { version = "1.0.143", features = ["derive"] }
serde_json = "1.0.83"
# A noop dependency that changes in the Rust repository, it's a bit of a hack.
# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`
# for more information.
rustc-workspace-hack = "1.0.0"
19 changes: 0 additions & 19 deletions src/tools/rustc-workspace-hack/Cargo.toml

This file was deleted.

25 changes: 0 additions & 25 deletions src/tools/rustc-workspace-hack/README.md

This file was deleted.

1 change: 0 additions & 1 deletion src/tools/rustc-workspace-hack/lib.rs

This file was deleted.

0 comments on commit befa5c9

Please sign in to comment.