Skip to content

Commit

Permalink
Ask the user to use feature(rustc_private) when linking to `rustc_d…
Browse files Browse the repository at this point in the history
…river`
  • Loading branch information
Zoxc committed Mar 24, 2024
1 parent cb1319d commit 8f5e879
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions compiler/rustc_metadata/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ metadata_crate_dep_multiple =
metadata_crate_dep_not_static =
`{$crate_name}` was unavailable as a static crate, preventing fully static linking
metadata_crate_dep_rustc_driver =
`feature(rustc_private)` is needed to link to the compiler's `rustc_driver` library
metadata_crate_location_unknown_type =
extern location for {$crate_name} is of an unknown type: {$path}
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_metadata/src/dependency_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
use crate::creader::CStore;
use crate::errors::{
BadPanicStrategy, CrateDepMultiple, IncompatiblePanicInDropStrategy, LibRequired,
NonStaticCrateDep, RequiredPanicStrategy, RlibRequired, RustcLibRequired, TwoPanicRuntimes,
NonStaticCrateDep, RequiredPanicStrategy, RlibRequired, RustcDriverHelp, RustcLibRequired,
TwoPanicRuntimes,
};

use rustc_data_structures::fx::{FxHashMap, FxHashSet};
Expand All @@ -64,6 +65,7 @@ use rustc_middle::ty::TyCtxt;
use rustc_session::config::CrateType;
use rustc_session::cstore::CrateDepKind;
use rustc_session::cstore::LinkagePreference::{self, RequireDynamic, RequireStatic};
use rustc_span::sym;

pub(crate) fn calculate(tcx: TyCtxt<'_>) -> Dependencies {
tcx.crate_types()
Expand Down Expand Up @@ -290,12 +292,15 @@ fn add_library(
// This error is probably a little obscure, but I imagine that it
// can be refined over time.
if link2 != link || link == RequireStatic {
let linking_to_rustc_driver = tcx.sess.psess.unstable_features.is_nightly_build()
&& tcx.crates(()).iter().any(|&cnum| tcx.crate_name(cnum) == sym::rustc_driver);
tcx.dcx().emit_err(CrateDepMultiple {
crate_name: tcx.crate_name(cnum),
non_static_deps: unavailable_as_static
.drain(..)
.map(|cnum| NonStaticCrateDep { crate_name: tcx.crate_name(cnum) })
.collect(),
rustc_driver_help: linking_to_rustc_driver.then_some(RustcDriverHelp),
});
}
}
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_metadata/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub struct CrateDepMultiple {
pub crate_name: Symbol,
#[subdiagnostic]
pub non_static_deps: Vec<NonStaticCrateDep>,
#[subdiagnostic]
pub rustc_driver_help: Option<RustcDriverHelp>,
}

#[derive(Subdiagnostic)]
Expand All @@ -48,6 +50,10 @@ pub struct NonStaticCrateDep {
pub crate_name: Symbol,
}

#[derive(Subdiagnostic)]
#[help(metadata_crate_dep_rustc_driver)]
pub struct RustcDriverHelp;

#[derive(Diagnostic)]
#[diag(metadata_two_panic_runtimes)]
pub struct TwoPanicRuntimes {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,7 @@ symbols! {
rustc_dirty,
rustc_do_not_const_check,
rustc_doc_primitive,
rustc_driver,
rustc_dummy,
rustc_dump_env_program_clauses,
rustc_dump_program_clauses,
Expand Down

0 comments on commit 8f5e879

Please sign in to comment.