1
Fork 0

Rollup merge of #138175 - sam-mccall:binobj, r=nnethercote

Support rmeta inputs for --crate-type=bin --emit=obj

This already works for --emit=metadata, but is possible anytime we're not linking.

Tests:
- `rmeta_bin` checks we're not changing --emit=link (already passes)
- `rmeta_bin-pass` tests the new behavior for --emit=obj (would fail today) and also --emit=metadata which isn't changing
This commit is contained in:
Manish Goregaokar 2025-03-12 10:19:27 -07:00 committed by GitHub
commit 40c7a9014e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 1 deletions

View file

@ -84,7 +84,7 @@ pub(crate) fn calculate(tcx: TyCtxt<'_>) -> Dependencies {
fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
let sess = &tcx.sess;
if !sess.opts.output_types.should_codegen() {
if !sess.opts.output_types.should_link() {
return IndexVec::new();
}

View file

@ -0,0 +1,14 @@
//@ compile-flags: --emit=obj,metadata --crate-type=bin
//@ aux-build:rmeta-meta.rs
//@ no-prefer-dynamic
//@ build-pass
// Check that building a metadata bin crate works with a dependent, metadata
// crate if linking is not requested.
extern crate rmeta_meta;
use rmeta_meta::Foo;
pub fn main() {
let _ = Foo { field: 42 };
}

View file

@ -0,0 +1,14 @@
//@ build-fail
//@ compile-flags: --crate-type=bin
//@ aux-build:rmeta-meta.rs
//@ no-prefer-dynamic
//@ error-pattern: crate `rmeta_meta` required to be available in rlib format, but was not found
// Check that building a bin crate fails if a dependent crate is metadata-only.
extern crate rmeta_meta;
use rmeta_meta::Foo;
fn main() {
let _ = Foo { field: 42 };
}

View file

@ -0,0 +1,4 @@
error: crate `rmeta_meta` required to be available in rlib format, but was not found in this form
error: aborting due to 1 previous error