]>
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" )
1044 . with_stderr ( "[ERROR] no bin target named `bin.rs`" )
1047 p
. cargo ( "build --bin a.rs" )
1051 [ERROR] no bin target named `a.rs`
1053 <tab>Did you mean `a`?" ,
1057 p
. cargo ( "build --example example.rs" )
1059 . with_stderr ( "[ERROR] no example target named `example.rs`" )
1062 p
. cargo ( "build --example a.rs" )
1066 [ERROR] no example target named `a.rs`
1068 <tab>Did you mean `a`?" ,
1074 fn incompatible_dependencies () {
1075 Package
:: new ( "bad" , "0.1.0" ). publish ();
1076 Package
:: new ( "bad" , "1.0.0" ). publish ();
1077 Package
:: new ( "bad" , "1.0.1" ). publish ();
1078 Package
:: new ( "bad" , "1.0.2" ). publish ();
1079 Package
:: new ( "bar" , "0.1.0" ). dep ( "bad" , "0.1.0" ). publish ();
1080 Package
:: new ( "baz" , "0.1.1" ). dep ( "bad" , "=1.0.0" ). publish ();
1081 Package
:: new ( "baz" , "0.1.0" ). dep ( "bad" , "=1.0.0" ). publish ();
1082 Package
:: new ( "qux" , "0.1.2" ). dep ( "bad" , ">=1.0.1" ). publish ();
1083 Package
:: new ( "qux" , "0.1.1" ). dep ( "bad" , ">=1.0.1" ). publish ();
1084 Package
:: new ( "qux" , "0.1.0" ). dep ( "bad" , ">=1.0.1" ). publish ();
1100 . file ( "src/main.rs" , "fn main() {} " )
1105 . with_stderr_contains (
1107 error: failed to select a version for `bad`.
1108 ... required by package `qux v0.1.0`
1109 ... which satisfies dependency `qux = \" ^0.1.0 \" ` of package `foo v0.0.1 ([..])`
1110 versions that meet the requirements `>=1.0.1` are: 1.0.2, 1.0.1
1112 all possible versions conflict with previously selected packages.
1114 previously selected package `bad v1.0.0`
1115 ... which satisfies dependency `bad = \" =1.0.0 \" ` of package `baz v0.1.0`
1116 ... which satisfies dependency `baz = \" ^0.1.0 \" ` of package `foo v0.0.1 ([..])`
1118 failed to select a version for `bad` which could resolve this conflict" ,
1124 fn incompatible_dependencies_with_multi_semver () {
1125 Package
:: new ( "bad" , "1.0.0" ). publish ();
1126 Package
:: new ( "bad" , "1.0.1" ). publish ();
1127 Package
:: new ( "bad" , "2.0.0" ). publish ();
1128 Package
:: new ( "bad" , "2.0.1" ). publish ();
1129 Package
:: new ( "bar" , "0.1.0" ). dep ( "bad" , "=1.0.0" ). publish ();
1130 Package
:: new ( "baz" , "0.1.0" ). dep ( "bad" , ">=2.0.1" ). publish ();
1143 bad = " >=1.0.1, <=2.0.0 "
1146 . file ( "src/main.rs" , "fn main() {} " )
1151 . with_stderr_contains (
1153 error: failed to select a version for `bad`.
1154 ... required by package `foo v0.0.1 ([..])`
1155 versions that meet the requirements `>=1.0.1, <=2.0.0` are: 2.0.0, 1.0.1
1157 all possible versions conflict with previously selected packages.
1159 previously selected package `bad v2.0.1`
1160 ... which satisfies dependency `bad = \" >=2.0.1 \" ` of package `baz v0.1.0`
1161 ... which satisfies dependency `baz = \" ^0.1.0 \" ` of package `foo v0.0.1 ([..])`
1163 previously selected package `bad v1.0.0`
1164 ... which satisfies dependency `bad = \" =1.0.0 \" ` of package `bar v0.1.0`
1165 ... which satisfies dependency `bar = \" ^0.1.0 \" ` of package `foo v0.0.1 ([..])`
1167 failed to select a version for `bad` which could resolve this conflict" ,
1173 fn compile_path_dep_then_change_version () {
1187 . file ( "src/lib.rs" , "" )
1188 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.0.1" ))
1189 . file ( "bar/src/lib.rs" , "" )
1192 p
. cargo ( "build" ). run ();
1194 p
. change_file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.0.2" ));
1196 p
. cargo ( "build" ). run ();
1200 fn ignores_carriage_return_in_lockfile () {
1202 . file ( "src/main.rs" , "mod a; fn main() {} " )
1203 . file ( "src/a.rs" , "" )
1206 p
. cargo ( "build" ). run ();
1208 let lock
= p
. read_lockfile ();
1209 p
. change_file ( "Cargo.lock" , & lock
. replace ( " \n " , " \r\n " ));
1210 p
. cargo ( "build" ). run ();
1214 fn cargo_default_env_metadata_env_var () {
1215 // Ensure that path dep + dylib + env_var get metadata
1216 // (even though path_dep + dylib should not)
1230 . file ( "src/lib.rs" , "// hi" )
1241 crate_type = [" dylib "]
1244 . file ( "bar/src/lib.rs" , "// hello" )
1247 // No metadata on libbar since it's a dylib path dependency
1249 . with_stderr (& format
!(
1251 [COMPILING] bar v0.0.1 ([CWD]/bar)
1252 [RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--crate-type dylib \
1254 -C prefer-dynamic[..]-C debuginfo=2 \
1257 -L dependency=[CWD]/target/debug/deps`
1258 [COMPILING] foo v0.0.1 ([CWD])
1259 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
1260 --emit=[..]link[..]-C debuginfo=2 \
1262 -C extra-filename=[..] \
1264 -L dependency=[CWD]/target/debug/deps \
1265 --extern bar=[CWD]/target/debug/deps/ {prefix} bar {suffix} `
1266 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]" ,
1267 prefix
= env
:: consts
:: DLL_PREFIX
,
1268 suffix
= env
:: consts
:: DLL_SUFFIX
,
1272 p
. cargo ( "clean" ). run ();
1274 // If you set the env-var, then we expect metadata on libbar
1276 . env ( "__CARGO_DEFAULT_LIB_METADATA" , "stable" )
1277 . with_stderr (& format
!(
1279 [COMPILING] bar v0.0.1 ([CWD]/bar)
1280 [RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--crate-type dylib \
1282 -C prefer-dynamic[..]-C debuginfo=2 \
1285 -L dependency=[CWD]/target/debug/deps`
1286 [COMPILING] foo v0.0.1 ([CWD])
1287 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
1288 --emit=[..]link[..]-C debuginfo=2 \
1290 -C extra-filename=[..] \
1292 -L dependency=[CWD]/target/debug/deps \
1293 --extern bar=[CWD]/target/debug/deps/ {prefix} bar-[..] {suffix} `
1294 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1296 prefix
= env
:: consts
:: DLL_PREFIX
,
1297 suffix
= env
:: consts
:: DLL_SUFFIX
,
1303 fn crate_env_vars () {
1310 version = " 0.5.1-alpha.1 "
1311 description = " This is foo "
1312 homepage = " https: //example.com"
1313 repository
= "https://example.com/repo.git"
1314 authors
= [ "wycats@example.com" ]
1315 license
= "MIT OR Apache-2.0"
1316 license
- file
= "license.txt"
1317 rust
- version
= "1.61.0"
1321 path
= "src/main.rs"
1330 static VERSION_MAJOR
: & '
static str = env
!( "CARGO_PKG_VERSION_MAJOR" );
1331 static VERSION_MINOR
: & '
static str = env
!( "CARGO_PKG_VERSION_MINOR" );
1332 static VERSION_PATCH
: & '
static str = env
!( "CARGO_PKG_VERSION_PATCH" );
1333 static VERSION_PRE
: & '
static str = env
!( "CARGO_PKG_VERSION_PRE" );
1334 static VERSION
: & '
static str = env
!( "CARGO_PKG_VERSION" );
1335 static CARGO_MANIFEST_DIR
: & '
static str = env
!( "CARGO_MANIFEST_DIR" );
1336 static PKG_NAME
: & '
static str = env
!( "CARGO_PKG_NAME" );
1337 static HOMEPAGE
: & '
static str = env
!( "CARGO_PKG_HOMEPAGE" );
1338 static REPOSITORY
: & '
static str = env
!( "CARGO_PKG_REPOSITORY" );
1339 static LICENSE
: & '
static str = env
!( "CARGO_PKG_LICENSE" );
1340 static LICENSE_FILE
: & '
static str = env
!( "CARGO_PKG_LICENSE_FILE" );
1341 static DESCRIPTION
: & '
static str = env
!( "CARGO_PKG_DESCRIPTION" );
1342 static RUST_VERSION
: & '
static str = env
!( "CARGO_PKG_RUST_VERSION" );
1343 static BIN_NAME
: & '
static str = env
!( "CARGO_BIN_NAME" );
1344 static CRATE_NAME
: & '
static str = env
!( "CARGO_CRATE_NAME" );
1348 let s
= format
!( " {} - {} - {} @ {} in {} " , VERSION_MAJOR
,
1349 VERSION_MINOR
, VERSION_PATCH
, VERSION_PRE
,
1350 CARGO_MANIFEST_DIR
);
1351 assert_eq
!( s
, foo
:: version ());
1353 assert_eq
!( "foo" , PKG_NAME
);
1354 assert_eq
!( "foo-bar" , BIN_NAME
);
1355 assert_eq
!( "foo_bar" , CRATE_NAME
);
1356 assert_eq
!( "https://example.com" , HOMEPAGE
);
1357 assert_eq
!( "https://example.com/repo.git" , REPOSITORY
);
1358 assert_eq
!( "MIT OR Apache-2.0" , LICENSE
);
1359 assert_eq
!( "license.txt" , LICENSE_FILE
);
1360 assert_eq
!( "This is foo" , DESCRIPTION
);
1361 assert_eq
!( "1.61.0" , RUST_VERSION
);
1362 let s
= format
!( " {} . {} . {} - {} " , VERSION_MAJOR
,
1363 VERSION_MINOR
, VERSION_PATCH
, VERSION_PRE
);
1364 assert_eq
!( s
, VERSION
);
1366 // Verify CARGO_TARGET_TMPDIR isn't set for bins
1367 assert
!( option_env
!( "CARGO_TARGET_TMPDIR" ). is_none ());
1375 use std
:: path
:: PathBuf
;
1377 pub fn version () -> String
{
1378 format
!( " {} - {} - {} @ {} in {} " ,
1379 env
!( "CARGO_PKG_VERSION_MAJOR" ),
1380 env
!( "CARGO_PKG_VERSION_MINOR" ),
1381 env
!( "CARGO_PKG_VERSION_PATCH" ),
1382 env
!( "CARGO_PKG_VERSION_PRE" ),
1383 env
!( "CARGO_MANIFEST_DIR" ))
1386 pub fn check_no_int_test_env () {
1387 env
:: var ( "CARGO_TARGET_DIR" ). unwrap_err ();
1390 pub fn check_tmpdir ( tmp
: Option
<& '
static str >) {
1391 let tmpdir
: PathBuf
= tmp
. unwrap (). into ();
1393 let exe
: PathBuf
= env
:: current_exe (). unwrap (). into ();
1394 let mut expected
: PathBuf
= exe
. parent (). unwrap ()
1398 expected
. push ( "tmp" );
1399 assert_eq
!( tmpdir
, expected
);
1401 // Check that CARGO_TARGET_TMPDIR isn't set for lib code
1402 assert
!( option_env
!( "CARGO_TARGET_TMPDIR" ). is_none ());
1403 env
:: var ( "CARGO_TARGET_TMPDIR" ). unwrap_err ();
1408 // Check that CARGO_TARGET_TMPDIR isn't set for unit tests
1409 assert
!( option_env
!( "CARGO_TARGET_TMPDIR" ). is_none ());
1410 env
:: var ( "CARGO_TARGET_TMPDIR" ). unwrap_err ();
1419 foo
:: check_tmpdir ( option_env
!( "CARGO_TARGET_TMPDIR" ));
1424 let p = if is_nightly() {
1433 fn env ( _
: & mut Bencher
) {
1434 foo
:: check_tmpdir ( option_env
!( "CARGO_TARGET_TMPDIR" ));
1444 p.cargo(" build
- v
").run();
1447 p.process(&p.bin(" foo
- bar
"))
1448 .with_stdout(" 0 - 5 - 1 @ alpha
. 1 in [ CWD
] ")
1452 p.cargo(" test
- v
").run();
1456 p.cargo(" bench
- v
").run();
1461 fn crate_authors_env_vars() {
1468 version
= "0.5.1-alpha.1"
1469 authors
= [ "wycats@example.com" , "neikos@example.com" ]
1477 static AUTHORS
: & '
static str = env
!( "CARGO_PKG_AUTHORS" );
1480 let s
= "wycats@example.com:neikos@example.com" ;
1481 assert_eq
!( AUTHORS
, foo
:: authors ());
1482 println
!( " {} " , AUTHORS
);
1483 assert_eq
!( s
, AUTHORS
);
1490 pub fn authors () -> String
{
1491 format
!( " {} " , env
!( "CARGO_PKG_AUTHORS" ))
1498 p.cargo(" build
- v
").run();
1501 p.process(&p.bin(" foo
"))
1502 .with_stdout(" wycats@example
. com
: neikos@example
. com
")
1506 p.cargo(" test
- v
").run();
1510 fn vv_prints_rustc_env_vars() {
1518 authors
= [ "escape=' \" @example.com" ]
1521 .file(" src
/ main
. rs
", " fn main () {}
")
1524 let mut b = p.cargo(" build
- vv
");
1527 b.with_stderr_contains(
1528 " [ RUNNING
] `
[..] set CARGO_PKG_NAME
= foo
&& [..] rustc
[..] `
"
1529 ).with_stderr_contains(
1530 r#" [ RUNNING
] `
[..] set CARGO_PKG_AUTHORS
= "escape=' \" @example.com" && [..] rustc
[..] `
"#
1533 b.with_stderr_contains(" [ RUNNING
] `
[..] CARGO_PKG_NAME
= foo
[..] rustc
[..] `
")
1534 .with_stderr_contains(
1535 r#" [ RUNNING
] `
[..] CARGO_PKG_AUTHORS
= 'escape
= '
\' '
"@example.com' [..]rustc [..]`" #,
1542 // The tester may already have LD_LIBRARY_PATH=::/foo/bar which leads to a false positive error
1543 fn setenv_for_removing_empty_component ( mut execs
: Execs
) -> Execs
{
1544 let v
= dylib_path_envvar ();
1545 if let Ok ( search_path
) = env
:: var ( v
) {
1546 let new_search_path
=
1547 env
:: join_paths ( env
:: split_paths (& search_path
). filter (| e
| ! e
. as_os_str (). is_empty ()))
1548 . expect ( "join_paths" );
1549 execs
. env ( v
, new_search_path
); // build_command() will override LD_LIBRARY_PATH accordingly
1554 // Regression test for #4277
1556 fn crate_library_path_env_var () {
1563 let search_path = env!(" {} ");
1564 let paths = std::env::split_paths(&search_path).collect::<Vec<_>>();
1565 assert!(!paths.contains(&" ".into()));
1573 setenv_for_removing_empty_component ( p
. cargo ( "run" )). run ();
1576 // Regression test for #4277
1578 fn build_with_fake_libc_not_loading () {
1580 . file ( "src/main.rs" , "fn main() {} " )
1581 . file ( "src/lib.rs" , r
# " " #)
1582 . file ( "libc.so.6" , r
# "" #)
1585 setenv_for_removing_empty_component ( p
. cargo ( "build" )). run ();
1588 // this is testing that src/<pkg-name>.rs still works (for now)
1590 fn many_crate_types_old_style_lib_location () {
1599 authors = [" wycats@example.com "]
1604 crate_type = [" rlib ", " dylib "]
1607 . file ( "src/foo.rs" , "pub fn foo() {} " )
1610 . with_stderr_contains (
1612 [WARNING] path `[..]src/foo.rs` was erroneously implicitly accepted for library `foo`,
1613 please rename the file to `src/lib.rs` or set lib.path in Cargo.toml" ,
1617 assert
!( p
. root (). join ( "target/debug/libfoo.rlib" ). is_file ());
1618 let fname
= format
!( " {} foo {} " , env
:: consts
:: DLL_PREFIX
, env
:: consts
:: DLL_SUFFIX
);
1619 assert
!( p
. root (). join ( "target/debug" ). join (& fname
). is_file ());
1623 fn many_crate_types_correct () {
1632 authors = [" wycats@example.com "]
1637 crate_type = [" rlib ", " dylib "]
1640 . file ( "src/lib.rs" , "pub fn foo() {} " )
1642 p
. cargo ( "build" ). run ();
1644 assert
!( p
. root (). join ( "target/debug/libfoo.rlib" ). is_file ());
1645 let fname
= format
!( " {} foo {} " , env
:: consts
:: DLL_PREFIX
, env
:: consts
:: DLL_SUFFIX
);
1646 assert
!( p
. root (). join ( "target/debug" ). join (& fname
). is_file ());
1650 fn set_both_dylib_and_cdylib_crate_types () {
1659 authors = [" wycats@example.com "]
1664 crate_type = [" cdylib ", " dylib "]
1667 . file ( "src/lib.rs" , "pub fn foo() {} " )
1673 error: failed to parse manifest at `[..]`
1676 library `foo` cannot set the crate type of both `dylib` and `cdylib`
1683 fn dev_dependencies_conflicting_warning () {
1699 . file ( "src/lib.rs" , "" )
1708 . file ( "a/src/lib.rs" , "" )
1711 . with_stderr_contains (
1712 "[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the `foo` package. \n
1713 `dev_dependencies` is ignored and not recommended for use in the future"
1719 fn build_dependencies_conflicting_warning () {
1729 [build-dependencies]
1731 [build_dependencies]
1735 . file ( "src/lib.rs" , "" )
1744 . file ( "a/src/lib.rs" , "" )
1747 . with_stderr_contains (
1748 "[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the `foo` package. \n
1749 `build_dependencies` is ignored and not recommended for use in the future"
1755 fn lib_crate_types_conflicting_warning () {
1763 authors = [" wycats@example.com "]
1767 crate-type = [" rlib ", " dylib "]
1768 crate_type = [" staticlib ", " dylib "]
1771 . file ( "src/lib.rs" , "pub fn foo() {} " )
1774 . with_stderr_contains (
1775 "[WARNING] conflicting between `crate-type` and `crate_type` in the `foo` library target. \n
1776 `crate_type` is ignored and not recommended for use in the future" ,
1782 fn examples_crate_types_conflicting_warning () {
1790 authors = [" wycats@example.com "]
1794 path = " examples/ex.rs "
1795 crate-type = [" rlib ", " dylib "]
1796 crate_type = [" proc_macro "]
1799 path = " examples/ex-goodbye.rs "
1800 crate-type = [" rlib ", " dylib "]
1801 crate_type = [" rlib ", " staticlib "]
1804 . file ( "src/lib.rs" , "" )
1808 fn main() { println!("ex"); }
1812 "examples/ex-goodbye.rs" ,
1814 fn main() { println!("goodbye"); }
1819 . with_stderr_contains (
1821 [WARNING] conflicting between `crate-type` and `crate_type` in the `ex` example target. \n
1822 `crate_type` is ignored and not recommended for use in the future
1823 [WARNING] conflicting between `crate-type` and `crate_type` in the `goodbye` example target. \n
1824 `crate_type` is ignored and not recommended for use in the future" ,
1830 fn self_dependency () {
1847 path = " src/test.rs "
1850 . file ( "src/test.rs" , "fn main() {} " )
1856 [ERROR] cyclic package dependency: package `test v0.0.0 ([CWD])` depends on itself. Cycle:
1857 package `test v0.0.0 ([CWD])`
1858 ... which satisfies path dependency `test` of package `test v0.0.0 ([..])`" ,
1864 /// Make sure broken and loop symlinks don't break the build
1866 /// This test requires you to be able to make symlinks.
1867 /// For windows, this may require you to enable developer mode.
1868 fn ignore_broken_symlinks () {
1869 if ! symlink_supported () {
1874 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
1875 . file ( "src/foo.rs" , & main_file ( r
# "" i am foo "" #, &[]))
1876 . symlink ( "Notafile" , "bar" )
1877 // To hit the symlink directory, we need a build script
1878 // to trigger a full scan of package files.
1879 . file ( "build.rs" , & main_file ( r
# "" build script "" #, &[]))
1880 . symlink_dir ( "a/b" , "a/b/c/d/foo" )
1884 . with_stderr_contains (
1885 "[WARNING] File system loop found: [..]/a/b/c/d/foo points to an ancestor [..]/a/b" ,
1888 assert
!( p
. bin ( "foo" ). is_file ());
1890 p
. process (& p
. bin ( "foo" )). with_stdout ( "i am foo \n " ). run ();
1894 fn missing_lib_and_bin () {
1895 let p
= project (). build ();
1900 [ERROR] failed to parse manifest at `[..]Cargo.toml`
1903 no targets specified in the manifest
1904 either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present \n " ,
1925 . file ( "src/main.rs" , "fn main() {} " )
1927 p
. cargo ( "build -v --release" )
1930 [COMPILING] test v0.0.0 ([CWD])
1931 [RUNNING] `rustc --crate-name test src/main.rs [..]--crate-type bin \
1936 [FINISHED] release [optimized] target(s) in [..]
1943 fn verbose_build () {
1944 let p
= project (). file ( "src/lib.rs" , "" ). build ();
1948 [COMPILING] foo v0.0.1 ([CWD])
1949 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
1950 --emit=[..]link[..]-C debuginfo=2 \
1953 -L dependency=[CWD]/target/debug/deps`
1954 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1961 fn verbose_release_build () {
1962 let p
= project (). file ( "src/lib.rs" , "" ). build ();
1963 p
. cargo ( "build -v --release" )
1966 [COMPILING] foo v0.0.1 ([CWD])
1967 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
1968 --emit=[..]link[..] \
1972 -L dependency=[CWD]/target/release/deps`
1973 [FINISHED] release [optimized] target(s) in [..]
1980 fn verbose_release_build_short () {
1981 let p
= project (). file ( "src/lib.rs" , "" ). build ();
1982 p
. cargo ( "build -v -r" )
1985 [COMPILING] foo v0.0.1 ([CWD])
1986 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
1987 --emit=[..]link[..] \
1991 -L dependency=[CWD]/target/release/deps`
1992 [FINISHED] release [optimized] target(s) in [..]
1999 fn verbose_release_build_deps () {
2014 . file ( "src/lib.rs" , "" )
2026 crate_type = [" dylib ", " rlib "]
2029 . file ( "foo/src/lib.rs" , "" )
2031 p
. cargo ( "build -v --release" )
2032 . with_stderr (& format
!(
2034 [COMPILING] foo v0.0.0 ([CWD]/foo)
2035 [RUNNING] `rustc --crate-name foo foo/src/lib.rs [..] \
2036 --crate-type dylib --crate-type rlib \
2038 -C prefer-dynamic[..] \
2042 -L dependency=[CWD]/target/release/deps`
2043 [COMPILING] test v0.0.0 ([CWD])
2044 [RUNNING] `rustc --crate-name test src/lib.rs [..]--crate-type lib \
2045 --emit=[..]link[..] \
2049 -L dependency=[CWD]/target/release/deps \
2050 --extern foo=[CWD]/target/release/deps/ {prefix} foo {suffix} \
2051 --extern foo=[CWD]/target/release/deps/libfoo.rlib`
2052 [FINISHED] release [optimized] target(s) in [..]
2054 prefix
= env
:: consts
:: DLL_PREFIX
,
2055 suffix
= env
:: consts
:: DLL_SUFFIX
2061 fn explicit_examples () {
2077 path = " examples/ex-hello.rs "
2081 path = " examples/ex-goodbye.rs "
2087 pub fn get_hello() -> &'static str { "Hello" }
2088 pub fn get_goodbye() -> &'static str { "Goodbye" }
2089 pub fn get_world() -> &'static str { "World" }
2093 "examples/ex-hello.rs" ,
2096 fn main() { println!("{} , {} !" , foo::get_hello(), foo::get_world()); }
2100 " examples
/ ex
- goodbye
. rs
",
2103 fn main () { println!("{}
, {}
! ", foo::get_goodbye(), foo::get_world()); }
2108 p
. cargo ( "build --examples" ). run ();
2109 p
. process (& p
. bin ( "examples/hello" ))
2110 . with_stdout ( "Hello, World! \n " )
2112 p
. process (& p
. bin ( "examples/goodbye" ))
2113 . with_stdout ( "Goodbye, World! \n " )
2118 fn non_existing_test () {
2135 . file ( "src/lib.rs" , "" )
2138 p
. cargo ( "build --tests -v" )
2142 [ERROR] failed to parse manifest at `[..]`
2145 can't find `hello` test at `tests/hello.rs` or `tests/hello/main.rs`. \
2146 Please specify test.path if you want to use a non-default path." ,
2152 fn non_existing_example () {
2169 . file ( "src/lib.rs" , "" )
2172 p
. cargo ( "build --examples -v" )
2176 [ERROR] failed to parse manifest at `[..]`
2179 can't find `hello` example at `examples/hello.rs` or `examples/hello/main.rs`. \
2180 Please specify example.path if you want to use a non-default path." ,
2186 fn non_existing_benchmark () {
2203 . file ( "src/lib.rs" , "" )
2206 p
. cargo ( "build --benches -v" )
2210 [ERROR] failed to parse manifest at `[..]`
2213 can't find `hello` bench at `benches/hello.rs` or `benches/hello/main.rs`. \
2214 Please specify bench.path if you want to use a non-default path." ,
2220 fn non_existing_binary () {
2222 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
2223 . file ( "src/lib.rs" , "" )
2224 . file ( "src/bin/ehlo.rs" , "" )
2231 [ERROR] failed to parse manifest at `[..]`
2234 can't find `foo` bin at `src/bin/foo.rs` or `src/bin/foo/main.rs`. \
2235 Please specify bin.path if you want to use a non-default path." ,
2241 fn commonly_wrong_path_of_test () {
2258 . file ( "src/lib.rs" , "" )
2259 . file ( "test/foo.rs" , "" )
2262 p
. cargo ( "build --tests -v" )
2266 [ERROR] failed to parse manifest at `[..]`
2269 can't find `foo` test at default paths, but found a file at `test/foo.rs`.
2270 Perhaps rename the file to `tests/foo.rs` for target auto-discovery, \
2271 or specify test.path if you want to use a non-default path." ,
2277 fn commonly_wrong_path_of_example () {
2294 . file ( "src/lib.rs" , "" )
2295 . file ( "example/foo.rs" , "" )
2298 p
. cargo ( "build --examples -v" )
2302 [ERROR] failed to parse manifest at `[..]`
2305 can't find `foo` example at default paths, but found a file at `example/foo.rs`.
2306 Perhaps rename the file to `examples/foo.rs` for target auto-discovery, \
2307 or specify example.path if you want to use a non-default path." ,
2313 fn commonly_wrong_path_of_benchmark () {
2330 . file ( "src/lib.rs" , "" )
2331 . file ( "bench/foo.rs" , "" )
2334 p
. cargo ( "build --benches -v" )
2338 [ERROR] failed to parse manifest at `[..]`
2341 can't find `foo` bench at default paths, but found a file at `bench/foo.rs`.
2342 Perhaps rename the file to `benches/foo.rs` for target auto-discovery, \
2343 or specify bench.path if you want to use a non-default path." ,
2349 fn commonly_wrong_path_binary () {
2351 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
2352 . file ( "src/lib.rs" , "" )
2353 . file ( "src/bins/foo.rs" , "" )
2360 [ERROR] failed to parse manifest at `[..]`
2363 can't find `foo` bin at default paths, but found a file at `src/bins/foo.rs`.
2364 Perhaps rename the file to `src/bin/foo.rs` for target auto-discovery, \
2365 or specify bin.path if you want to use a non-default path." ,
2371 fn commonly_wrong_path_subdir_binary () {
2373 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
2374 . file ( "src/lib.rs" , "" )
2375 . file ( "src/bins/foo/main.rs" , "" )
2382 [ERROR] failed to parse manifest at `[..]`
2385 can't find `foo` bin at default paths, but found a file at `src/bins/foo/main.rs`.
2386 Perhaps rename the file to `src/bin/foo/main.rs` for target auto-discovery, \
2387 or specify bin.path if you want to use a non-default path." ,
2393 fn found_multiple_target_files () {
2395 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
2396 . file ( "src/lib.rs" , "" )
2397 . file ( "src/bin/foo.rs" , "" )
2398 . file ( "src/bin/foo/main.rs" , "" )
2403 // Don't assert the inferred paths since the order is non-deterministic.
2406 [ERROR] failed to parse manifest at `[..]`
2409 cannot infer path for `foo` bin
2410 Cargo doesn't know which to use because multiple target files found \
2411 at `src/bin/foo[..].rs` and `src/bin/foo[..].rs`." ,
2417 fn legacy_binary_paths_warnings () {
2431 . file ( "src/lib.rs" , "" )
2432 . file ( "src/main.rs" , "fn main() {} " )
2436 . with_stderr_contains (
2438 [WARNING] path `[..]src/main.rs` was erroneously implicitly accepted for binary `bar`,
2439 please set bin.path in Cargo.toml" ,
2456 . file ( "src/lib.rs" , "" )
2457 . file ( "src/bin/main.rs" , "fn main() {} " )
2461 . with_stderr_contains (
2463 [WARNING] path `[..]src/bin/main.rs` was erroneously implicitly accepted for binary `bar`,
2464 please set bin.path in Cargo.toml" ,
2481 . file ( "src/bar.rs" , "fn main() {} " )
2485 . with_stderr_contains (
2487 [WARNING] path `[..]src/bar.rs` was erroneously implicitly accepted for binary `bar`,
2488 please set bin.path in Cargo.toml" ,
2494 fn implicit_examples () {
2499 pub fn get_hello() -> &'static str { "Hello" }
2500 pub fn get_goodbye() -> &'static str { "Goodbye" }
2501 pub fn get_world() -> &'static str { "World" }
2505 "examples/hello.rs" ,
2509 println!(" {}, {}! ", foo::get_hello(), foo::get_world());
2514 "examples/goodbye.rs" ,
2518 println!(" {}, {}! ", foo::get_goodbye(), foo::get_world());
2524 p
. cargo ( "build --examples" ). run ();
2525 p
. process (& p
. bin ( "examples/hello" ))
2526 . with_stdout ( "Hello, World! \n " )
2528 p
. process (& p
. bin ( "examples/goodbye" ))
2529 . with_stdout ( "Goodbye, World! \n " )
2534 fn standard_build_no_ndebug () {
2536 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
2541 if cfg!(debug_assertions) {
2551 p
. cargo ( "build" ). run ();
2552 p
. process (& p
. bin ( "foo" )). with_stdout ( "slow \n " ). run ();
2556 fn release_build_ndebug () {
2558 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
2563 if cfg!(debug_assertions) {
2573 p
. cargo ( "build --release" ). run ();
2574 p
. process (& p
. release_bin ( "foo" )). with_stdout ( "fast \n " ). run ();
2578 fn inferred_main_bin () {
2579 let p
= project (). file ( "src/main.rs" , "fn main() {} " ). build ();
2581 p
. cargo ( "build" ). run ();
2582 p
. process (& p
. bin ( "foo" )). run ();
2586 fn deletion_causes_failure () {
2600 . file ( "src/main.rs" , "extern crate bar; fn main() {} " )
2601 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.0.1" ))
2602 . file ( "bar/src/lib.rs" , "" )
2605 p
. cargo ( "build" ). run ();
2606 p
. change_file ( "Cargo.toml" , & basic_manifest ( "foo" , "0.0.1" ));
2609 . with_stderr_contains ( "[..]can't find crate for `bar`" )
2614 fn bad_cargo_toml_in_target_dir () {
2616 . file ( "src/main.rs" , "fn main() {} " )
2617 . file ( "target/Cargo.toml" , "bad-toml" )
2620 p
. cargo ( "build" ). run ();
2621 p
. process (& p
. bin ( "foo" )). run ();
2625 fn lib_with_standard_name () {
2627 . file ( "Cargo.toml" , & basic_manifest ( "syntax" , "0.0.1" ))
2628 . file ( "src/lib.rs" , "pub fn foo() {} " )
2631 "extern crate syntax; fn main() { syntax::foo() } " ,
2638 [COMPILING] syntax v0.0.1 ([CWD])
2639 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2646 fn simple_staticlib () {
2658 crate-type = [" staticlib "]
2661 . file ( "src/lib.rs" , "pub fn foo() {} " )
2664 // env var is a test for #1381
2665 p
. cargo ( "build" ). env ( "CARGO_LOG" , "nekoneko=trace" ). run ();
2669 fn staticlib_rlib_and_bin () {
2681 crate-type = [" staticlib ", " rlib "]
2684 . file ( "src/lib.rs" , "pub fn foo() {} " )
2685 . file ( "src/main.rs" , "extern crate foo; fn main() { foo::foo(); } " )
2688 p
. cargo ( "build -v" ). run ();
2692 fn opt_out_of_bin () {
2705 . file ( "src/lib.rs" , "" )
2706 . file ( "src/main.rs" , "bad syntax" )
2708 p
. cargo ( "build" ). run ();
2727 . file ( "src/bar.rs" , "" )
2729 p
. cargo ( "build" ). run ();
2733 fn freshness_ignores_excluded () {
2743 exclude = [" src/b*.rs "]
2746 . file ( "build.rs" , "fn main() {} " )
2747 . file ( "src/lib.rs" , "pub fn bar() -> i32 { 1 } " )
2749 foo
. root (). move_into_the_past ();
2754 [COMPILING] foo v0.0.0 ([CWD])
2755 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2760 // Smoke test to make sure it doesn't compile again
2761 println
!( "first pass" );
2762 foo
. cargo ( "build" ). with_stdout ( "" ). run ();
2764 // Modify an ignored file and make sure we don't rebuild
2765 println
!( "second pass" );
2766 foo
. change_file ( "src/bar.rs" , "" );
2767 foo
. cargo ( "build" ). with_stdout ( "" ). run ();
2771 fn rebuild_preserves_out_dir () {
2788 use std::path::Path;
2791 let path = Path::new(&env::var(" OUT_DIR ").unwrap()).join(" foo ");
2792 if env::var_os(" FIRST ").is_some() {
2793 File::create(&path).unwrap();
2795 File::create(&path).unwrap();
2800 . file ( "src/lib.rs" , "pub fn bar() -> i32 { 1 } " )
2802 foo
. root (). move_into_the_past ();
2808 [COMPILING] foo v0.0.0 ([CWD])
2809 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2814 foo
. change_file ( "src/bar.rs" , "" );
2818 [COMPILING] foo v0.0.0 ([CWD])
2819 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2840 . file ( "src/lib.rs" , "pub fn bar() -> i32 { 1 } " )
2841 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.0.0" ))
2842 . file ( "bar/src/main.rs" , "" )
2844 foo
. cargo ( "build" ). run ();
2848 fn recompile_space_in_name () {
2860 path = " src/my lib.rs "
2863 . file ( "src/my lib.rs" , "" )
2865 foo
. cargo ( "build" ). run ();
2866 foo
. root (). move_into_the_past ();
2867 foo
. cargo ( "build" ). with_stdout ( "" ). run ();
2872 fn credentials_is_unreadable () {
2873 use cargo_test_support
:: paths
:: home
;
2874 use std
:: os
:: unix
:: prelude
::*;
2876 . file ( "Cargo.toml" , & basic_manifest ( "foo" , "0.1.0" ))
2877 . file ( "src/lib.rs" , "" )
2880 let credentials
= home (). join ( ".cargo/credentials" );
2881 t
!( fs
:: create_dir_all ( credentials
. parent (). unwrap ()));
2889 let stat
= fs
:: metadata ( credentials
. as_path ()). unwrap ();
2890 let mut perms
= stat
. permissions ();
2891 perms
. set_mode ( 0o000 );
2892 fs
:: set_permissions ( credentials
, perms
). unwrap ();
2894 p
. cargo ( "build" ). run ();
2899 fn ignore_bad_directories () {
2900 use std
:: os
:: unix
:: prelude
::*;
2902 . file ( "Cargo.toml" , & basic_manifest ( "foo" , "0.0.0" ))
2903 . file ( "src/lib.rs" , "" )
2905 let dir
= foo
. root (). join ( "tmp" );
2906 fs
:: create_dir (& dir
). unwrap ();
2907 let stat
= fs
:: metadata (& dir
). unwrap ();
2908 let mut perms
= stat
. permissions ();
2909 perms
. set_mode ( 0o644 );
2910 fs
:: set_permissions (& dir
, perms
. clone ()). unwrap ();
2911 foo
. cargo ( "build" ). run ();
2912 perms
. set_mode ( 0o755 );
2913 fs
:: set_permissions (& dir
, perms
). unwrap ();
2917 fn bad_cargo_config () {
2919 . file ( "Cargo.toml" , & basic_manifest ( "foo" , "0.0.0" ))
2920 . file ( "src/lib.rs" , "" )
2921 . file ( ".cargo/config" , "this is not valid toml" )
2923 foo
. cargo ( "build -v" )
2927 [ERROR] could not load Cargo configuration
2930 could not parse TOML configuration in `[..]`
2933 could not parse input as TOML
2936 TOML parse error at line 1, column 6
2938 1 | this is not valid toml
2948 fn cargo_platform_specific_dependency () {
2949 let host
= rustc_host ();
2958 authors = [" wycats@example.com "]
2961 [target. {host} .dependencies]
2962 dep = {{ path = "dep" } }
2963 [target. {host} .build-dependencies]
2964 build = {{ path = "build" } }
2965 [target. {host} .dev-dependencies]
2966 dev = {{ path = "dev" } }
2971 . file ( "src/main.rs" , "extern crate dep; fn main() { dep::dep() } " )
2974 "extern crate dev; #[test] fn foo() { dev::dev() } " ,
2978 "extern crate build; fn main() { build::build(); } " ,
2980 . file ( "dep/Cargo.toml" , & basic_manifest ( "dep" , "0.5.0" ))
2981 . file ( "dep/src/lib.rs" , "pub fn dep() {} " )
2982 . file ( "build/Cargo.toml" , & basic_manifest ( "build" , "0.5.0" ))
2983 . file ( "build/src/lib.rs" , "pub fn build() {} " )
2984 . file ( "dev/Cargo.toml" , & basic_manifest ( "dev" , "0.5.0" ))
2985 . file ( "dev/src/lib.rs" , "pub fn dev() {} " )
2988 p
. cargo ( "build" ). run ();
2990 assert
!( p
. bin ( "foo" ). is_file ());
2991 p
. cargo ( "test" ). run ();
2995 fn cargo_platform_specific_dependency_build_dependencies_conflicting_warning () {
2996 let host
= rustc_host ();
3005 authors = [" wycats@example.com "]
3008 [target. {host} .build-dependencies]
3009 build = {{ path = "build" } }
3010 [target. {host} .build_dependencies]
3011 build = {{ path = "build" } }
3016 . file ( "src/main.rs" , "fn main() { } " )
3019 "extern crate build; fn main() { build::build(); } " ,
3021 . file ( "build/Cargo.toml" , & basic_manifest ( "build" , "0.5.0" ))
3022 . file ( "build/src/lib.rs" , "pub fn build() {} " )
3026 . with_stderr_contains (
3027 format
!( "[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the ` {} ` platform target. \n
3028 `build_dependencies` is ignored and not recommended for use in the future" , host
)
3032 assert
!( p
. bin ( "foo" ). is_file ());
3036 fn cargo_platform_specific_dependency_dev_dependencies_conflicting_warning () {
3037 let host
= rustc_host ();
3046 authors = [" wycats@example.com "]
3048 [target. {host} .dev-dependencies]
3049 dev = {{ path = "dev" } }
3050 [target. {host} .dev_dependencies]
3051 dev = {{ path = "dev" } }
3056 . file ( "src/main.rs" , "fn main() { } " )
3059 "extern crate dev; #[test] fn foo() { dev::dev() } " ,
3061 . file ( "dev/Cargo.toml" , & basic_manifest ( "dev" , "0.5.0" ))
3062 . file ( "dev/src/lib.rs" , "pub fn dev() {} " )
3066 . with_stderr_contains (
3067 format
!( "[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the ` {} ` platform target. \n
3068 `dev_dependencies` is ignored and not recommended for use in the future" , host
)
3072 assert
!( p
. bin ( "foo" ). is_file ());
3073 p
. cargo ( "test" ). run ();
3077 fn bad_platform_specific_dependency () {
3086 authors = [" wycats@example.com "]
3088 [target.wrong-target.dependencies.bar]
3092 . file ( "src/main.rs" , & main_file ( r
# "" {} ", bar::gimme()" #, &[ "bar" ]))
3093 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.5.0" ))
3096 r
# "pub fn gimme() -> String { format!("") } " #,
3102 . with_stderr_contains ( "[..]can't find crate for `bar`" )
3107 fn cargo_platform_specific_dependency_wrong_platform () {
3116 authors = [" wycats@example.com "]
3118 [target.non-existing-triplet.dependencies.bar]
3122 . file ( "src/main.rs" , "fn main() {} " )
3123 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.5.0" ))
3126 "invalid rust file, should not be compiled" ,
3130 p
. cargo ( "build" ). run ();
3132 assert
!( p
. bin ( "foo" ). is_file ());
3133 p
. process (& p
. bin ( "foo" )). run ();
3135 let lockfile
= p
. read_lockfile ();
3136 assert
!( lockfile
. contains ( "bar" ));
3140 fn example_as_lib () {
3152 crate-type = [" lib "]
3155 . file ( "src/lib.rs" , "" )
3156 . file ( "examples/ex.rs" , "" )
3159 p
. cargo ( "build --example=ex" ). run ();
3160 assert
!( p
. example_lib ( "ex" , "lib" ). is_file ());
3164 fn example_as_rlib () {
3176 crate-type = [" rlib "]
3179 . file ( "src/lib.rs" , "" )
3180 . file ( "examples/ex.rs" , "" )
3183 p
. cargo ( "build --example=ex" ). run ();
3184 assert
!( p
. example_lib ( "ex" , "rlib" ). is_file ());
3188 fn example_as_dylib () {
3200 crate-type = [" dylib "]
3203 . file ( "src/lib.rs" , "" )
3204 . file ( "examples/ex.rs" , "" )
3207 p
. cargo ( "build --example=ex" ). run ();
3208 assert
!( p
. example_lib ( "ex" , "dylib" ). is_file ());
3212 fn example_as_proc_macro () {
3224 crate-type = [" proc-macro "]
3227 . file ( "src/lib.rs" , "" )
3231 extern crate proc_macro;
3232 use proc_macro::TokenStream;
3235 pub fn eat(_item: TokenStream) -> TokenStream {
3242 p
. cargo ( "build --example=ex" ). run ();
3243 assert
!( p
. example_lib ( "ex" , "proc-macro" ). is_file ());
3247 fn example_bin_same_name () {
3249 . file ( "src/main.rs" , "fn main() {} " )
3250 . file ( "examples/foo.rs" , "fn main() {} " )
3253 p
. cargo ( "build --examples" ). run ();
3255 assert
!(! p
. bin ( "foo" ). is_file ());
3256 // We expect a file of the form bin/foo-{metadata_hash}
3257 assert
!( p
. bin ( "examples/foo" ). is_file ());
3259 p
. cargo ( "build --examples" ). run ();
3261 assert
!(! p
. bin ( "foo" ). is_file ());
3262 // We expect a file of the form bin/foo-{metadata_hash}
3263 assert
!( p
. bin ( "examples/foo" ). is_file ());
3267 fn compile_then_delete () {
3268 let p
= project (). file ( "src/main.rs" , "fn main() {} " ). build ();
3270 p
. cargo ( "run -v" ). run ();
3271 assert
!( p
. bin ( "foo" ). is_file ());
3273 // On windows unlinking immediately after running often fails, so sleep
3276 fs
:: remove_file (& p
. bin ( "foo" )). unwrap ();
3277 p
. cargo ( "run -v" ). run ();
3281 fn transitive_dependencies_not_available () {
3291 [dependencies.aaaaa]
3297 "extern crate bbbbb; extern crate aaaaa; fn main() {} " ,
3307 [dependencies.bbbbb]
3311 . file ( "a/src/lib.rs" , "extern crate bbbbb;" )
3312 . file ( "b/Cargo.toml" , & basic_manifest ( "bbbbb" , "0.0.1" ))
3313 . file ( "b/src/lib.rs" , "" )
3318 . with_stderr_contains ( "[..] can't find crate for `bbbbb`[..]" )
3323 fn cyclic_deps_rejected () {
3337 . file ( "src/lib.rs" , "" )
3350 . file ( "a/src/lib.rs" , "" )
3356 "[ERROR] cyclic package dependency: package `a v0.0.1 ([CWD]/a)` depends on itself. Cycle:
3357 package `a v0.0.1 ([CWD]/a)`
3358 ... which satisfies path dependency `a` of package `foo v0.0.1 ([CWD])`
3359 ... which satisfies path dependency `foo` of package `a v0.0.1 ([..])`" ,
3364 fn predictable_filenames () {
3376 crate-type = [" dylib ", " rlib "]
3379 . file ( "src/lib.rs" , "" )
3382 p
. cargo ( "build -v" ). run ();
3383 assert
!( p
. root (). join ( "target/debug/libfoo.rlib" ). is_file ());
3384 let dylib_name
= format
!( " {} foo {} " , env
:: consts
:: DLL_PREFIX
, env
:: consts
:: DLL_SUFFIX
);
3385 assert
!( p
. root (). join ( "target/debug" ). join ( dylib_name
). is_file ());
3389 fn dashes_to_underscores () {
3391 . file ( "Cargo.toml" , & basic_manifest ( "foo-bar" , "0.0.1" ))
3392 . file ( "src/lib.rs" , "" )
3393 . file ( "src/main.rs" , "extern crate foo_bar; fn main() {} " )
3396 p
. cargo ( "build -v" ). run ();
3397 assert
!( p
. bin ( "foo-bar" ). is_file ());
3401 fn dashes_in_crate_name_bad () {
3415 . file ( "src/lib.rs" , "" )
3416 . file ( "src/main.rs" , "extern crate foo_bar; fn main() {} " )
3423 [ERROR] failed to parse manifest at `[..]/foo/Cargo.toml`
3426 library target names cannot contain hyphens: foo-bar
3433 fn rustc_env_var () {
3434 let p
= project (). file ( "src/lib.rs" , "" ). build ();
3437 . env ( "RUSTC" , "rustc-that-does-not-exist" )
3441 [ERROR] could not execute process `rustc-that-does-not-exist -vV` ([..])
3448 assert
!(! p
. bin ( "a" ). is_file ());
3454 . file ( "src/lib.rs" , "" )
3455 . file ( "src/bin/a.rs" , "fn main() {} " )
3456 . file ( "src/bin/b.rs" , "fn main() {} " )
3457 . file ( "examples/a.rs" , "fn main() {} " )
3458 . file ( "examples/b.rs" , "fn main() {} " )
3461 p
. cargo ( "build --lib" ). run ();
3462 assert
!(! p
. bin ( "a" ). is_file ());
3464 p
. cargo ( "build --bin=a --example=a" ). run ();
3465 assert
!( p
. bin ( "a" ). is_file ());
3466 assert
!(! p
. bin ( "b" ). is_file ());
3467 assert
!( p
. bin ( "examples/a" ). is_file ());
3468 assert
!(! p
. bin ( "examples/b" ). is_file ());
3472 fn filtering_implicit_bins () {
3474 . file ( "src/lib.rs" , "" )
3475 . file ( "src/bin/a.rs" , "fn main() {} " )
3476 . file ( "src/bin/b.rs" , "fn main() {} " )
3477 . file ( "examples/a.rs" , "fn main() {} " )
3478 . file ( "examples/b.rs" , "fn main() {} " )
3481 p
. cargo ( "build --bins" ). run ();
3482 assert
!( p
. bin ( "a" ). is_file ());
3483 assert
!( p
. bin ( "b" ). is_file ());
3484 assert
!(! p
. bin ( "examples/a" ). is_file ());
3485 assert
!(! p
. bin ( "examples/b" ). is_file ());
3489 fn filtering_implicit_examples () {
3491 . file ( "src/lib.rs" , "" )
3492 . file ( "src/bin/a.rs" , "fn main() {} " )
3493 . file ( "src/bin/b.rs" , "fn main() {} " )
3494 . file ( "examples/a.rs" , "fn main() {} " )
3495 . file ( "examples/b.rs" , "fn main() {} " )
3498 p
. cargo ( "build --examples" ). run ();
3499 assert
!(! p
. bin ( "a" ). is_file ());
3500 assert
!(! p
. bin ( "b" ). is_file ());
3501 assert
!( p
. bin ( "examples/a" ). is_file ());
3502 assert
!( p
. bin ( "examples/b" ). is_file ());
3506 fn ignore_dotfile () {
3508 . file ( "src/bin/.a.rs" , "" )
3509 . file ( "src/bin/a.rs" , "fn main() {} " )
3512 p
. cargo ( "build" ). run ();
3516 fn ignore_dotdirs () {
3518 . file ( "src/bin/a.rs" , "fn main() {} " )
3519 . file ( ".git/Cargo.toml" , "" )
3520 . file ( ".pc/dummy-fix.patch/Cargo.toml" , "" )
3523 p
. cargo ( "build" ). run ();
3528 let p
= ProjectBuilder
:: new ( root (). join ( ".foo" ))
3529 . file ( "src/bin/a.rs" , "fn main() {} " )
3531 p
. cargo ( "build" ). run ();
3535 fn custom_target_dir_env () {
3536 let p
= project (). file ( "src/main.rs" , "fn main() {} " ). build ();
3538 let exe_name
= format
!( "foo {} " , env
:: consts
:: EXE_SUFFIX
);
3540 p
. cargo ( "build" ). env ( "CARGO_TARGET_DIR" , "foo/target" ). run ();
3541 assert
!( p
. root (). join ( "foo/target/debug" ). join (& exe_name
). is_file ());
3542 assert
!(! p
. root (). join ( "target/debug" ). join (& exe_name
). is_file ());
3544 p
. cargo ( "build" ). run ();
3545 assert
!( p
. root (). join ( "foo/target/debug" ). join (& exe_name
). is_file ());
3546 assert
!( p
. root (). join ( "target/debug" ). join (& exe_name
). is_file ());
3549 . env ( "CARGO_BUILD_TARGET_DIR" , "foo2/target" )
3551 assert
!( p
. root (). join ( "foo2/target/debug" ). join (& exe_name
). is_file ());
3557 target-dir = " foo/target "
3560 p
. cargo ( "build" ). env ( "CARGO_TARGET_DIR" , "bar/target" ). run ();
3561 assert
!( p
. root (). join ( "bar/target/debug" ). join (& exe_name
). is_file ());
3562 assert
!( p
. root (). join ( "foo/target/debug" ). join (& exe_name
). is_file ());
3563 assert
!( p
. root (). join ( "target/debug" ). join (& exe_name
). is_file ());
3567 fn custom_target_dir_line_parameter () {
3568 let p
= project (). file ( "src/main.rs" , "fn main() {} " ). build ();
3570 let exe_name
= format
!( "foo {} " , env
:: consts
:: EXE_SUFFIX
);
3572 p
. cargo ( "build --target-dir foo/target" ). run ();
3573 assert
!( p
. root (). join ( "foo/target/debug" ). join (& exe_name
). is_file ());
3574 assert
!(! p
. root (). join ( "target/debug" ). join (& exe_name
). is_file ());
3576 p
. cargo ( "build" ). run ();
3577 assert
!( p
. root (). join ( "foo/target/debug" ). join (& exe_name
). is_file ());
3578 assert
!( p
. root (). join ( "target/debug" ). join (& exe_name
). is_file ());
3584 target-dir = " foo/target "
3587 p
. cargo ( "build --target-dir bar/target" ). run ();
3588 assert
!( p
. root (). join ( "bar/target/debug" ). join (& exe_name
). is_file ());
3589 assert
!( p
. root (). join ( "foo/target/debug" ). join (& exe_name
). is_file ());
3590 assert
!( p
. root (). join ( "target/debug" ). join (& exe_name
). is_file ());
3592 p
. cargo ( "build --target-dir foobar/target" )
3593 . env ( "CARGO_TARGET_DIR" , "bar/target" )
3597 . join ( "foobar/target/debug" )
3600 assert
!( p
. root (). join ( "bar/target/debug" ). join (& exe_name
). is_file ());
3601 assert
!( p
. root (). join ( "foo/target/debug" ). join (& exe_name
). is_file ());
3602 assert
!( p
. root (). join ( "target/debug" ). join (& exe_name
). is_file ());
3606 fn build_multiple_packages () {
3625 . file ( "src/foo.rs" , & main_file ( r
# "" i am foo "" #, &[]))
3626 . file ( "d1/Cargo.toml" , & basic_bin_manifest ( "d1" ))
3627 . file ( "d1/src/lib.rs" , "" )
3628 . file ( "d1/src/main.rs" , "fn main() { println!(\"d1\"); } " )
3642 . file ( "d2/src/main.rs" , "fn main() { println!(\"d2\"); } " )
3645 p
. cargo ( "build -p d1 -p d2 -p foo" ). run ();
3647 assert
!( p
. bin ( "foo" ). is_file ());
3648 p
. process (& p
. bin ( "foo" )). with_stdout ( "i am foo \n " ). run ();
3653 . join ( format
!( "d1 {} " , env
:: consts
:: EXE_SUFFIX
));
3657 . join ( format
!( "d2 {} " , env
:: consts
:: EXE_SUFFIX
));
3659 assert
!( d1_path
. is_file ());
3660 p
. process ( d1_path
). with_stdout ( "d1" ). run ();
3662 assert
!( d2_path
. is_file ());
3663 p
. process ( d2_path
). with_stdout ( "d2" ). run ();
3684 . file ( "src/bin/foo.rs" , & main_file ( r
# "" i am foo "" #, &[]))
3685 . file ( "d1/Cargo.toml" , & basic_bin_manifest ( "d1" ))
3686 . file ( "d1/src/lib.rs" , "" )
3687 . file ( "d1/src/main.rs" , "fn main() { println!(\"d1\"); } " )
3690 p
. cargo ( "build -p notAValidDep" )
3692 . with_stderr ( "[ERROR] package ID specification `notAValidDep` did not match any packages" )
3695 p
. cargo ( "build -p d1 -p notAValidDep" )
3697 . with_stderr ( "[ERROR] package ID specification `notAValidDep` did not match any packages" )
3702 fn manifest_with_bom_is_ok () {
3713 . file ( "src/lib.rs" , "" )
3715 p
. cargo ( "build -v" ). run ();
3719 fn panic_abort_compiles_with_panic_abort () {
3733 . file ( "src/lib.rs" , "" )
3736 . with_stderr_contains ( "[..] -C panic=abort [..]" )
3741 fn compiler_json_error_format () {
3750 authors = [" wycats@example.com "]
3758 "fn main() { println!(\"cargo:rustc-cfg=xyz\") } " ,
3760 . file ( "src/main.rs" , "fn main() { let unused = 92; } " )
3761 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.5.0" ))
3762 . file ( "bar/src/lib.rs" , r
# "fn dead() {} " #)
3765 let output
= | fresh
| {
3768 " reason ":" compiler-artifact ",
3769 " package_id ":" foo 0.5.0 ([..]) ",
3770 " manifest_path ": " [..] ",
3772 " kind ":[" custom-build "],
3773 " crate_types ":[" bin "],
3777 " name ":" build-script-build ",
3778 " src_path ":" [..]build.rs ",
3782 " debug_assertions ": true,
3785 " overflow_checks ": true,
3790 " filenames ": " {...} ",
3795 " reason ":" compiler-message ",
3796 " package_id ":" bar 0.5.0 ([..]) ",
3797 " manifest_path ": " [..] ",
3800 " crate_types ":[" lib "],
3805 " src_path ":" [..]lib.rs ",
3812 " reason ":" compiler-artifact ",
3814 " debug_assertions ": true,
3817 " overflow_checks ": true,
3822 " package_id ":" bar 0.5.0 ([..]) ",
3823 " manifest_path ": " [..] ",
3826 " crate_types ":[" lib "],
3831 " src_path ":" [..]lib.rs ",
3842 " reason ":" build-script-executed ",
3843 " package_id ":" foo 0.5.0 ([..]) ",
3848 " out_dir ": " [..]target/debug/build/foo-[..]/out "
3852 " reason ":" compiler-message ",
3853 " package_id ":" foo 0.5.0 ([..]) ",
3854 " manifest_path ": " [..] ",
3857 " crate_types ":[" bin "],
3862 " src_path ":" [..]main.rs ",
3869 " reason ":" compiler-artifact ",
3870 " package_id ":" foo 0.5.0 ([..]) ",
3871 " manifest_path ": " [..] ",
3874 " crate_types ":[" bin "],
3879 " src_path ":" [..]main.rs ",
3883 " debug_assertions ": true,
3886 " overflow_checks ": true,
3889 " executable ": " [..]/foo/target/debug/foo[EXE] ",
3891 " filenames ": " {...} ",
3895 {"reason": "build-finished", "success": true}
3897 . replace ( "$FRESH" , fresh
)
3900 // Use `jobs=1` to ensure that the order of messages is consistent.
3901 p
. cargo ( "build -v --message-format=json --jobs=1" )
3902 . with_json_contains_unordered (& output ( "false" ))
3905 // With fresh build, we should repeat the artifacts,
3906 // and replay the cached compiler warnings.
3907 p
. cargo ( "build -v --message-format=json --jobs=1" )
3908 . with_json_contains_unordered (& output ( "true" ))
3913 fn wrong_message_format_option () {
3915 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
3916 . file ( "src/main.rs" , "fn main() {} " )
3919 p
. cargo ( "build --message-format XML" )
3921 . with_stderr_contains (
3923 error: invalid message format specifier: `xml`
3930 fn message_format_json_forward_stderr () {
3932 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
3933 . file ( "src/main.rs" , "fn main() { let unused = 0; } " )
3936 p
. cargo ( "rustc --release --bin foo --message-format JSON" )
3937 . with_json_contains_unordered (
3940 " reason ":" compiler-message ",
3941 " package_id ":" foo 0.5.0 ([..]) ",
3942 " manifest_path ": " [..] ",
3945 " crate_types ":[" bin "],
3957 " reason ":" compiler-artifact ",
3958 " package_id ":" foo 0.5.0 ([..]) ",
3959 " manifest_path ": " [..] ",
3962 " crate_types ":[" bin "],
3971 " debug_assertions ":false,
3974 " overflow_checks ": false,
3977 " executable ": " {...} ",
3979 " filenames ": " {...} ",
3983 {"reason": "build-finished", "success": true}
3990 fn no_warn_about_package_metadata () {
4005 [package.metadata.another]
4009 . file ( "src/lib.rs" , "" )
4013 "[..] foo v0.0.1 ([..]) \n\
4014 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] \n " ,
4020 fn no_warn_about_workspace_metadata () {
4028 [workspace.metadata]
4029 something = " something_else "
4033 [workspace.metadata.another]
4045 . file ( "foo/src/lib.rs" , "" )
4050 "[..] foo v0.0.1 ([..]) \n\
4051 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] \n " ,
4057 fn cargo_build_empty_target () {
4059 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
4060 . file ( "src/main.rs" , "fn main() {} " )
4063 p
. cargo ( "build --target" )
4066 . with_stderr_contains ( "[..] target was empty" )
4071 fn build_all_workspace () {
4081 bar = { path = "bar" }
4086 . file ( "src/main.rs" , "fn main() {} " )
4087 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4088 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4091 p
. cargo ( "build --workspace" )
4094 [COMPILING] bar v0.1.0 ([..])
4095 [COMPILING] foo v0.1.0 ([..])
4096 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4103 fn build_all_exclude () {
4113 members = [" bar ", " baz "]
4116 . file ( "src/main.rs" , "fn main() {} " )
4117 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4118 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4119 . file ( "baz/Cargo.toml" , & basic_manifest ( "baz" , "0.1.0" ))
4120 . file ( "baz/src/lib.rs" , "pub fn baz() { break_the_build(); } " )
4123 p
. cargo ( "build --workspace --exclude baz" )
4124 . with_stderr_does_not_contain ( "[COMPILING] baz v0.1.0 [..]" )
4125 . with_stderr_unordered (
4127 [COMPILING] foo v0.1.0 ([..])
4128 [COMPILING] bar v0.1.0 ([..])
4129 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4136 fn build_all_exclude_not_found () {
4149 . file ( "src/main.rs" , "fn main() {} " )
4150 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4151 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4154 p
. cargo ( "build --workspace --exclude baz" )
4155 . with_stderr_does_not_contain ( "[COMPILING] baz v0.1.0 [..]" )
4156 . with_stderr_unordered (
4158 [WARNING] excluded package(s) `baz` not found in workspace [..]
4159 [COMPILING] foo v0.1.0 ([..])
4160 [COMPILING] bar v0.1.0 ([..])
4161 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4168 fn build_all_exclude_glob () {
4178 members = [" bar ", " baz "]
4181 . file ( "src/main.rs" , "fn main() {} " )
4182 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4183 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4184 . file ( "baz/Cargo.toml" , & basic_manifest ( "baz" , "0.1.0" ))
4185 . file ( "baz/src/lib.rs" , "pub fn baz() { break_the_build(); } " )
4188 p
. cargo ( "build --workspace --exclude '*z'" )
4189 . with_stderr_does_not_contain ( "[COMPILING] baz v0.1.0 [..]" )
4190 . with_stderr_unordered (
4192 [COMPILING] foo v0.1.0 ([..])
4193 [COMPILING] bar v0.1.0 ([..])
4194 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4201 fn build_all_exclude_glob_not_found () {
4214 . file ( "src/main.rs" , "fn main() {} " )
4215 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4216 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4219 p
. cargo ( "build --workspace --exclude '*z'" )
4220 . with_stderr_does_not_contain ( "[COMPILING] baz v0.1.0 [..]" )
4223 [WARNING] excluded package pattern(s) `*z` not found in workspace [..]
4224 [COMPILING] [..] v0.1.0 ([..])
4225 [COMPILING] [..] v0.1.0 ([..])
4226 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4233 fn build_all_exclude_broken_glob () {
4234 let p
= project (). file ( "src/main.rs" , "fn main() {} " ). build ();
4236 p
. cargo ( "build --workspace --exclude '[*z'" )
4238 . with_stderr_contains ( "[ERROR] cannot build glob pattern from `[*z`" )
4243 fn build_all_workspace_implicit_examples () {
4253 bar = { path = "bar" }
4258 . file ( "src/lib.rs" , "" )
4259 . file ( "src/bin/a.rs" , "fn main() {} " )
4260 . file ( "src/bin/b.rs" , "fn main() {} " )
4261 . file ( "examples/c.rs" , "fn main() {} " )
4262 . file ( "examples/d.rs" , "fn main() {} " )
4263 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4264 . file ( "bar/src/lib.rs" , "" )
4265 . file ( "bar/src/bin/e.rs" , "fn main() {} " )
4266 . file ( "bar/src/bin/f.rs" , "fn main() {} " )
4267 . file ( "bar/examples/g.rs" , "fn main() {} " )
4268 . file ( "bar/examples/h.rs" , "fn main() {} " )
4271 p
. cargo ( "build --workspace --examples" )
4273 "[..] Compiling bar v0.1.0 ([..]) \n\
4274 [..] Compiling foo v0.1.0 ([..]) \n\
4275 [..] Finished dev [unoptimized + debuginfo] target(s) in [..] \n " ,
4278 assert
!(! p
. bin ( "a" ). is_file ());
4279 assert
!(! p
. bin ( "b" ). is_file ());
4280 assert
!( p
. bin ( "examples/c" ). is_file ());
4281 assert
!( p
. bin ( "examples/d" ). is_file ());
4282 assert
!(! p
. bin ( "e" ). is_file ());
4283 assert
!(! p
. bin ( "f" ). is_file ());
4284 assert
!( p
. bin ( "examples/g" ). is_file ());
4285 assert
!( p
. bin ( "examples/h" ). is_file ());
4289 fn build_all_virtual_manifest () {
4295 members = [" bar ", " baz "]
4298 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4299 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4300 . file ( "baz/Cargo.toml" , & basic_manifest ( "baz" , "0.1.0" ))
4301 . file ( "baz/src/lib.rs" , "pub fn baz() {} " )
4304 // The order in which bar and baz are built is not guaranteed
4305 p
. cargo ( "build --workspace" )
4306 . with_stderr_unordered (
4308 [COMPILING] baz v0.1.0 ([..])
4309 [COMPILING] bar v0.1.0 ([..])
4310 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4317 fn build_virtual_manifest_all_implied () {
4323 members = [" bar ", " baz "]
4326 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4327 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4328 . file ( "baz/Cargo.toml" , & basic_manifest ( "baz" , "0.1.0" ))
4329 . file ( "baz/src/lib.rs" , "pub fn baz() {} " )
4332 // The order in which `bar` and `baz` are built is not guaranteed.
4334 . with_stderr_unordered (
4336 [COMPILING] baz v0.1.0 ([..])
4337 [COMPILING] bar v0.1.0 ([..])
4338 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4345 fn build_virtual_manifest_one_project () {
4351 members = [" bar ", " baz "]
4354 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4355 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4356 . file ( "baz/Cargo.toml" , & basic_manifest ( "baz" , "0.1.0" ))
4357 . file ( "baz/src/lib.rs" , "pub fn baz() { break_the_build(); } " )
4360 p
. cargo ( "build -p bar" )
4361 . with_stderr_does_not_contain ( "[..]baz[..]" )
4364 [COMPILING] bar v0.1.0 ([..])
4365 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4372 fn build_virtual_manifest_glob () {
4378 members = [" bar ", " baz "]
4381 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4382 . file ( "bar/src/lib.rs" , "pub fn bar() { break_the_build(); } " )
4383 . file ( "baz/Cargo.toml" , & basic_manifest ( "baz" , "0.1.0" ))
4384 . file ( "baz/src/lib.rs" , "pub fn baz() {} " )
4387 p
. cargo ( "build -p '*z'" )
4388 . with_stderr_does_not_contain ( "[..]bar[..]" )
4391 [COMPILING] baz v0.1.0 ([..])
4392 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4399 fn build_virtual_manifest_glob_not_found () {
4408 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4409 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4412 p
. cargo ( "build -p bar -p '*z'" )
4414 . with_stderr ( "[ERROR] package pattern(s) `*z` not found in workspace [..]" )
4419 fn build_virtual_manifest_broken_glob () {
4428 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4429 . file ( "bar/src/lib.rs" , "pub fn bar() {} " )
4432 p
. cargo ( "build -p '[*z'" )
4434 . with_stderr_contains ( "[ERROR] cannot build glob pattern from `[*z`" )
4439 fn build_all_virtual_manifest_implicit_examples () {
4445 members = [" bar ", " baz "]
4448 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
4449 . file ( "bar/src/lib.rs" , "" )
4450 . file ( "bar/src/bin/a.rs" , "fn main() {} " )
4451 . file ( "bar/src/bin/b.rs" , "fn main() {} " )
4452 . file ( "bar/examples/c.rs" , "fn main() {} " )
4453 . file ( "bar/examples/d.rs" , "fn main() {} " )
4454 . file ( "baz/Cargo.toml" , & basic_manifest ( "baz" , "0.1.0" ))
4455 . file ( "baz/src/lib.rs" , "" )
4456 . file ( "baz/src/bin/e.rs" , "fn main() {} " )
4457 . file ( "baz/src/bin/f.rs" , "fn main() {} " )
4458 . file ( "baz/examples/g.rs" , "fn main() {} " )
4459 . file ( "baz/examples/h.rs" , "fn main() {} " )
4462 // The order in which bar and baz are built is not guaranteed
4463 p
. cargo ( "build --workspace --examples" )
4464 . with_stderr_unordered (
4466 [COMPILING] baz v0.1.0 ([..])
4467 [COMPILING] bar v0.1.0 ([..])
4468 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
4472 assert
!(! p
. bin ( "a" ). is_file ());
4473 assert
!(! p
. bin ( "b" ). is_file ());
4474 assert
!( p
. bin ( "examples/c" ). is_file ());
4475 assert
!( p
. bin ( "examples/d" ). is_file ());
4476 assert
!(! p
. bin ( "e" ). is_file ());
4477 assert
!(! p
. bin ( "f" ). is_file ());
4478 assert
!( p
. bin ( "examples/g" ). is_file ());
4479 assert
!( p
. bin ( "examples/h" ). is_file ());
4483 fn build_all_member_dependency_same_name () {
4503 . file ( "a/src/lib.rs" , "pub fn a() {} " )
4506 Package
:: new ( "a" , "0.1.0" ). publish ();
4508 p
. cargo ( "build --workspace" )
4510 "[UPDATING] `[..]` index \n\
4511 [DOWNLOADING] crates ... \n\
4512 [DOWNLOADED] a v0.1.0 ([..]) \n\
4513 [COMPILING] a v0.1.0 \n\
4514 [COMPILING] a v0.1.0 ([..]) \n\
4515 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] \n " ,
4521 fn run_proper_binary () {
4536 . file ( "src/lib.rs" , "" )
4539 r
# "fn main() { panic!("This should never be run."); } " #,
4541 . file ( "src/bin/other.rs" , "fn main() {} " )
4544 p
. cargo ( "run --bin other" ). run ();
4548 fn run_proper_binary_main_rs () {
4550 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
4551 . file ( "src/lib.rs" , "" )
4552 . file ( "src/bin/main.rs" , "fn main() {} " )
4555 p
. cargo ( "run --bin foo" ). run ();
4559 fn run_proper_alias_binary_from_src () {
4574 . file ( "src/foo.rs" , r
# "fn main() { println!("foo"); } " #)
4575 . file ( "src/bar.rs" , r
# "fn main() { println!("bar"); } " #)
4578 p
. cargo ( "build --workspace" ). run ();
4579 p
. process (& p
. bin ( "foo" )). with_stdout ( "foo \n " ). run ();
4580 p
. process (& p
. bin ( "bar" )). with_stdout ( "bar \n " ). run ();
4584 fn run_proper_alias_binary_main_rs () {
4599 . file ( "src/main.rs" , r
# "fn main() { println!("main"); } " #)
4602 p
. cargo ( "build --workspace" ). run ();
4603 p
. process (& p
. bin ( "foo" )). with_stdout ( "main \n " ). run ();
4604 p
. process (& p
. bin ( "bar" )). with_stdout ( "main \n " ). run ();
4608 fn run_proper_binary_main_rs_as_foo () {
4610 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
4613 r
# " fn main() { panic!("This should never be run."); } " #,
4615 . file ( "src/main.rs" , "fn main() {} " )
4618 p
. cargo ( "run --bin foo" ). run ();
4622 fn rustc_wrapper () {
4623 let p
= project (). file ( "src/lib.rs" , "" ). build ();
4624 let wrapper
= tools
:: echo_wrapper ();
4625 let running
= format
!(
4626 "[RUNNING] ` {} rustc --crate-name foo [..]" ,
4630 . env ( "RUSTC_WRAPPER" , & wrapper
)
4631 . with_stderr_contains (& running
)
4633 p
. build_dir (). rm_rf ();
4635 . env ( "RUSTC_WORKSPACE_WRAPPER" , & wrapper
)
4636 . with_stderr_contains (& running
)
4641 fn rustc_wrapper_relative () {
4642 Package
:: new ( "bar" , "1.0.0" ). publish ();
4655 . file ( "src/lib.rs" , "" )
4657 let wrapper
= tools
:: echo_wrapper ();
4658 let exe_name
= wrapper
. file_name (). unwrap (). to_str (). unwrap ();
4659 let relative_path
= format
!( "./ {} " , exe_name
);
4660 fs
:: hard_link (& wrapper
, p
. root (). join ( exe_name
)). unwrap ();
4661 let running
= format
!( "[RUNNING] `[ROOT]/foo/./ {} rustc[..]" , exe_name
);
4663 . env ( "RUSTC_WRAPPER" , & relative_path
)
4664 . with_stderr_contains (& running
)
4666 p
. build_dir (). rm_rf ();
4668 . env ( "RUSTC_WORKSPACE_WRAPPER" , & relative_path
)
4669 . with_stderr_contains (& running
)
4671 p
. build_dir (). rm_rf ();
4673 ".cargo/config.toml" ,
4676 build.rustc-wrapper = " ./{} "
4681 p
. cargo ( "build -v" ). with_stderr_contains (& running
). run ();
4685 fn rustc_wrapper_from_path () {
4686 let p
= project (). file ( "src/lib.rs" , "" ). build ();
4688 . env ( "RUSTC_WRAPPER" , "wannabe_sccache" )
4690 . with_stderr_contains ( "[..]`wannabe_sccache rustc [..]" )
4692 p
. build_dir (). rm_rf ();
4694 . env ( "RUSTC_WORKSPACE_WRAPPER" , "wannabe_sccache" )
4696 . with_stderr_contains ( "[..]`wannabe_sccache rustc [..]" )
4701 fn cdylib_not_lifted () {
4712 crate-type = [" cdylib "]
4715 . file ( "src/lib.rs" , "" )
4718 p
. cargo ( "build" ). run ();
4720 let files
= if cfg
!( windows
) {
4721 if cfg
!( target_env
= "msvc" ) {
4722 vec
![ "foo.dll.lib" , "foo.dll.exp" , "foo.dll" ]
4724 vec
![ "libfoo.dll.a" , "foo.dll" ]
4726 } else if cfg
!( target_os
= "macos" ) {
4727 vec
![ "libfoo.dylib" ]
4733 println
!( "checking: {} " , file
);
4734 assert
!( p
. root (). join ( "target/debug/deps" ). join (& file
). is_file ());
4739 fn cdylib_final_outputs () {
4750 crate-type = [" cdylib "]
4753 . file ( "src/lib.rs" , "" )
4756 p
. cargo ( "build" ). run ();
4758 let files
= if cfg
!( windows
) {
4759 if cfg
!( target_env
= "msvc" ) {
4760 vec
![ "foo_bar.dll.lib" , "foo_bar.dll" ]
4762 vec
![ "foo_bar.dll" , "libfoo_bar.dll.a" ]
4764 } else if cfg
!( target_os
= "macos" ) {
4765 vec
![ "libfoo_bar.dylib" ]
4767 vec
![ "libfoo_bar.so" ]
4771 println
!( "checking: {} " , file
);
4772 assert
!( p
. root (). join ( "target/debug" ). join (& file
). is_file ());
4777 // NOTE: Windows MSVC and wasm32-unknown-emscripten do not use metadata. Skip them.
4778 // See <https://github.com/rust-lang/cargo/issues/9325#issuecomment-1030662699>
4779 #[cfg(not(all(target_os = "windows" , target_env = "msvc" )))]
4780 fn no_dep_info_collision_when_cdylib_and_bin_coexist () {
4790 crate-type = [" cdylib "]
4793 . file ( "src/main.rs" , "fn main() {} " )
4794 . file ( "src/lib.rs" , "" )
4798 . with_stderr_unordered (
4800 [COMPILING] foo v1.0.0 ([CWD])
4801 [RUNNING] `rustc [..] --crate-type bin [..] -C metadata=[..]`
4802 [RUNNING] `rustc [..] --crate-type cdylib [..] -C metadata=[..]`
4808 let deps_dir
= p
. target_debug_dir (). join ( "deps" );
4809 assert
!( deps_dir
. join ( "foo.d" ). exists ());
4810 let dep_info_count
= deps_dir
4814 let filename
= e
. as_ref (). unwrap (). file_name ();
4815 let filename
= filename
. to_str (). unwrap ();
4816 filename
. starts_with ( "foo" ) && filename
. ends_with ( ".d" )
4820 // bin -> foo-<meta>.d
4821 assert_eq
!( dep_info_count
, 2 );
4825 fn deterministic_cfg_flags () {
4826 // This bug is non-deterministic.
4839 default = [" f_a ", " f_b ", " f_c ", " f_d "]
4850 println!(" cargo:rustc-cfg=cfg_a ");
4851 println!(" cargo:rustc-cfg=cfg_b ");
4852 println!(" cargo:rustc-cfg=cfg_c ");
4853 println!(" cargo:rustc-cfg=cfg_d ");
4854 println!(" cargo:rustc-cfg=cfg_e ");
4858 . file ( "src/main.rs" , "fn main() {} " )
4864 [COMPILING] foo v0.1.0 [..]
4867 [RUNNING] `rustc --crate-name foo [..] \
4868 --cfg[..]default[..]--cfg[..]f_a[..]--cfg[..]f_b[..] \
4869 --cfg[..]f_c[..]--cfg[..]f_d[..] \
4870 --cfg cfg_a --cfg cfg_b --cfg cfg_c --cfg cfg_d --cfg cfg_e`
4871 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]" ,
4877 fn explicit_bins_without_paths () {
4894 . file ( "src/lib.rs" , "" )
4895 . file ( "src/main.rs" , "fn main() {} " )
4896 . file ( "src/bin/bar.rs" , "fn main() {} " )
4899 p
. cargo ( "build" ). run ();
4903 fn no_bin_in_src_with_lib () {
4905 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
4906 . file ( "src/lib.rs" , "" )
4907 . file ( "src/foo.rs" , "fn main() {} " )
4912 . with_stderr_contains (
4914 [ERROR] failed to parse manifest at `[..]`
4917 can't find `foo` bin at `src/bin/foo.rs` or `src/bin/foo/main.rs`. [..]" ,
4923 fn inferred_bins () {
4925 . file ( "src/main.rs" , "fn main() {} " )
4926 . file ( "src/bin/bar.rs" , "fn main() {} " )
4927 . file ( "src/bin/baz/main.rs" , "fn main() {} " )
4930 p
. cargo ( "build" ). run ();
4931 assert
!( p
. bin ( "foo" ). is_file ());
4932 assert
!( p
. bin ( "bar" ). is_file ());
4933 assert
!( p
. bin ( "baz" ). is_file ());
4937 fn inferred_bins_duplicate_name () {
4938 // this should fail, because we have two binaries with the same name
4940 . file ( "src/main.rs" , "fn main() {} " )
4941 . file ( "src/bin/bar.rs" , "fn main() {} " )
4942 . file ( "src/bin/bar/main.rs" , "fn main() {} " )
4945 p
. cargo ( "build" ). with_status ( 101 ). with_stderr_contains (
4946 "[..]found duplicate binary name bar, but all binary targets must have a unique name[..]" ,
4952 fn inferred_bin_path () {
4964 # Note, no `path` key!
4967 . file ( "src/bin/bar/main.rs" , "fn main() {} " )
4970 p
. cargo ( "build" ). run ();
4971 assert
!( p
. bin ( "bar" ). is_file ());
4975 fn inferred_examples () {
4977 . file ( "src/lib.rs" , "fn main() {} " )
4978 . file ( "examples/bar.rs" , "fn main() {} " )
4979 . file ( "examples/baz/main.rs" , "fn main() {} " )
4982 p
. cargo ( "build --examples" ). run ();
4983 assert
!( p
. bin ( "examples/bar" ). is_file ());
4984 assert
!( p
. bin ( "examples/baz" ). is_file ());
4988 fn inferred_tests () {
4990 . file ( "src/lib.rs" , "fn main() {} " )
4991 . file ( "tests/bar.rs" , "fn main() {} " )
4992 . file ( "tests/baz/main.rs" , "fn main() {} " )
4995 p
. cargo ( "test --test=bar --test=baz" ). run ();
4999 fn inferred_benchmarks () {
5001 . file ( "src/lib.rs" , "fn main() {} " )
5002 . file ( "benches/bar.rs" , "fn main() {} " )
5003 . file ( "benches/baz/main.rs" , "fn main() {} " )
5006 p
. cargo ( "bench --bench=bar --bench=baz" ). run ();
5010 fn target_edition () {
5023 . file ( "src/lib.rs" , "" )
5027 . with_stderr_contains (
5029 [COMPILING] foo v0.0.1 ([..])
5030 [RUNNING] `rustc [..]--edition=2018 [..]
5037 fn target_edition_override () {
5062 p
. cargo ( "build -v" ). run ();
5066 fn same_metadata_different_directory () {
5067 // A top-level crate built in two different workspaces should have the
5068 // same metadata hash.
5071 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
5072 . file ( "src/foo.rs" , & main_file ( r
# "" i am foo "" #, &[]))
5074 let output
= t
!( String
:: from_utf8 (
5075 t
!( p
. cargo ( "build -v" ). exec_with_output ()). stderr
,
5077 let metadata
= output
5079 . find (| arg
| arg
. starts_with ( "metadata=" ))
5084 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
5085 . file ( "src/foo.rs" , & main_file ( r
# "" i am foo "" #, &[]))
5089 . with_stderr_contains ( format
!( "[..] {} [..]" , metadata
))
5094 fn building_a_dependent_crate_without_bin_should_fail () {
5095 Package
:: new ( "testless" , "0.1.0" )
5107 . file ( "src/lib.rs" , "" )
5122 . file ( "src/lib.rs" , "" )
5127 . with_stderr_contains (
5128 "[..]can't find `a_bin` bin at `src/bin/a_bin.rs` or `src/bin/a_bin/main.rs`[..]" ,
5134 #[cfg(any(target_os = "macos" , target_os = "ios" ))]
5135 fn uplift_dsym_of_bin_on_mac () {
5137 . file ( "src/main.rs" , "fn main() { panic!(); } " )
5138 . file ( "src/bin/b.rs" , "fn main() { panic!(); } " )
5139 . file ( "examples/c.rs" , "fn main() { panic!(); } " )
5140 . file ( "tests/d.rs" , "fn main() { panic!(); } " )
5143 p
. cargo ( "build --bins --examples --tests" )
5146 assert
!( p
. target_debug_dir (). join ( "foo.dSYM" ). is_dir ());
5147 assert
!( p
. target_debug_dir (). join ( "b.dSYM" ). is_dir ());
5148 assert
!( p
. target_debug_dir (). join ( "b.dSYM" ). is_symlink ());
5149 assert
!( p
. target_debug_dir (). join ( "examples/c.dSYM" ). is_dir ());
5150 assert
!(! p
. target_debug_dir (). join ( "c.dSYM" ). exists ());
5151 assert
!(! p
. target_debug_dir (). join ( "d.dSYM" ). exists ());
5155 #[cfg(any(target_os = "macos" , target_os = "ios" ))]
5156 fn uplift_dsym_of_bin_on_mac_when_broken_link_exists () {
5158 . file ( "src/main.rs" , "fn main() { panic!(); } " )
5160 let dsym
= p
. target_debug_dir (). join ( "foo.dSYM" );
5162 p
. cargo ( "build" ). enable_mac_dsym (). run ();
5163 assert
!( dsym
. is_dir ());
5165 // Simulate the situation where the underlying dSYM bundle goes missing
5166 // but the uplifted symlink to it remains. This would previously cause
5167 // builds to permanently fail until the bad symlink was manually removed.
5170 p
. target_debug_dir ()
5172 . join ( "foo-baaaaaadbaaaaaad.dSYM" ),
5175 assert
!( dsym
. is_symlink ());
5176 assert
!(! dsym
. exists ());
5178 p
. cargo ( "build" ). enable_mac_dsym (). run ();
5179 assert
!( dsym
. is_dir ());
5183 #[cfg(all(target_os = "windows" , target_env = "msvc" ))]
5184 fn uplift_pdb_of_bin_on_windows () {
5186 . file ( "src/main.rs" , "fn main() { panic!(); } " )
5187 . file ( "src/bin/b.rs" , "fn main() { panic!(); } " )
5188 . file ( "src/bin/foo-bar.rs" , "fn main() { panic!(); } " )
5189 . file ( "examples/c.rs" , "fn main() { panic!(); } " )
5190 . file ( "tests/d.rs" , "fn main() { panic!(); } " )
5193 p
. cargo ( "build --bins --examples --tests" ). run ();
5194 assert
!( p
. target_debug_dir (). join ( "foo.pdb" ). is_file ());
5195 assert
!( p
. target_debug_dir (). join ( "b.pdb" ). is_file ());
5196 assert
!( p
. target_debug_dir (). join ( "examples/c.pdb" ). exists ());
5197 assert
!( p
. target_debug_dir (). join ( "foo-bar.exe" ). is_file ());
5198 assert
!( p
. target_debug_dir (). join ( "foo_bar.pdb" ). is_file ());
5199 assert
!(! p
. target_debug_dir (). join ( "c.pdb" ). exists ());
5200 assert
!(! p
. target_debug_dir (). join ( "d.pdb" ). exists ());
5203 // Ensure that `cargo build` chooses the correct profile for building
5204 // targets based on filters (assuming `--profile` is not specified).
5206 fn build_filter_infer_profile () {
5208 . file ( "src/lib.rs" , "" )
5209 . file ( "src/main.rs" , "fn main() {} " )
5210 . file ( "tests/t1.rs" , "" )
5211 . file ( "benches/b1.rs" , "" )
5212 . file ( "examples/ex1.rs" , "fn main() {} " )
5216 . with_stderr_contains (
5217 "[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
5218 --emit=[..]link[..]" ,
5220 . with_stderr_contains (
5221 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
5222 --emit=[..]link[..]" ,
5226 p
. root (). join ( "target" ). rm_rf ();
5227 p
. cargo ( "build -v --test=t1" )
5228 . with_stderr_contains (
5229 "[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
5230 --emit=[..]link[..]-C debuginfo=2 [..]" ,
5232 . with_stderr_contains (
5233 "[RUNNING] `rustc --crate-name t1 tests/t1.rs [..]--emit=[..]link[..] \
5234 -C debuginfo=2 [..]" ,
5236 . with_stderr_contains (
5237 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
5238 --emit=[..]link[..]-C debuginfo=2 [..]" ,
5242 p
. root (). join ( "target" ). rm_rf ();
5243 // Bench uses test profile without `--release`.
5244 p
. cargo ( "build -v --bench=b1" )
5245 . with_stderr_contains (
5246 "[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
5247 --emit=[..]link[..]-C debuginfo=2 [..]" ,
5249 . with_stderr_contains (
5250 "[RUNNING] `rustc --crate-name b1 benches/b1.rs [..]--emit=[..]link[..] \
5251 -C debuginfo=2 [..]" ,
5253 . with_stderr_does_not_contain ( "opt-level" )
5254 . with_stderr_contains (
5255 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
5256 --emit=[..]link[..]-C debuginfo=2 [..]" ,
5262 fn targets_selected_default () {
5263 let p
= project (). file ( "src/main.rs" , "fn main() {} " ). build ();
5266 . with_stderr_contains (
5267 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
5268 --emit=[..]link[..]" ,
5271 . with_stderr_does_not_contain (
5272 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link \
5273 -C opt-level=3 --test [..]" ,
5276 . with_stderr_does_not_contain (
5277 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link[..] \
5278 -C debuginfo=2 --test [..]" ,
5284 fn targets_selected_all () {
5285 let p
= project (). file ( "src/main.rs" , "fn main() {} " ). build ();
5286 p
. cargo ( "build -v --all-targets" )
5288 . with_stderr_contains (
5289 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
5290 --emit=[..]link[..]" ,
5293 . with_stderr_contains (
5294 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link[..] \
5295 -C debuginfo=2 --test [..]" ,
5301 fn all_targets_no_lib () {
5302 let p
= project (). file ( "src/main.rs" , "fn main() {} " ). build ();
5303 p
. cargo ( "build -v --all-targets" )
5305 . with_stderr_contains (
5306 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
5307 --emit=[..]link[..]" ,
5310 . with_stderr_contains (
5311 "[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link[..] \
5312 -C debuginfo=2 --test [..]" ,
5318 fn no_linkable_target () {
5319 // Issue 3169: this is currently not an error as per discussion in PR #4797.
5329 the_lib = { path = "the_lib" }
5332 . file ( "src/main.rs" , "fn main() {} " )
5334 "the_lib/Cargo.toml" ,
5341 crate-type = [" staticlib "]
5344 . file ( "the_lib/src/lib.rs" , "pub fn foo() {} " )
5347 . with_stderr_contains (
5348 "[WARNING] The package `the_lib` provides no linkable [..] \
5349 while compiling `foo`. [..] in `the_lib`'s Cargo.toml. [..]" ,
5355 fn avoid_dev_deps () {
5356 Package
:: new ( "foo" , "1.0.0" ). publish ();
5370 . file ( "src/main.rs" , "fn main() {} " )
5378 [ERROR] no matching package named `baz` found
5379 location searched: registry `crates-io`
5380 required by package `bar v0.1.0 ([..]/foo)`
5384 p
. cargo ( "build -Zavoid-dev-deps" )
5385 . masquerade_as_nightly_cargo ()
5390 fn default_cargo_config_jobs () {
5392 . file ( "src/lib.rs" , "" )
5401 p
. cargo ( "build -v" ). run ();
5405 fn good_cargo_config_jobs () {
5407 . file ( "src/lib.rs" , "" )
5416 p
. cargo ( "build -v" ). run ();
5422 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
5423 . file ( "src/foo.rs" , & main_file ( r
# "" i am foo "" #, &[]))
5426 p
. cargo ( "build --jobs 1" ). run ();
5428 p
. cargo ( "build --jobs -1" ). run ();
5432 fn invalid_cargo_config_jobs () {
5434 . file ( "src/lib.rs" , "" )
5445 . with_stderr_contains ( "error: jobs may not be 0" )
5452 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
5453 . file ( "src/foo.rs" , & main_file ( r
# "" i am foo "" #, &[]))
5456 p
. cargo ( "build --jobs 0" )
5458 . with_stderr_contains ( "error: jobs must not be zero" )
5461 p
. cargo ( "build --jobs over9000" )
5463 . with_stderr ( "error: Invalid value: could not parse `over9000` as a number" )
5468 fn target_filters_workspace () {
5475 members = [" a ", " b "]
5478 . file ( "a/Cargo.toml" , & basic_lib_manifest ( "a" ))
5479 . file ( "a/src/lib.rs" , "" )
5480 . file ( "a/examples/ex1.rs" , "fn main() {} " )
5481 . file ( "b/Cargo.toml" , & basic_bin_manifest ( "b" ))
5482 . file ( "b/src/lib.rs" , "" )
5483 . file ( "b/src/main.rs" , "fn main() {} " )
5486 ws
. cargo ( "build -v --example ex" )
5490 [ERROR] no example target named `ex`
5492 <tab>Did you mean `ex1`?" ,
5496 ws
. cargo ( "build -v --example 'ex??'" )
5500 [ERROR] no example target matches pattern `ex??`
5502 <tab>Did you mean `ex1`?" ,
5506 ws
. cargo ( "build -v --lib" )
5507 . with_stderr_contains ( "[RUNNING] `rustc [..]a/src/lib.rs[..]" )
5508 . with_stderr_contains ( "[RUNNING] `rustc [..]b/src/lib.rs[..]" )
5511 ws
. cargo ( "build -v --example ex1" )
5512 . with_stderr_contains ( "[RUNNING] `rustc [..]a/examples/ex1.rs[..]" )
5517 fn target_filters_workspace_not_found () {
5524 members = [" a ", " b "]
5527 . file ( "a/Cargo.toml" , & basic_bin_manifest ( "a" ))
5528 . file ( "a/src/main.rs" , "fn main() {} " )
5529 . file ( "b/Cargo.toml" , & basic_bin_manifest ( "b" ))
5530 . file ( "b/src/main.rs" , "fn main() {} " )
5533 ws
. cargo ( "build -v --lib" )
5535 . with_stderr ( "[ERROR] no library targets found in packages: a, b" )
5541 fn signal_display () {
5542 // Cause the compiler to crash with a signal.
5551 pm = { path = "pm" }
5577 extern crate proc_macro;
5578 use proc_macro::TokenStream;
5580 #[proc_macro_derive(Foo)]
5581 pub fn derive(_input: TokenStream) -> TokenStream {
5582 std::process::abort()
5592 [COMPILING] foo [..]
5593 [ERROR] could not compile `foo`
5596 process didn't exit successfully: `rustc [..]` (signal: 6, SIGABRT: process abort signal)
5604 fn tricky_pipelining () {
5613 bar = { path = "bar" }
5616 . file ( "src/lib.rs" , "extern crate bar;" )
5617 . file ( "bar/Cargo.toml" , & basic_lib_manifest ( "bar" ))
5618 . file ( "bar/src/lib.rs" , "" )
5621 foo
. cargo ( "build -p bar" ). run ();
5622 foo
. cargo ( "build -p foo" ). run ();
5626 fn pipelining_works () {
5635 bar = { path = "bar" }
5638 . file ( "src/lib.rs" , "extern crate bar;" )
5639 . file ( "bar/Cargo.toml" , & basic_lib_manifest ( "bar" ))
5640 . file ( "bar/src/lib.rs" , "" )
5656 fn pipelining_big_graph () {
5657 // Create a crate graph of the form {a,b}{0..29}, where {a,b}(n) depend on {a,b}(n+1)
5658 // Then have `foo`, a binary crate, depend on the whole thing.
5659 let mut project
= project ()
5667 a1 = { path = "a1" }
5668 b1 = { path = "b1" }
5671 . file ( "src/main.rs" , "fn main() {} " );
5674 for x
in &[ "a" , "b" ] {
5677 & format
!( " {x}{n} /Cargo.toml" , x
= x
, n
= n
),
5684 a {np1} = {{ path = "../a{np1} " }}
5685 b{np1}
= {{ path = "../b{np1}
" }}
5692 . file (& format
!( " {x}{n} /src/lib.rs" , x
= x
, n
= n
), "" );
5697 . file ( "a30/Cargo.toml" , & basic_lib_manifest ( "a30" ))
5700 r
# "compile_error!(" don't actually build me ");" #,
5702 . file ( "b30/Cargo.toml" , & basic_lib_manifest ( "b30" ))
5703 . file ( "b30/src/lib.rs" , "" )
5705 foo
. cargo ( "build -p foo" )
5707 . with_stderr_contains ( "[ERROR] could not compile `a30`[..]" )
5712 fn forward_rustc_output () {
5722 bar = { path = "bar" }
5725 . file ( "src/lib.rs" , "bar::foo!();" )
5739 extern crate proc_macro;
5743 pub fn foo(input: TokenStream) -> TokenStream {
5749 eprintln!(" {{a "); // " malformed json "
5757 . with_stdout ( "a \n b \n {} " )
5772 fn build_lib_only () {
5774 . file ( "src/main.rs" , "fn main() {} " )
5775 . file ( "src/lib.rs" , r
# " " #)
5778 p
. cargo ( "build --lib -v" )
5781 [COMPILING] foo v0.0.1 ([CWD])
5782 [RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
5783 --emit=[..]link[..]-C debuginfo=2 \
5786 -L dependency=[CWD]/target/debug/deps`
5787 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]" ,
5793 fn build_with_no_lib () {
5795 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
5796 . file ( "src/main.rs" , "fn main() {} " )
5799 p
. cargo ( "build --lib" )
5801 . with_stderr ( "[ERROR] no library targets found in package `foo`" )
5806 fn build_with_relative_cargo_home_path () {
5815 authors = [" wycats@example.com "]
5819 " test-dependency " = { path = "src/test_dependency" }
5822 . file ( "src/main.rs" , "fn main() {} " )
5823 . file ( "src/test_dependency/src/lib.rs" , r
# " " #)
5825 "src/test_dependency/Cargo.toml" ,
5826 & basic_manifest ( "test-dependency" , "0.0.1" ),
5830 p
. cargo ( "build" ). env ( "CARGO_HOME" , "./cargo_home/" ). run ();
5834 fn user_specific_cfgs_are_filtered_out () {
5836 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
5837 . file ( "src/main.rs" , r
# "fn main() {} " #)
5842 assert!(std::env::var_os(" CARGO_CFG_PROC_MACRO ").is_none());
5843 assert!(std::env::var_os(" CARGO_CFG_DEBUG_ASSERTIONS ").is_none());
5849 p
. cargo ( "rustc -- --cfg debug_assertions --cfg proc_macro" )
5851 p
. process (& p
. bin ( "foo" )). run ();
5856 // What happens when stdout or stderr is closed during a build.
5858 // Server to know when rustc has spawned.
5859 let listener
= std
:: net
:: TcpListener
:: bind ( "127.0.0.1:0" ). unwrap ();
5860 let addr
= listener
. local_addr (). unwrap ();
5881 use proc_macro::TokenStream;
5885 pub fn repro(_input: TokenStream) -> TokenStream {
5886 println!(" hello stdout! ");
5887 eprintln!(" hello stderr! ");
5888 // Tell the test we have started.
5889 let mut socket = std::net::TcpStream::connect(" __ADDR__ ").unwrap();
5890 // Wait for the test to tell us to start printing.
5892 drop(socket.read_exact(&mut buf));
5893 let use_stderr = std::env::var(" __CARGO_REPRO_STDERR ").is_ok();
5894 // Emit at least 1MB of data.
5895 // Linux pipes can buffer up to 64KB.
5896 // This test seems to be sensitive to having other threads
5897 // calling fork. My hypothesis is that the stdout/stderr
5898 // file descriptors are duplicated into the child process,
5899 // and during the short window between fork and exec, the
5900 // file descriptor is kept alive long enough for the
5901 // build to finish. It's a half-baked theory, but this
5902 // seems to prevent the spurious errors in CI.
5903 // An alternative solution is to run this test in
5904 // a single-threaded environment.
5905 for i in 0..100000 {
5907 eprintln!(" 0123456789{} ", i);
5909 println!(" 0123456789{} ", i);
5915 . replace ( "__ADDR__" , & addr
. to_string ()),
5918 "src/bin/foobar.rs" ,
5927 // The `stderr` flag here indicates if this should forcefully close stderr or stdout.
5928 let spawn
= | stderr
: bool
| {
5929 let mut cmd
= p
. cargo ( "build" ). build_command ();
5930 cmd
. stdout ( Stdio
:: piped ()). stderr ( Stdio
:: piped ());
5932 cmd
. env ( "__CARGO_REPRO_STDERR" , "1" );
5934 let mut child
= cmd
. spawn (). unwrap ();
5935 // Wait for proc macro to start.
5936 let pm_conn
= listener
. accept (). unwrap (). 0 ;
5937 // Close stderr or stdout.
5939 drop ( child
. stderr
. take ());
5941 drop ( child
. stdout
. take ());
5943 // Tell the proc-macro to continue;
5945 // Read the output from the other channel.
5946 let out
: & mut dyn Read
= if stderr
{
5947 child
. stdout
. as_mut (). unwrap ()
5949 child
. stderr
. as_mut (). unwrap ()
5951 let mut result
= String
:: new ();
5952 out
. read_to_string (& mut result
). unwrap ();
5953 let status
= child
. wait (). unwrap ();
5954 assert
!(! status
. success ());
5958 let stderr
= spawn ( false );
5959 compare
:: match_unordered (
5961 [COMPILING] foo [..]
5964 [WARNING] build failed, waiting for other jobs to finish...
5971 // Try again with stderr.
5972 p
. build_dir (). rm_rf ();
5973 let stdout
= spawn ( true );
5974 assert_eq
!( stdout
, "hello stdout! \n " );
5978 fn close_output_during_drain () {
5979 // Test to close the output during the build phase (drain_the_queue).
5980 // There was a bug where it would hang.
5982 // Server to know when rustc has spawned.
5983 let listener
= std
:: net
:: TcpListener
:: bind ( "127.0.0.1:0" ). unwrap ();
5984 let addr
= listener
. local_addr (). unwrap ();
5986 // Create a wrapper so the test can know when compiling has started.
5987 let rustc_wrapper
= {
5990 . file ( "Cargo.toml" , & basic_manifest ( "compiler" , "1.0.0" ))
5994 use std::process::Command;
5999 // Only wait on the first dependency.
6000 if matches!(env::var(" CARGO_PKG_NAME ").as_deref(), Ok(" dep ")) {
6001 let mut socket = std::net::TcpStream::connect(" __ADDR__ ").unwrap();
6002 // Wait for the test to tell us to start printing.
6004 drop(socket.read_exact(&mut buf));
6006 let mut cmd = Command::new(" rustc ");
6007 for arg in env::args_os().skip(1) {
6010 std::process::exit(cmd.status().unwrap().code().unwrap());
6013 . replace ( "__ADDR__" , & addr
. to_string ()),
6016 p
. cargo ( "build" ). run ();
6020 Package
:: new ( "dep" , "1.0.0" ). publish ();
6033 . file ( "src/lib.rs" , "" )
6036 // Spawn cargo, wait for the first rustc to start, and then close stderr.
6037 let mut cmd
= process (& cargo_exe ())
6040 . env ( "RUSTC" , rustc_wrapper
)
6042 cmd
. stdout ( Stdio
:: piped ()). stderr ( Stdio
:: piped ());
6043 let mut child
= cmd
. spawn (). expect ( "cargo should spawn" );
6044 // Wait for the rustc wrapper to start.
6045 let rustc_conn
= listener
. accept (). unwrap (). 0 ;
6046 // Close stderr to force an error.
6047 drop ( child
. stderr
. take ());
6048 // Tell the wrapper to continue.
6050 match child
. wait () {
6051 Ok ( status
) => assert
!(! status
. success ()),
6052 Err ( e
) => panic
!( "child wait failed: {} " , e
),
6056 use cargo_test_support
:: registry
:: Dependency
;
6059 fn reduced_reproduction_8249 () {
6060 // https://github.com/rust-lang/cargo/issues/8249
6061 Package
:: new ( "a-src" , "0.1.0" ). links ( "a" ). publish ();
6062 Package
:: new ( "a-src" , "0.2.0" ). links ( "a" ). publish ();
6064 Package
:: new ( "b" , "0.1.0" )
6065 . add_dep ( Dependency
:: new ( "a-src" , "0.1" ). optional ( true ))
6067 Package
:: new ( "b" , "0.2.0" )
6068 . add_dep ( Dependency
:: new ( "a-src" , "0.2" ). optional ( true ))
6071 Package
:: new ( "c" , "1.0.0" )
6072 . add_dep (& Dependency
:: new ( "b" , "0.1.0" ))
6084 b = { version = "*", features = ["a-src"] }
6088 . file ( "src/lib.rs" , "" )
6091 p
. cargo ( "generate-lockfile" ). run ();
6092 cargo_util
:: paths
:: append (& p
. root (). join ( "Cargo.toml" ), b
"c = \" * \" " ). unwrap ();
6093 p
. cargo ( "check" ). run ();
6094 p
. cargo ( "check" ). run ();
6098 fn target_directory_backup_exclusion () {
6100 . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ))
6101 . file ( "src/foo.rs" , & main_file ( r
# "" i am foo "" #, &[]))
6104 // Newly created target/ should have CACHEDIR.TAG inside...
6105 p
. cargo ( "build" ). run ();
6106 let cachedir_tag
= p
. build_dir (). join ( "CACHEDIR.TAG" );
6107 assert
!( cachedir_tag
. is_file ());
6108 assert
!( fs
:: read_to_string (& cachedir_tag
)
6110 . starts_with ( "Signature: 8a477f597d28d172789f06886806bc55" ));
6111 // ...but if target/ already exists CACHEDIR.TAG should not be created in it.
6112 fs
:: remove_file (& cachedir_tag
). unwrap ();
6113 p
. cargo ( "build" ). run ();
6114 assert
!(!& cachedir_tag
. is_file ());
6118 fn simple_terminal_width () {
6120 // --diagnostic-width is stabilized in 1.64
6134 p
. cargo ( "build -Zterminal-width=20" )
6135 . masquerade_as_nightly_cargo ()
6137 . with_stderr_contains ( "3 | ..._: () = 42;" )
6142 fn build_script_o0_default () {
6144 . file ( "src/lib.rs" , "" )
6145 . file ( "build.rs" , "fn main() {} " )
6148 p
. cargo ( "build -v --release" )
6149 . with_stderr_does_not_contain ( "[..]build_script_build[..]opt-level[..]" )
6154 fn build_script_o0_default_even_with_release () {
6167 . file ( "src/lib.rs" , "" )
6168 . file ( "build.rs" , "fn main() {} " )
6171 p
. cargo ( "build -v --release" )
6172 . with_stderr_does_not_contain ( "[..]build_script_build[..]opt-level[..]" )
6177 fn primary_package_env_var () {
6178 // Test that CARGO_PRIMARY_PACKAGE is enabled only for "foo" and not for any dependency.
6180 let is_primary_package
= r
# "
6181 pub fn is_primary_package() -> bool {{
6182 option_env!(" CARGO_PRIMARY_PACKAGE ").is_some()
6186 Package
:: new ( "qux" , "0.1.0" )
6187 . file ( "src/lib.rs" , is_primary_package
)
6190 let baz
= git
:: new ( "baz" , | project
| {
6192 . file ( "Cargo.toml" , & basic_manifest ( "baz" , "0.1.0" ))
6193 . file ( "src/lib.rs" , is_primary_package
)
6206 bar = {{ path = "bar" } }
6207 baz = {{ git = '{} ' }}
6224 fn verify_primary_package() {{
6225 assert!(!bar::is_primary_package());
6226 assert!(!baz::is_primary_package());
6227 assert!(!qux::is_primary_package());
6228 assert!(is_primary_package());
6234 . file ( "bar/Cargo.toml" , & basic_manifest ( "bar" , "0.1.0" ))
6235 . file ( "bar/src/lib.rs" , is_primary_package
)
6238 foo
. cargo ( "test" ). run ();