Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the replacement source instead of the original source when generating -C metadata and -C extra-filename #14822

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cargo/core/compiler/build_runner/compilation_files.rs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To help us track this, #14729 hasn't been accepted yet

(we generally ask for issues to be accepted before posting PRs, see https://doc.crates.io/contrib/process/index.html)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I meant #14821, which is an issue. I updated the initial report.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two PRs are independent, one is for cargo vendor, the other one for cargo build. Any of them would already improve the situation and remove hacky workarounds in our workflow.

Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ fn compute_metadata(
// to pull crates from anywhere without worrying about conflicts.
unit.pkg
.package_id()
.with_source_id(unit.replaced_source)
.stable_hash(bcx.ws.root())
.hash(&mut hasher);

Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/compiler/standard_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ pub fn generate_std_roots(
);
list.push(interner.intern(
pkg,
pkg.package_id().source_id(),
lib,
profile,
*kind,
Expand Down
5 changes: 4 additions & 1 deletion src/cargo/core/compiler/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::core::compiler::unit_dependencies::IsArtifact;
use crate::core::compiler::{CompileKind, CompileMode, CompileTarget, CrateType};
use crate::core::manifest::{Target, TargetKind};
use crate::core::profiles::Profile;
use crate::core::Package;
use crate::core::{Package, SourceId};
use crate::util::hex::short_hash;
use crate::util::interning::InternedString;
use crate::util::GlobalContext;
Expand Down Expand Up @@ -42,6 +42,7 @@ pub struct UnitInner {
/// Information about available targets, which files to include/exclude, etc. Basically stuff in
/// `Cargo.toml`.
pub pkg: Package,
pub replaced_source: SourceId,
/// Information about the specific target to build, out of the possible targets in `pkg`. Not
/// to be confused with *target-triple* (or *target architecture* ...), the target arch for a
/// build.
Expand Down Expand Up @@ -226,6 +227,7 @@ impl UnitInterner {
pub fn intern(
&self,
pkg: &Package,
replaced_source: SourceId,
target: &Target,
profile: Profile,
kind: CompileKind,
Expand Down Expand Up @@ -262,6 +264,7 @@ impl UnitInterner {
};
let inner = self.intern_inner(&UnitInner {
pkg: pkg.clone(),
replaced_source,
target,
profile,
kind,
Expand Down
9 changes: 9 additions & 0 deletions src/cargo/core/compiler/unit_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,17 @@ fn new_unit_dep_with_profile(
_ => None,
};
let features = state.activated_features(pkg.package_id(), features_for);

let replaced_source = state
.package_set
.sources()
.get(pkg.package_id().source_id())
.unwrap()
.replaced_source_id();

let unit = state.interner.intern(
pkg,
replaced_source,
target,
profile,
kind,
Expand Down
3 changes: 3 additions & 0 deletions src/cargo/ops/cargo_compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ fn traverse_and_share(
canonical_profile.debuginfo = canonical_debuginfo;
let unit_probe = interner.intern(
&unit.pkg,
unit.replaced_source,
&unit.target,
canonical_profile,
to_host.unwrap(),
Expand Down Expand Up @@ -723,6 +724,7 @@ fn traverse_and_share(

let new_unit = interner.intern(
&unit.pkg,
unit.replaced_source,
&unit.target,
profile,
canonical_kind,
Expand Down Expand Up @@ -887,6 +889,7 @@ fn override_rustc_crate_types(
target.set_kind(f(crate_types));
interner.intern(
&unit.pkg,
unit.replaced_source,
&target,
unit.profile.clone(),
unit.kind,
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/ops/cargo_compile/unit_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ impl<'a> UnitGenerator<'a, '_> {
let kind = kind.for_target(target);
self.interner.intern(
pkg,
pkg.package_id().source_id(),
target,
profile,
kind,
Expand Down Expand Up @@ -671,6 +672,7 @@ Rustdoc did not scrape the following examples because they require dev-dependenc
}
None => Vec::new(),
};

if target.is_lib() || unavailable_features.is_empty() {
units.extend(self.new_units(pkg, target, mode));
} else if requires_features {
Expand Down
Loading