File tree Expand file tree Collapse file tree 4 files changed +60
-0
lines changed Expand file tree Collapse file tree 4 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,8 @@ pub struct TargetInfo {
3939 pub rustflags : Vec < String > ,
4040 /// Extra flags to pass to `rustdoc`, see `env_args`.
4141 pub rustdocflags : Vec < String > ,
42+ // Remove this when it hits stable (1.41).
43+ pub supports_pathless_extern : Option < bool > ,
4244}
4345
4446/// Kind of each file generated by a Unit, part of `FileType`.
@@ -101,6 +103,13 @@ impl TargetInfo {
101103 . args ( & rustflags)
102104 . env_remove ( "RUSTC_LOG" ) ;
103105
106+ let mut pathless_test = process. clone ( ) ;
107+ pathless_test. args ( & [ "--extern" , "proc_macro" ] ) ;
108+ let supports_pathless_extern = match kind {
109+ CompileKind :: Host => Some ( rustc. cached_output ( & pathless_test) . is_ok ( ) ) ,
110+ _ => None ,
111+ } ;
112+
104113 if let CompileKind :: Target ( target) = kind {
105114 process. arg ( "--target" ) . arg ( target. rustc_target ( ) ) ;
106115 }
@@ -183,6 +192,7 @@ impl TargetInfo {
183192 "RUSTDOCFLAGS" ,
184193 ) ?,
185194 cfg,
195+ supports_pathless_extern,
186196 } )
187197 }
188198
Original file line number Diff line number Diff line change @@ -1010,6 +1010,17 @@ pub fn extern_args<'a>(
10101010 link_to ( & dep, dep. extern_crate_name , dep. noprelude ) ?;
10111011 }
10121012 }
1013+ if unit. target . proc_macro ( )
1014+ && cx
1015+ . bcx
1016+ . info ( CompileKind :: Host )
1017+ . supports_pathless_extern
1018+ . unwrap ( )
1019+ {
1020+ // Automatically import `proc_macro`.
1021+ result. push ( OsString :: from ( "--extern" ) ) ;
1022+ result. push ( OsString :: from ( "proc_macro" ) ) ;
1023+ }
10131024
10141025 Ok ( result)
10151026}
Original file line number Diff line number Diff line change @@ -440,3 +440,37 @@ Caused by:
440440 . with_status ( 101 )
441441 . run ( ) ;
442442}
443+
444+ #[ cargo_test]
445+ fn proc_macro_extern_prelude ( ) {
446+ if !is_nightly ( ) {
447+ // remove once pathless `--extern` hits stable (1.41)
448+ return ;
449+ }
450+ // Check that proc_macro is in the extern prelude.
451+ let p = project ( )
452+ . file (
453+ "Cargo.toml" ,
454+ r#"
455+ [package]
456+ name = "foo"
457+ version = "0.1.0"
458+ edition = "2018"
459+ [lib]
460+ proc-macro = true
461+ "# ,
462+ )
463+ . file (
464+ "src/lib.rs" ,
465+ r#"
466+ use proc_macro::TokenStream;
467+ #[proc_macro]
468+ pub fn foo(input: TokenStream) -> TokenStream {
469+ "".parse().unwrap()
470+ }
471+ "# ,
472+ )
473+ . build ( ) ;
474+ p. cargo ( "test" ) . run ( ) ;
475+ p. cargo ( "doc" ) . run ( ) ;
476+ }
Original file line number Diff line number Diff line change @@ -6,6 +6,11 @@ use std::env;
66
77#[ cargo_test]
88fn rustc_info_cache ( ) {
9+ if !cargo_test_support:: is_nightly ( ) {
10+ // remove once pathless `--extern` hits stable (1.41)
11+ return ;
12+ }
13+
914 let p = project ( )
1015 . file ( "src/main.rs" , r#"fn main() { println!("hello"); }"# )
1116 . build ( ) ;
You can’t perform that action at this time.
0 commit comments