diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index 4ea780c5477..9d45ab41fc6 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -4,7 +4,6 @@ use crate::core::compiler::context::Metadata; use crate::core::compiler::job_queue::JobState; use crate::core::{profiles::ProfileRoot, PackageId}; use crate::util::errors::{CargoResult, CargoResultExt}; -use crate::util::interning::InternedString; use crate::util::machine_message::{self, Message}; use crate::util::{self, internal, paths, profile}; use cargo_platform::Cfg; @@ -268,7 +267,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { } }) .collect::>(); - let pkg_name = unit.pkg.name(); + let crate_name = unit.target.crate_name(); let pkg_descr = unit.pkg.to_string(); let build_script_outputs = Arc::clone(&cx.build_script_outputs); let id = unit.pkg.package_id(); @@ -278,7 +277,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { let host_target_root = cx.files().host_dest().to_path_buf(); let all = ( id, - pkg_name, + crate_name.clone(), pkg_descr.clone(), Arc::clone(&build_script_outputs), output_file.clone(), @@ -398,7 +397,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { paths::write(&root_output_file, util::path2bytes(&script_out_dir)?)?; let parsed_output = BuildOutput::parse( &output.stdout, - pkg_name, + crate_name, &pkg_descr, &script_out_dir, &script_out_dir, @@ -420,12 +419,12 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { // itself to run when we actually end up just discarding what we calculated // above. let fresh = Work::new(move |state| { - let (id, pkg_name, pkg_descr, build_script_outputs, output_file, script_out_dir) = all; + let (id, crate_name, pkg_descr, build_script_outputs, output_file, script_out_dir) = all; let output = match prev_output { Some(output) => output, None => BuildOutput::parse_file( &output_file, - pkg_name, + crate_name, &pkg_descr, &prev_script_out_dir, &script_out_dir, @@ -477,7 +476,7 @@ fn insert_warnings_in_build_outputs( impl BuildOutput { pub fn parse_file( path: &Path, - pkg_name: InternedString, + crate_name: String, pkg_descr: &str, script_out_dir_when_generated: &Path, script_out_dir: &Path, @@ -487,7 +486,7 @@ impl BuildOutput { let contents = paths::read_bytes(path)?; BuildOutput::parse( &contents, - pkg_name, + crate_name, pkg_descr, script_out_dir_when_generated, script_out_dir, @@ -497,10 +496,12 @@ impl BuildOutput { } // Parses the output of a script. - // The `pkg_name` is used for error messages. + // The `pkg_descr` is used for error messages. + // The `crate_name` is used for determining if RUSTC_BOOTSTRAP should be allowed. pub fn parse( input: &[u8], - pkg_name: InternedString, + // Takes String instead of InternedString so passing `unit.pkg.name()` will give a compile error. + crate_name: String, pkg_descr: &str, script_out_dir_when_generated: &Path, script_out_dir: &Path, @@ -589,13 +590,12 @@ impl BuildOutput { // behavior, so still only give a warning. // NOTE: cargo only allows nightly features on RUSTC_BOOTSTRAP=1, but we // want setting any value of RUSTC_BOOTSTRAP to downgrade this to a warning - // (so that `RUSTC_BOOTSTRAP=pkg_name` will work) + // (so that `RUSTC_BOOTSTRAP=crate_name` will work) let rustc_bootstrap_allows = |name: &str| { - std::env::var("RUSTC_BOOTSTRAP").map_or(false, |var| { - var.split(',').any(|s| s == name) - }) + std::env::var("RUSTC_BOOTSTRAP") + .map_or(false, |var| var.split(',').any(|s| s == name)) }; - if nightly_features_allowed || rustc_bootstrap_allows(&*pkg_name) { + if nightly_features_allowed || rustc_bootstrap_allows(&*crate_name) { warnings.push(format!("Cannot set `RUSTC_BOOTSTRAP={}` from {}.\n\ note: Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.", val, whence @@ -608,7 +608,7 @@ impl BuildOutput { help: If you're sure you want to do this in your project, set the environment variable `RUSTC_BOOTSTRAP={}` before running cargo instead.", val, whence, - pkg_name, + crate_name, ); } } else { @@ -865,7 +865,7 @@ fn prev_build_output(cx: &mut Context<'_, '_>, unit: &Unit) -> (Option