-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Only include metadata for non-dynamic libraries in rustc-dev #105609
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,14 @@ pub struct LibRequired<'a> { | |
pub kind: &'a str, | ||
} | ||
|
||
#[derive(Diagnostic)] | ||
#[diag(metadata_rustc_lib_required)] | ||
#[help] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @davidtwco why is this |
||
pub struct RustcLibRequired<'a> { | ||
pub crate_name: Symbol, | ||
pub kind: &'a str, | ||
} | ||
|
||
#[derive(Diagnostic)] | ||
#[diag(metadata_crate_dep_multiple)] | ||
#[help] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,7 +141,14 @@ impl Step for Std { | |
&compiler.host, | ||
target, | ||
)); | ||
run_cargo(builder, cargo, &libstd_stamp(builder, compiler, target), target_deps, false); | ||
run_cargo( | ||
builder, | ||
cargo, | ||
&libstd_stamp(builder, compiler, target), | ||
target_deps, | ||
false, | ||
false, | ||
); | ||
|
||
builder.ensure(StdLink::from_std( | ||
self, | ||
|
@@ -728,7 +735,14 @@ impl Step for Rustc { | |
&compiler.host, | ||
target, | ||
)); | ||
run_cargo(builder, cargo, &librustc_stamp(builder, compiler, target), vec![], false); | ||
run_cargo( | ||
builder, | ||
cargo, | ||
&librustc_stamp(builder, compiler, target), | ||
vec![], | ||
false, | ||
true, // Only ship rustc_driver.so and .rmeta files, not all intermediate .rlib files. | ||
); | ||
|
||
builder.ensure(RustcLink::from_rustc( | ||
self, | ||
|
@@ -984,7 +998,7 @@ impl Step for CodegenBackend { | |
"Building stage{} codegen backend {} ({} -> {})", | ||
compiler.stage, backend, &compiler.host, target | ||
)); | ||
let files = run_cargo(builder, cargo, &tmp_stamp, vec![], false); | ||
let files = run_cargo(builder, cargo, &tmp_stamp, vec![], false, false); | ||
if builder.config.dry_run() { | ||
return; | ||
} | ||
|
@@ -1411,6 +1425,7 @@ pub fn run_cargo( | |
stamp: &Path, | ||
additional_target_deps: Vec<(PathBuf, DependencyType)>, | ||
is_check: bool, | ||
rlib_only_metadata: bool, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This getting to be quite a lot of arguments. AFAICT There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, ok. let's put this refactor off for later, it's not important for now. |
||
) -> Vec<PathBuf> { | ||
if builder.config.dry_run() { | ||
return Vec::new(); | ||
|
@@ -1444,13 +1459,35 @@ pub fn run_cargo( | |
}; | ||
for filename in filenames { | ||
// Skip files like executables | ||
if !(filename.ends_with(".rlib") | ||
|| filename.ends_with(".lib") | ||
let mut keep = false; | ||
if filename.ends_with(".lib") | ||
|| filename.ends_with(".a") | ||
|| is_debug_info(&filename) | ||
|| is_dylib(&filename) | ||
|| (is_check && filename.ends_with(".rmeta"))) | ||
{ | ||
// Always keep native libraries, rust dylibs and debuginfo | ||
keep = true; | ||
} | ||
if is_check && filename.ends_with(".rmeta") { | ||
// During check builds we need to keep crate metadata | ||
keep = true; | ||
} else if rlib_only_metadata { | ||
if filename.contains("jemalloc_sys") || filename.contains("rustc_smir") { | ||
// jemalloc_sys and rustc_smir are not linked into librustc_driver.so, | ||
// so we need to distribute them as rlib to be able to use them. | ||
keep |= filename.ends_with(".rlib"); | ||
} else { | ||
// Distribute the rest of the rustc crates as rmeta files only to reduce | ||
// the tarball sizes by about 50%. The object files are linked into | ||
// librustc_driver.so, so it is still possible to link against them. | ||
keep |= filename.ends_with(".rmeta"); | ||
} | ||
} else { | ||
// In all other cases keep all rlibs | ||
keep |= filename.ends_with(".rlib"); | ||
} | ||
|
||
if !keep { | ||
continue; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Test that we get the following hint when trying to use a compiler crate without rustc_driver. | ||
// error-pattern: try adding `extern crate rustc_driver;` at the top level of this crate | ||
// compile-flags: --emit link | ||
// The exactly list of required crates depends on the target. as such only test Unix targets. | ||
// only-unix | ||
|
||
#![feature(rustc_private)] | ||
|
||
extern crate rustc_serialize; | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
error: crate `rustc_serialize` required to be available in rlib format, but was not found in this form | ||
| | ||
= help: try adding `extern crate rustc_driver;` at the top level of this crate | ||
|
||
error: crate `smallvec` required to be available in rlib format, but was not found in this form | ||
|
||
error: crate `thin_vec` required to be available in rlib format, but was not found in this form | ||
|
||
error: crate `indexmap` required to be available in rlib format, but was not found in this form | ||
|
||
error: crate `hashbrown` required to be available in rlib format, but was not found in this form | ||
|
||
error: crate `ahash` required to be available in rlib format, but was not found in this form | ||
|
||
error: crate `once_cell` required to be available in rlib format, but was not found in this form | ||
|
||
error: crate `getrandom` required to be available in rlib format, but was not found in this form | ||
|
||
error: crate `cfg_if` required to be available in rlib format, but was not found in this form | ||
|
||
error: crate `libc` required to be available in rlib format, but was not found in this form | ||
|
||
error: aborting due to 10 previous errors | ||
|
Uh oh!
There was an error while loading. Please reload this page.