]>
git.proxmox.com Git - cargo.git/blob - tests/testsuite/build.rs
1 //! Tests for the `cargo build` command.
4 core
:: compiler
:: CompileMode
,
5 core
:: {Shell, Workspace}
,
9 use cargo_test_support
:: compare
;
10 use cargo_test_support
:: paths
:: {root, CargoPathExt}
;
11 use cargo_test_support
:: registry
:: Package
;
12 use cargo_test_support
:: tools
;
13 use cargo_test_support
::{
14 basic_bin_manifest
, basic_lib_manifest
, basic_manifest
, cargo_exe
, git
, is_nightly
, main_file
,
15 paths
, process
, project
, rustc_host
, sleep_ms
, symlink_supported
, t
, Execs
, ProjectBuilder
,
17 use cargo_util
:: paths
:: dylib_path_envvar
;
21 use std
:: process
:: Stdio
;
24 fn cargo_compile_simple () {
26 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
27 . file ( "src/foo.rs" , & main_file ( r
# "" i am foo "" #, &[]))
30 p
. cargo ( "build" ). run ();
31 assert
!( p
. bin ( "foo" ). is_file ());
33 p
. process (& p
. bin ( "foo" )). with_stdout ( "i am foo \n " ). run ();
37 fn cargo_fail_with_no_stderr () {
39 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
40 . file ( "src/foo.rs" , & String
:: from ( "refusal" ))
42 p
. cargo ( "build --message-format=json" )
44 . with_stderr_does_not_contain ( "--- stderr" )
48 /// Checks that the `CARGO_INCREMENTAL` environment variable results in
49 /// `rustc` getting `-C incremental` passed to it.
51 fn cargo_compile_incremental () {
53 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
54 . file ( "src/foo.rs" , & main_file ( r
# "" i am foo "" #, &[]))
58 . env ( "CARGO_INCREMENTAL" , "1" )
59 . with_stderr_contains (
60 "[RUNNING] `rustc [..] -C incremental=[..]/target/debug/incremental[..]` \n " ,
65 . env ( "CARGO_INCREMENTAL" , "1" )
66 . with_stderr_contains (
67 "[RUNNING] `rustc [..] -C incremental=[..]/target/debug/incremental[..]` \n " ,
73 fn incremental_profile () {
90 . file ( "src/main.rs" , "fn main() {} " )
94 . env_remove ( "CARGO_INCREMENTAL" )
95 . with_stderr_does_not_contain ( "[..]C incremental=[..]" )
99 . env ( "CARGO_INCREMENTAL" , "1" )
100 . with_stderr_contains ( "[..]C incremental=[..]" )
103 p
. cargo ( "build --release -v" )
104 . env_remove ( "CARGO_INCREMENTAL" )
105 . with_stderr_contains ( "[..]C incremental=[..]" )
108 p
. cargo ( "build --release -v" )
109 . env ( "CARGO_INCREMENTAL" , "0" )
110 . with_stderr_does_not_contain ( "[..]C incremental=[..]" )
115 fn incremental_config () {
117 . file ( "src/main.rs" , "fn main() {} " )
128 . env_remove ( "CARGO_INCREMENTAL" )
129 . with_stderr_does_not_contain ( "[..]C incremental=[..]" )
133 . env ( "CARGO_INCREMENTAL" , "1" )
134 . with_stderr_contains ( "[..]C incremental=[..]" )
139 fn cargo_compile_with_workspace_excluded () {
140 let p
= project (). file ( "src/main.rs" , "fn main() {} " ). build ();
142 p
. cargo ( "build --workspace --exclude foo" )
143 . with_stderr_does_not_contain ( "[..]virtual[..]" )
144 . with_stderr_contains ( "[..]no packages to compile" )
150 fn cargo_compile_manifest_path () {
152 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
153 . file ( "src/foo.rs" , & main_file ( r
# "" i am foo "" #, &[]))
156 p
. cargo ( "build --manifest-path foo/Cargo.toml" )
157 . cwd ( p
. root (). parent (). unwrap ())
159 assert
!( p
. bin ( "foo" ). is_file ());
163 fn cargo_compile_with_invalid_manifest () {
164 let p
= project (). file ( "Cargo.toml" , "" ). build ();
170 [ERROR] failed to parse manifest at `[..]`
173 virtual manifests must be configured with [workspace]
180 fn cargo_compile_with_invalid_manifest2 () {
195 [ERROR] failed to parse manifest at `[..]`
198 could not parse input as TOML
201 TOML parse error at line 3, column 23
206 Expected quoted string
213 fn cargo_compile_with_invalid_manifest3 () {
214 let p
= project (). file ( "src/Cargo.toml" , "a = bar" ). build ();
216 p
. cargo ( "build --manifest-path src/Cargo.toml" )
220 [ERROR] failed to parse manifest at `[..]`
223 could not parse input as TOML
226 TOML parse error at line 1, column 5
231 Expected quoted string
238 fn cargo_compile_duplicate_build_targets () {
251 crate-type = [" dylib "]
256 . file ( "src/main.rs" , "#![allow(warnings)] fn main() {} " )
262 warning: file found to be present in multiple build targets: [..]main.rs
263 [COMPILING] foo v0.0.1 ([..])
271 fn cargo_compile_with_invalid_version () {
273 . file ( "Cargo.toml" , & basic_manifest ( "foo" , "1.0" ))
280 [ERROR] failed to parse manifest at `[..]`
283 unexpected end of input while parsing minor version number for key `package.version`
290 fn cargo_compile_with_empty_package_name () {
292 . file ( "Cargo.toml" , & basic_manifest ( "" , "0.0.0" ))
299 [ERROR] failed to parse manifest at `[..]`
302 package name cannot be an empty string
309 fn cargo_compile_with_invalid_package_name () {
311 . file ( "Cargo.toml" , & basic_manifest ( "foo::bar" , "0.0.0" ))
318 [ERROR] failed to parse manifest at `[..]`
321 invalid character `:` in package name: `foo::bar`, [..]
328 fn cargo_compile_with_invalid_bin_target_name () {
348 [ERROR] failed to parse manifest at `[..]`
351 binary target names cannot be empty
358 fn cargo_compile_with_forbidden_bin_target_name () {
378 [ERROR] failed to parse manifest at `[..]`
381 the binary target name `build` is forbidden, it conflicts with with cargo's build directory names
388 fn cargo_compile_with_bin_and_crate_type () {
401 crate-type = [" cdylib ", " rlib "]
404 . file ( "src/foo.rs" , "fn main() {} " )
411 [ERROR] failed to parse manifest at `[..]`
414 the target `the_foo_bin` is a binary and can't have any crate-types set \
415 (currently \" cdylib, rlib \" )" ,
421 fn cargo_compile_api_exposes_artifact_paths () {
438 crate-type = [" cdylib ", " rlib "]
441 . file ( "src/foo.rs" , "pub fn bar() {} " )
442 . file ( "src/bin.rs" , "pub fn main() {} " )
445 let shell
= Shell
:: from_write ( Box
:: new ( Vec
:: new ()));
446 let config
= Config
:: new ( shell
, env
:: current_dir (). unwrap (), paths
:: home ());
447 let ws
= Workspace
:: new (& p
. root (). join ( "Cargo.toml" ), & config
). unwrap ();
448 let compile_options
= CompileOptions
:: new ( ws
. config (), CompileMode
:: Build
). unwrap ();
450 let result
= cargo
:: ops
:: compile (& ws
, & compile_options
). unwrap ();
452 assert_eq
!( 1 , result
. binaries
. len ());
453 assert
!( result
. binaries
[ 0 ]. path
. exists ());
454 assert
!( result
. binaries
[ 0 ]
458 . contains ( "the_foo_bin" ));
460 assert_eq
!( 1 , result
. cdylibs
. len ());
461 // The exact library path varies by platform, but should certainly exist at least
462 assert
!( result
. cdylibs
[ 0 ]. path
. exists ());
463 assert
!( result
. cdylibs
[ 0 ]
467 . contains ( "the_foo_lib" ));
471 fn cargo_compile_with_bin_and_proc () {
487 . file ( "src/foo.rs" , "fn main() {} " )
494 [ERROR] failed to parse manifest at `[..]`
497 the target `the_foo_bin` is a binary and can't have `proc-macro` set `true`" ,
503 fn cargo_compile_with_invalid_lib_target_name () {
523 [ERROR] failed to parse manifest at `[..]`
526 library target names cannot be empty
533 fn cargo_compile_with_invalid_non_numeric_dep_version () {
552 [ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
555 failed to parse the version requirement `y` for dependency `crossbeam`
558 unexpected character 'y' while parsing major version number
565 fn cargo_compile_without_manifest () {
566 let p
= project (). no_manifest (). build ();
570 . with_stderr ( "[ERROR] could not find `Cargo.toml` in `[..]` or any parent directory" )
575 #[cfg(target_os = "linux" )]
576 fn cargo_compile_with_lowercase_cargo_toml () {
579 . file ( "cargo.toml" , & basic_manifest ( "foo" , "0.1.0" ))
580 . file ( "src/lib.rs" , & main_file ( r
# "" i am foo "" #, &[]))
586 "[ERROR] could not find `Cargo.toml` in `[..]` or any parent directory, \
587 but found cargo.toml please try to rename it to Cargo.toml" ,
593 fn cargo_compile_with_invalid_code () {
595 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
596 . file ( "src/foo.rs" , "invalid rust code!" )
601 . with_stderr_contains ( "[ERROR] could not compile `foo` due to previous error \n " )
603 assert
!( p
. root (). join ( "Cargo.lock" ). is_file ());
607 fn cargo_compile_with_invalid_code_in_deps () {
623 . file ( "src/main.rs" , "invalid rust code!" )
627 . file ( "Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
628 . file ( "src/lib.rs" , "invalid rust code!" )
632 . file ( "Cargo.toml" , & basic_manifest ( "baz" , "0.1.0" ))
633 . file ( "src/lib.rs" , "invalid rust code!" )
637 . with_stderr_contains ( "[..]invalid rust code[..]" )
638 . with_stderr_contains ( "[ERROR] could not compile [..]" )
643 fn cargo_compile_with_warnings_in_the_root_package () {
645 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
646 . file ( "src/foo.rs" , "fn main() {} fn dead() {} " )
650 . with_stderr_contains ( "[WARNING] [..]dead[..]" )
655 fn cargo_compile_with_warnings_in_a_dep_package () {
664 authors = [" wycats@example.com "]
674 . file ( "src/foo.rs" , & main_file ( r
# "" {} ", bar::gimme()" #, &[ "bar" ]))
675 . file ( "bar/Cargo.toml" , & basic_lib_manifest ( "bar" ))
679 pub fn gimme() -> &'static str {
689 . with_stderr_contains ( "[WARNING] [..]dead[..]" )
692 assert
!( p
. bin ( "foo" ). is_file ());
694 p
. process (& p
. bin ( "foo" )). with_stdout ( "test passed \n " ). run ();
698 fn cargo_compile_with_nested_deps_inferred () {
707 authors = [" wycats@example.com "]
716 . file ( "src/foo.rs" , & main_file ( r
# "" {} ", bar::gimme()" #, &[ "bar" ]))
724 authors = [" wycats@example.com "]
735 pub fn gimme() -> String {
740 . file ( "baz/Cargo.toml" , & basic_manifest ( "baz" , "0.5.0" ))
744 pub fn gimme() -> String {
745 " test passed ".to_string()
751 p
. cargo ( "build" ). run ();
753 assert
!( p
. bin ( "foo" ). is_file ());
754 assert
!(! p
. bin ( "libbar.rlib" ). is_file ());
755 assert
!(! p
. bin ( "libbaz.rlib" ). is_file ());
757 p
. process (& p
. bin ( "foo" )). with_stdout ( "test passed \n " ). run ();
761 fn cargo_compile_with_nested_deps_correct_bin () {
770 authors = [" wycats@example.com "]
779 . file ( "src/main.rs" , & main_file ( r
# "" {} ", bar::gimme()" #, &[ "bar" ]))
787 authors = [" wycats@example.com "]
798 pub fn gimme() -> String {
803 . file ( "baz/Cargo.toml" , & basic_manifest ( "baz" , "0.5.0" ))
807 pub fn gimme() -> String {
808 " test passed ".to_string()
814 p
. cargo ( "build" ). run ();
816 assert
!( p
. bin ( "foo" ). is_file ());
817 assert
!(! p
. bin ( "libbar.rlib" ). is_file ());
818 assert
!(! p
. bin ( "libbaz.rlib" ). is_file ());
820 p
. process (& p
. bin ( "foo" )). with_stdout ( "test passed \n " ). run ();
824 fn cargo_compile_with_nested_deps_shorthand () {
833 authors = [" wycats@example.com "]
839 . file ( "src/main.rs" , & main_file ( r
# "" {} ", bar::gimme()" #, &[ "bar" ]))
847 authors = [" wycats@example.com "]
862 pub fn gimme() -> String {
867 . file ( "baz/Cargo.toml" , & basic_lib_manifest ( "baz" ))
871 pub fn gimme() -> String {
872 " test passed ".to_string()
878 p
. cargo ( "build" ). run ();
880 assert
!( p
. bin ( "foo" ). is_file ());
881 assert
!(! p
. bin ( "libbar.rlib" ). is_file ());
882 assert
!(! p
. bin ( "libbaz.rlib" ). is_file ());
884 p
. process (& p
. bin ( "foo" )). with_stdout ( "test passed \n " ). run ();
888 fn cargo_compile_with_nested_deps_longhand () {
897 authors = [" wycats@example.com "]
908 . file ( "src/foo.rs" , & main_file ( r
# "" {} ", bar::gimme()" #, &[ "bar" ]))
916 authors = [" wycats@example.com "]
932 pub fn gimme() -> String {
937 . file ( "baz/Cargo.toml" , & basic_lib_manifest ( "baz" ))
941 pub fn gimme() -> String {
942 " test passed ".to_string()
948 p
. cargo ( "build" ). run ();
950 assert
!( p
. bin ( "foo" ). is_file ());
951 assert
!(! p
. bin ( "libbar.rlib" ). is_file ());
952 assert
!(! p
. bin ( "libbaz.rlib" ). is_file ());
954 p
. process (& p
. bin ( "foo" )). with_stdout ( "test passed \n " ). run ();
957 // Check that Cargo gives a sensible error if a dependency can't be found
958 // because of a name mismatch.
960 fn cargo_compile_with_dep_name_mismatch () {
969 authors = [" wycats@example.com "]
975 [dependencies.notquitebar]
980 . file ( "src/bin/foo.rs" , & main_file ( r
# "" i am foo "" #, &[ "bar" ]))
981 . file ( "bar/Cargo.toml" , & basic_bin_manifest ( "bar" ))
982 . file ( "bar/src/bar.rs" , & main_file ( r
# "" i am bar "" #, &[]))
989 error: no matching package named `notquitebar` found
990 location searched: [CWD]/bar
991 required by package `foo v0.0.1 ([CWD])`
997 // Ensure that renamed deps have a valid name
999 fn cargo_compile_with_invalid_dep_rename () {
1009 " haha this isn't a valid name 🐛 " = { package = "libc", version = "0.1" }
1012 . file ( "src/main.rs" , & main_file ( r
# "" What's good? "" #, &[]))
1019 error: failed to parse manifest at `[..]`
1022 invalid character ` ` in dependency name: `haha this isn't a valid name 🐛`, characters must be Unicode XID characters (numbers, `-`, `_`, or most letters)
1029 fn cargo_compile_with_filename () {
1031 . file ( "src/lib.rs" , "" )
1036 fn main() { println!("hello a.rs"); }
1039 . file ( "examples/a.rs" , r
# "fn main() { println!("example"); } " #)
1042 p
. cargo ( "build --bin bin.rs" )
1046 [ERROR] no bin target named `bin.rs`.
1047 Available bin targets:
1054 p
. cargo ( "build --bin a.rs" )
1058 [ERROR] no bin target named `a.rs`
1060 <tab>Did you mean `a`?" ,
1064 p
. cargo ( "build --example example.rs" )
1068 [ERROR] no example target named `example.rs`.
1069 Available example targets:
1076 p
. cargo ( "build --example a.rs" )
1080 [ERROR] no example target named `a.rs`
1082 <tab>Did you mean `a`?" ,
1088 fn incompatible_dependencies () {
1089 Package
:: new ( "bad" , "0.1.0" ). publish ();
1090 Package
:: new ( "bad" , "1.0.0" ). publish ();
1091 Package
:: new ( "bad" , "1.0.1" ). publish ();
1092 Package
:: new ( "bad" , "1.0.2" ). publish ();
1093 Package
:: new ( "bar" , "0.1.0" ). dep ( "bad" , "0.1.0" ). publish ();
1094 Package
:: new ( "baz" , "0.1.1" ). dep ( "bad" , "=1.0.0" ). publish ();
1095 Package
:: new ( "baz" , "0.1.0" ). dep ( "bad" , "=1.0.0" ). publish ();
1096 Package
:: new ( "qux" , "0.1.2" ). dep ( "bad" , ">=1.0.1" ). publish ();
1097 Package
:: new ( "qux" , "0.1.1" ). dep ( "bad" , ">=1.0.1" ). publish ();
1098 Package
:: new ( "qux" , "0.1.0" ). dep ( "bad" , ">=1.0.1" ). publish ();
1114 . file ( "src/main.rs" , "fn main() {} " )
1119 . with_stderr_contains (
1121 error: failed to select a version for `bad`.
1122 ... required by package `qux v0.1.0`
1123 ... which satisfies dependency `qux = \" ^0.1.0 \" ` of package `foo v0.0.1 ([..])`
1124 versions that meet the requirements `>=1.0.1` are: 1.0.2, 1.0.1
1126 all possible versions conflict with previously selected packages.
1128 previously selected package `bad v1.0.0`
1129 ... which satisfies dependency `bad = \" =1.0.0 \" ` of package `baz v0.1.0`
1130 ... which satisfies dependency `baz = \" ^0.1.0 \" ` of package `foo v0.0.1 ([..])`
1132 failed to select a version for `bad` which could resolve this conflict" ,
1138 fn incompatible_dependencies_with_multi_semver () {
1139 Package
:: new ( "bad" , "1.0.0" ). publish ();
1140 Package
:: new ( "bad" , "1.0.1" ). publish ();
1141 Package
:: new ( "bad" , "2.0.0" ). publish ();
1142 Package
:: new ( "bad" , "2.0.1" ). publish ();
1143 Package
:: new ( "bar" , "0.1.0" ). dep ( "bad" , "=1.0.0" ). publish ();
1144 Package
:: new ( "baz" , "0.1.0" ). dep ( "bad" , ">=2.0.1" ). publish ();
1157 bad = " >=1.0.1, <=2.0.0 "
1160 . file ( "src/main.rs" , "fn main() {} " )
1165 . with_stderr_contains (
1167 error: failed to select a version for `bad`.
1168 ... required by package `foo v0.0.1 ([..])`
1169 versions that meet the requirements `>=1.0.1, <=2.0.0` are: 2.0.0, 1.0.1
1171 all possible versions conflict with previously selected packages.
1173 previously selected package `bad v2.0.1`
1174 ... which satisfies dependency `bad = \" >=2.0.1 \" ` of package `baz v0.1.0`
1175 ... which satisfies dependency `baz = \" ^0.1.0 \" ` of package `foo v0.0.1 ([..])`
1177 previously selected package `bad v1.0.0`
1178 ... which satisfies dependency `bad = \" =1.0.0 \" ` of package `bar v0.1.0`
1179 ... which satisfies dependency `bar = \" ^0.1.0 \" ` of package `foo v0.0.1 ([..])`
1181 failed to select a version for `bad` which could resolve this conflict" ,
1187 fn compile_path_dep_then_change_version () {
1201 . file ( "src/lib.rs" , "" )
1202 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.0.1" ))
1203 . file ( "bar/src/lib.rs" , "" )
1206 p
. cargo ( "build" ). run ();
1208 p
. change_file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.0.2" ));
1210 p
. cargo ( "build" ). run ();
1214 fn ignores_carriage_return_in_lockfile () {
1216 . file ( "src/main.rs" , "mod a; fn main() {} " )
1217 . file ( "src/a.rs" , "" )
1220 p
. cargo ( "build" ). run ();
1222 let lock
= p
. read_lockfile ();
1223 p
. change_file ( "Cargo.lock" , & lock
. replace ( " \n " , " \r\n " ));
1224 p
. cargo ( "build" ). run ();
1228 fn cargo_default_env_metadata_env_var () {
1229 // Ensure that path dep + dylib + env_var get metadata
1230 // (even though path_dep + dylib should not)
1244 . file ( "src/lib.rs" , "// hi" )
1255 crate_type = [" dylib "]
1258 . file ( "bar/src/lib.rs" , "// hello" )
1261 // No metadata on libbar since it's a dylib path dependency
1263 . with_stderr (& format
!(
1265 [COMPILING] bar v0.0.1 ([CWD]/bar)
1266 [RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--crate-type dylib \
1268 -C prefer-dynamic[..]-C debuginfo=2 \
1271 -L dependency=[CWD]/target/debug/deps`
1272 [COMPILING] foo v0.0.1 ([CWD])
1273 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
1274 --emit=[..]link[..]-C debuginfo=2 \
1276 -C extra-filename=[..] \
1278 -L dependency=[CWD]/target/debug/deps \
1279 --extern bar=[CWD]/target/debug/deps/ {prefix} bar {suffix} `
1280 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]" ,
1281 prefix
= env
:: consts
:: DLL_PREFIX
,
1282 suffix
= env
:: consts
:: DLL_SUFFIX
,
1286 p
. cargo ( "clean" ). run ();
1288 // If you set the env-var, then we expect metadata on libbar
1290 . env ( "__CARGO_DEFAULT_LIB_METADATA" , "stable" )
1291 . with_stderr (& format
!(
1293 [COMPILING] bar v0.0.1 ([CWD]/bar)
1294 [RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--crate-type dylib \
1296 -C prefer-dynamic[..]-C debuginfo=2 \
1299 -L dependency=[CWD]/target/debug/deps`
1300 [COMPILING] foo v0.0.1 ([CWD])
1301 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
1302 --emit=[..]link[..]-C debuginfo=2 \
1304 -C extra-filename=[..] \
1306 -L dependency=[CWD]/target/debug/deps \
1307 --extern bar=[CWD]/target/debug/deps/ {prefix} bar-[..] {suffix} `
1308 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1310 prefix
= env
:: consts
:: DLL_PREFIX
,
1311 suffix
= env
:: consts
:: DLL_SUFFIX
,
1317 fn crate_env_vars () {
1324 version = " 0.5.1-alpha.1 "
1325 description = " This is foo "
1326 homepage = " https: //example.com"
1327 repository
= "https://example.com/repo.git"
1328 authors
= [ "wycats@example.com" ]
1329 license
= "MIT OR Apache-2.0"
1330 license
- file
= "license.txt"
1331 rust
- version
= "1.61.0"
1335 path
= "src/main.rs"
1344 static VERSION_MAJOR
: & '
static str = env
!( "CARGO_PKG_VERSION_MAJOR" );
1345 static VERSION_MINOR
: & '
static str = env
!( "CARGO_PKG_VERSION_MINOR" );
1346 static VERSION_PATCH
: & '
static str = env
!( "CARGO_PKG_VERSION_PATCH" );
1347 static VERSION_PRE
: & '
static str = env
!( "CARGO_PKG_VERSION_PRE" );
1348 static VERSION
: & '
static str = env
!( "CARGO_PKG_VERSION" );
1349 static CARGO_MANIFEST_DIR
: & '
static str = env
!( "CARGO_MANIFEST_DIR" );
1350 static PKG_NAME
: & '
static str = env
!( "CARGO_PKG_NAME" );
1351 static HOMEPAGE
: & '
static str = env
!( "CARGO_PKG_HOMEPAGE" );
1352 static REPOSITORY
: & '
static str = env
!( "CARGO_PKG_REPOSITORY" );
1353 static LICENSE
: & '
static str = env
!( "CARGO_PKG_LICENSE" );
1354 static LICENSE_FILE
: & '
static str = env
!( "CARGO_PKG_LICENSE_FILE" );
1355 static DESCRIPTION
: & '
static str = env
!( "CARGO_PKG_DESCRIPTION" );
1356 static RUST_VERSION
: & '
static str = env
!( "CARGO_PKG_RUST_VERSION" );
1357 static BIN_NAME
: & '
static str = env
!( "CARGO_BIN_NAME" );
1358 static CRATE_NAME
: & '
static str = env
!( "CARGO_CRATE_NAME" );
1362 let s
= format
!( " {} - {} - {} @ {} in {} " , VERSION_MAJOR
,
1363 VERSION_MINOR
, VERSION_PATCH
, VERSION_PRE
,
1364 CARGO_MANIFEST_DIR
);
1365 assert_eq
!( s
, foo
:: version ());
1367 assert_eq
!( "foo" , PKG_NAME
);
1368 assert_eq
!( "foo-bar" , BIN_NAME
);
1369 assert_eq
!( "foo_bar" , CRATE_NAME
);
1370 assert_eq
!( "https://example.com" , HOMEPAGE
);
1371 assert_eq
!( "https://example.com/repo.git" , REPOSITORY
);
1372 assert_eq
!( "MIT OR Apache-2.0" , LICENSE
);
1373 assert_eq
!( "license.txt" , LICENSE_FILE
);
1374 assert_eq
!( "This is foo" , DESCRIPTION
);
1375 assert_eq
!( "1.61.0" , RUST_VERSION
);
1376 let s
= format
!( " {} . {} . {} - {} " , VERSION_MAJOR
,
1377 VERSION_MINOR
, VERSION_PATCH
, VERSION_PRE
);
1378 assert_eq
!( s
, VERSION
);
1380 // Verify CARGO_TARGET_TMPDIR isn't set for bins
1381 assert
!( option_env
!( "CARGO_TARGET_TMPDIR" ). is_none ());
1389 use std
:: path
:: PathBuf
;
1391 pub fn version () -> String
{
1392 format
!( " {} - {} - {} @ {} in {} " ,
1393 env
!( "CARGO_PKG_VERSION_MAJOR" ),
1394 env
!( "CARGO_PKG_VERSION_MINOR" ),
1395 env
!( "CARGO_PKG_VERSION_PATCH" ),
1396 env
!( "CARGO_PKG_VERSION_PRE" ),
1397 env
!( "CARGO_MANIFEST_DIR" ))
1400 pub fn check_no_int_test_env () {
1401 env
:: var ( "CARGO_TARGET_DIR" ). unwrap_err ();
1404 pub fn check_tmpdir ( tmp
: Option
<& '
static str >) {
1405 let tmpdir
: PathBuf
= tmp
. unwrap (). into ();
1407 let exe
: PathBuf
= env
:: current_exe (). unwrap (). into ();
1408 let mut expected
: PathBuf
= exe
. parent (). unwrap ()
1412 expected
. push ( "tmp" );
1413 assert_eq
!( tmpdir
, expected
);
1415 // Check that CARGO_TARGET_TMPDIR isn't set for lib code
1416 assert
!( option_env
!( "CARGO_TARGET_TMPDIR" ). is_none ());
1417 env
:: var ( "CARGO_TARGET_TMPDIR" ). unwrap_err ();
1422 // Check that CARGO_TARGET_TMPDIR isn't set for unit tests
1423 assert
!( option_env
!( "CARGO_TARGET_TMPDIR" ). is_none ());
1424 env
:: var ( "CARGO_TARGET_TMPDIR" ). unwrap_err ();
1433 foo
:: check_tmpdir ( option_env
!( "CARGO_TARGET_TMPDIR" ));
1438 let p = if is_nightly() {
1447 fn env ( _
: & mut Bencher
) {
1448 foo
:: check_tmpdir ( option_env
!( "CARGO_TARGET_TMPDIR" ));
1458 p.cargo(" build
- v
").run();
1461 p.process(&p.bin(" foo
- bar
"))
1462 .with_stdout(" 0 - 5 - 1 @ alpha
. 1 in [ CWD
] ")
1466 p.cargo(" test
- v
").run();
1470 p.cargo(" bench
- v
").run();
1475 fn crate_authors_env_vars() {
1482 version
= "0.5.1-alpha.1"
1483 authors
= [ "wycats@example.com" , "neikos@example.com" ]
1491 static AUTHORS
: & '
static str = env
!( "CARGO_PKG_AUTHORS" );
1494 let s
= "wycats@example.com:neikos@example.com" ;
1495 assert_eq
!( AUTHORS
, foo
:: authors ());
1496 println
!( " {} " , AUTHORS
);
1497 assert_eq
!( s
, AUTHORS
);
1504 pub fn authors () -> String
{
1505 format
!( " {} " , env
!( "CARGO_PKG_AUTHORS" ))
1512 p.cargo(" build
- v
").run();
1515 p.process(&p.bin(" foo
"))
1516 .with_stdout(" wycats@example
. com
: neikos@example
. com
")
1520 p.cargo(" test
- v
").run();
1524 fn vv_prints_rustc_env_vars() {
1532 authors
= [ "escape=' \" @example.com" ]
1535 .file(" src
/ main
. rs
", " fn main () {}
")
1538 let mut b = p.cargo(" build
- vv
");
1541 b.with_stderr_contains(
1542 " [ RUNNING
] `
[..] set CARGO_PKG_NAME
= foo
&& [..] rustc
[..] `
"
1543 ).with_stderr_contains(
1544 r#" [ RUNNING
] `
[..] set CARGO_PKG_AUTHORS
= "escape=' \" @example.com" && [..] rustc
[..] `
"#
1547 b.with_stderr_contains(" [ RUNNING
] `
[..] CARGO_PKG_NAME
= foo
[..] rustc
[..] `
")
1548 .with_stderr_contains(
1549 r#" [ RUNNING
] `
[..] CARGO_PKG_AUTHORS
= 'escape
= '
\' '
"@example.com' [..]rustc [..]`" #,
1556 // The tester may already have LD_LIBRARY_PATH=::/foo/bar which leads to a false positive error
1557 fn setenv_for_removing_empty_component ( mut execs
: Execs
) -> Execs
{
1558 let v
= dylib_path_envvar ();
1559 if let Ok ( search_path
) = env
:: var ( v
) {
1560 let new_search_path
=
1561 env
:: join_paths ( env
:: split_paths (& search_path
). filter (| e
| ! e
. as_os_str (). is_empty ()))
1562 . expect ( "join_paths" );
1563 execs
. env ( v
, new_search_path
); // build_command() will override LD_LIBRARY_PATH accordingly
1568 // Regression test for #4277
1570 fn crate_library_path_env_var () {
1577 let search_path = env!(" {} ");
1578 let paths = std::env::split_paths(&search_path).collect::<Vec<_>>();
1579 assert!(!paths.contains(&" ".into()));
1587 setenv_for_removing_empty_component ( p
. cargo ( "run" )). run ();
1590 // Regression test for #4277
1592 fn build_with_fake_libc_not_loading () {
1594 . file ( "src/main.rs" , "fn main() {} " )
1595 . file ( "src/lib.rs" , r
# " " #)
1596 . file ( "libc.so.6" , r
# "" #)
1599 setenv_for_removing_empty_component ( p
. cargo ( "build" )). run ();
1602 // this is testing that src/<pkg-name>.rs still works (for now)
1604 fn many_crate_types_old_style_lib_location () {
1613 authors = [" wycats@example.com "]
1618 crate_type = [" rlib ", " dylib "]
1621 . file ( "src/foo.rs" , "pub fn foo() {} " )
1624 . with_stderr_contains (
1626 [WARNING] path `[..]src/foo.rs` was erroneously implicitly accepted for library `foo`,
1627 please rename the file to `src/lib.rs` or set lib.path in Cargo.toml" ,
1631 assert
!( p
. root (). join ( "target/debug/libfoo.rlib" ). is_file ());
1632 let fname
= format
!( " {} foo {} " , env
:: consts
:: DLL_PREFIX
, env
:: consts
:: DLL_SUFFIX
);
1633 assert
!( p
. root (). join ( "target/debug" ). join (& fname
). is_file ());
1637 fn many_crate_types_correct () {
1646 authors = [" wycats@example.com "]
1651 crate_type = [" rlib ", " dylib "]
1654 . file ( "src/lib.rs" , "pub fn foo() {} " )
1656 p
. cargo ( "build" ). run ();
1658 assert
!( p
. root (). join ( "target/debug/libfoo.rlib" ). is_file ());
1659 let fname
= format
!( " {} foo {} " , env
:: consts
:: DLL_PREFIX
, env
:: consts
:: DLL_SUFFIX
);
1660 assert
!( p
. root (). join ( "target/debug" ). join (& fname
). is_file ());
1664 fn set_both_dylib_and_cdylib_crate_types () {
1673 authors = [" wycats@example.com "]
1678 crate_type = [" cdylib ", " dylib "]
1681 . file ( "src/lib.rs" , "pub fn foo() {} " )
1687 error: failed to parse manifest at `[..]`
1690 library `foo` cannot set the crate type of both `dylib` and `cdylib`
1697 fn dev_dependencies_conflicting_warning () {
1713 . file ( "src/lib.rs" , "" )
1722 . file ( "a/src/lib.rs" , "" )
1725 . with_stderr_contains (
1726 "[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the `foo` package. \n
1727 `dev_dependencies` is ignored and not recommended for use in the future"
1733 fn build_dependencies_conflicting_warning () {
1743 [build-dependencies]
1745 [build_dependencies]
1749 . file ( "src/lib.rs" , "" )
1758 . file ( "a/src/lib.rs" , "" )
1761 . with_stderr_contains (
1762 "[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the `foo` package. \n
1763 `build_dependencies` is ignored and not recommended for use in the future"
1769 fn lib_crate_types_conflicting_warning () {
1777 authors = [" wycats@example.com "]
1781 crate-type = [" rlib ", " dylib "]
1782 crate_type = [" staticlib ", " dylib "]
1785 . file ( "src/lib.rs" , "pub fn foo() {} " )
1788 . with_stderr_contains (
1789 "[WARNING] conflicting between `crate-type` and `crate_type` in the `foo` library target. \n
1790 `crate_type` is ignored and not recommended for use in the future" ,
1796 fn examples_crate_types_conflicting_warning () {
1804 authors = [" wycats@example.com "]
1808 path = " examples/ex.rs "
1809 crate-type = [" rlib ", " dylib "]
1810 crate_type = [" proc_macro "]
1813 path = " examples/ex-goodbye.rs "
1814 crate-type = [" rlib ", " dylib "]
1815 crate_type = [" rlib ", " staticlib "]
1818 . file ( "src/lib.rs" , "" )
1822 fn main() { println!("ex"); }
1826 "examples/ex-goodbye.rs" ,
1828 fn main() { println!("goodbye"); }
1833 . with_stderr_contains (
1835 [WARNING] conflicting between `crate-type` and `crate_type` in the `ex` example target. \n
1836 `crate_type` is ignored and not recommended for use in the future
1837 [WARNING] conflicting between `crate-type` and `crate_type` in the `goodbye` example target. \n
1838 `crate_type` is ignored and not recommended for use in the future" ,
1844 fn self_dependency () {
1861 path = " src/test.rs "
1864 . file ( "src/test.rs" , "fn main() {} " )
1870 [ERROR] cyclic package dependency: package `test v0.0.0 ([CWD])` depends on itself. Cycle:
1871 package `test v0.0.0 ([CWD])`
1872 ... which satisfies path dependency `test` of package `test v0.0.0 ([..])`" ,
1878 /// Make sure broken and loop symlinks don't break the build
1880 /// This test requires you to be able to make symlinks.
1881 /// For windows, this may require you to enable developer mode.
1882 fn ignore_broken_symlinks () {
1883 if ! symlink_supported () {
1888 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
1889 . file ( "src/foo.rs" , & main_file ( r
# "" i am foo "" #, &[]))
1890 . symlink ( "Notafile" , "bar" )
1891 // To hit the symlink directory, we need a build script
1892 // to trigger a full scan of package files.
1893 . file ( "build.rs" , & main_file ( r
# "" build script "" #, &[]))
1894 . symlink_dir ( "a/b" , "a/b/c/d/foo" )
1898 . with_stderr_contains (
1899 "[WARNING] File system loop found: [..]/a/b/c/d/foo points to an ancestor [..]/a/b" ,
1902 assert
!( p
. bin ( "foo" ). is_file ());
1904 p
. process (& p
. bin ( "foo" )). with_stdout ( "i am foo \n " ). run ();
1908 fn missing_lib_and_bin () {
1909 let p
= project (). build ();
1914 [ERROR] failed to parse manifest at `[..]Cargo.toml`
1917 no targets specified in the manifest
1918 either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present \n " ,
1939 . file ( "src/main.rs" , "fn main() {} " )
1941 p
. cargo ( "build -v --release" )
1944 [COMPILING] test v0.0.0 ([CWD])
1945 [RUNNING] `rustc --crate-name test src/main.rs [..]--crate-type bin \
1950 [FINISHED] release [optimized] target(s) in [..]
1957 fn verbose_build () {
1958 let p
= project (). file ( "src/lib.rs" , "" ). build ();
1962 [COMPILING] foo v0.0.1 ([CWD])
1963 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
1964 --emit=[..]link[..]-C debuginfo=2 \
1967 -L dependency=[CWD]/target/debug/deps`
1968 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1975 fn verbose_release_build () {
1976 let p
= project (). file ( "src/lib.rs" , "" ). build ();
1977 p
. cargo ( "build -v --release" )
1980 [COMPILING] foo v0.0.1 ([CWD])
1981 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
1982 --emit=[..]link[..] \
1986 -L dependency=[CWD]/target/release/deps`
1987 [FINISHED] release [optimized] target(s) in [..]
1994 fn verbose_release_build_short () {
1995 let p
= project (). file ( "src/lib.rs" , "" ). build ();
1996 p
. cargo ( "build -v -r" )
1999 [COMPILING] foo v0.0.1 ([CWD])
2000 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
2001 --emit=[..]link[..] \
2005 -L dependency=[CWD]/target/release/deps`
2006 [FINISHED] release [optimized] target(s) in [..]
2013 fn verbose_release_build_deps () {
2028 . file ( "src/lib.rs" , "" )
2040 crate_type = [" dylib ", " rlib "]
2043 . file ( "foo/src/lib.rs" , "" )
2045 p
. cargo ( "build -v --release" )
2046 . with_stderr (& format
!(
2048 [COMPILING] foo v0.0.0 ([CWD]/foo)
2049 [RUNNING] `rustc --crate-name foo foo/src/lib.rs [..] \
2050 --crate-type dylib --crate-type rlib \
2052 -C prefer-dynamic[..] \
2056 -L dependency=[CWD]/target/release/deps`
2057 [COMPILING] test v0.0.0 ([CWD])
2058 [RUNNING] `rustc --crate-name test src/lib.rs [..]--crate-type lib \
2059 --emit=[..]link[..] \
2063 -L dependency=[CWD]/target/release/deps \
2064 --extern foo=[CWD]/target/release/deps/ {prefix} foo {suffix} \
2065 --extern foo=[CWD]/target/release/deps/libfoo.rlib`
2066 [FINISHED] release [optimized] target(s) in [..]
2068 prefix
= env
:: consts
:: DLL_PREFIX
,
2069 suffix
= env
:: consts
:: DLL_SUFFIX
2075 fn explicit_examples () {
2091 path = " examples/ex-hello.rs "
2095 path = " examples/ex-goodbye.rs "
2101 pub fn get_hello() -> &'static str { "Hello" }
2102 pub fn get_goodbye() -> &'static str { "Goodbye" }
2103 pub fn get_world() -> &'static str { "World" }
2107 "examples/ex-hello.rs" ,
2110 fn main() { println!("{} , {} !" , foo::get_hello(), foo::get_world()); }
2114 " examples
/ ex
- goodbye
. rs
",
2117 fn main () { println!("{}
, {}
! ", foo::get_goodbye(), foo::get_world()); }
2122 p
. cargo ( "build --examples" ). run ();
2123 p
. process (& p
. bin ( "examples/hello" ))
2124 . with_stdout ( "Hello, World! \n " )
2126 p
. process (& p
. bin ( "examples/goodbye" ))
2127 . with_stdout ( "Goodbye, World! \n " )
2132 fn non_existing_test () {
2149 . file ( "src/lib.rs" , "" )
2152 p
. cargo ( "build --tests -v" )
2156 [ERROR] failed to parse manifest at `[..]`
2159 can't find `hello` test at `tests/hello.rs` or `tests/hello/main.rs`. \
2160 Please specify test.path if you want to use a non-default path." ,
2166 fn non_existing_example () {
2183 . file ( "src/lib.rs" , "" )
2186 p
. cargo ( "build --examples -v" )
2190 [ERROR] failed to parse manifest at `[..]`
2193 can't find `hello` example at `examples/hello.rs` or `examples/hello/main.rs`. \
2194 Please specify example.path if you want to use a non-default path." ,
2200 fn non_existing_benchmark () {
2217 . file ( "src/lib.rs" , "" )
2220 p
. cargo ( "build --benches -v" )
2224 [ERROR] failed to parse manifest at `[..]`
2227 can't find `hello` bench at `benches/hello.rs` or `benches/hello/main.rs`. \
2228 Please specify bench.path if you want to use a non-default path." ,
2234 fn non_existing_binary () {
2236 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
2237 . file ( "src/lib.rs" , "" )
2238 . file ( "src/bin/ehlo.rs" , "" )
2245 [ERROR] failed to parse manifest at `[..]`
2248 can't find `foo` bin at `src/bin/foo.rs` or `src/bin/foo/main.rs`. \
2249 Please specify bin.path if you want to use a non-default path." ,
2255 fn commonly_wrong_path_of_test () {
2272 . file ( "src/lib.rs" , "" )
2273 . file ( "test/foo.rs" , "" )
2276 p
. cargo ( "build --tests -v" )
2280 [ERROR] failed to parse manifest at `[..]`
2283 can't find `foo` test at default paths, but found a file at `test/foo.rs`.
2284 Perhaps rename the file to `tests/foo.rs` for target auto-discovery, \
2285 or specify test.path if you want to use a non-default path." ,
2291 fn commonly_wrong_path_of_example () {
2308 . file ( "src/lib.rs" , "" )
2309 . file ( "example/foo.rs" , "" )
2312 p
. cargo ( "build --examples -v" )
2316 [ERROR] failed to parse manifest at `[..]`
2319 can't find `foo` example at default paths, but found a file at `example/foo.rs`.
2320 Perhaps rename the file to `examples/foo.rs` for target auto-discovery, \
2321 or specify example.path if you want to use a non-default path." ,
2327 fn commonly_wrong_path_of_benchmark () {
2344 . file ( "src/lib.rs" , "" )
2345 . file ( "bench/foo.rs" , "" )
2348 p
. cargo ( "build --benches -v" )
2352 [ERROR] failed to parse manifest at `[..]`
2355 can't find `foo` bench at default paths, but found a file at `bench/foo.rs`.
2356 Perhaps rename the file to `benches/foo.rs` for target auto-discovery, \
2357 or specify bench.path if you want to use a non-default path." ,
2363 fn commonly_wrong_path_binary () {
2365 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
2366 . file ( "src/lib.rs" , "" )
2367 . file ( "src/bins/foo.rs" , "" )
2374 [ERROR] failed to parse manifest at `[..]`
2377 can't find `foo` bin at default paths, but found a file at `src/bins/foo.rs`.
2378 Perhaps rename the file to `src/bin/foo.rs` for target auto-discovery, \
2379 or specify bin.path if you want to use a non-default path." ,
2385 fn commonly_wrong_path_subdir_binary () {
2387 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
2388 . file ( "src/lib.rs" , "" )
2389 . file ( "src/bins/foo/main.rs" , "" )
2396 [ERROR] failed to parse manifest at `[..]`
2399 can't find `foo` bin at default paths, but found a file at `src/bins/foo/main.rs`.
2400 Perhaps rename the file to `src/bin/foo/main.rs` for target auto-discovery, \
2401 or specify bin.path if you want to use a non-default path." ,
2407 fn found_multiple_target_files () {
2409 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
2410 . file ( "src/lib.rs" , "" )
2411 . file ( "src/bin/foo.rs" , "" )
2412 . file ( "src/bin/foo/main.rs" , "" )
2417 // Don't assert the inferred paths since the order is non-deterministic.
2420 [ERROR] failed to parse manifest at `[..]`
2423 cannot infer path for `foo` bin
2424 Cargo doesn't know which to use because multiple target files found \
2425 at `src/bin/foo[..].rs` and `src/bin/foo[..].rs`." ,
2431 fn legacy_binary_paths_warnings () {
2445 . file ( "src/lib.rs" , "" )
2446 . file ( "src/main.rs" , "fn main() {} " )
2450 . with_stderr_contains (
2452 [WARNING] path `[..]src/main.rs` was erroneously implicitly accepted for binary `bar`,
2453 please set bin.path in Cargo.toml" ,
2470 . file ( "src/lib.rs" , "" )
2471 . file ( "src/bin/main.rs" , "fn main() {} " )
2475 . with_stderr_contains (
2477 [WARNING] path `[..]src/bin/main.rs` was erroneously implicitly accepted for binary `bar`,
2478 please set bin.path in Cargo.toml" ,
2495 . file ( "src/bar.rs" , "fn main() {} " )
2499 . with_stderr_contains (
2501 [WARNING] path `[..]src/bar.rs` was erroneously implicitly accepted for binary `bar`,
2502 please set bin.path in Cargo.toml" ,
2508 fn implicit_examples () {
2513 pub fn get_hello() -> &'static str { "Hello" }
2514 pub fn get_goodbye() -> &'static str { "Goodbye" }
2515 pub fn get_world() -> &'static str { "World" }
2519 "examples/hello.rs" ,
2523 println!(" {}, {}! ", foo::get_hello(), foo::get_world());
2528 "examples/goodbye.rs" ,
2532 println!(" {}, {}! ", foo::get_goodbye(), foo::get_world());
2538 p
. cargo ( "build --examples" ). run ();
2539 p
. process (& p
. bin ( "examples/hello" ))
2540 . with_stdout ( "Hello, World! \n " )
2542 p
. process (& p
. bin ( "examples/goodbye" ))
2543 . with_stdout ( "Goodbye, World! \n " )
2548 fn standard_build_no_ndebug () {
2550 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
2555 if cfg!(debug_assertions) {
2565 p
. cargo ( "build" ). run ();
2566 p
. process (& p
. bin ( "foo" )). with_stdout ( "slow \n " ). run ();
2570 fn release_build_ndebug () {
2572 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
2577 if cfg!(debug_assertions) {
2587 p
. cargo ( "build --release" ). run ();
2588 p
. process (& p
. release_bin ( "foo" )). with_stdout ( "fast \n " ). run ();
2592 fn inferred_main_bin () {
2593 let p
= project (). file ( "src/main.rs" , "fn main() {} " ). build ();
2595 p
. cargo ( "build" ). run ();
2596 p
. process (& p
. bin ( "foo" )). run ();
2600 fn deletion_causes_failure () {
2614 . file ( "src/main.rs" , "extern crate bar; fn main() {} " )
2615 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.0.1" ))
2616 . file ( "bar/src/lib.rs" , "" )
2619 p
. cargo ( "build" ). run ();
2620 p
. change_file ( "Cargo.toml" , & basic_manifest ( "foo" , "0.0.1" ));
2623 . with_stderr_contains ( "[..]can't find crate for `bar`" )
2628 fn bad_cargo_toml_in_target_dir () {
2630 . file ( "src/main.rs" , "fn main() {} " )
2631 . file ( "target/Cargo.toml" , "bad-toml" )
2634 p
. cargo ( "build" ). run ();
2635 p
. process (& p
. bin ( "foo" )). run ();
2639 fn lib_with_standard_name () {
2641 . file ( "Cargo.toml" , & basic_manifest ( "syntax" , "0.0.1" ))
2642 . file ( "src/lib.rs" , "pub fn foo() {} " )
2645 "extern crate syntax; fn main() { syntax::foo() } " ,
2652 [COMPILING] syntax v0.0.1 ([CWD])
2653 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2660 fn simple_staticlib () {
2672 crate-type = [" staticlib "]
2675 . file ( "src/lib.rs" , "pub fn foo() {} " )
2678 // env var is a test for #1381
2679 p
. cargo ( "build" ). env ( "CARGO_LOG" , "nekoneko=trace" ). run ();
2683 fn staticlib_rlib_and_bin () {
2695 crate-type = [" staticlib ", " rlib "]
2698 . file ( "src/lib.rs" , "pub fn foo() {} " )
2699 . file ( "src/main.rs" , "extern crate foo; fn main() { foo::foo(); } " )
2702 p
. cargo ( "build -v" ). run ();
2706 fn opt_out_of_bin () {
2719 . file ( "src/lib.rs" , "" )
2720 . file ( "src/main.rs" , "bad syntax" )
2722 p
. cargo ( "build" ). run ();
2741 . file ( "src/bar.rs" , "" )
2743 p
. cargo ( "build" ). run ();
2747 fn freshness_ignores_excluded () {
2757 exclude = [" src/b*.rs "]
2760 . file ( "build.rs" , "fn main() {} " )
2761 . file ( "src/lib.rs" , "pub fn bar() -> i32 { 1 } " )
2763 foo
. root (). move_into_the_past ();
2768 [COMPILING] foo v0.0.0 ([CWD])
2769 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2774 // Smoke test to make sure it doesn't compile again
2775 println
!( "first pass" );
2776 foo
. cargo ( "build" ). with_stdout ( "" ). run ();
2778 // Modify an ignored file and make sure we don't rebuild
2779 println
!( "second pass" );
2780 foo
. change_file ( "src/bar.rs" , "" );
2781 foo
. cargo ( "build" ). with_stdout ( "" ). run ();
2785 fn rebuild_preserves_out_dir () {
2802 use std::path::Path;
2805 let path = Path::new(&env::var(" OUT_DIR ").unwrap()).join(" foo ");
2806 if env::var_os(" FIRST ").is_some() {
2807 File::create(&path).unwrap();
2809 File::create(&path).unwrap();
2814 . file ( "src/lib.rs" , "pub fn bar() -> i32 { 1 } " )
2816 foo
. root (). move_into_the_past ();
2822 [COMPILING] foo v0.0.0 ([CWD])
2823 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2828 foo
. change_file ( "src/bar.rs" , "" );
2832 [COMPILING] foo v0.0.0 ([CWD])
2833 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2854 . file ( "src/lib.rs" , "pub fn bar() -> i32 { 1 } " )
2855 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.0.0" ))
2856 . file ( "bar/src/main.rs" , "" )
2858 foo
. cargo ( "build" ). run ();
2862 fn recompile_space_in_name () {
2874 path = " src/my lib.rs "
2877 . file ( "src/my lib.rs" , "" )
2879 foo
. cargo ( "build" ). run ();
2880 foo
. root (). move_into_the_past ();
2881 foo
. cargo ( "build" ). with_stdout ( "" ). run ();
2886 fn credentials_is_unreadable () {
2887 use cargo_test_support
:: paths
:: home
;
2888 use std
:: os
:: unix
:: prelude
::*;
2890 . file ( "Cargo.toml" , & basic_manifest ( "foo" , "0.1.0" ))
2891 . file ( "src/lib.rs" , "" )
2894 let credentials
= home (). join ( ".cargo/credentials" );
2895 t
!( fs
:: create_dir_all ( credentials
. parent (). unwrap ()));
2903 let stat
= fs
:: metadata ( credentials
. as_path ()). unwrap ();
2904 let mut perms
= stat
. permissions ();
2905 perms
. set_mode ( 0o000 );
2906 fs
:: set_permissions ( credentials
, perms
). unwrap ();
2908 p
. cargo ( "build" ). run ();
2913 fn ignore_bad_directories () {
2914 use std
:: os
:: unix
:: prelude
::*;
2916 . file ( "Cargo.toml" , & basic_manifest ( "foo" , "0.0.0" ))
2917 . file ( "src/lib.rs" , "" )
2919 let dir
= foo
. root (). join ( "tmp" );
2920 fs
:: create_dir (& dir
). unwrap ();
2921 let stat
= fs
:: metadata (& dir
). unwrap ();
2922 let mut perms
= stat
. permissions ();
2923 perms
. set_mode ( 0o644 );
2924 fs
:: set_permissions (& dir
, perms
. clone ()). unwrap ();
2925 foo
. cargo ( "build" ). run ();
2926 perms
. set_mode ( 0o755 );
2927 fs
:: set_permissions (& dir
, perms
). unwrap ();
2931 fn bad_cargo_config () {
2933 . file ( "Cargo.toml" , & basic_manifest ( "foo" , "0.0.0" ))
2934 . file ( "src/lib.rs" , "" )
2935 . file ( ".cargo/config" , "this is not valid toml" )
2937 foo
. cargo ( "build -v" )
2941 [ERROR] could not load Cargo configuration
2944 could not parse TOML configuration in `[..]`
2947 could not parse input as TOML
2950 TOML parse error at line 1, column 6
2952 1 | this is not valid toml
2962 fn cargo_platform_specific_dependency () {
2963 let host
= rustc_host ();
2972 authors = [" wycats@example.com "]
2975 [target. {host} .dependencies]
2976 dep = {{ path = "dep" } }
2977 [target. {host} .build-dependencies]
2978 build = {{ path = "build" } }
2979 [target. {host} .dev-dependencies]
2980 dev = {{ path = "dev" } }
2985 . file ( "src/main.rs" , "extern crate dep; fn main() { dep::dep() } " )
2988 "extern crate dev; #[test] fn foo() { dev::dev() } " ,
2992 "extern crate build; fn main() { build::build(); } " ,
2994 . file ( "dep/Cargo.toml" , & basic_manifest ( "dep" , "0.5.0" ))
2995 . file ( "dep/src/lib.rs" , "pub fn dep() {} " )
2996 . file ( "build/Cargo.toml" , & basic_manifest ( "build" , "0.5.0" ))
2997 . file ( "build/src/lib.rs" , "pub fn build() {} " )
2998 . file ( "dev/Cargo.toml" , & basic_manifest ( "dev" , "0.5.0" ))
2999 . file ( "dev/src/lib.rs" , "pub fn dev() {} " )
3002 p
. cargo ( "build" ). run ();
3004 assert
!( p
. bin ( "foo" ). is_file ());
3005 p
. cargo ( "test" ). run ();
3009 fn cargo_platform_specific_dependency_build_dependencies_conflicting_warning () {
3010 let host
= rustc_host ();
3019 authors = [" wycats@example.com "]
3022 [target. {host} .build-dependencies]
3023 build = {{ path = "build" } }
3024 [target. {host} .build_dependencies]
3025 build = {{ path = "build" } }
3030 . file ( "src/main.rs" , "fn main() { } " )
3033 "extern crate build; fn main() { build::build(); } " ,
3035 . file ( "build/Cargo.toml" , & basic_manifest ( "build" , "0.5.0" ))
3036 . file ( "build/src/lib.rs" , "pub fn build() {} " )
3040 . with_stderr_contains (
3041 format
!( "[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the ` {} ` platform target. \n
3042 `build_dependencies` is ignored and not recommended for use in the future" , host
)
3046 assert
!( p
. bin ( "foo" ). is_file ());
3050 fn cargo_platform_specific_dependency_dev_dependencies_conflicting_warning () {
3051 let host
= rustc_host ();
3060 authors = [" wycats@example.com "]
3062 [target. {host} .dev-dependencies]
3063 dev = {{ path = "dev" } }
3064 [target. {host} .dev_dependencies]
3065 dev = {{ path = "dev" } }
3070 . file ( "src/main.rs" , "fn main() { } " )
3073 "extern crate dev; #[test] fn foo() { dev::dev() } " ,
3075 . file ( "dev/Cargo.toml" , & basic_manifest ( "dev" , "0.5.0" ))
3076 . file ( "dev/src/lib.rs" , "pub fn dev() {} " )
3080 . with_stderr_contains (
3081 format
!( "[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the ` {} ` platform target. \n
3082 `dev_dependencies` is ignored and not recommended for use in the future" , host
)
3086 assert
!( p
. bin ( "foo" ). is_file ());
3087 p
. cargo ( "test" ). run ();
3091 fn bad_platform_specific_dependency () {
3100 authors = [" wycats@example.com "]
3102 [target.wrong-target.dependencies.bar]
3106 . file ( "src/main.rs" , & main_file ( r
# "" {} ", bar::gimme()" #, &[ "bar" ]))
3107 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.5.0" ))
3110 r
# "pub fn gimme() -> String { format!("") } " #,
3116 . with_stderr_contains ( "[..]can't find crate for `bar`" )
3121 fn cargo_platform_specific_dependency_wrong_platform () {
3130 authors = [" wycats@example.com "]
3132 [target.non-existing-triplet.dependencies.bar]
3136 . file ( "src/main.rs" , "fn main() {} " )
3137 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.5.0" ))
3140 "invalid rust file, should not be compiled" ,
3144 p
. cargo ( "build" ). run ();
3146 assert
!( p
. bin ( "foo" ). is_file ());
3147 p
. process (& p
. bin ( "foo" )). run ();
3149 let lockfile
= p
. read_lockfile ();
3150 assert
!( lockfile
. contains ( "bar" ));
3154 fn example_as_lib () {
3166 crate-type = [" lib "]
3169 . file ( "src/lib.rs" , "" )
3170 . file ( "examples/ex.rs" , "" )
3173 p
. cargo ( "build --example=ex" ). run ();
3174 assert
!( p
. example_lib ( "ex" , "lib" ). is_file ());
3178 fn example_as_rlib () {
3190 crate-type = [" rlib "]
3193 . file ( "src/lib.rs" , "" )
3194 . file ( "examples/ex.rs" , "" )
3197 p
. cargo ( "build --example=ex" ). run ();
3198 assert
!( p
. example_lib ( "ex" , "rlib" ). is_file ());
3202 fn example_as_dylib () {
3214 crate-type = [" dylib "]
3217 . file ( "src/lib.rs" , "" )
3218 . file ( "examples/ex.rs" , "" )
3221 p
. cargo ( "build --example=ex" ). run ();
3222 assert
!( p
. example_lib ( "ex" , "dylib" ). is_file ());
3226 fn example_as_proc_macro () {
3238 crate-type = [" proc-macro "]
3241 . file ( "src/lib.rs" , "" )
3245 extern crate proc_macro;
3246 use proc_macro::TokenStream;
3249 pub fn eat(_item: TokenStream) -> TokenStream {
3256 p
. cargo ( "build --example=ex" ). run ();
3257 assert
!( p
. example_lib ( "ex" , "proc-macro" ). is_file ());
3261 fn example_bin_same_name () {
3263 . file ( "src/main.rs" , "fn main() {} " )
3264 . file ( "examples/foo.rs" , "fn main() {} " )
3267 p
. cargo ( "build --examples" ). run ();
3269 assert
!(! p
. bin ( "foo" ). is_file ());
3270 // We expect a file of the form bin/foo-{metadata_hash}
3271 assert
!( p
. bin ( "examples/foo" ). is_file ());
3273 p
. cargo ( "build --examples" ). run ();
3275 assert
!(! p
. bin ( "foo" ). is_file ());
3276 // We expect a file of the form bin/foo-{metadata_hash}
3277 assert
!( p
. bin ( "examples/foo" ). is_file ());
3281 fn compile_then_delete () {
3282 let p
= project (). file ( "src/main.rs" , "fn main() {} " ). build ();
3284 p
. cargo ( "run -v" ). run ();
3285 assert
!( p
. bin ( "foo" ). is_file ());
3287 // On windows unlinking immediately after running often fails, so sleep
3290 fs
:: remove_file (& p
. bin ( "foo" )). unwrap ();
3291 p
. cargo ( "run -v" ). run ();
3295 fn transitive_dependencies_not_available () {
3305 [dependencies.aaaaa]
3311 "extern crate bbbbb; extern crate aaaaa; fn main() {} " ,
3321 [dependencies.bbbbb]
3325 . file ( "a/src/lib.rs" , "extern crate bbbbb;" )
3326 . file ( "b/Cargo.toml" , & basic_manifest ( "bbbbb" , "0.0.1" ))
3327 . file ( "b/src/lib.rs" , "" )
3332 . with_stderr_contains ( "[..] can't find crate for `bbbbb`[..]" )
3337 fn cyclic_deps_rejected () {
3351 . file ( "src/lib.rs" , "" )
3364 . file ( "a/src/lib.rs" , "" )
3370 "[ERROR] cyclic package dependency: package `a v0.0.1 ([CWD]/a)` depends on itself. Cycle:
3371 package `a v0.0.1 ([CWD]/a)`
3372 ... which satisfies path dependency `a` of package `foo v0.0.1 ([CWD])`
3373 ... which satisfies path dependency `foo` of package `a v0.0.1 ([..])`" ,
3378 fn predictable_filenames () {
3390 crate-type = [" dylib ", " rlib "]
3393 . file ( "src/lib.rs" , "" )
3396 p
. cargo ( "build -v" ). run ();
3397 assert
!( p
. root (). join ( "target/debug/libfoo.rlib" ). is_file ());
3398 let dylib_name
= format
!( " {} foo {} " , env
:: consts
:: DLL_PREFIX
, env
:: consts
:: DLL_SUFFIX
);
3399 assert
!( p
. root (). join ( "target/debug" ). join ( dylib_name
). is_file ());
3403 fn dashes_to_underscores () {
3405 . file ( "Cargo.toml" , & basic_manifest ( "foo-bar" , "0.0.1" ))
3406 . file ( "src/lib.rs" , "" )
3407 . file ( "src/main.rs" , "extern crate foo_bar; fn main() {} " )
3410 p
. cargo ( "build -v" ). run ();
3411 assert
!( p
. bin ( "foo-bar" ). is_file ());
3415 fn dashes_in_crate_name_bad () {
3429 . file ( "src/lib.rs" , "" )
3430 . file ( "src/main.rs" , "extern crate foo_bar; fn main() {} " )
3437 [ERROR] failed to parse manifest at `[..]/foo/Cargo.toml`
3440 library target names cannot contain hyphens: foo-bar
3447 fn rustc_env_var () {
3448 let p
= project (). file ( "src/lib.rs" , "" ). build ();
3451 . env ( "RUSTC" , "rustc-that-does-not-exist" )
3455 [ERROR] could not execute process `rustc-that-does-not-exist -vV` ([..])
3462 assert
!(! p
. bin ( "a" ). is_file ());
3468 . file ( "src/lib.rs" , "" )
3469 . file ( "src/bin/a.rs" , "fn main() {} " )
3470 . file ( "src/bin/b.rs" , "fn main() {} " )
3471 . file ( "examples/a.rs" , "fn main() {} " )
3472 . file ( "examples/b.rs" , "fn main() {} " )
3475 p
. cargo ( "build --lib" ). run ();
3476 assert
!(! p
. bin ( "a" ). is_file ());
3478 p
. cargo ( "build --bin=a --example=a" ). run ();
3479 assert
!( p
. bin ( "a" ). is_file ());
3480 assert
!(! p
. bin ( "b" ). is_file ());
3481 assert
!( p
. bin ( "examples/a" ). is_file ());
3482 assert
!(! p
. bin ( "examples/b" ). is_file ());
3486 fn filtering_implicit_bins () {
3488 . file ( "src/lib.rs" , "" )
3489 . file ( "src/bin/a.rs" , "fn main() {} " )
3490 . file ( "src/bin/b.rs" , "fn main() {} " )
3491 . file ( "examples/a.rs" , "fn main() {} " )
3492 . file ( "examples/b.rs" , "fn main() {} " )
3495 p
. cargo ( "build --bins" ). run ();
3496 assert
!( p
. bin ( "a" ). is_file ());
3497 assert
!( p
. bin ( "b" ). is_file ());
3498 assert
!(! p
. bin ( "examples/a" ). is_file ());
3499 assert
!(! p
. bin ( "examples/b" ). is_file ());
3503 fn filtering_implicit_examples () {
3505 . file ( "src/lib.rs" , "" )
3506 . file ( "src/bin/a.rs" , "fn main() {} " )
3507 . file ( "src/bin/b.rs" , "fn main() {} " )
3508 . file ( "examples/a.rs" , "fn main() {} " )
3509 . file ( "examples/b.rs" , "fn main() {} " )
3512 p
. cargo ( "build --examples" ). run ();
3513 assert
!(! p
. bin ( "a" ). is_file ());
3514 assert
!(! p
. bin ( "b" ). is_file ());
3515 assert
!( p
. bin ( "examples/a" ). is_file ());
3516 assert
!( p
. bin ( "examples/b" ). is_file ());
3520 fn ignore_dotfile () {
3522 . file ( "src/bin/.a.rs" , "" )
3523 . file ( "src/bin/a.rs" , "fn main() {} " )
3526 p
. cargo ( "build" ). run ();
3530 fn ignore_dotdirs () {
3532 . file ( "src/bin/a.rs" , "fn main() {} " )
3533 . file ( ".git/Cargo.toml" , "" )
3534 . file ( ".pc/dummy-fix.patch/Cargo.toml" , "" )
3537 p
. cargo ( "build" ). run ();
3542 let p
= ProjectBuilder
:: new ( root (). join ( ".foo" ))
3543 . file ( "src/bin/a.rs" , "fn main() {} " )
3545 p
. cargo ( "build" ). run ();
3549 fn custom_target_dir_env () {
3550 let p
= project (). file ( "src/main.rs" , "fn main() {} " ). build ();
3552 let exe_name
= format
!( "foo {} " , env
:: consts
:: EXE_SUFFIX
);
3554 p
. cargo ( "build" ). env ( "CARGO_TARGET_DIR" , "foo/target" ). run ();
3555 assert
!( p
. root (). join ( "foo/target/debug" ). join (& exe_name
). is_file ());
3556 assert
!(! p
. root (). join ( "target/debug" ). join (& exe_name
). is_file ());
3558 p
. cargo ( "build" ). run ();
3559 assert
!( p
. root (). join ( "foo/target/debug" ). join (& exe_name
). is_file ());
3560 assert
!( p
. root (). join ( "target/debug" ). join (& exe_name
). is_file ());
3563 . env ( "CARGO_BUILD_TARGET_DIR" , "foo2/target" )
3565 assert
!( p
. root (). join ( "foo2/target/debug" ). join (& exe_name
). is_file ());
3571 target-dir = " foo/target "
3574 p
. cargo ( "build" ). env ( "CARGO_TARGET_DIR" , "bar/target" ). run ();
3575 assert
!( p
. root (). join ( "bar/target/debug" ). join (& exe_name
). is_file ());
3576 assert
!( p
. root (). join ( "foo/target/debug" ). join (& exe_name
). is_file ());
3577 assert
!( p
. root (). join ( "target/debug" ). join (& exe_name
). is_file ());
3581 fn custom_target_dir_line_parameter () {
3582 let p
= project (). file ( "src/main.rs" , "fn main() {} " ). build ();
3584 let exe_name
= format
!( "foo {} " , env
:: consts
:: EXE_SUFFIX
);
3586 p
. cargo ( "build --target-dir foo/target" ). run ();
3587 assert
!( p
. root (). join ( "foo/target/debug" ). join (& exe_name
). is_file ());
3588 assert
!(! p
. root (). join ( "target/debug" ). join (& exe_name
). is_file ());
3590 p
. cargo ( "build" ). run ();
3591 assert
!( p
. root (). join ( "foo/target/debug" ). join (& exe_name
). is_file ());
3592 assert
!( p
. root (). join ( "target/debug" ). join (& exe_name
). is_file ());
3598 target-dir = " foo/target "
3601 p
. cargo ( "build --target-dir bar/target" ). run ();
3602 assert
!( p
. root (). join ( "bar/target/debug" ). join (& exe_name
). is_file ());
3603 assert
!( p
. root (). join ( "foo/target/debug" ). join (& exe_name
). is_file ());
3604 assert
!( p
. root (). join ( "target/debug" ). join (& exe_name
). is_file ());
3606 p
. cargo ( "build --target-dir foobar/target" )
3607 . env ( "CARGO_TARGET_DIR" , "bar/target" )
3611 . join ( "foobar/target/debug" )
3614 assert
!( p
. root (). join ( "bar/target/debug" ). join (& exe_name
). is_file ());
3615 assert
!( p
. root (). join ( "foo/target/debug" ). join (& exe_name
). is_file ());
3616 assert
!( p
. root (). join ( "target/debug" ). join (& exe_name
). is_file ());
3620 fn build_multiple_packages () {
3639 . file ( "src/foo.rs" , & main_file ( r
# "" i am foo "" #, &[]))
3640 . file ( "d1/Cargo.toml" , & basic_bin_manifest ( "d1" ))
3641 . file ( "d1/src/lib.rs" , "" )
3642 . file ( "d1/src/main.rs" , "fn main() { println!(\"d1\"); } " )
3656 . file ( "d2/src/main.rs" , "fn main() { println!(\"d2\"); } " )
3659 p
. cargo ( "build -p d1 -p d2 -p foo" ). run ();
3661 assert
!( p
. bin ( "foo" ). is_file ());
3662 p
. process (& p
. bin ( "foo" )). with_stdout ( "i am foo \n " ). run ();
3667 . join ( format
!( "d1 {} " , env
:: consts
:: EXE_SUFFIX
));
3671 . join ( format
!( "d2 {} " , env
:: consts
:: EXE_SUFFIX
));
3673 assert
!( d1_path
. is_file ());
3674 p
. process ( d1_path
). with_stdout ( "d1" ). run ();
3676 assert
!( d2_path
. is_file ());
3677 p
. process ( d2_path
). with_stdout ( "d2" ). run ();
3698 . file ( "src/bin/foo.rs" , & main_file ( r
# "" i am foo "" #, &[]))
3699 . file ( "d1/Cargo.toml" , & basic_bin_manifest ( "d1" ))
3700 . file ( "d1/src/lib.rs" , "" )
3701 . file ( "d1/src/main.rs" , "fn main() { println!(\"d1\"); } " )
3704 p
. cargo ( "build -p notAValidDep" )
3706 . with_stderr ( "[ERROR] package ID specification `notAValidDep` did not match any packages" )
3709 p
. cargo ( "build -p d1 -p notAValidDep" )
3711 . with_stderr ( "[ERROR] package ID specification `notAValidDep` did not match any packages" )
3716 fn manifest_with_bom_is_ok () {
3727 . file ( "src/lib.rs" , "" )
3729 p
. cargo ( "build -v" ). run ();
3733 fn panic_abort_compiles_with_panic_abort () {
3747 . file ( "src/lib.rs" , "" )
3750 . with_stderr_contains ( "[..] -C panic=abort [..]" )
3755 fn compiler_json_error_format () {
3764 authors = [" wycats@example.com "]
3772 "fn main() { println!(\"cargo:rustc-cfg=xyz\") } " ,
3774 . file ( "src/main.rs" , "fn main() { let unused = 92; } " )
3775 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.5.0" ))
3776 . file ( "bar/src/lib.rs" , r
# "fn dead() {} " #)
3779 let output
= | fresh
| {
3782 " reason ":" compiler-artifact ",
3783 " package_id ":" foo 0.5.0 ([..]) ",
3784 " manifest_path ": " [..] ",
3786 " kind ":[" custom-build "],
3787 " crate_types ":[" bin "],
3791 " name ":" build-script-build ",
3792 " src_path ":" [..]build.rs ",
3796 " debug_assertions ": true,
3799 " overflow_checks ": true,
3804 " filenames ": " {...} ",
3809 " reason ":" compiler-message ",
3810 " package_id ":" bar 0.5.0 ([..]) ",
3811 " manifest_path ": " [..] ",
3814 " crate_types ":[" lib "],
3819 " src_path ":" [..]lib.rs ",
3826 " reason ":" compiler-artifact ",
3828 " debug_assertions ": true,
3831 " overflow_checks ": true,
3836 " package_id ":" bar 0.5.0 ([..]) ",
3837 " manifest_path ": " [..] ",
3840 " crate_types ":[" lib "],
3845 " src_path ":" [..]lib.rs ",
3856 " reason ":" build-script-executed ",
3857 " package_id ":" foo 0.5.0 ([..]) ",
3862 " out_dir ": " [..]target/debug/build/foo-[..]/out "
3866 " reason ":" compiler-message ",
3867 " package_id ":" foo 0.5.0 ([..]) ",
3868 " manifest_path ": " [..] ",
3871 " crate_types ":[" bin "],
3876 " src_path ":" [..]main.rs ",
3883 " reason ":" compiler-artifact ",
3884 " package_id ":" foo 0.5.0 ([..]) ",
3885 " manifest_path ": " [..] ",
3888 " crate_types ":[" bin "],
3893 " src_path ":" [..]main.rs ",
3897 " debug_assertions ": true,
3900 " overflow_checks ": true,
3903 " executable ": " [..]/foo/target/debug/foo[EXE] ",
3905 " filenames ": " {...} ",
3909 {"reason": "build-finished", "success": true}
3911 . replace ( "$FRESH" , fresh
)
3914 // Use `jobs=1` to ensure that the order of messages is consistent.
3915 p
. cargo ( "build -v --message-format=json --jobs=1" )
3916 . with_json_contains_unordered (& output ( "false" ))
3919 // With fresh build, we should repeat the artifacts,
3920 // and replay the cached compiler warnings.
3921 p
. cargo ( "build -v --message-format=json --jobs=1" )
3922 . with_json_contains_unordered (& output ( "true" ))
3927 fn wrong_message_format_option () {
3929 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
3930 . file ( "src/main.rs" , "fn main() {} " )
3933 p
. cargo ( "build --message-format XML" )
3935 . with_stderr_contains (
3937 error: invalid message format specifier: `xml`
3944 fn message_format_json_forward_stderr () {
3946 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
3947 . file ( "src/main.rs" , "fn main() { let unused = 0; } " )
3950 p
. cargo ( "rustc --release --bin foo --message-format JSON" )
3951 . with_json_contains_unordered (
3954 " reason ":" compiler-message ",
3955 " package_id ":" foo 0.5.0 ([..]) ",
3956 " manifest_path ": " [..] ",
3959 " crate_types ":[" bin "],
3971 " reason ":" compiler-artifact ",
3972 " package_id ":" foo 0.5.0 ([..]) ",
3973 " manifest_path ": " [..] ",
3976 " crate_types ":[" bin "],
3985 " debug_assertions ":false,
3988 " overflow_checks ": false,
3991 " executable ": " {...} ",
3993 " filenames ": " {...} ",
3997 {"reason": "build-finished", "success": true}
4004 fn no_warn_about_package_metadata () {
4019 [package.metadata.another]
4023 . file ( "src/lib.rs" , "" )
4027 "[..] foo v0.0.1 ([..]) \n\
4028 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] \n " ,
4034 fn no_warn_about_workspace_metadata () {
4042 [workspace.metadata]
4043 something = " something_else "
4047 [workspace.metadata.another]
4059 . file ( "foo/src/lib.rs" , "" )
4064 "[..] foo v0.0.1 ([..]) \n\
4065 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] \n " ,
4071 fn cargo_build_empty_target () {
4073 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
4074 . file ( "src/main.rs" , "fn main() {} " )
4077 p
. cargo ( "build --target" )
4080 . with_stderr_contains ( "[..] target was empty" )
4085 fn build_all_workspace () {
4095 bar = { path = "bar" }
4100 . file ( "src/main.rs" , "fn main() {} " )
4101 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4102 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4105 p
. cargo ( "build --workspace" )
4108 [COMPILING] bar v0.1.0 ([..])
4109 [COMPILING] foo v0.1.0 ([..])
4110 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4117 fn build_all_exclude () {
4127 members = [" bar ", " baz "]
4130 . file ( "src/main.rs" , "fn main() {} " )
4131 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4132 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4133 . file ( "baz/Cargo.toml" , & basic_manifest ( "baz" , "0.1.0" ))
4134 . file ( "baz/src/lib.rs" , "pub fn baz() { break_the_build(); } " )
4137 p
. cargo ( "build --workspace --exclude baz" )
4138 . with_stderr_does_not_contain ( "[COMPILING] baz v0.1.0 [..]" )
4139 . with_stderr_unordered (
4141 [COMPILING] foo v0.1.0 ([..])
4142 [COMPILING] bar v0.1.0 ([..])
4143 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4150 fn build_all_exclude_not_found () {
4163 . file ( "src/main.rs" , "fn main() {} " )
4164 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4165 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4168 p
. cargo ( "build --workspace --exclude baz" )
4169 . with_stderr_does_not_contain ( "[COMPILING] baz v0.1.0 [..]" )
4170 . with_stderr_unordered (
4172 [WARNING] excluded package(s) `baz` not found in workspace [..]
4173 [COMPILING] foo v0.1.0 ([..])
4174 [COMPILING] bar v0.1.0 ([..])
4175 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4182 fn build_all_exclude_glob () {
4192 members = [" bar ", " baz "]
4195 . file ( "src/main.rs" , "fn main() {} " )
4196 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4197 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4198 . file ( "baz/Cargo.toml" , & basic_manifest ( "baz" , "0.1.0" ))
4199 . file ( "baz/src/lib.rs" , "pub fn baz() { break_the_build(); } " )
4202 p
. cargo ( "build --workspace --exclude '*z'" )
4203 . with_stderr_does_not_contain ( "[COMPILING] baz v0.1.0 [..]" )
4204 . with_stderr_unordered (
4206 [COMPILING] foo v0.1.0 ([..])
4207 [COMPILING] bar v0.1.0 ([..])
4208 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4215 fn build_all_exclude_glob_not_found () {
4228 . file ( "src/main.rs" , "fn main() {} " )
4229 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4230 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4233 p
. cargo ( "build --workspace --exclude '*z'" )
4234 . with_stderr_does_not_contain ( "[COMPILING] baz v0.1.0 [..]" )
4237 [WARNING] excluded package pattern(s) `*z` not found in workspace [..]
4238 [COMPILING] [..] v0.1.0 ([..])
4239 [COMPILING] [..] v0.1.0 ([..])
4240 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4247 fn build_all_exclude_broken_glob () {
4248 let p
= project (). file ( "src/main.rs" , "fn main() {} " ). build ();
4250 p
. cargo ( "build --workspace --exclude '[*z'" )
4252 . with_stderr_contains ( "[ERROR] cannot build glob pattern from `[*z`" )
4257 fn build_all_workspace_implicit_examples () {
4267 bar = { path = "bar" }
4272 . file ( "src/lib.rs" , "" )
4273 . file ( "src/bin/a.rs" , "fn main() {} " )
4274 . file ( "src/bin/b.rs" , "fn main() {} " )
4275 . file ( "examples/c.rs" , "fn main() {} " )
4276 . file ( "examples/d.rs" , "fn main() {} " )
4277 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4278 . file ( "bar/src/lib.rs" , "" )
4279 . file ( "bar/src/bin/e.rs" , "fn main() {} " )
4280 . file ( "bar/src/bin/f.rs" , "fn main() {} " )
4281 . file ( "bar/examples/g.rs" , "fn main() {} " )
4282 . file ( "bar/examples/h.rs" , "fn main() {} " )
4285 p
. cargo ( "build --workspace --examples" )
4287 "[..] Compiling bar v0.1.0 ([..]) \n\
4288 [..] Compiling foo v0.1.0 ([..]) \n\
4289 [..] Finished dev [unoptimized + debuginfo] target(s) in [..] \n " ,
4292 assert
!(! p
. bin ( "a" ). is_file ());
4293 assert
!(! p
. bin ( "b" ). is_file ());
4294 assert
!( p
. bin ( "examples/c" ). is_file ());
4295 assert
!( p
. bin ( "examples/d" ). is_file ());
4296 assert
!(! p
. bin ( "e" ). is_file ());
4297 assert
!(! p
. bin ( "f" ). is_file ());
4298 assert
!( p
. bin ( "examples/g" ). is_file ());
4299 assert
!( p
. bin ( "examples/h" ). is_file ());
4303 fn build_all_virtual_manifest () {
4309 members = [" bar ", " baz "]
4312 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4313 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4314 . file ( "baz/Cargo.toml" , & basic_manifest ( "baz" , "0.1.0" ))
4315 . file ( "baz/src/lib.rs" , "pub fn baz() {} " )
4318 // The order in which bar and baz are built is not guaranteed
4319 p
. cargo ( "build --workspace" )
4320 . with_stderr_unordered (
4322 [COMPILING] baz v0.1.0 ([..])
4323 [COMPILING] bar v0.1.0 ([..])
4324 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4331 fn build_virtual_manifest_all_implied () {
4337 members = [" bar ", " baz "]
4340 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4341 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4342 . file ( "baz/Cargo.toml" , & basic_manifest ( "baz" , "0.1.0" ))
4343 . file ( "baz/src/lib.rs" , "pub fn baz() {} " )
4346 // The order in which `bar` and `baz` are built is not guaranteed.
4348 . with_stderr_unordered (
4350 [COMPILING] baz v0.1.0 ([..])
4351 [COMPILING] bar v0.1.0 ([..])
4352 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4359 fn build_virtual_manifest_one_project () {
4365 members = [" bar ", " baz "]
4368 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4369 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4370 . file ( "baz/Cargo.toml" , & basic_manifest ( "baz" , "0.1.0" ))
4371 . file ( "baz/src/lib.rs" , "pub fn baz() { break_the_build(); } " )
4374 p
. cargo ( "build -p bar" )
4375 . with_stderr_does_not_contain ( "[..]baz[..]" )
4378 [COMPILING] bar v0.1.0 ([..])
4379 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4386 fn build_virtual_manifest_glob () {
4392 members = [" bar ", " baz "]
4395 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4396 . file ( "bar/src/lib.rs" , "pub fn bar() { break_the_build(); } " )
4397 . file ( "baz/Cargo.toml" , & basic_manifest ( "baz" , "0.1.0" ))
4398 . file ( "baz/src/lib.rs" , "pub fn baz() {} " )
4401 p
. cargo ( "build -p '*z'" )
4402 . with_stderr_does_not_contain ( "[..]bar[..]" )
4405 [COMPILING] baz v0.1.0 ([..])
4406 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4413 fn build_virtual_manifest_glob_not_found () {
4422 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4423 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4426 p
. cargo ( "build -p bar -p '*z'" )
4428 . with_stderr ( "[ERROR] package pattern(s) `*z` not found in workspace [..]" )
4433 fn build_virtual_manifest_broken_glob () {
4442 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4443 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4446 p
. cargo ( "build -p '[*z'" )
4448 . with_stderr_contains ( "[ERROR] cannot build glob pattern from `[*z`" )
4453 fn build_all_virtual_manifest_implicit_examples () {
4459 members = [" bar ", " baz "]
4462 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4463 . file ( "bar/src/lib.rs" , "" )
4464 . file ( "bar/src/bin/a.rs" , "fn main() {} " )
4465 . file ( "bar/src/bin/b.rs" , "fn main() {} " )
4466 . file ( "bar/examples/c.rs" , "fn main() {} " )
4467 . file ( "bar/examples/d.rs" , "fn main() {} " )
4468 . file ( "baz/Cargo.toml" , & basic_manifest ( "baz" , "0.1.0" ))
4469 . file ( "baz/src/lib.rs" , "" )
4470 . file ( "baz/src/bin/e.rs" , "fn main() {} " )
4471 . file ( "baz/src/bin/f.rs" , "fn main() {} " )
4472 . file ( "baz/examples/g.rs" , "fn main() {} " )
4473 . file ( "baz/examples/h.rs" , "fn main() {} " )
4476 // The order in which bar and baz are built is not guaranteed
4477 p
. cargo ( "build --workspace --examples" )
4478 . with_stderr_unordered (
4480 [COMPILING] baz v0.1.0 ([..])
4481 [COMPILING] bar v0.1.0 ([..])
4482 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4486 assert
!(! p
. bin ( "a" ). is_file ());
4487 assert
!(! p
. bin ( "b" ). is_file ());
4488 assert
!( p
. bin ( "examples/c" ). is_file ());
4489 assert
!( p
. bin ( "examples/d" ). is_file ());
4490 assert
!(! p
. bin ( "e" ). is_file ());
4491 assert
!(! p
. bin ( "f" ). is_file ());
4492 assert
!( p
. bin ( "examples/g" ). is_file ());
4493 assert
!( p
. bin ( "examples/h" ). is_file ());
4497 fn build_all_member_dependency_same_name () {
4517 . file ( "a/src/lib.rs" , "pub fn a() {} " )
4520 Package
:: new ( "a" , "0.1.0" ). publish ();
4522 p
. cargo ( "build --workspace" )
4524 "[UPDATING] `[..]` index \n\
4525 [DOWNLOADING] crates ... \n\
4526 [DOWNLOADED] a v0.1.0 ([..]) \n\
4527 [COMPILING] a v0.1.0 \n\
4528 [COMPILING] a v0.1.0 ([..]) \n\
4529 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] \n " ,
4535 fn run_proper_binary () {
4550 . file ( "src/lib.rs" , "" )
4553 r
# "fn main() { panic!("This should never be run."); } " #,
4555 . file ( "src/bin/other.rs" , "fn main() {} " )
4558 p
. cargo ( "run --bin other" ). run ();
4562 fn run_proper_binary_main_rs () {
4564 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
4565 . file ( "src/lib.rs" , "" )
4566 . file ( "src/bin/main.rs" , "fn main() {} " )
4569 p
. cargo ( "run --bin foo" ). run ();
4573 fn run_proper_alias_binary_from_src () {
4588 . file ( "src/foo.rs" , r
# "fn main() { println!("foo"); } " #)
4589 . file ( "src/bar.rs" , r
# "fn main() { println!("bar"); } " #)
4592 p
. cargo ( "build --workspace" ). run ();
4593 p
. process (& p
. bin ( "foo" )). with_stdout ( "foo \n " ). run ();
4594 p
. process (& p
. bin ( "bar" )). with_stdout ( "bar \n " ). run ();
4598 fn run_proper_alias_binary_main_rs () {
4613 . file ( "src/main.rs" , r
# "fn main() { println!("main"); } " #)
4616 p
. cargo ( "build --workspace" ). run ();
4617 p
. process (& p
. bin ( "foo" )). with_stdout ( "main \n " ). run ();
4618 p
. process (& p
. bin ( "bar" )). with_stdout ( "main \n " ). run ();
4622 fn run_proper_binary_main_rs_as_foo () {
4624 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
4627 r
# " fn main() { panic!("This should never be run."); } " #,
4629 . file ( "src/main.rs" , "fn main() {} " )
4632 p
. cargo ( "run --bin foo" ). run ();
4636 fn rustc_wrapper () {
4637 let p
= project (). file ( "src/lib.rs" , "" ). build ();
4638 let wrapper
= tools
:: echo_wrapper ();
4639 let running
= format
!(
4640 "[RUNNING] ` {} rustc --crate-name foo [..]" ,
4644 . env ( "RUSTC_WRAPPER" , & wrapper
)
4645 . with_stderr_contains (& running
)
4647 p
. build_dir (). rm_rf ();
4649 . env ( "RUSTC_WORKSPACE_WRAPPER" , & wrapper
)
4650 . with_stderr_contains (& running
)
4655 fn rustc_wrapper_relative () {
4656 Package
:: new ( "bar" , "1.0.0" ). publish ();
4669 . file ( "src/lib.rs" , "" )
4671 let wrapper
= tools
:: echo_wrapper ();
4672 let exe_name
= wrapper
. file_name (). unwrap (). to_str (). unwrap ();
4673 let relative_path
= format
!( "./ {} " , exe_name
);
4674 fs
:: hard_link (& wrapper
, p
. root (). join ( exe_name
)). unwrap ();
4675 let running
= format
!( "[RUNNING] `[ROOT]/foo/./ {} rustc[..]" , exe_name
);
4677 . env ( "RUSTC_WRAPPER" , & relative_path
)
4678 . with_stderr_contains (& running
)
4680 p
. build_dir (). rm_rf ();
4682 . env ( "RUSTC_WORKSPACE_WRAPPER" , & relative_path
)
4683 . with_stderr_contains (& running
)
4685 p
. build_dir (). rm_rf ();
4687 ".cargo/config.toml" ,
4690 build.rustc-wrapper = " ./{} "
4695 p
. cargo ( "build -v" ). with_stderr_contains (& running
). run ();
4699 fn rustc_wrapper_from_path () {
4700 let p
= project (). file ( "src/lib.rs" , "" ). build ();
4702 . env ( "RUSTC_WRAPPER" , "wannabe_sccache" )
4704 . with_stderr_contains ( "[..]`wannabe_sccache rustc [..]" )
4706 p
. build_dir (). rm_rf ();
4708 . env ( "RUSTC_WORKSPACE_WRAPPER" , "wannabe_sccache" )
4710 . with_stderr_contains ( "[..]`wannabe_sccache rustc [..]" )
4715 fn cdylib_not_lifted () {
4726 crate-type = [" cdylib "]
4729 . file ( "src/lib.rs" , "" )
4732 p
. cargo ( "build" ). run ();
4734 let files
= if cfg
!( windows
) {
4735 if cfg
!( target_env
= "msvc" ) {
4736 vec
![ "foo.dll.lib" , "foo.dll.exp" , "foo.dll" ]
4738 vec
![ "libfoo.dll.a" , "foo.dll" ]
4740 } else if cfg
!( target_os
= "macos" ) {
4741 vec
![ "libfoo.dylib" ]
4747 println
!( "checking: {} " , file
);
4748 assert
!( p
. root (). join ( "target/debug/deps" ). join (& file
). is_file ());
4753 fn cdylib_final_outputs () {
4764 crate-type = [" cdylib "]
4767 . file ( "src/lib.rs" , "" )
4770 p
. cargo ( "build" ). run ();
4772 let files
= if cfg
!( windows
) {
4773 if cfg
!( target_env
= "msvc" ) {
4774 vec
![ "foo_bar.dll.lib" , "foo_bar.dll" ]
4776 vec
![ "foo_bar.dll" , "libfoo_bar.dll.a" ]
4778 } else if cfg
!( target_os
= "macos" ) {
4779 vec
![ "libfoo_bar.dylib" ]
4781 vec
![ "libfoo_bar.so" ]
4785 println
!( "checking: {} " , file
);
4786 assert
!( p
. root (). join ( "target/debug" ). join (& file
). is_file ());
4791 // NOTE: Windows MSVC and wasm32-unknown-emscripten do not use metadata. Skip them.
4792 // See <https://github.com/rust-lang/cargo/issues/9325#issuecomment-1030662699>
4793 #[cfg(not(all(target_os = "windows" , target_env = "msvc" )))]
4794 fn no_dep_info_collision_when_cdylib_and_bin_coexist () {
4804 crate-type = [" cdylib "]
4807 . file ( "src/main.rs" , "fn main() {} " )
4808 . file ( "src/lib.rs" , "" )
4812 . with_stderr_unordered (
4814 [COMPILING] foo v1.0.0 ([CWD])
4815 [RUNNING] `rustc [..] --crate-type bin [..] -C metadata=[..]`
4816 [RUNNING] `rustc [..] --crate-type cdylib [..] -C metadata=[..]`
4822 let deps_dir
= p
. target_debug_dir (). join ( "deps" );
4823 assert
!( deps_dir
. join ( "foo.d" ). exists ());
4824 let dep_info_count
= deps_dir
4828 let filename
= e
. as_ref (). unwrap (). file_name ();
4829 let filename
= filename
. to_str (). unwrap ();
4830 filename
. starts_with ( "foo" ) && filename
. ends_with ( ".d" )
4834 // bin -> foo-<meta>.d
4835 assert_eq
!( dep_info_count
, 2 );
4839 fn deterministic_cfg_flags () {
4840 // This bug is non-deterministic.
4853 default = [" f_a ", " f_b ", " f_c ", " f_d "]
4864 println!(" cargo:rustc-cfg=cfg_a ");
4865 println!(" cargo:rustc-cfg=cfg_b ");
4866 println!(" cargo:rustc-cfg=cfg_c ");
4867 println!(" cargo:rustc-cfg=cfg_d ");
4868 println!(" cargo:rustc-cfg=cfg_e ");
4872 . file ( "src/main.rs" , "fn main() {} " )
4878 [COMPILING] foo v0.1.0 [..]
4881 [RUNNING] `rustc --crate-name foo [..] \
4882 --cfg[..]default[..]--cfg[..]f_a[..]--cfg[..]f_b[..] \
4883 --cfg[..]f_c[..]--cfg[..]f_d[..] \
4884 --cfg cfg_a --cfg cfg_b --cfg cfg_c --cfg cfg_d --cfg cfg_e`
4885 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]" ,
4891 fn explicit_bins_without_paths () {
4908 . file ( "src/lib.rs" , "" )
4909 . file ( "src/main.rs" , "fn main() {} " )
4910 . file ( "src/bin/bar.rs" , "fn main() {} " )
4913 p
. cargo ( "build" ). run ();
4917 fn no_bin_in_src_with_lib () {
4919 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
4920 . file ( "src/lib.rs" , "" )
4921 . file ( "src/foo.rs" , "fn main() {} " )
4926 . with_stderr_contains (
4928 [ERROR] failed to parse manifest at `[..]`
4931 can't find `foo` bin at `src/bin/foo.rs` or `src/bin/foo/main.rs`. [..]" ,
4937 fn inferred_bins () {
4939 . file ( "src/main.rs" , "fn main() {} " )
4940 . file ( "src/bin/bar.rs" , "fn main() {} " )
4941 . file ( "src/bin/baz/main.rs" , "fn main() {} " )
4944 p
. cargo ( "build" ). run ();
4945 assert
!( p
. bin ( "foo" ). is_file ());
4946 assert
!( p
. bin ( "bar" ). is_file ());
4947 assert
!( p
. bin ( "baz" ). is_file ());
4951 fn inferred_bins_duplicate_name () {
4952 // this should fail, because we have two binaries with the same name
4954 . file ( "src/main.rs" , "fn main() {} " )
4955 . file ( "src/bin/bar.rs" , "fn main() {} " )
4956 . file ( "src/bin/bar/main.rs" , "fn main() {} " )
4959 p
. cargo ( "build" ). with_status ( 101 ). with_stderr_contains (
4960 "[..]found duplicate binary name bar, but all binary targets must have a unique name[..]" ,
4966 fn inferred_bin_path () {
4978 # Note, no `path` key!
4981 . file ( "src/bin/bar/main.rs" , "fn main() {} " )
4984 p
. cargo ( "build" ). run ();
4985 assert
!( p
. bin ( "bar" ). is_file ());
4989 fn inferred_examples () {
4991 . file ( "src/lib.rs" , "fn main() {} " )
4992 . file ( "examples/bar.rs" , "fn main() {} " )
4993 . file ( "examples/baz/main.rs" , "fn main() {} " )
4996 p
. cargo ( "build --examples" ). run ();
4997 assert
!( p
. bin ( "examples/bar" ). is_file ());
4998 assert
!( p
. bin ( "examples/baz" ). is_file ());
5002 fn inferred_tests () {
5004 . file ( "src/lib.rs" , "fn main() {} " )
5005 . file ( "tests/bar.rs" , "fn main() {} " )
5006 . file ( "tests/baz/main.rs" , "fn main() {} " )
5009 p
. cargo ( "test --test=bar --test=baz" ). run ();
5013 fn inferred_benchmarks () {
5015 . file ( "src/lib.rs" , "fn main() {} " )
5016 . file ( "benches/bar.rs" , "fn main() {} " )
5017 . file ( "benches/baz/main.rs" , "fn main() {} " )
5020 p
. cargo ( "bench --bench=bar --bench=baz" ). run ();
5024 fn target_edition () {
5037 . file ( "src/lib.rs" , "" )
5041 . with_stderr_contains (
5043 [COMPILING] foo v0.0.1 ([..])
5044 [RUNNING] `rustc [..]--edition=2018 [..]
5051 fn target_edition_override () {
5076 p
. cargo ( "build -v" ). run ();
5080 fn same_metadata_different_directory () {
5081 // A top-level crate built in two different workspaces should have the
5082 // same metadata hash.
5085 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
5086 . file ( "src/foo.rs" , & main_file ( r
# "" i am foo "" #, &[]))
5088 let output
= t
!( String
:: from_utf8 (
5089 t
!( p
. cargo ( "build -v" ). exec_with_output ()). stderr
,
5091 let metadata
= output
5093 . find (| arg
| arg
. starts_with ( "metadata=" ))
5098 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
5099 . file ( "src/foo.rs" , & main_file ( r
# "" i am foo "" #, &[]))
5103 . with_stderr_contains ( format
!( "[..] {} [..]" , metadata
))
5108 fn building_a_dependent_crate_without_bin_should_fail () {
5109 Package
:: new ( "testless" , "0.1.0" )
5121 . file ( "src/lib.rs" , "" )
5136 . file ( "src/lib.rs" , "" )
5141 . with_stderr_contains (
5142 "[..]can't find `a_bin` bin at `src/bin/a_bin.rs` or `src/bin/a_bin/main.rs`[..]" ,
5148 #[cfg(any(target_os = "macos" , target_os = "ios" ))]
5149 fn uplift_dsym_of_bin_on_mac () {
5151 . file ( "src/main.rs" , "fn main() { panic!(); } " )
5152 . file ( "src/bin/b.rs" , "fn main() { panic!(); } " )
5153 . file ( "examples/c.rs" , "fn main() { panic!(); } " )
5154 . file ( "tests/d.rs" , "fn main() { panic!(); } " )
5157 p
. cargo ( "build --bins --examples --tests" )
5160 assert
!( p
. target_debug_dir (). join ( "foo.dSYM" ). is_dir ());
5161 assert
!( p
. target_debug_dir (). join ( "b.dSYM" ). is_dir ());
5162 assert
!( p
. target_debug_dir (). join ( "b.dSYM" ). is_symlink ());
5163 assert
!( p
. target_debug_dir (). join ( "examples/c.dSYM" ). is_dir ());
5164 assert
!(! p
. target_debug_dir (). join ( "c.dSYM" ). exists ());
5165 assert
!(! p
. target_debug_dir (). join ( "d.dSYM" ). exists ());
5169 #[cfg(any(target_os = "macos" , target_os = "ios" ))]
5170 fn uplift_dsym_of_bin_on_mac_when_broken_link_exists () {
5172 . file ( "src/main.rs" , "fn main() { panic!(); } " )
5174 let dsym
= p
. target_debug_dir (). join ( "foo.dSYM" );
5176 p
. cargo ( "build" ). enable_mac_dsym (). run ();
5177 assert
!( dsym
. is_dir ());
5179 // Simulate the situation where the underlying dSYM bundle goes missing
5180 // but the uplifted symlink to it remains. This would previously cause
5181 // builds to permanently fail until the bad symlink was manually removed.
5184 p
. target_debug_dir ()
5186 . join ( "foo-baaaaaadbaaaaaad.dSYM" ),
5189 assert
!( dsym
. is_symlink ());
5190 assert
!(! dsym
. exists ());
5192 p
. cargo ( "build" ). enable_mac_dsym (). run ();
5193 assert
!( dsym
. is_dir ());
5197 #[cfg(all(target_os = "windows" , target_env = "msvc" ))]
5198 fn uplift_pdb_of_bin_on_windows () {
5200 . file ( "src/main.rs" , "fn main() { panic!(); } " )
5201 . file ( "src/bin/b.rs" , "fn main() { panic!(); } " )
5202 . file ( "src/bin/foo-bar.rs" , "fn main() { panic!(); } " )
5203 . file ( "examples/c.rs" , "fn main() { panic!(); } " )
5204 . file ( "tests/d.rs" , "fn main() { panic!(); } " )
5207 p
. cargo ( "build --bins --examples --tests" ). run ();
5208 assert
!( p
. target_debug_dir (). join ( "foo.pdb" ). is_file ());
5209 assert
!( p
. target_debug_dir (). join ( "b.pdb" ). is_file ());
5210 assert
!( p
. target_debug_dir (). join ( "examples/c.pdb" ). exists ());
5211 assert
!( p
. target_debug_dir (). join ( "foo-bar.exe" ). is_file ());
5212 assert
!( p
. target_debug_dir (). join ( "foo_bar.pdb" ). is_file ());
5213 assert
!(! p
. target_debug_dir (). join ( "c.pdb" ). exists ());
5214 assert
!(! p
. target_debug_dir (). join ( "d.pdb" ). exists ());
5217 // Ensure that `cargo build` chooses the correct profile for building
5218 // targets based on filters (assuming `--profile` is not specified).
5220 fn build_filter_infer_profile () {
5222 . file ( "src/lib.rs" , "" )
5223 . file ( "src/main.rs" , "fn main() {} " )
5224 . file ( "tests/t1.rs" , "" )
5225 . file ( "benches/b1.rs" , "" )
5226 . file ( "examples/ex1.rs" , "fn main() {} " )
5230 . with_stderr_contains (
5231 "[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
5232 --emit=[..]link[..]" ,
5234 . with_stderr_contains (
5235 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
5236 --emit=[..]link[..]" ,
5240 p
. root (). join ( "target" ). rm_rf ();
5241 p
. cargo ( "build -v --test=t1" )
5242 . with_stderr_contains (
5243 "[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
5244 --emit=[..]link[..]-C debuginfo=2 [..]" ,
5246 . with_stderr_contains (
5247 "[RUNNING] `rustc --crate-name t1 tests/t1.rs [..]--emit=[..]link[..] \
5248 -C debuginfo=2 [..]" ,
5250 . with_stderr_contains (
5251 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
5252 --emit=[..]link[..]-C debuginfo=2 [..]" ,
5256 p
. root (). join ( "target" ). rm_rf ();
5257 // Bench uses test profile without `--release`.
5258 p
. cargo ( "build -v --bench=b1" )
5259 . with_stderr_contains (
5260 "[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
5261 --emit=[..]link[..]-C debuginfo=2 [..]" ,
5263 . with_stderr_contains (
5264 "[RUNNING] `rustc --crate-name b1 benches/b1.rs [..]--emit=[..]link[..] \
5265 -C debuginfo=2 [..]" ,
5267 . with_stderr_does_not_contain ( "opt-level" )
5268 . with_stderr_contains (
5269 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
5270 --emit=[..]link[..]-C debuginfo=2 [..]" ,
5276 fn targets_selected_default () {
5277 let p
= project (). file ( "src/main.rs" , "fn main() {} " ). build ();
5280 . with_stderr_contains (
5281 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
5282 --emit=[..]link[..]" ,
5285 . with_stderr_does_not_contain (
5286 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link \
5287 -C opt-level=3 --test [..]" ,
5290 . with_stderr_does_not_contain (
5291 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link[..] \
5292 -C debuginfo=2 --test [..]" ,
5298 fn targets_selected_all () {
5299 let p
= project (). file ( "src/main.rs" , "fn main() {} " ). build ();
5300 p
. cargo ( "build -v --all-targets" )
5302 . with_stderr_contains (
5303 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
5304 --emit=[..]link[..]" ,
5307 . with_stderr_contains (
5308 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link[..] \
5309 -C debuginfo=2 --test [..]" ,
5315 fn all_targets_no_lib () {
5316 let p
= project (). file ( "src/main.rs" , "fn main() {} " ). build ();
5317 p
. cargo ( "build -v --all-targets" )
5319 . with_stderr_contains (
5320 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
5321 --emit=[..]link[..]" ,
5324 . with_stderr_contains (
5325 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link[..] \
5326 -C debuginfo=2 --test [..]" ,
5332 fn no_linkable_target () {
5333 // Issue 3169: this is currently not an error as per discussion in PR #4797.
5343 the_lib = { path = "the_lib" }
5346 . file ( "src/main.rs" , "fn main() {} " )
5348 "the_lib/Cargo.toml" ,
5355 crate-type = [" staticlib "]
5358 . file ( "the_lib/src/lib.rs" , "pub fn foo() {} " )
5361 . with_stderr_contains (
5362 "[WARNING] The package `the_lib` provides no linkable [..] \
5363 while compiling `foo`. [..] in `the_lib`'s Cargo.toml. [..]" ,
5369 fn avoid_dev_deps () {
5370 Package
:: new ( "foo" , "1.0.0" ). publish ();
5384 . file ( "src/main.rs" , "fn main() {} " )
5392 [ERROR] no matching package named `baz` found
5393 location searched: registry `crates-io`
5394 required by package `bar v0.1.0 ([..]/foo)`
5398 p
. cargo ( "build -Zavoid-dev-deps" )
5399 . masquerade_as_nightly_cargo (&[ "avoid-dev-deps" ])
5404 fn default_cargo_config_jobs () {
5406 . file ( "src/lib.rs" , "" )
5415 p
. cargo ( "build -v" ). run ();
5419 fn good_cargo_config_jobs () {
5421 . file ( "src/lib.rs" , "" )
5430 p
. cargo ( "build -v" ). run ();
5436 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
5437 . file ( "src/foo.rs" , & main_file ( r
# "" i am foo "" #, &[]))
5440 p
. cargo ( "build --jobs 1" ). run ();
5442 p
. cargo ( "build --jobs -1" ). run ();
5446 fn invalid_cargo_config_jobs () {
5448 . file ( "src/lib.rs" , "" )
5459 . with_stderr_contains ( "error: jobs may not be 0" )
5466 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
5467 . file ( "src/foo.rs" , & main_file ( r
# "" i am foo "" #, &[]))
5470 p
. cargo ( "build --jobs 0" )
5472 . with_stderr_contains ( "error: jobs may not be 0" )
5475 p
. cargo ( "build --jobs over9000" )
5477 . with_stderr ( "error: Invalid value: could not parse `over9000` as a number" )
5482 fn target_filters_workspace () {
5489 members = [" a ", " b "]
5492 . file ( "a/Cargo.toml" , & basic_lib_manifest ( "a" ))
5493 . file ( "a/src/lib.rs" , "" )
5494 . file ( "a/examples/ex1.rs" , "fn main() {} " )
5495 . file ( "b/Cargo.toml" , & basic_bin_manifest ( "b" ))
5496 . file ( "b/src/lib.rs" , "" )
5497 . file ( "b/src/main.rs" , "fn main() {} " )
5500 ws
. cargo ( "build -v --example ex" )
5504 [ERROR] no example target named `ex`
5506 <tab>Did you mean `ex1`?" ,
5510 ws
. cargo ( "build -v --example 'ex??'" )
5514 [ERROR] no example target matches pattern `ex??`
5516 <tab>Did you mean `ex1`?" ,
5520 ws
. cargo ( "build -v --lib" )
5521 . with_stderr_contains ( "[RUNNING] `rustc [..]a/src/lib.rs[..]" )
5522 . with_stderr_contains ( "[RUNNING] `rustc [..]b/src/lib.rs[..]" )
5525 ws
. cargo ( "build -v --example ex1" )
5526 . with_stderr_contains ( "[RUNNING] `rustc [..]a/examples/ex1.rs[..]" )
5531 fn target_filters_workspace_not_found () {
5538 members = [" a ", " b "]
5541 . file ( "a/Cargo.toml" , & basic_bin_manifest ( "a" ))
5542 . file ( "a/src/main.rs" , "fn main() {} " )
5543 . file ( "b/Cargo.toml" , & basic_bin_manifest ( "b" ))
5544 . file ( "b/src/main.rs" , "fn main() {} " )
5547 ws
. cargo ( "build -v --lib" )
5549 . with_stderr ( "[ERROR] no library targets found in packages: a, b" )
5555 fn signal_display () {
5556 // Cause the compiler to crash with a signal.
5565 pm = { path = "pm" }
5591 extern crate proc_macro;
5592 use proc_macro::TokenStream;
5594 #[proc_macro_derive(Foo)]
5595 pub fn derive(_input: TokenStream) -> TokenStream {
5596 std::process::abort()
5606 [COMPILING] foo [..]
5607 [ERROR] could not compile `foo`
5610 process didn't exit successfully: `rustc [..]` (signal: 6, SIGABRT: process abort signal)
5618 fn tricky_pipelining () {
5627 bar = { path = "bar" }
5630 . file ( "src/lib.rs" , "extern crate bar;" )
5631 . file ( "bar/Cargo.toml" , & basic_lib_manifest ( "bar" ))
5632 . file ( "bar/src/lib.rs" , "" )
5635 foo
. cargo ( "build -p bar" ). run ();
5636 foo
. cargo ( "build -p foo" ). run ();
5640 fn pipelining_works () {
5649 bar = { path = "bar" }
5652 . file ( "src/lib.rs" , "extern crate bar;" )
5653 . file ( "bar/Cargo.toml" , & basic_lib_manifest ( "bar" ))
5654 . file ( "bar/src/lib.rs" , "" )
5670 fn pipelining_big_graph () {
5671 // Create a crate graph of the form {a,b}{0..29}, where {a,b}(n) depend on {a,b}(n+1)
5672 // Then have `foo`, a binary crate, depend on the whole thing.
5673 let mut project
= project ()
5681 a1 = { path = "a1" }
5682 b1 = { path = "b1" }
5685 . file ( "src/main.rs" , "fn main() {} " );
5688 for x
in &[ "a" , "b" ] {
5691 & format
!( " {x}{n} /Cargo.toml" , x
= x
, n
= n
),
5698 a {np1} = {{ path = "../a{np1} " }}
5699 b{np1}
= {{ path = "../b{np1}
" }}
5706 . file (& format
!( " {x}{n} /src/lib.rs" , x
= x
, n
= n
), "" );
5711 . file ( "a30/Cargo.toml" , & basic_lib_manifest ( "a30" ))
5714 r
# "compile_error!(" don't actually build me ");" #,
5716 . file ( "b30/Cargo.toml" , & basic_lib_manifest ( "b30" ))
5717 . file ( "b30/src/lib.rs" , "" )
5719 foo
. cargo ( "build -p foo" )
5721 . with_stderr_contains ( "[ERROR] could not compile `a30`[..]" )
5726 fn forward_rustc_output () {
5736 bar = { path = "bar" }
5739 . file ( "src/lib.rs" , "bar::foo!();" )
5753 extern crate proc_macro;
5757 pub fn foo(input: TokenStream) -> TokenStream {
5763 eprintln!(" {{a "); // " malformed json "
5771 . with_stdout ( "a \n b \n {} " )
5786 fn build_lib_only () {
5788 . file ( "src/main.rs" , "fn main() {} " )
5789 . file ( "src/lib.rs" , r
# " " #)
5792 p
. cargo ( "build --lib -v" )
5795 [COMPILING] foo v0.0.1 ([CWD])
5796 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
5797 --emit=[..]link[..]-C debuginfo=2 \
5800 -L dependency=[CWD]/target/debug/deps`
5801 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]" ,
5807 fn build_with_no_lib () {
5809 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
5810 . file ( "src/main.rs" , "fn main() {} " )
5813 p
. cargo ( "build --lib" )
5815 . with_stderr ( "[ERROR] no library targets found in package `foo`" )
5820 fn build_with_relative_cargo_home_path () {
5829 authors = [" wycats@example.com "]
5833 " test-dependency " = { path = "src/test_dependency" }
5836 . file ( "src/main.rs" , "fn main() {} " )
5837 . file ( "src/test_dependency/src/lib.rs" , r
# " " #)
5839 "src/test_dependency/Cargo.toml" ,
5840 & basic_manifest ( "test-dependency" , "0.0.1" ),
5844 p
. cargo ( "build" ). env ( "CARGO_HOME" , "./cargo_home/" ). run ();
5848 fn user_specific_cfgs_are_filtered_out () {
5850 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
5851 . file ( "src/main.rs" , r
# "fn main() {} " #)
5856 assert!(std::env::var_os(" CARGO_CFG_PROC_MACRO ").is_none());
5857 assert!(std::env::var_os(" CARGO_CFG_DEBUG_ASSERTIONS ").is_none());
5863 p
. cargo ( "rustc -- --cfg debug_assertions --cfg proc_macro" )
5865 p
. process (& p
. bin ( "foo" )). run ();
5870 // What happens when stdout or stderr is closed during a build.
5872 // Server to know when rustc has spawned.
5873 let listener
= std
:: net
:: TcpListener
:: bind ( "127.0.0.1:0" ). unwrap ();
5874 let addr
= listener
. local_addr (). unwrap ();
5895 use proc_macro::TokenStream;
5899 pub fn repro(_input: TokenStream) -> TokenStream {
5900 println!(" hello stdout! ");
5901 eprintln!(" hello stderr! ");
5902 // Tell the test we have started.
5903 let mut socket = std::net::TcpStream::connect(" __ADDR__ ").unwrap();
5904 // Wait for the test to tell us to start printing.
5906 drop(socket.read_exact(&mut buf));
5907 let use_stderr = std::env::var(" __CARGO_REPRO_STDERR ").is_ok();
5908 // Emit at least 1MB of data.
5909 // Linux pipes can buffer up to 64KB.
5910 // This test seems to be sensitive to having other threads
5911 // calling fork. My hypothesis is that the stdout/stderr
5912 // file descriptors are duplicated into the child process,
5913 // and during the short window between fork and exec, the
5914 // file descriptor is kept alive long enough for the
5915 // build to finish. It's a half-baked theory, but this
5916 // seems to prevent the spurious errors in CI.
5917 // An alternative solution is to run this test in
5918 // a single-threaded environment.
5919 for i in 0..100000 {
5921 eprintln!(" 0123456789{} ", i);
5923 println!(" 0123456789{} ", i);
5929 . replace ( "__ADDR__" , & addr
. to_string ()),
5932 "src/bin/foobar.rs" ,
5941 // The `stderr` flag here indicates if this should forcefully close stderr or stdout.
5942 let spawn
= | stderr
: bool
| {
5943 let mut cmd
= p
. cargo ( "build" ). build_command ();
5944 cmd
. stdout ( Stdio
:: piped ()). stderr ( Stdio
:: piped ());
5946 cmd
. env ( "__CARGO_REPRO_STDERR" , "1" );
5948 let mut child
= cmd
. spawn (). unwrap ();
5949 // Wait for proc macro to start.
5950 let pm_conn
= listener
. accept (). unwrap (). 0 ;
5951 // Close stderr or stdout.
5953 drop ( child
. stderr
. take ());
5955 drop ( child
. stdout
. take ());
5957 // Tell the proc-macro to continue;
5959 // Read the output from the other channel.
5960 let out
: & mut dyn Read
= if stderr
{
5961 child
. stdout
. as_mut (). unwrap ()
5963 child
. stderr
. as_mut (). unwrap ()
5965 let mut result
= String
:: new ();
5966 out
. read_to_string (& mut result
). unwrap ();
5967 let status
= child
. wait (). unwrap ();
5968 assert
!(! status
. success ());
5972 let stderr
= spawn ( false );
5973 compare
:: match_unordered (
5975 [COMPILING] foo [..]
5978 [WARNING] build failed, waiting for other jobs to finish...
5985 // Try again with stderr.
5986 p
. build_dir (). rm_rf ();
5987 let stdout
= spawn ( true );
5988 assert_eq
!( stdout
, "hello stdout! \n " );
5992 fn close_output_during_drain () {
5993 // Test to close the output during the build phase (drain_the_queue).
5994 // There was a bug where it would hang.
5996 // Server to know when rustc has spawned.
5997 let listener
= std
:: net
:: TcpListener
:: bind ( "127.0.0.1:0" ). unwrap ();
5998 let addr
= listener
. local_addr (). unwrap ();
6000 // Create a wrapper so the test can know when compiling has started.
6001 let rustc_wrapper
= {
6004 . file ( "Cargo.toml" , & basic_manifest ( "compiler" , "1.0.0" ))
6008 use std::process::Command;
6013 // Only wait on the first dependency.
6014 if matches!(env::var(" CARGO_PKG_NAME ").as_deref(), Ok(" dep ")) {
6015 let mut socket = std::net::TcpStream::connect(" __ADDR__ ").unwrap();
6016 // Wait for the test to tell us to start printing.
6018 drop(socket.read_exact(&mut buf));
6020 let mut cmd = Command::new(" rustc ");
6021 for arg in env::args_os().skip(1) {
6024 std::process::exit(cmd.status().unwrap().code().unwrap());
6027 . replace ( "__ADDR__" , & addr
. to_string ()),
6030 p
. cargo ( "build" ). run ();
6034 Package
:: new ( "dep" , "1.0.0" ). publish ();
6047 . file ( "src/lib.rs" , "" )
6050 // Spawn cargo, wait for the first rustc to start, and then close stderr.
6051 let mut cmd
= process (& cargo_exe ())
6054 . env ( "RUSTC" , rustc_wrapper
)
6056 cmd
. stdout ( Stdio
:: piped ()). stderr ( Stdio
:: piped ());
6057 let mut child
= cmd
. spawn (). expect ( "cargo should spawn" );
6058 // Wait for the rustc wrapper to start.
6059 let rustc_conn
= listener
. accept (). unwrap (). 0 ;
6060 // Close stderr to force an error.
6061 drop ( child
. stderr
. take ());
6062 // Tell the wrapper to continue.
6064 match child
. wait () {
6065 Ok ( status
) => assert
!(! status
. success ()),
6066 Err ( e
) => panic
!( "child wait failed: {} " , e
),
6070 use cargo_test_support
:: registry
:: Dependency
;
6073 fn reduced_reproduction_8249 () {
6074 // https://github.com/rust-lang/cargo/issues/8249
6075 Package
:: new ( "a-src" , "0.1.0" ). links ( "a" ). publish ();
6076 Package
:: new ( "a-src" , "0.2.0" ). links ( "a" ). publish ();
6078 Package
:: new ( "b" , "0.1.0" )
6079 . add_dep ( Dependency
:: new ( "a-src" , "0.1" ). optional ( true ))
6081 Package
:: new ( "b" , "0.2.0" )
6082 . add_dep ( Dependency
:: new ( "a-src" , "0.2" ). optional ( true ))
6085 Package
:: new ( "c" , "1.0.0" )
6086 . add_dep (& Dependency
:: new ( "b" , "0.1.0" ))
6098 b = { version = "*", features = ["a-src"] }
6102 . file ( "src/lib.rs" , "" )
6105 p
. cargo ( "generate-lockfile" ). run ();
6106 cargo_util
:: paths
:: append (& p
. root (). join ( "Cargo.toml" ), b
"c = \" * \" " ). unwrap ();
6107 p
. cargo ( "check" ). run ();
6108 p
. cargo ( "check" ). run ();
6112 fn target_directory_backup_exclusion () {
6114 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
6115 . file ( "src/foo.rs" , & main_file ( r
# "" i am foo "" #, &[]))
6118 // Newly created target/ should have CACHEDIR.TAG inside...
6119 p
. cargo ( "build" ). run ();
6120 let cachedir_tag
= p
. build_dir (). join ( "CACHEDIR.TAG" );
6121 assert
!( cachedir_tag
. is_file ());
6122 assert
!( fs
:: read_to_string (& cachedir_tag
)
6124 . starts_with ( "Signature: 8a477f597d28d172789f06886806bc55" ));
6125 // ...but if target/ already exists CACHEDIR.TAG should not be created in it.
6126 fs
:: remove_file (& cachedir_tag
). unwrap ();
6127 p
. cargo ( "build" ). run ();
6128 assert
!(!& cachedir_tag
. is_file ());
6131 #[cargo_test(>=1.64, reason = "--diagnostic-width is stabilized in 1.64" )]
6132 fn simple_terminal_width () {
6144 p
. cargo ( "build -Zterminal-width=20" )
6145 . masquerade_as_nightly_cargo (&[ "terminal-width" ])
6147 . with_stderr_contains ( "3 | ..._: () = 42;" )
6152 fn build_script_o0_default () {
6154 . file ( "src/lib.rs" , "" )
6155 . file ( "build.rs" , "fn main() {} " )
6158 p
. cargo ( "build -v --release" )
6159 . with_stderr_does_not_contain ( "[..]build_script_build[..]opt-level[..]" )
6164 fn build_script_o0_default_even_with_release () {
6177 . file ( "src/lib.rs" , "" )
6178 . file ( "build.rs" , "fn main() {} " )
6181 p
. cargo ( "build -v --release" )
6182 . with_stderr_does_not_contain ( "[..]build_script_build[..]opt-level[..]" )
6187 fn primary_package_env_var () {
6188 // Test that CARGO_PRIMARY_PACKAGE is enabled only for "foo" and not for any dependency.
6190 let is_primary_package
= r
# "
6191 pub fn is_primary_package() -> bool {{
6192 option_env!(" CARGO_PRIMARY_PACKAGE ").is_some()
6196 Package
:: new ( "qux" , "0.1.0" )
6197 . file ( "src/lib.rs" , is_primary_package
)
6200 let baz
= git
:: new ( "baz" , | project
| {
6202 . file ( "Cargo.toml" , & basic_manifest ( "baz" , "0.1.0" ))
6203 . file ( "src/lib.rs" , is_primary_package
)
6216 bar = {{ path = "bar" } }
6217 baz = {{ git = '{} ' }}
6234 fn verify_primary_package() {{
6235 assert!(!bar::is_primary_package());
6236 assert!(!baz::is_primary_package());
6237 assert!(!qux::is_primary_package());
6238 assert!(is_primary_package());
6244 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
6245 . file ( "bar/src/lib.rs" , is_primary_package
)
6248 foo
. cargo ( "test" ). run ();