Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit c2fa6db

Browse files
committed
Add host link path if building for specific target
This is necessary to make proc-macros work, since they are built for the host, not the given target. Host and target being equal doesn't help, since specifying an explicit target will still lead to a separate folder under `target/`.
1 parent 11f4dee commit c2fa6db

File tree

1 file changed

+44
-21
lines changed

1 file changed

+44
-21
lines changed

src/bin/cargo-semver.rs

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,11 @@ fn run(config: &cargo::Config, matches: &getopts::Matches) -> Result<()> {
130130
let mut child = Command::new("rust-semver-public");
131131
child
132132
.arg("--crate-type=lib")
133-
.args(&["--extern", &*format!("new={}", current_rlib.display())])
134-
.args(&[format!("-L{}", current_deps_output.display())]);
133+
.args(&["--extern", &*format!("new={}", current_rlib.display())]);
134+
135+
for link_path in current_deps_output {
136+
child.args(&[format!("-L{}", link_path.display())]);
137+
}
135138

136139
if let Some(target) = matches.opt_str("target") {
137140
child.args(&["--target", &target]);
@@ -195,13 +198,16 @@ fn run(config: &cargo::Config, matches: &getopts::Matches) -> Result<()> {
195198
stable.rlib_and_dep_output(config, &name, false, matches)?;
196199

197200
if matches.opt_present("d") {
198-
println!(
199-
"--extern old={} -L{} --extern new={} -L{}",
200-
stable_rlib.display(),
201-
stable_deps_output.display(),
202-
current_rlib.display(),
203-
current_deps_output.display()
204-
);
201+
print!("--extern old={} ", stable_rlib.display());
202+
for link_path in stable_deps_output {
203+
print!("-L {} ", link_path.display());
204+
}
205+
print!("--extern new={}", current_rlib.display());
206+
for link_path in current_deps_output {
207+
print!("-L {} ", link_path.display());
208+
}
209+
println!();
210+
205211
return Ok(());
206212
}
207213

@@ -210,10 +216,14 @@ fn run(config: &cargo::Config, matches: &getopts::Matches) -> Result<()> {
210216
let mut child = Command::new("rust-semverver");
211217
child
212218
.arg("--crate-type=lib")
213-
.args(&["--extern", &*format!("old={}", stable_rlib.display())])
214-
.args(&[format!("-L{}", stable_deps_output.display())])
215-
.args(&["--extern", &*format!("new={}", current_rlib.display())])
216-
.args(&[format!("-L{}", current_deps_output.display())]);
219+
.args(&["--extern", &*format!("old={}", stable_rlib.display())]);
220+
for link_path in stable_deps_output {
221+
child.args(&[format!("-L{}", link_path.display())]);
222+
}
223+
child.args(&["--extern", &*format!("new={}", current_rlib.display())]);
224+
for link_path in current_deps_output {
225+
child.args(&[format!("-L{}", link_path.display())]);
226+
}
217227

218228
if let Some(target) = matches.opt_str("target") {
219229
child.args(&["--target", &target]);
@@ -235,6 +245,8 @@ fn run(config: &cargo::Config, matches: &getopts::Matches) -> Result<()> {
235245
},
236246
);
237247

248+
debug!("rust-semverver invocation: {:?}", child);
249+
238250
let mut child = child
239251
.spawn()
240252
.map_err(|e| anyhow::Error::msg(format!("could not spawn rustc: {}", e)))?;
@@ -474,7 +486,7 @@ impl<'a> WorkInfo<'a> {
474486
name: &str,
475487
current: bool,
476488
matches: &getopts::Matches,
477-
) -> Result<(PathBuf, PathBuf)> {
489+
) -> Result<(PathBuf, Vec<PathBuf>)> {
478490
// We don't need codegen-ready artifacts (which .rlib files are) so
479491
// settle for .rmeta files, which result from `cargo check` mode
480492
let mode = cargo::core::compiler::CompileMode::Check { test: false };
@@ -531,18 +543,29 @@ impl<'a> WorkInfo<'a> {
531543
let build_plan: BuildPlan = serde_json::from_slice(&plan_output)
532544
.map_err(|_| anyhow::anyhow!("Can't read build plan"))?;
533545

534-
// TODO: handle multiple outputs gracefully
535-
for i in &build_plan.invocations {
546+
debug!("{:?}", &build_plan.invocations);
547+
let paths = build_plan.invocations.iter().find_map(|i| {
536548
if let Some(kind) = i.target_kind.get(0) {
537549
if kind.contains("lib") && i.package_name == name {
538-
let deps_output = &compilation.deps_output[&compile_kind];
539-
540-
return Ok((i.outputs[0].clone(), deps_output.clone()));
550+
let rlib_path = i.outputs[0].clone();
551+
let mut link_paths = vec![
552+
compilation.deps_output[&compile_kind].clone(),
553+
compilation.deps_output[&cargo::core::compiler::CompileKind::Host].clone(),
554+
];
555+
// if host and `compile_kind` are the same, only return once
556+
link_paths.dedup();
557+
return Some((rlib_path, link_paths));
541558
}
542559
}
543-
}
544560

545-
Err(anyhow::Error::msg("lost build artifact".to_owned()))
561+
None
562+
});
563+
564+
if let Some(paths) = paths {
565+
Ok(paths)
566+
} else {
567+
Err(anyhow::Error::msg("lost build artifact".to_owned()))
568+
}
546569
}
547570
}
548571

0 commit comments

Comments
 (0)