Skip to content

Commit 7197c66

Browse files
committed
Auto merge of #8819 - EmbarkStudios:target-root-path, r=ehuss
Make host_root return host.root(), not host.dest() Also create host_dest function to let other callsites retain their old functionality. Fixes #8817, verified it works on the original problem reported in the `rust-gpu` repo. I did two things here: 1) Rename `host_root` (which returns `self.host.dest()`) to be `host_dest`. This has three callsites. I did this to make it more clear that it returns dest, not root. 2) For the callsite that's relevant in #8817, I created a "new" `host_root` function (that returns `self.host.root()`). This means that the callsite that this PR is actually fixing doesn't show up in this diff :/ - but I thought it was more clear this way. (Also copied the example path docs over from `layout.rs` to hopefully avoid this mistake again in the future) I tried to look into if the other two callsites should actually be calling `host.root()` instead of `dest`, because I imagine the same mistake could have been made again, but it quickly grew out of my understanding (this is my first time in the cargo codebase). Feel free to let me know if they should also call `host.root()` too, and I can update them. Thanks! (oh gosh I have no idea what I'm doing, I hope this is right) r? `@alexcrichton`
2 parents becb4c2 + 628f701 commit 7197c66

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

src/cargo/core/compiler/context/compilation_files.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,16 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
207207
}
208208
}
209209

210-
/// Returns the root of the build output tree for the host
211-
pub fn host_root(&self) -> &Path {
210+
/// Returns the final artifact path for the host (`/…/target/debug`)
211+
pub fn host_dest(&self) -> &Path {
212212
self.host.dest()
213213
}
214214

215+
/// Returns the root of the build output tree for the host (`/…/target`)
216+
pub fn host_root(&self) -> &Path {
217+
self.host.root()
218+
}
219+
215220
/// Returns the host `deps` directory path.
216221
pub fn host_deps(&self) -> &Path {
217222
self.host.deps()

src/cargo/core/compiler/custom_build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
272272
let output_file = script_run_dir.join("output");
273273
let err_file = script_run_dir.join("stderr");
274274
let root_output_file = script_run_dir.join("root-output");
275-
let host_target_root = cx.files().host_root().to_path_buf();
275+
let host_target_root = cx.files().host_dest().to_path_buf();
276276
let all = (
277277
id,
278278
pkg_name.clone(),

src/cargo/core/compiler/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
217217
exec.init(cx, unit);
218218
let exec = exec.clone();
219219

220-
let root_output = cx.files().host_root().to_path_buf();
220+
let root_output = cx.files().host_dest().to_path_buf();
221221
let target_dir = cx.bcx.ws.target_dir().into_path_unlocked();
222222
let pkg_root = unit.pkg.root().to_path_buf();
223223
let cwd = rustc

tests/testsuite/dep_info.rs

+36
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,42 @@ fn build_dep_info_dylib() {
176176
assert!(p.example_lib("ex", "dylib").with_extension("d").is_file());
177177
}
178178

179+
#[cargo_test]
180+
fn dep_path_inside_target_has_correct_path() {
181+
let p = project()
182+
.file("Cargo.toml", &basic_bin_manifest("a"))
183+
.file("target/debug/blah", "")
184+
.file(
185+
"src/main.rs",
186+
r#"
187+
fn main() {
188+
let x = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/target/debug/blah"));
189+
}
190+
"#,
191+
)
192+
.build();
193+
194+
p.cargo("build").run();
195+
196+
let depinfo_path = &p.bin("a").with_extension("d");
197+
198+
assert!(depinfo_path.is_file(), "{:?}", depinfo_path);
199+
200+
let depinfo = p.read_file(depinfo_path.to_str().unwrap());
201+
202+
let bin_path = p.bin("a");
203+
let target_debug_blah = Path::new("target").join("debug").join("blah");
204+
if !depinfo.lines().any(|line| {
205+
line.starts_with(&format!("{}:", bin_path.display()))
206+
&& line.contains(target_debug_blah.to_str().unwrap())
207+
}) {
208+
panic!(
209+
"Could not find {:?}: {:?} in {:?}",
210+
bin_path, target_debug_blah, depinfo_path
211+
);
212+
}
213+
}
214+
179215
#[cargo_test]
180216
fn no_rewrite_if_no_change() {
181217
let p = project().file("src/lib.rs", "").build();

0 commit comments

Comments
 (0)