]> git.proxmox.com Git - cargo.git/blob - tests/testsuite/rustc.rs
New test for `cargo rustc --crate-type` with dependency
[cargo.git] / tests / testsuite / rustc.rs
1 //! Tests for the `cargo rustc` command.
2
3 use cargo_test_support::{basic_bin_manifest, basic_lib_manifest, basic_manifest, project};
4
5 const CARGO_RUSTC_ERROR: &str =
6 "[ERROR] extra arguments to `rustc` can only be passed to one target, consider filtering
7 the package by passing, e.g., `--lib` or `--bin NAME` to specify a single target";
8
9 #[cargo_test]
10 fn build_lib_for_foo() {
11 let p = project()
12 .file("src/main.rs", "fn main() {}")
13 .file("src/lib.rs", r#" "#)
14 .build();
15
16 p.cargo("rustc --lib -v")
17 .with_stderr(
18 "\
19 [COMPILING] foo v0.0.1 ([CWD])
20 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
21 --emit=[..]link[..]-C debuginfo=2 \
22 -C metadata=[..] \
23 --out-dir [..] \
24 -L dependency=[CWD]/target/debug/deps`
25 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
26 ",
27 )
28 .run();
29 }
30
31 #[cargo_test]
32 fn lib() {
33 let p = project()
34 .file("src/main.rs", "fn main() {}")
35 .file("src/lib.rs", r#" "#)
36 .build();
37
38 p.cargo("rustc --lib -v -- -C debug-assertions=off")
39 .with_stderr(
40 "\
41 [COMPILING] foo v0.0.1 ([CWD])
42 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
43 --emit=[..]link[..]-C debuginfo=2 \
44 -C debug-assertions=off \
45 -C metadata=[..] \
46 --out-dir [..] \
47 -L dependency=[CWD]/target/debug/deps`
48 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
49 ",
50 )
51 .run();
52 }
53
54 #[cargo_test]
55 fn build_main_and_allow_unstable_options() {
56 let p = project()
57 .file("src/main.rs", "fn main() {}")
58 .file("src/lib.rs", r#" "#)
59 .build();
60
61 p.cargo("rustc -v --bin foo -- -C debug-assertions")
62 .with_stderr(format!(
63 "\
64 [COMPILING] {name} v{version} ([CWD])
65 [RUNNING] `rustc --crate-name {name} src/lib.rs [..]--crate-type lib \
66 --emit=[..]link[..]-C debuginfo=2 \
67 -C metadata=[..] \
68 --out-dir [..] \
69 -L dependency=[CWD]/target/debug/deps`
70 [RUNNING] `rustc --crate-name {name} src/main.rs [..]--crate-type bin \
71 --emit=[..]link[..]-C debuginfo=2 \
72 -C debug-assertions \
73 -C metadata=[..] \
74 --out-dir [..] \
75 -L dependency=[CWD]/target/debug/deps \
76 --extern {name}=[CWD]/target/debug/deps/lib{name}-[..].rlib`
77 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
78 ",
79 name = "foo",
80 version = "0.0.1"
81 ))
82 .run();
83 }
84
85 #[cargo_test]
86 fn fails_when_trying_to_build_main_and_lib_with_args() {
87 let p = project()
88 .file("src/main.rs", "fn main() {}")
89 .file("src/lib.rs", r#" "#)
90 .build();
91
92 p.cargo("rustc -v -- -C debug-assertions")
93 .with_status(101)
94 .with_stderr(CARGO_RUSTC_ERROR)
95 .run();
96 }
97
98 #[cargo_test]
99 fn build_with_args_to_one_of_multiple_binaries() {
100 let p = project()
101 .file("src/bin/foo.rs", "fn main() {}")
102 .file("src/bin/bar.rs", "fn main() {}")
103 .file("src/bin/baz.rs", "fn main() {}")
104 .file("src/lib.rs", r#" "#)
105 .build();
106
107 p.cargo("rustc -v --bin bar -- -C debug-assertions")
108 .with_stderr(
109 "\
110 [COMPILING] foo v0.0.1 ([CWD])
111 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link[..]\
112 -C debuginfo=2 -C metadata=[..] \
113 --out-dir [..]`
114 [RUNNING] `rustc --crate-name bar src/bin/bar.rs [..]--crate-type bin --emit=[..]link[..]\
115 -C debuginfo=2 -C debug-assertions [..]`
116 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
117 ",
118 )
119 .run();
120 }
121
122 #[cargo_test]
123 fn fails_with_args_to_all_binaries() {
124 let p = project()
125 .file("src/bin/foo.rs", "fn main() {}")
126 .file("src/bin/bar.rs", "fn main() {}")
127 .file("src/bin/baz.rs", "fn main() {}")
128 .file("src/lib.rs", r#" "#)
129 .build();
130
131 p.cargo("rustc -v -- -C debug-assertions")
132 .with_status(101)
133 .with_stderr(CARGO_RUSTC_ERROR)
134 .run();
135 }
136
137 #[cargo_test]
138 fn fails_with_crate_type_and_without_unstable_options() {
139 let p = project().file("src/lib.rs", r#" "#).build();
140
141 p.cargo("rustc --crate-type lib")
142 .masquerade_as_nightly_cargo()
143 .with_status(101)
144 .with_stderr(
145 "[ERROR] the `crate-type` flag is unstable, pass `-Z unstable-options` to enable it
146 See https://github.com/rust-lang/cargo/issues/10083 for more information about the `crate-type` flag.",
147 )
148 .run();
149 }
150
151 #[cargo_test]
152 fn fails_with_crate_type_to_multi_binaries() {
153 let p = project()
154 .file("src/bin/foo.rs", "fn main() {}")
155 .file("src/bin/bar.rs", "fn main() {}")
156 .file("src/bin/baz.rs", "fn main() {}")
157 .file("src/lib.rs", r#" "#)
158 .build();
159
160 p.cargo("rustc --crate-type lib -Zunstable-options")
161 .masquerade_as_nightly_cargo()
162 .with_status(101)
163 .with_stderr(
164 "[ERROR] crate types to rustc can only be passed to one target, consider filtering
165 the package by passing, e.g., `--lib` or `--example` to specify a single target",
166 )
167 .run();
168 }
169
170 #[cargo_test]
171 fn fails_with_crate_type_to_multi_examples() {
172 let p = project()
173 .file(
174 "Cargo.toml",
175 r#"
176 [package]
177 name = "foo"
178 version = "0.0.1"
179 authors = []
180
181 [[example]]
182 name = "ex1"
183 crate-type = ["rlib"]
184 [[example]]
185 name = "ex2"
186 crate-type = ["rlib"]
187 "#,
188 )
189 .file("src/lib.rs", "")
190 .file("examples/ex1.rs", "")
191 .file("examples/ex2.rs", "")
192 .build();
193
194 p.cargo("rustc -v --example ex1 --example ex2 --crate-type lib,cdylib -Zunstable-options")
195 .masquerade_as_nightly_cargo()
196 .with_status(101)
197 .with_stderr(
198 "[ERROR] crate types to rustc can only be passed to one target, consider filtering
199 the package by passing, e.g., `--lib` or `--example` to specify a single target",
200 )
201 .run();
202 }
203
204 #[cargo_test]
205 fn fails_with_crate_type_to_binary() {
206 let p = project().file("src/bin/foo.rs", "fn main() {}").build();
207
208 p.cargo("rustc --crate-type lib -Zunstable-options")
209 .masquerade_as_nightly_cargo()
210 .with_status(101)
211 .with_stderr(
212 "[ERROR] crate types can only be specified for libraries and example libraries.
213 Binaries, tests, and benchmarks are always the `bin` crate type",
214 )
215 .run();
216 }
217
218 #[cargo_test]
219 fn build_with_crate_type_for_foo() {
220 let p = project().file("src/lib.rs", "").build();
221
222 p.cargo("rustc -v --crate-type cdylib -Zunstable-options")
223 .masquerade_as_nightly_cargo()
224 .with_stderr(
225 "\
226 [COMPILING] foo v0.0.1 ([CWD])
227 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type cdylib [..]
228 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
229 ",
230 )
231 .run();
232 }
233
234 #[cargo_test]
235 fn build_with_crate_type_for_foo_with_deps() {
236 let p = project()
237 .file(
238 "src/lib.rs",
239 r#"
240 extern crate a;
241 pub fn foo() { a::hello(); }
242 "#,
243 )
244 .file(
245 "Cargo.toml",
246 r#"
247 [package]
248 name = "foo"
249 version = "0.0.1"
250 authors = []
251
252 [dependencies]
253 a = { path = "a" }
254 "#,
255 )
256 .file("a/Cargo.toml", &basic_manifest("a", "0.1.0"))
257 .file("a/src/lib.rs", "pub fn hello() {}")
258 .build();
259
260 p.cargo("rustc -v --crate-type cdylib -Zunstable-options")
261 .masquerade_as_nightly_cargo()
262 .with_stderr(
263 "\
264 [COMPILING] a v0.1.0 ([CWD]/a)
265 [RUNNING] `rustc --crate-name a a/src/lib.rs [..]--crate-type lib [..]
266 [COMPILING] foo v0.0.1 ([CWD])
267 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type cdylib [..]
268 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
269 ",
270 )
271 .run();
272 }
273
274 #[cargo_test]
275 fn build_with_crate_types_for_foo() {
276 let p = project().file("src/lib.rs", "").build();
277
278 p.cargo("rustc -v --crate-type lib,cdylib -Zunstable-options")
279 .masquerade_as_nightly_cargo()
280 .with_stderr(
281 "\
282 [COMPILING] foo v0.0.1 ([CWD])
283 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib,cdylib [..]
284 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
285 ",
286 )
287 .run();
288 }
289
290 #[cargo_test]
291 fn build_with_crate_type_to_example() {
292 let p = project()
293 .file(
294 "Cargo.toml",
295 r#"
296 [package]
297 name = "foo"
298 version = "0.0.1"
299 authors = []
300
301 [[example]]
302 name = "ex"
303 crate-type = ["rlib"]
304 "#,
305 )
306 .file("src/lib.rs", "")
307 .file("examples/ex.rs", "")
308 .build();
309
310 p.cargo("rustc -v --example ex --crate-type cdylib -Zunstable-options")
311 .masquerade_as_nightly_cargo()
312 .with_stderr(
313 "\
314 [COMPILING] foo v0.0.1 ([CWD])
315 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib [..]
316 [RUNNING] `rustc --crate-name ex examples/ex.rs [..]--crate-type cdylib [..]
317 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
318 ",
319 )
320 .run();
321 }
322
323 #[cargo_test]
324 fn build_with_crate_types_to_example() {
325 let p = project()
326 .file(
327 "Cargo.toml",
328 r#"
329 [package]
330 name = "foo"
331 version = "0.0.1"
332 authors = []
333
334 [[example]]
335 name = "ex"
336 crate-type = ["rlib"]
337 "#,
338 )
339 .file("src/lib.rs", "")
340 .file("examples/ex.rs", "")
341 .build();
342
343 p.cargo("rustc -v --example ex --crate-type lib,cdylib -Zunstable-options")
344 .masquerade_as_nightly_cargo()
345 .with_stderr(
346 "\
347 [COMPILING] foo v0.0.1 ([CWD])
348 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib [..]
349 [RUNNING] `rustc --crate-name ex examples/ex.rs [..]--crate-type lib,cdylib [..]
350 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
351 ",
352 )
353 .run();
354 }
355
356 #[cargo_test]
357 fn build_with_crate_types_to_one_of_multi_examples() {
358 let p = project()
359 .file(
360 "Cargo.toml",
361 r#"
362 [package]
363 name = "foo"
364 version = "0.0.1"
365 authors = []
366
367 [[example]]
368 name = "ex1"
369 crate-type = ["rlib"]
370 [[example]]
371 name = "ex2"
372 crate-type = ["rlib"]
373 "#,
374 )
375 .file("src/lib.rs", "")
376 .file("examples/ex1.rs", "")
377 .file("examples/ex2.rs", "")
378 .build();
379
380 p.cargo("rustc -v --example ex1 --crate-type lib,cdylib -Zunstable-options")
381 .masquerade_as_nightly_cargo()
382 .with_stderr(
383 "\
384 [COMPILING] foo v0.0.1 ([CWD])
385 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib [..]
386 [RUNNING] `rustc --crate-name ex1 examples/ex1.rs [..]--crate-type lib,cdylib [..]
387 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
388 ",
389 )
390 .run();
391 }
392
393 #[cargo_test]
394 fn build_with_args_to_one_of_multiple_tests() {
395 let p = project()
396 .file("tests/foo.rs", r#" "#)
397 .file("tests/bar.rs", r#" "#)
398 .file("tests/baz.rs", r#" "#)
399 .file("src/lib.rs", r#" "#)
400 .build();
401
402 p.cargo("rustc -v --test bar -- -C debug-assertions")
403 .with_stderr(
404 "\
405 [COMPILING] foo v0.0.1 ([CWD])
406 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link[..]\
407 -C debuginfo=2 -C metadata=[..] \
408 --out-dir [..]`
409 [RUNNING] `rustc --crate-name bar tests/bar.rs [..]--emit=[..]link[..]-C debuginfo=2 \
410 -C debug-assertions [..]--test[..]`
411 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
412 ",
413 )
414 .run();
415 }
416
417 #[cargo_test]
418 fn build_foo_with_bar_dependency() {
419 let foo = project()
420 .file(
421 "Cargo.toml",
422 r#"
423 [package]
424 name = "foo"
425 version = "0.0.1"
426 authors = []
427
428 [dependencies.bar]
429 path = "../bar"
430 "#,
431 )
432 .file("src/main.rs", "extern crate bar; fn main() { bar::baz() }")
433 .build();
434 let _bar = project()
435 .at("bar")
436 .file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
437 .file("src/lib.rs", "pub fn baz() {}")
438 .build();
439
440 foo.cargo("rustc -v -- -C debug-assertions")
441 .with_stderr(
442 "\
443 [COMPILING] bar v0.1.0 ([..])
444 [RUNNING] `[..] -C debuginfo=2 [..]`
445 [COMPILING] foo v0.0.1 ([CWD])
446 [RUNNING] `[..] -C debuginfo=2 -C debug-assertions [..]`
447 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
448 ",
449 )
450 .run();
451 }
452
453 #[cargo_test]
454 fn build_only_bar_dependency() {
455 let foo = project()
456 .file(
457 "Cargo.toml",
458 r#"
459 [package]
460 name = "foo"
461 version = "0.0.1"
462 authors = []
463
464 [dependencies.bar]
465 path = "../bar"
466 "#,
467 )
468 .file("src/main.rs", "extern crate bar; fn main() { bar::baz() }")
469 .build();
470 let _bar = project()
471 .at("bar")
472 .file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
473 .file("src/lib.rs", "pub fn baz() {}")
474 .build();
475
476 foo.cargo("rustc -v -p bar -- -C debug-assertions")
477 .with_stderr(
478 "\
479 [COMPILING] bar v0.1.0 ([..])
480 [RUNNING] `rustc --crate-name bar [..]--crate-type lib [..] -C debug-assertions [..]`
481 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
482 ",
483 )
484 .run();
485 }
486
487 #[cargo_test]
488 fn targets_selected_default() {
489 let p = project().file("src/main.rs", "fn main() {}").build();
490 p.cargo("rustc -v")
491 // bin
492 .with_stderr_contains(
493 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
494 --emit=[..]link[..]",
495 )
496 // bench
497 .with_stderr_does_not_contain(
498 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link \
499 -C opt-level=3 --test [..]",
500 )
501 // unit test
502 .with_stderr_does_not_contain(
503 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link \
504 -C debuginfo=2 --test [..]",
505 )
506 .run();
507 }
508
509 #[cargo_test]
510 fn targets_selected_all() {
511 let p = project().file("src/main.rs", "fn main() {}").build();
512 p.cargo("rustc -v --all-targets")
513 // bin
514 .with_stderr_contains(
515 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
516 --emit=[..]link[..]",
517 )
518 // unit test
519 .with_stderr_contains(
520 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link[..]\
521 -C debuginfo=2 --test [..]",
522 )
523 .run();
524 }
525
526 #[cargo_test]
527 fn fail_with_multiple_packages() {
528 let foo = project()
529 .file(
530 "Cargo.toml",
531 r#"
532 [package]
533 name = "foo"
534 version = "0.0.1"
535 authors = []
536
537 [dependencies.bar]
538 path = "../bar"
539
540 [dependencies.baz]
541 path = "../baz"
542 "#,
543 )
544 .file("src/main.rs", "fn main() {}")
545 .build();
546
547 let _bar = project()
548 .at("bar")
549 .file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
550 .file(
551 "src/main.rs",
552 r#"
553 fn main() {
554 if cfg!(flag = "1") { println!("Yeah from bar!"); }
555 }
556 "#,
557 )
558 .build();
559
560 let _baz = project()
561 .at("baz")
562 .file("Cargo.toml", &basic_manifest("baz", "0.1.0"))
563 .file(
564 "src/main.rs",
565 r#"
566 fn main() {
567 if cfg!(flag = "1") { println!("Yeah from baz!"); }
568 }
569 "#,
570 )
571 .build();
572
573 foo.cargo("rustc -v -p bar -p baz")
574 .with_status(1)
575 .with_stderr_contains(
576 "\
577 error: The argument '--package [<SPEC>...]' was provided more than once, \
578 but cannot be used multiple times
579 ",
580 )
581 .run();
582 }
583
584 #[cargo_test]
585 fn fail_with_glob() {
586 let p = project()
587 .file(
588 "Cargo.toml",
589 r#"
590 [workspace]
591 members = ["bar"]
592 "#,
593 )
594 .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
595 .file("bar/src/lib.rs", "pub fn bar() { break_the_build(); }")
596 .build();
597
598 p.cargo("rustc -p '*z'")
599 .with_status(101)
600 .with_stderr("[ERROR] Glob patterns on package selection are not supported.")
601 .run();
602 }
603
604 #[cargo_test]
605 fn rustc_with_other_profile() {
606 let p = project()
607 .file(
608 "Cargo.toml",
609 r#"
610 [package]
611 name = "foo"
612 version = "0.0.1"
613 authors = []
614
615 [dev-dependencies]
616 a = { path = "a" }
617 "#,
618 )
619 .file(
620 "src/main.rs",
621 r#"
622 #[cfg(test)] extern crate a;
623
624 #[test]
625 fn foo() {}
626 "#,
627 )
628 .file("a/Cargo.toml", &basic_manifest("a", "0.1.0"))
629 .file("a/src/lib.rs", "")
630 .build();
631
632 p.cargo("rustc --profile test").run();
633 }
634
635 #[cargo_test]
636 fn rustc_fingerprint() {
637 // Verify that the fingerprint includes the rustc args.
638 let p = project()
639 .file("Cargo.toml", &basic_lib_manifest("foo"))
640 .file("src/lib.rs", "")
641 .build();
642
643 p.cargo("rustc -v -- -C debug-assertions")
644 .with_stderr(
645 "\
646 [COMPILING] foo [..]
647 [RUNNING] `rustc [..]-C debug-assertions [..]
648 [FINISHED] [..]
649 ",
650 )
651 .run();
652
653 p.cargo("rustc -v -- -C debug-assertions")
654 .with_stderr(
655 "\
656 [FRESH] foo [..]
657 [FINISHED] [..]
658 ",
659 )
660 .run();
661
662 p.cargo("rustc -v")
663 .with_stderr_does_not_contain("-C debug-assertions")
664 .with_stderr(
665 "\
666 [COMPILING] foo [..]
667 [RUNNING] `rustc [..]
668 [FINISHED] [..]
669 ",
670 )
671 .run();
672
673 p.cargo("rustc -v")
674 .with_stderr(
675 "\
676 [FRESH] foo [..]
677 [FINISHED] [..]
678 ",
679 )
680 .run();
681 }
682
683 #[cargo_test]
684 fn rustc_test_with_implicit_bin() {
685 let p = project()
686 .file("Cargo.toml", &basic_bin_manifest("foo"))
687 .file(
688 "src/main.rs",
689 r#"
690 #[cfg(foo)]
691 fn f() { compile_fail!("Foo shouldn't be set."); }
692 fn main() {}
693 "#,
694 )
695 .file(
696 "tests/test1.rs",
697 r#"
698 #[cfg(not(foo))]
699 fn f() { compile_fail!("Foo should be set."); }
700 "#,
701 )
702 .build();
703
704 p.cargo("rustc --test test1 -v -- --cfg foo")
705 .with_stderr_contains(
706 "\
707 [RUNNING] `rustc --crate-name test1 tests/test1.rs [..] --cfg foo [..]
708 ",
709 )
710 .with_stderr_contains(
711 "\
712 [RUNNING] `rustc --crate-name foo src/main.rs [..]
713 ",
714 )
715 .run();
716 }
717
718 #[cargo_test]
719 fn rustc_with_print_cfg_single_target() {
720 let p = project()
721 .file("Cargo.toml", &basic_bin_manifest("foo"))
722 .file("src/main.rs", r#"fn main() {} "#)
723 .build();
724
725 p.cargo("rustc -Z unstable-options --target x86_64-pc-windows-msvc --print cfg")
726 .masquerade_as_nightly_cargo()
727 .with_stdout_contains("debug_assertions")
728 .with_stdout_contains("target_arch=\"x86_64\"")
729 .with_stdout_contains("target_endian=\"little\"")
730 .with_stdout_contains("target_env=\"msvc\"")
731 .with_stdout_contains("target_family=\"windows\"")
732 .with_stdout_contains("target_os=\"windows\"")
733 .with_stdout_contains("target_pointer_width=\"64\"")
734 .with_stdout_contains("target_vendor=\"pc\"")
735 .with_stdout_contains("windows")
736 .run();
737 }
738
739 #[cargo_test]
740 fn rustc_with_print_cfg_multiple_targets() {
741 let p = project()
742 .file("Cargo.toml", &basic_bin_manifest("foo"))
743 .file("src/main.rs", r#"fn main() {} "#)
744 .build();
745
746 p.cargo("rustc -Z unstable-options -Z multitarget --target x86_64-pc-windows-msvc --target i686-unknown-linux-gnu --print cfg")
747 .masquerade_as_nightly_cargo()
748 .with_stdout_contains("debug_assertions")
749 .with_stdout_contains("target_arch=\"x86_64\"")
750 .with_stdout_contains("target_endian=\"little\"")
751 .with_stdout_contains("target_env=\"msvc\"")
752 .with_stdout_contains("target_family=\"windows\"")
753 .with_stdout_contains("target_os=\"windows\"")
754 .with_stdout_contains("target_pointer_width=\"64\"")
755 .with_stdout_contains("target_vendor=\"pc\"")
756 .with_stdout_contains("windows")
757 .with_stdout_contains("target_env=\"gnu\"")
758 .with_stdout_contains("target_family=\"unix\"")
759 .with_stdout_contains("target_pointer_width=\"32\"")
760 .with_stdout_contains("target_vendor=\"unknown\"")
761 .with_stdout_contains("target_os=\"linux\"")
762 .with_stdout_contains("unix")
763 .run();
764 }
765
766 #[cargo_test]
767 fn rustc_with_print_cfg_rustflags_env_var() {
768 let p = project()
769 .file("Cargo.toml", &basic_bin_manifest("foo"))
770 .file("src/main.rs", r#"fn main() {} "#)
771 .build();
772
773 p.cargo("rustc -Z unstable-options --target x86_64-pc-windows-msvc --print cfg")
774 .masquerade_as_nightly_cargo()
775 .env("RUSTFLAGS", "-C target-feature=+crt-static")
776 .with_stdout_contains("debug_assertions")
777 .with_stdout_contains("target_arch=\"x86_64\"")
778 .with_stdout_contains("target_endian=\"little\"")
779 .with_stdout_contains("target_env=\"msvc\"")
780 .with_stdout_contains("target_family=\"windows\"")
781 .with_stdout_contains("target_feature=\"crt-static\"")
782 .with_stdout_contains("target_os=\"windows\"")
783 .with_stdout_contains("target_pointer_width=\"64\"")
784 .with_stdout_contains("target_vendor=\"pc\"")
785 .with_stdout_contains("windows")
786 .run();
787 }
788
789 #[cargo_test]
790 fn rustc_with_print_cfg_config_toml() {
791 let p = project()
792 .file("Cargo.toml", &basic_bin_manifest("foo"))
793 .file(
794 ".cargo/config.toml",
795 r#"
796 [target.x86_64-pc-windows-msvc]
797 rustflags = ["-C", "target-feature=+crt-static"]
798 "#,
799 )
800 .file("src/main.rs", r#"fn main() {} "#)
801 .build();
802
803 p.cargo("rustc -Z unstable-options --target x86_64-pc-windows-msvc --print cfg")
804 .masquerade_as_nightly_cargo()
805 .env("RUSTFLAGS", "-C target-feature=+crt-static")
806 .with_stdout_contains("debug_assertions")
807 .with_stdout_contains("target_arch=\"x86_64\"")
808 .with_stdout_contains("target_endian=\"little\"")
809 .with_stdout_contains("target_env=\"msvc\"")
810 .with_stdout_contains("target_family=\"windows\"")
811 .with_stdout_contains("target_feature=\"crt-static\"")
812 .with_stdout_contains("target_os=\"windows\"")
813 .with_stdout_contains("target_pointer_width=\"64\"")
814 .with_stdout_contains("target_vendor=\"pc\"")
815 .with_stdout_contains("windows")
816 .run();
817 }