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

internal: Improve proc-macro error msg for failed build scripts #18402

Merged
merged 1 commit into from
Oct 24, 2024
Merged
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
23 changes: 13 additions & 10 deletions crates/project-model/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ fn cargo_to_crate_graph(
proc_macros,
cargo,
pkg_data,
build_data,
build_data.zip(Some(build_scripts.error().is_some())),
cfg_options.clone(),
file_id,
name,
Expand Down Expand Up @@ -1285,7 +1285,7 @@ fn handle_rustc_crates(
proc_macros,
rustc_workspace,
&rustc_workspace[pkg],
build_scripts.get_output(pkg),
build_scripts.get_output(pkg).zip(Some(build_scripts.error().is_some())),
cfg_options.clone(),
file_id,
&rustc_workspace[tgt].name,
Expand Down Expand Up @@ -1345,7 +1345,7 @@ fn add_target_crate_root(
proc_macros: &mut ProcMacroPaths,
cargo: &CargoWorkspace,
pkg: &PackageData,
build_data: Option<&BuildScriptOutput>,
build_data: Option<(&BuildScriptOutput, bool)>,
cfg_options: CfgOptions,
file_id: FileId,
cargo_name: &str,
Expand All @@ -1368,7 +1368,7 @@ fn add_target_crate_root(
for feature in pkg.active_features.iter() {
opts.insert_key_value(sym::feature.clone(), Symbol::intern(feature));
}
if let Some(cfgs) = build_data.as_ref().map(|it| &it.cfgs) {
if let Some(cfgs) = build_data.map(|(it, _)| &it.cfgs) {
opts.extend(cfgs.iter().cloned());
}
opts
Expand All @@ -1379,7 +1379,7 @@ fn add_target_crate_root(
inject_cargo_env(&mut env);
inject_rustc_tool_env(&mut env, cargo, cargo_name, kind);

if let Some(envs) = build_data.map(|it| &it.envs) {
if let Some(envs) = build_data.map(|(it, _)| &it.envs) {
for (k, v) in envs {
env.set(k, v.clone());
}
Expand All @@ -1396,11 +1396,14 @@ fn add_target_crate_root(
origin,
);
if let TargetKind::Lib { is_proc_macro: true } = kind {
let proc_macro = match build_data.as_ref().map(|it| it.proc_macro_dylib_path.as_ref()) {
Some(it) => match it {
Some(path) => Ok((cargo_name.to_owned(), path.clone())),
None => Err("proc-macro crate build data is missing dylib path".to_owned()),
},
let proc_macro = match build_data {
Some((BuildScriptOutput { proc_macro_dylib_path, .. }, has_errors)) => {
match proc_macro_dylib_path {
Some(path) => Ok((cargo_name.to_owned(), path.clone())),
None if has_errors => Err("failed to build proc-macro".to_owned()),
None => Err("proc-macro crate build data is missing dylib path".to_owned()),
}
}
None => Err("proc-macro crate is missing its build data".to_owned()),
};
proc_macros.insert(crate_id, proc_macro);
Expand Down