Skip to content

Commit 481c31a

Browse files
authored
Rollup merge of rust-lang#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
2 parents 1ce7e1f + 607987e commit 481c31a

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

compiler/rustc_metadata/src/dependency_format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub(crate) fn calculate(tcx: TyCtxt<'_>) -> Dependencies {
8484
fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
8585
let sess = &tcx.sess;
8686

87-
if !sess.opts.output_types.should_codegen() {
87+
if !sess.opts.output_types.should_link() {
8888
return IndexVec::new();
8989
}
9090

tests/ui/rmeta/rmeta_bin-pass.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ compile-flags: --emit=obj,metadata --crate-type=bin
2+
//@ aux-build:rmeta-meta.rs
3+
//@ no-prefer-dynamic
4+
//@ build-pass
5+
6+
// Check that building a metadata bin crate works with a dependent, metadata
7+
// crate if linking is not requested.
8+
9+
extern crate rmeta_meta;
10+
use rmeta_meta::Foo;
11+
12+
pub fn main() {
13+
let _ = Foo { field: 42 };
14+
}

tests/ui/rmeta/rmeta_bin.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ build-fail
2+
//@ compile-flags: --crate-type=bin
3+
//@ aux-build:rmeta-meta.rs
4+
//@ no-prefer-dynamic
5+
//@ error-pattern: crate `rmeta_meta` required to be available in rlib format, but was not found
6+
7+
// Check that building a bin crate fails if a dependent crate is metadata-only.
8+
9+
extern crate rmeta_meta;
10+
use rmeta_meta::Foo;
11+
12+
fn main() {
13+
let _ = Foo { field: 42 };
14+
}

tests/ui/rmeta/rmeta_bin.stderr

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

0 commit comments

Comments
 (0)