File tree 7 files changed +133
-10
lines changed
7 files changed +133
-10
lines changed Original file line number Diff line number Diff line change @@ -99,11 +99,6 @@ impl BuildConfig {
99
99
} ,
100
100
} ;
101
101
102
- if gctx. cli_unstable ( ) . build_std . is_some ( ) && requested_kinds[ 0 ] . is_host ( ) {
103
- // TODO: This should eventually be fixed.
104
- anyhow:: bail!( "-Zbuild-std requires --target" ) ;
105
- }
106
-
107
102
Ok ( BuildConfig {
108
103
requested_kinds,
109
104
jobs,
Original file line number Diff line number Diff line change @@ -435,10 +435,6 @@ component:
435
435
$ rustup component add rust-src --toolchain nightly
436
436
```
437
437
438
- It is also required today that the ` -Z build-std ` flag is combined with the
439
- ` --target ` flag. Note that you're not forced to do a cross compilation, you're
440
- just forced to pass ` --target ` in one form or another.
441
-
442
438
Usage looks like:
443
439
444
440
``` console
@@ -472,7 +468,6 @@ The value here is a comma-separated list of standard library crates to build.
472
468
As a summary, a list of requirements today to use ` -Z build-std ` are:
473
469
474
470
* You must install libstd's source code through ` rustup component add rust-src `
475
- * You must pass ` --target `
476
471
* You must use both a nightly Cargo and a nightly rustc
477
472
* The ` -Z build-std ` flag must be passed to all ` cargo ` invocations.
478
473
Original file line number Diff line number Diff line change @@ -154,6 +154,66 @@ fn basic() {
154
154
assert_eq ! ( p. glob( deps_dir. join( "*.dylib" ) ) . count( ) , 0 ) ;
155
155
}
156
156
157
+ #[ cargo_test( build_std_real) ]
158
+ fn host_proc_macro ( ) {
159
+ let p = project ( )
160
+ . file (
161
+ "Cargo.toml" ,
162
+ r#"
163
+ [package]
164
+ name = "foo"
165
+ version = "0.1.0"
166
+ edition = "2021"
167
+
168
+ [dependencies]
169
+ macro_test = { path = "macro_test" }
170
+ "# ,
171
+ )
172
+ . file (
173
+ "src/main.rs" ,
174
+ r#"
175
+ extern crate macro_test;
176
+ use macro_test::make_answer;
177
+
178
+ make_answer!();
179
+
180
+ fn main() {
181
+ println!("Hello, World: {}", answer());
182
+ }
183
+ "# ,
184
+ )
185
+ . file (
186
+ "macro_test/Cargo.toml" ,
187
+ r#"
188
+ [package]
189
+ name = "macro_test"
190
+ version = "0.1.0"
191
+ edition = "2021"
192
+
193
+ [lib]
194
+ proc-macro = true
195
+ "# ,
196
+ )
197
+ . file (
198
+ "macro_test/src/lib.rs" ,
199
+ r#"
200
+ extern crate proc_macro;
201
+ use proc_macro::TokenStream;
202
+
203
+ #[proc_macro]
204
+ pub fn make_answer(_item: TokenStream) -> TokenStream {
205
+ "fn answer() -> u32 { 42 }".parse().unwrap()
206
+ }
207
+ "# ,
208
+ )
209
+ . build ( ) ;
210
+
211
+ p. cargo ( "build" )
212
+ . build_std_arg ( "std" )
213
+ . build_std_arg ( "proc_macro" )
214
+ . run ( ) ;
215
+ }
216
+
157
217
#[ cargo_test( build_std_real) ]
158
218
fn cross_custom ( ) {
159
219
let p = project ( )
Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " dep_test"
3
+ version = " 0.1.0"
4
+ edition = " 2021"
Original file line number Diff line number Diff line change
1
+
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ edition = "2018"
6
6
7
7
[dependencies ]
8
8
registry-dep-using-alloc = { version = " *" , features = [' mockbuild' ] }
9
+ dep_test = { path = " ../../dep_test" }
9
10
10
11
[features ]
11
12
feature1 = []
Original file line number Diff line number Diff line change @@ -246,6 +246,73 @@ fn basic() {
246
246
p. cargo ( "test" ) . build_std ( & setup) . target_host ( ) . run ( ) ;
247
247
}
248
248
249
+ #[ cargo_test( build_std_mock) ]
250
+ fn shared_std_dependency_rebuild ( ) {
251
+ let manifest_dir = std:: env:: var ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ;
252
+ let setup = setup ( ) ;
253
+ let p = project ( )
254
+ . file (
255
+ "Cargo.toml" ,
256
+ format ! (
257
+ "
258
+ [package]
259
+ name = \" foo\"
260
+ version = \" 0.1.0\"
261
+ edition = \" 2021\"
262
+
263
+ [build-dependencies]
264
+ dep_test = {{ path = \" {}/tests/testsuite/mock-std/dep_test\" }}
265
+ " ,
266
+ manifest_dir
267
+ )
268
+ . as_str ( ) ,
269
+ )
270
+ . file (
271
+ "src/main.rs" ,
272
+ r#"
273
+ fn main() {
274
+ println!("Hello, World!");
275
+ }
276
+ "# ,
277
+ )
278
+ . file (
279
+ "build.rs" ,
280
+ r#"
281
+ fn main() {
282
+ println!("cargo::rerun-if-changed=build.rs");
283
+ }
284
+ "# ,
285
+ )
286
+ . build ( ) ;
287
+
288
+ p. cargo ( "build -v" )
289
+ . build_std ( & setup)
290
+ . target_host ( )
291
+ . with_stderr_data ( str![ [ r#"
292
+ ...
293
+ [RUNNING] `[..] rustc --crate-name dep_test [..]`
294
+ ...
295
+ [RUNNING] `[..] rustc --crate-name dep_test [..]`
296
+ ...
297
+ "# ] ] )
298
+ . run ( ) ;
299
+
300
+ // TODO: Because of the way in which std is resolved, it's mandatory that this is left commented
301
+ // out as it will fail. This case should result in `dep_test` only being built once, however
302
+ // it's still being built twice. This is a bug.
303
+ //
304
+ // p.cargo("build -v")
305
+ // .build_std(&setup)
306
+ // .with_stderr_does_not_contain(str![[r#"
307
+ //...
308
+ //[RUNNING] `[..] rustc --crate-name dep_test [..]`
309
+ //...
310
+ //[RUNNING] `[..] rustc --crate-name dep_test [..]`
311
+ //...
312
+ //"#]])
313
+ // .run();
314
+ }
315
+
249
316
#[ cargo_test( build_std_mock) ]
250
317
fn simple_lib_std ( ) {
251
318
let setup = setup ( ) ;
You can’t perform that action at this time.
0 commit comments