Skip to content

Commit 93722f7

Browse files
committed
Auto merge of rust-lang#134906 - jieyouxu:multi-crate-type, r=lqd,fmease
tests: add basic test coverage for stable `--crate-type` flag I experimented locally with making the compiler panic if multiple crate types are passed to a single `--crate-type` flag, and it turns out not only does the compiler successfully bootstrap, only two ui tests failed: ``` failures: [ui] tests/ui/sepcomp/sepcomp-lib.rs [ui] tests/ui/sepcomp/sepcomp-lib-lto.rs test result: FAILED. 4 passed; 2 failed; 18181 ignored; 0 measured; 0 filtered out; finished in 364.55ms ``` These are not specific tests for the `--crate-type` flag, only their auxiliary *happens* to use a `--crate-type` with two crate types: ```rs //@ compile-flags: -C codegen-units=3 --crate-type=rlib,dylib -g ``` I was not able to find a specific test in run-make test suite either. So this PR tries to add some basic test coverage for the stable `--crate-type` flag's interface (including to check that `--crate-type` accepts multiple crate types), since I imagine it might be slightly awkward if we accidentally regressed this. r? compiler
2 parents f95c996 + 92e8e84 commit 93722f7

4 files changed

+67
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: unknown crate type: ``
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: unknown crate type: `proc_macro`
2+

Diff for: tests/ui/invalid-compile-flags/crate-type-flag.rs

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//! Check that `rustc`'s `--crate-type` flag accepts `--crate-type=<valid_type>` as well as the
2+
//! multi-value version `--crate-type=<valid_type_1>,<valid_type_2>`.
3+
//!
4+
//! This test does not try to check if the output artifacts are valid.
5+
6+
// FIXME(#132309): add a proper `supports-crate-type` directive.
7+
8+
// Single valid crate types should pass
9+
//@ revisions: lib rlib staticlib dylib cdylib bin proc_dash_macro
10+
11+
//@[lib] compile-flags: --crate-type=lib
12+
//@[lib] check-pass
13+
14+
//@[rlib] compile-flags: --crate-type=rlib
15+
//@[rlib] check-pass
16+
17+
//@[staticlib] compile-flags: --crate-type=staticlib
18+
//@[staticlib] check-pass
19+
20+
//@[dylib] ignore-musl (dylibs are not supported)
21+
//@[dylib] ignore-wasm (dylibs are not supported)
22+
//@[dylib] compile-flags: --crate-type=dylib
23+
//@[dylib] check-pass
24+
25+
//@[cdylib] ignore-musl (cdylibs are not supported)
26+
//@[cdylib] compile-flags: --crate-type=cdylib
27+
//@[cdylib] check-pass
28+
29+
//@[bin] compile-flags: --crate-type=bin
30+
//@[bin] check-pass
31+
32+
//@[proc_dash_macro] ignore-wasm (proc-macro is not supported)
33+
//@[proc_dash_macro] compile-flags: --crate-type=proc-macro
34+
//@[proc_dash_macro] check-pass
35+
36+
//@ revisions: multivalue multivalue_combined
37+
38+
//@[multivalue] compile-flags: --crate-type=lib,rlib,staticlib
39+
//@[multivalue] check-pass
40+
41+
//@[multivalue_combined] ignore-musl (dylibs are not supported)
42+
//@[multivalue_combined] ignore-wasm (dylibs are not supported)
43+
//@[multivalue_combined] compile-flags: --crate-type=lib,rlib,staticlib --crate-type=dylib
44+
//@[multivalue_combined] check-pass
45+
46+
// `proc-macro` is accepted, but `proc_macro` is not.
47+
//@ revisions: proc_underscore_macro
48+
//@[proc_underscore_macro] compile-flags: --crate-type=proc_macro
49+
//@[proc_underscore_macro] error-pattern: "unknown crate type: `proc_macro`"
50+
51+
// Empty `--crate-type` not accepted.
52+
//@ revisions: empty_crate_type
53+
//@[empty_crate_type] compile-flags: --crate-type=
54+
//@[empty_crate_type] error-pattern: "unknown crate type: ``"
55+
56+
// Random unknown crate type. Also check that we can handle non-ASCII.
57+
//@ revisions: unknown
58+
//@[unknown] compile-flags: --crate-type=🤡
59+
//@[unknown] error-pattern: "unknown crate type: `🤡`"
60+
61+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: unknown crate type: `🤡`
2+

0 commit comments

Comments
 (0)