2019-11-25 02:42:45 +00:00
//! Tests for build.rs scripts.
2021-06-16 02:23:17 +00:00
use cargo_test_support ::compare ::assert_match_exact ;
2023-01-22 15:12:57 +00:00
use cargo_test_support ::install ::cargo_home ;
2021-06-15 23:23:06 +00:00
use cargo_test_support ::paths ::CargoPathExt ;
2019-09-12 17:14:29 +00:00
use cargo_test_support ::registry ::Package ;
2021-06-18 19:14:58 +00:00
use cargo_test_support ::tools ;
Make cargo forward pre-existing CARGO if set
Currently, Cargo will always set `$CARGO` to point to what it detects
its own path to be (using `std::env::current_exe`). Unfortunately, this
runs into trouble when Cargo is used as a library, or when `current_exe`
is not actually the binary itself (e.g., when invoked through Valgrind
or `ld.so`), since `$CARGO` will not point at something that can be used
as `cargo`. This, in turn, means that users can't currently rely on
`$CARGO` to do the right thing, and will sometimes have to invoke
`cargo` directly from `$PATH` instead, which may not reflect the `cargo`
that's currently in use.
This patch makes Cargo re-use the existing value of `$CARGO` if it's
already set in the environment. For Cargo subcommands, this will mean
that the initial invocation of `cargo` in `cargo foo` will set `$CARGO`,
and then Cargo-as-a-library inside of `cargo-foo` will inherit that
(correct) value instead of overwriting it with the incorrect value
`cargo-foo`. For other execution environments that do not have `cargo`
in their call stack, it gives them the opportunity to set a working
value for `$CARGO`.
One note about the implementation of this is that the test suite now
needs to override `$CARGO` explicitly so that the _user's_ `$CARGO` does
not interfere with the contents of the tests. It _could_ remove `$CARGO`
instead, but overriding it seemed less error-prone.
Fixes #10119.
Fixes #10113.
2022-10-25 18:49:23 +00:00
use cargo_test_support ::{
basic_manifest , cargo_exe , cross_compile , is_coarse_mtime , project , project_in ,
} ;
2020-12-12 21:59:51 +00:00
use cargo_test_support ::{ rustc_host , sleep_ms , slow_cpu_multiplier , symlink_supported } ;
Make cargo forward pre-existing CARGO if set
Currently, Cargo will always set `$CARGO` to point to what it detects
its own path to be (using `std::env::current_exe`). Unfortunately, this
runs into trouble when Cargo is used as a library, or when `current_exe`
is not actually the binary itself (e.g., when invoked through Valgrind
or `ld.so`), since `$CARGO` will not point at something that can be used
as `cargo`. This, in turn, means that users can't currently rely on
`$CARGO` to do the right thing, and will sometimes have to invoke
`cargo` directly from `$PATH` instead, which may not reflect the `cargo`
that's currently in use.
This patch makes Cargo re-use the existing value of `$CARGO` if it's
already set in the environment. For Cargo subcommands, this will mean
that the initial invocation of `cargo` in `cargo foo` will set `$CARGO`,
and then Cargo-as-a-library inside of `cargo-foo` will inherit that
(correct) value instead of overwriting it with the incorrect value
`cargo-foo`. For other execution environments that do not have `cargo`
in their call stack, it gives them the opportunity to set a working
value for `$CARGO`.
One note about the implementation of this is that the test suite now
needs to override `$CARGO` explicitly so that the _user's_ `$CARGO` does
not interfere with the contents of the tests. It _could_ remove `$CARGO`
instead, but overriding it seemed less error-prone.
Fixes #10119.
Fixes #10113.
2022-10-25 18:49:23 +00:00
use cargo_util ::paths ::{ self , remove_dir_all } ;
2021-03-20 20:43:33 +00:00
use std ::env ;
use std ::fs ;
use std ::io ;
use std ::thread ;
2014-10-22 18:32:40 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn custom_build_script_failed ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2014-10-22 21:32:57 +00:00
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ " wycats@example.com " ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/main.rs " , " fn main() {} " )
2018-07-25 00:30:32 +00:00
. file ( " build.rs " , " fn main() { std::process::exit(101); } " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_status ( 101 )
2018-09-03 09:38:29 +00:00
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2018-09-08 02:42:26 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ CWD ] )
2019-09-25 01:17:36 +00:00
[ RUNNING ] ` rustc - - crate - name build_script_build build . rs [ .. ] - - crate - type bin [ .. ] `
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` [ .. ] / build - script - build `
2018-09-08 02:42:26 +00:00
[ ERROR ] failed to run custom build command for ` foo v0 . 5.0 ( [ CWD ] ) `
2019-04-30 17:59:25 +00:00
2022-03-21 14:17:37 +00:00
Caused by :
process didn ' t exit successfully : ` [ .. ] / build - script - build ` ( exit [ .. ] : 101 ) " ,
)
. run ( ) ;
}
#[ cargo_test ]
fn custom_build_script_failed_backtraces_message ( ) {
// In this situation (no dependency sharing), debuginfo is turned off in
// `dev.build-override`. However, if an error occurs running e.g. a build
// script, and backtraces are opted into: a message explaining how to
// improve backtraces is also displayed.
let p = project ( )
. file (
" Cargo.toml " ,
r #"
[ package ]
name = " foo "
version = " 0.5.0 "
authors = [ " wycats@example.com " ]
build = " build.rs "
" #,
)
. file ( " src/main.rs " , " fn main() {} " )
. file ( " build.rs " , " fn main() { std::process::exit(101); } " )
. build ( ) ;
p . cargo ( " build -v " )
. env ( " RUST_BACKTRACE " , " 1 " )
. with_status ( 101 )
. with_stderr (
" \
[ COMPILING ] foo v0 . 5.0 ( [ CWD ] )
[ RUNNING ] ` rustc - - crate - name build_script_build build . rs [ .. ] - - crate - type bin [ .. ] `
[ RUNNING ] ` [ .. ] / build - script - build `
[ ERROR ] failed to run custom build command for ` foo v0 . 5.0 ( [ CWD ] ) `
2023-01-31 21:38:30 +00:00
note : To improve backtraces for build dependencies , set the \
CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG = true environment variable [ .. ]
Caused by :
process didn ' t exit successfully : ` [ .. ] / build - script - build ` ( exit [ .. ] : 101 ) " ,
)
. run ( ) ;
p . cargo ( " check -v " )
. env ( " RUST_BACKTRACE " , " 1 " )
. with_status ( 101 )
. with_stderr (
" \
[ COMPILING ] foo v0 . 5.0 ( [ CWD ] )
[ RUNNING ] ` [ .. ] / build - script - build `
[ ERROR ] failed to run custom build command for ` foo v0 . 5.0 ( [ CWD ] ) `
note : To improve backtraces for build dependencies , set the \
CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG = true environment variable [ .. ]
2022-03-21 14:17:37 +00:00
2023-01-31 22:09:54 +00:00
Caused by :
process didn ' t exit successfully : ` [ .. ] / build - script - build ` ( exit [ .. ] : 101 ) " ,
)
. run ( ) ;
}
#[ cargo_test ]
fn custom_build_script_failed_backtraces_message_with_debuginfo ( ) {
// This is the same test as `custom_build_script_failed_backtraces_message` above, this time
// ensuring that the message dedicated to improving backtraces by requesting debuginfo is not
// shown when debuginfo is already turned on.
let p = project ( )
. file (
" Cargo.toml " ,
r #"
[ package ]
name = " foo "
version = " 0.5.0 "
authors = [ " wycats@example.com " ]
build = " build.rs "
" #,
)
. file ( " src/main.rs " , " fn main() {} " )
. file ( " build.rs " , " fn main() { std::process::exit(101); } " )
. build ( ) ;
p . cargo ( " build -v " )
. env ( " RUST_BACKTRACE " , " 1 " )
. env ( " CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG " , " true " )
. with_status ( 101 )
. with_stderr (
" \
[ COMPILING ] foo v0 . 5.0 ( [ CWD ] )
[ RUNNING ] ` rustc - - crate - name build_script_build build . rs [ .. ] - - crate - type bin [ .. ] `
[ RUNNING ] ` [ .. ] / build - script - build `
[ ERROR ] failed to run custom build command for ` foo v0 . 5.0 ( [ CWD ] ) `
2019-04-30 17:59:25 +00:00
Caused by :
2021-03-26 16:18:37 +00:00
process didn ' t exit successfully : ` [ .. ] / build - script - build ` ( exit [ .. ] : 101 ) " ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-10-22 21:32:57 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn custom_build_env_vars ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2014-10-22 21:32:57 +00:00
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ " wycats@example.com " ]
2014-10-22 21:32:57 +00:00
2020-09-27 00:59:58 +00:00
[ features ]
bar_feat = [ " bar/foo " ]
2014-10-22 21:32:57 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies . bar ]
path = " bar "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/main.rs " , " fn main() {} " )
2018-03-14 15:17:44 +00:00
. file (
" bar/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2014-10-22 21:32:57 +00:00
2020-09-27 00:59:58 +00:00
name = " bar "
version = " 0.5.0 "
authors = [ " wycats@example.com " ]
build = " build.rs "
2014-10-22 21:32:57 +00:00
2020-09-27 00:59:58 +00:00
[ features ]
foo = [ ]
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " bar/src/lib.rs " , " pub fn hello() {} " ) ;
2014-10-22 21:32:57 +00:00
Make cargo forward pre-existing CARGO if set
Currently, Cargo will always set `$CARGO` to point to what it detects
its own path to be (using `std::env::current_exe`). Unfortunately, this
runs into trouble when Cargo is used as a library, or when `current_exe`
is not actually the binary itself (e.g., when invoked through Valgrind
or `ld.so`), since `$CARGO` will not point at something that can be used
as `cargo`. This, in turn, means that users can't currently rely on
`$CARGO` to do the right thing, and will sometimes have to invoke
`cargo` directly from `$PATH` instead, which may not reflect the `cargo`
that's currently in use.
This patch makes Cargo re-use the existing value of `$CARGO` if it's
already set in the environment. For Cargo subcommands, this will mean
that the initial invocation of `cargo` in `cargo foo` will set `$CARGO`,
and then Cargo-as-a-library inside of `cargo-foo` will inherit that
(correct) value instead of overwriting it with the incorrect value
`cargo-foo`. For other execution environments that do not have `cargo`
in their call stack, it gives them the opportunity to set a working
value for `$CARGO`.
One note about the implementation of this is that the test suite now
needs to override `$CARGO` explicitly so that the _user's_ `$CARGO` does
not interfere with the contents of the tests. It _could_ remove `$CARGO`
instead, but overriding it seemed less error-prone.
Fixes #10119.
Fixes #10113.
2022-10-25 18:49:23 +00:00
let cargo = cargo_exe ( ) . canonicalize ( ) . unwrap ( ) ;
let cargo = cargo . to_str ( ) . unwrap ( ) ;
let rustc = paths ::resolve_executable ( " rustc " . as_ref ( ) )
. unwrap ( )
. canonicalize ( )
. unwrap ( ) ;
let rustc = rustc . to_str ( ) . unwrap ( ) ;
2018-03-14 15:17:44 +00:00
let file_content = format! (
Make cargo forward pre-existing CARGO if set
Currently, Cargo will always set `$CARGO` to point to what it detects
its own path to be (using `std::env::current_exe`). Unfortunately, this
runs into trouble when Cargo is used as a library, or when `current_exe`
is not actually the binary itself (e.g., when invoked through Valgrind
or `ld.so`), since `$CARGO` will not point at something that can be used
as `cargo`. This, in turn, means that users can't currently rely on
`$CARGO` to do the right thing, and will sometimes have to invoke
`cargo` directly from `$PATH` instead, which may not reflect the `cargo`
that's currently in use.
This patch makes Cargo re-use the existing value of `$CARGO` if it's
already set in the environment. For Cargo subcommands, this will mean
that the initial invocation of `cargo` in `cargo foo` will set `$CARGO`,
and then Cargo-as-a-library inside of `cargo-foo` will inherit that
(correct) value instead of overwriting it with the incorrect value
`cargo-foo`. For other execution environments that do not have `cargo`
in their call stack, it gives them the opportunity to set a working
value for `$CARGO`.
One note about the implementation of this is that the test suite now
needs to override `$CARGO` explicitly so that the _user's_ `$CARGO` does
not interfere with the contents of the tests. It _could_ remove `$CARGO`
instead, but overriding it seemed less error-prone.
Fixes #10119.
Fixes #10113.
2022-10-25 18:49:23 +00:00
r ##"
2015-02-06 07:27:53 +00:00
use std ::env ;
2015-02-27 01:04:25 +00:00
use std ::path ::Path ;
2014-10-22 21:32:57 +00:00
fn main ( ) { {
2015-02-13 04:10:07 +00:00
let _target = env ::var ( " TARGET " ) . unwrap ( ) ;
let _ncpus = env ::var ( " NUM_JOBS " ) . unwrap ( ) ;
2015-02-27 01:04:25 +00:00
let _dir = env ::var ( " CARGO_MANIFEST_DIR " ) . unwrap ( ) ;
2014-10-22 21:32:57 +00:00
2015-02-13 04:10:07 +00:00
let opt = env ::var ( " OPT_LEVEL " ) . unwrap ( ) ;
2015-02-27 01:04:25 +00:00
assert_eq! ( opt , " 0 " ) ;
2014-10-22 21:32:57 +00:00
2015-02-13 04:10:07 +00:00
let opt = env ::var ( " PROFILE " ) . unwrap ( ) ;
2015-03-21 03:23:53 +00:00
assert_eq! ( opt , " debug " ) ;
2014-10-22 21:32:57 +00:00
2015-02-13 04:10:07 +00:00
let debug = env ::var ( " DEBUG " ) . unwrap ( ) ;
2015-02-27 01:04:25 +00:00
assert_eq! ( debug , " true " ) ;
2014-10-22 21:32:57 +00:00
2015-02-13 04:10:07 +00:00
let out = env ::var ( " OUT_DIR " ) . unwrap ( ) ;
2015-02-27 01:04:25 +00:00
assert! ( out . starts_with ( r "{0}" ) ) ;
2020-04-17 01:41:03 +00:00
assert! ( Path ::new ( & out ) . is_dir ( ) ) ;
2014-10-22 21:32:57 +00:00
2015-02-13 04:10:07 +00:00
let _host = env ::var ( " HOST " ) . unwrap ( ) ;
2014-12-03 18:09:46 +00:00
2015-02-13 04:10:07 +00:00
let _feat = env ::var ( " CARGO_FEATURE_FOO " ) . unwrap ( ) ;
2016-07-09 17:19:30 +00:00
Make cargo forward pre-existing CARGO if set
Currently, Cargo will always set `$CARGO` to point to what it detects
its own path to be (using `std::env::current_exe`). Unfortunately, this
runs into trouble when Cargo is used as a library, or when `current_exe`
is not actually the binary itself (e.g., when invoked through Valgrind
or `ld.so`), since `$CARGO` will not point at something that can be used
as `cargo`. This, in turn, means that users can't currently rely on
`$CARGO` to do the right thing, and will sometimes have to invoke
`cargo` directly from `$PATH` instead, which may not reflect the `cargo`
that's currently in use.
This patch makes Cargo re-use the existing value of `$CARGO` if it's
already set in the environment. For Cargo subcommands, this will mean
that the initial invocation of `cargo` in `cargo foo` will set `$CARGO`,
and then Cargo-as-a-library inside of `cargo-foo` will inherit that
(correct) value instead of overwriting it with the incorrect value
`cargo-foo`. For other execution environments that do not have `cargo`
in their call stack, it gives them the opportunity to set a working
value for `$CARGO`.
One note about the implementation of this is that the test suite now
needs to override `$CARGO` explicitly so that the _user's_ `$CARGO` does
not interfere with the contents of the tests. It _could_ remove `$CARGO`
instead, but overriding it seemed less error-prone.
Fixes #10119.
Fixes #10113.
2022-10-25 18:49:23 +00:00
let cargo = env ::var ( " CARGO " ) . unwrap ( ) ;
if env ::var_os ( " CHECK_CARGO_IS_RUSTC " ) . is_some ( ) { {
assert_eq! ( cargo , r # "{rustc}"# ) ;
} } else { {
assert_eq! ( cargo , r # "{cargo}"# ) ;
} }
2017-11-29 20:32:28 +00:00
2016-07-09 17:19:30 +00:00
let rustc = env ::var ( " RUSTC " ) . unwrap ( ) ;
assert_eq! ( rustc , " rustc " ) ;
let rustdoc = env ::var ( " RUSTDOC " ) . unwrap ( ) ;
assert_eq! ( rustdoc , " rustdoc " ) ;
2018-04-23 15:11:10 +00:00
2021-06-18 19:14:58 +00:00
assert! ( env ::var ( " RUSTC_WRAPPER " ) . is_err ( ) ) ;
2021-07-06 16:25:03 +00:00
assert! ( env ::var ( " RUSTC_WORKSPACE_WRAPPER " ) . is_err ( ) ) ;
2021-06-18 19:14:58 +00:00
2018-04-23 15:11:10 +00:00
assert! ( env ::var ( " RUSTC_LINKER " ) . is_err ( ) ) ;
2021-06-18 19:14:58 +00:00
2021-06-29 19:08:50 +00:00
assert! ( env ::var ( " RUSTFLAGS " ) . is_err ( ) ) ;
let rustflags = env ::var ( " CARGO_ENCODED_RUSTFLAGS " ) . unwrap ( ) ;
2021-06-18 19:14:58 +00:00
assert_eq! ( rustflags , " " ) ;
2014-10-22 21:32:57 +00:00
} }
Make cargo forward pre-existing CARGO if set
Currently, Cargo will always set `$CARGO` to point to what it detects
its own path to be (using `std::env::current_exe`). Unfortunately, this
runs into trouble when Cargo is used as a library, or when `current_exe`
is not actually the binary itself (e.g., when invoked through Valgrind
or `ld.so`), since `$CARGO` will not point at something that can be used
as `cargo`. This, in turn, means that users can't currently rely on
`$CARGO` to do the right thing, and will sometimes have to invoke
`cargo` directly from `$PATH` instead, which may not reflect the `cargo`
that's currently in use.
This patch makes Cargo re-use the existing value of `$CARGO` if it's
already set in the environment. For Cargo subcommands, this will mean
that the initial invocation of `cargo` in `cargo foo` will set `$CARGO`,
and then Cargo-as-a-library inside of `cargo-foo` will inherit that
(correct) value instead of overwriting it with the incorrect value
`cargo-foo`. For other execution environments that do not have `cargo`
in their call stack, it gives them the opportunity to set a working
value for `$CARGO`.
One note about the implementation of this is that the test suite now
needs to override `$CARGO` explicitly so that the _user's_ `$CARGO` does
not interfere with the contents of the tests. It _could_ remove `$CARGO`
instead, but overriding it seemed less error-prone.
Fixes #10119.
Fixes #10113.
2022-10-25 18:49:23 +00:00
" ##,
2018-03-14 15:17:44 +00:00
p . root ( )
. join ( " target " )
. join ( " debug " )
. join ( " build " )
2021-06-24 16:56:14 +00:00
. display ( ) ,
2018-03-14 15:17:44 +00:00
) ;
2014-10-22 21:32:57 +00:00
2017-07-22 03:12:21 +00:00
let p = p . file ( " bar/build.rs " , & file_content ) . build ( ) ;
2014-10-22 21:32:57 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build --features bar_feat " ) . run ( ) ;
Make cargo forward pre-existing CARGO if set
Currently, Cargo will always set `$CARGO` to point to what it detects
its own path to be (using `std::env::current_exe`). Unfortunately, this
runs into trouble when Cargo is used as a library, or when `current_exe`
is not actually the binary itself (e.g., when invoked through Valgrind
or `ld.so`), since `$CARGO` will not point at something that can be used
as `cargo`. This, in turn, means that users can't currently rely on
`$CARGO` to do the right thing, and will sometimes have to invoke
`cargo` directly from `$PATH` instead, which may not reflect the `cargo`
that's currently in use.
This patch makes Cargo re-use the existing value of `$CARGO` if it's
already set in the environment. For Cargo subcommands, this will mean
that the initial invocation of `cargo` in `cargo foo` will set `$CARGO`,
and then Cargo-as-a-library inside of `cargo-foo` will inherit that
(correct) value instead of overwriting it with the incorrect value
`cargo-foo`. For other execution environments that do not have `cargo`
in their call stack, it gives them the opportunity to set a working
value for `$CARGO`.
One note about the implementation of this is that the test suite now
needs to override `$CARGO` explicitly so that the _user's_ `$CARGO` does
not interfere with the contents of the tests. It _could_ remove `$CARGO`
instead, but overriding it seemed less error-prone.
Fixes #10119.
Fixes #10113.
2022-10-25 18:49:23 +00:00
p . cargo ( " build --features bar_feat " )
// we use rustc since $CARGO is only used if it points to a path that exists
. env ( " CHECK_CARGO_IS_RUSTC " , " 1 " )
. env ( cargo ::CARGO_ENV , rustc )
. run ( ) ;
2018-04-24 06:18:33 +00:00
}
2021-06-18 19:14:58 +00:00
#[ cargo_test ]
fn custom_build_env_var_rustflags ( ) {
let rustflags = " --cfg=special " ;
let rustflags_alt = " --cfg=notspecial " ;
let p = project ( )
. file (
" .cargo/config " ,
& format! (
r #"
[ build ]
rustflags = [ " {} " ]
" #,
rustflags
) ,
)
. file (
" build.rs " ,
& format! (
r #"
use std ::env ;
fn main ( ) { {
// Static assertion that exactly one of the cfg paths is always taken.
2021-06-29 19:08:50 +00:00
assert! ( env ::var ( " RUSTFLAGS " ) . is_err ( ) ) ;
2021-06-18 19:14:58 +00:00
let x ;
#[ cfg(special) ]
2021-06-29 19:08:50 +00:00
{ { assert_eq! ( env ::var ( " CARGO_ENCODED_RUSTFLAGS " ) . unwrap ( ) , " {} " ) ; x = String ::new ( ) ; } }
2021-06-18 19:14:58 +00:00
#[ cfg(notspecial) ]
2021-06-29 19:08:50 +00:00
{ { assert_eq! ( env ::var ( " CARGO_ENCODED_RUSTFLAGS " ) . unwrap ( ) , " {} " ) ; x = String ::new ( ) ; } }
2021-06-18 19:14:58 +00:00
let _ = x ;
} }
" #,
rustflags , rustflags_alt ,
) ,
)
. file ( " src/lib.rs " , " " )
. build ( ) ;
p . cargo ( " check " ) . run ( ) ;
// RUSTFLAGS overrides build.rustflags, so --cfg=special shouldn't be passed
p . cargo ( " check " ) . env ( " RUSTFLAGS " , rustflags_alt ) . run ( ) ;
}
2021-06-29 19:08:50 +00:00
#[ cargo_test ]
2021-06-29 19:26:50 +00:00
fn custom_build_env_var_encoded_rustflags ( ) {
// NOTE: We use "-Clink-arg=-B nope" here rather than, say, "-A missing_docs", since for the
// latter it won't matter if the whitespace accidentally gets split, as rustc will do the right
// thing either way.
2021-06-29 19:08:50 +00:00
let p = project ( )
. file (
" .cargo/config " ,
r #"
[ build ]
2021-06-29 19:26:50 +00:00
rustflags = [ " -Clink-arg=-B nope " , " --cfg=foo " ]
2021-06-29 19:08:50 +00:00
" #,
)
. file (
" build.rs " ,
r #"
use std ::env ;
fn main ( ) { {
2021-06-29 19:26:50 +00:00
assert_eq! ( env ::var ( " CARGO_ENCODED_RUSTFLAGS " ) . unwrap ( ) , " -Clink-arg=-B nope \x1f --cfg=foo " ) ;
2021-06-29 19:08:50 +00:00
} }
" #,
)
. file ( " src/lib.rs " , " " )
. build ( ) ;
p . cargo ( " check " ) . run ( ) ;
}
2021-06-18 19:14:58 +00:00
#[ cargo_test ]
fn custom_build_env_var_rustc_wrapper ( ) {
let wrapper = tools ::echo_wrapper ( ) ;
let p = project ( )
. file (
" build.rs " ,
2021-06-18 19:40:29 +00:00
r #"
use std ::env ;
2021-06-18 19:14:58 +00:00
2021-06-18 19:40:29 +00:00
fn main ( ) { {
assert_eq! (
2021-06-24 16:55:57 +00:00
env ::var ( " RUSTC_WRAPPER " ) . unwrap ( ) ,
2021-06-18 19:40:29 +00:00
env ::var ( " CARGO_RUSTC_WRAPPER_CHECK " ) . unwrap ( )
) ;
} }
" #,
2021-06-18 19:14:58 +00:00
)
. file ( " src/lib.rs " , " " )
. build ( ) ;
2021-06-18 19:40:29 +00:00
p . cargo ( " check " )
. env ( " CARGO_BUILD_RUSTC_WRAPPER " , & wrapper )
. env ( " CARGO_RUSTC_WRAPPER_CHECK " , & wrapper )
. run ( ) ;
2021-06-18 19:14:58 +00:00
}
2021-07-06 16:25:03 +00:00
#[ cargo_test ]
fn custom_build_env_var_rustc_workspace_wrapper ( ) {
let wrapper = tools ::echo_wrapper ( ) ;
2021-07-12 16:34:39 +00:00
// Workspace wrapper should be set for any crate we're operating directly on.
2021-07-06 16:25:03 +00:00
let p = project ( )
. file (
" build.rs " ,
r #"
use std ::env ;
fn main ( ) { {
assert_eq! (
env ::var ( " RUSTC_WORKSPACE_WRAPPER " ) . unwrap ( ) ,
env ::var ( " CARGO_RUSTC_WORKSPACE_WRAPPER_CHECK " ) . unwrap ( )
) ;
} }
" #,
)
. file ( " src/lib.rs " , " " )
. build ( ) ;
p . cargo ( " check " )
. env ( " CARGO_BUILD_RUSTC_WORKSPACE_WRAPPER " , & wrapper )
. env ( " CARGO_RUSTC_WORKSPACE_WRAPPER_CHECK " , & wrapper )
. run ( ) ;
2021-07-12 16:34:39 +00:00
// But should not be set for a crate from the registry, as then it's not in a workspace.
Package ::new ( " bar " , " 0.1.0 " )
. file (
" Cargo.toml " ,
r #"
[ package ]
name = " bar "
version = " 0.1.0 "
links = " a "
" #,
)
. file (
" build.rs " ,
r #"
use std ::env ;
fn main ( ) { {
assert! ( env ::var ( " RUSTC_WORKSPACE_WRAPPER " ) . is_err ( ) ) ;
} }
" #,
)
. file ( " src/lib.rs " , " " )
. publish ( ) ;
let p = project ( )
. file (
" Cargo.toml " ,
r #"
[ package ]
name = " foo "
version = " 0.1.0 "
[ dependencies ]
bar = " 0.1 "
" #,
)
. file ( " src/lib.rs " , " " )
. build ( ) ;
p . cargo ( " check " )
. env ( " CARGO_BUILD_RUSTC_WORKSPACE_WRAPPER " , & wrapper )
. run ( ) ;
2021-07-06 16:25:03 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-04-24 06:18:33 +00:00
fn custom_build_env_var_rustc_linker ( ) {
2018-08-28 09:20:03 +00:00
if cross_compile ::disabled ( ) {
return ;
}
2018-04-23 15:11:10 +00:00
let target = cross_compile ::alternate ( ) ;
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-04-23 15:11:10 +00:00
. file (
" .cargo/config " ,
& format! (
r #"
[ target . { } ]
linker = " /path/to/linker "
" #,
target
2018-08-28 09:20:03 +00:00
) ,
2018-12-08 11:19:47 +00:00
)
. file (
2018-04-23 15:11:10 +00:00
" build.rs " ,
r #"
use std ::env ;
fn main ( ) {
2018-04-23 16:28:38 +00:00
assert! ( env ::var ( " RUSTC_LINKER " ) . unwrap ( ) . ends_with ( " /path/to/linker " ) ) ;
2018-04-23 15:11:10 +00:00
}
2018-08-28 09:20:03 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-04-23 15:11:10 +00:00
. build ( ) ;
// no crate type set => linker never called => build succeeds if and
// only if build.rs succeeds, despite linker binary not existing.
2018-08-28 09:20:03 +00:00
p . cargo ( " build --target " ) . arg ( & target ) . run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-10-27 14:13:37 +00:00
2023-08-22 03:01:33 +00:00
// Only run this test on linux, since it's difficult to construct
// a case suitable for all platforms.
// See:https://github.com/rust-lang/cargo/pull/12535#discussion_r1306618264
#[ cargo_test ]
#[ cfg(target_os = " linux " ) ]
fn custom_build_env_var_rustc_linker_with_target_cfg ( ) {
if cross_compile ::disabled ( ) {
return ;
}
let target = cross_compile ::alternate ( ) ;
let p = project ( )
. file (
" .cargo/config " ,
r #"
[ target . ' cfg ( target_pointer_width = " 32 " ) ' ]
linker = " /path/to/linker "
" #,
)
. file (
" build.rs " ,
r #"
use std ::env ;
fn main ( ) {
assert! ( env ::var ( " RUSTC_LINKER " ) . unwrap ( ) . ends_with ( " /path/to/linker " ) ) ;
}
" #,
)
. file ( " src/lib.rs " , " " )
. build ( ) ;
// no crate type set => linker never called => build succeeds if and
// only if build.rs succeeds, despite linker binary not existing.
p . cargo ( " build --target " ) . arg ( & target ) . run ( ) ;
}
2021-04-02 03:06:31 +00:00
#[ cargo_test ]
fn custom_build_env_var_rustc_linker_bad_host_target ( ) {
let target = rustc_host ( ) ;
let p = project ( )
. file (
" .cargo/config " ,
& format! (
r #"
[ target . { } ]
linker = " /path/to/linker "
" #,
target
) ,
)
2022-02-17 18:22:03 +00:00
. file ( " build.rs " , " fn main() {} " )
2021-04-02 03:06:31 +00:00
. file ( " src/lib.rs " , " " )
. build ( ) ;
// build.rs should fail since host == target when no target is set
p . cargo ( " build --verbose " )
. with_status ( 101 )
. with_stderr_contains (
" \
[ COMPILING ] foo v0 . 0.1 ( [ CWD ] )
[ RUNNING ] ` rustc - - crate - name build_script_build build . rs [ .. ] - - crate - type bin [ .. ] - C linker = [ .. ] / path / to / linker [ .. ] `
[ ERROR ] linker ` [ .. ] / path / to / linker ` not found
"
)
. run ( ) ;
}
#[ cargo_test ]
fn custom_build_env_var_rustc_linker_host_target ( ) {
let target = rustc_host ( ) ;
let p = project ( )
. file (
" .cargo/config " ,
& format! (
r #"
2021-04-23 13:23:13 +00:00
target - applies - to - host = false
2021-04-02 03:06:31 +00:00
[ target . { } ]
linker = " /path/to/linker "
" #,
target
) ,
)
. file (
" build.rs " ,
r #"
use std ::env ;
fn main ( ) {
assert! ( env ::var ( " RUSTC_LINKER " ) . unwrap ( ) . ends_with ( " /path/to/linker " ) ) ;
}
" #,
)
. file ( " src/lib.rs " , " " )
. build ( ) ;
// no crate type set => linker never called => build succeeds if and
// only if build.rs succeeds, despite linker binary not existing.
2022-02-17 18:10:53 +00:00
p . cargo ( " build -Z target-applies-to-host --target " )
. arg ( & target )
2022-07-16 02:32:23 +00:00
. masquerade_as_nightly_cargo ( & [ " target-applies-to-host " ] )
2022-02-17 18:10:53 +00:00
. run ( ) ;
2021-04-02 03:06:31 +00:00
}
2021-04-23 13:23:13 +00:00
#[ cargo_test ]
fn custom_build_env_var_rustc_linker_host_target_env ( ) {
let target = rustc_host ( ) ;
let p = project ( )
. file (
" .cargo/config " ,
& format! (
r #"
[ target . { } ]
linker = " /path/to/linker "
" #,
target
) ,
)
. file (
" build.rs " ,
r #"
use std ::env ;
fn main ( ) {
assert! ( env ::var ( " RUSTC_LINKER " ) . unwrap ( ) . ends_with ( " /path/to/linker " ) ) ;
}
" #,
)
. file ( " src/lib.rs " , " " )
. build ( ) ;
// no crate type set => linker never called => build succeeds if and
// only if build.rs succeeds, despite linker binary not existing.
2022-02-17 18:10:53 +00:00
p . cargo ( " build -Z target-applies-to-host --target " )
. env ( " CARGO_TARGET_APPLIES_TO_HOST " , " false " )
. arg ( & target )
2022-07-16 02:32:23 +00:00
. masquerade_as_nightly_cargo ( & [ " target-applies-to-host " ] )
2022-02-17 18:10:53 +00:00
. run ( ) ;
2021-04-23 13:23:13 +00:00
}
2021-05-01 18:25:57 +00:00
#[ cargo_test ]
fn custom_build_invalid_host_config_feature_flag ( ) {
let target = rustc_host ( ) ;
let p = project ( )
. file (
" .cargo/config " ,
& format! (
r #"
[ target . { } ]
linker = " /path/to/linker "
" #,
target
) ,
)
2022-02-17 18:22:03 +00:00
. file ( " build.rs " , " fn main() {} " )
2021-05-01 18:25:57 +00:00
. file ( " src/lib.rs " , " " )
. build ( ) ;
// build.rs should fail due to -Zhost-config being set without -Ztarget-applies-to-host
2022-02-17 18:10:53 +00:00
p . cargo ( " build -Z host-config --target " )
. arg ( & target )
2022-07-16 02:32:23 +00:00
. masquerade_as_nightly_cargo ( & [ " host-config " ] )
2022-02-17 18:10:53 +00:00
. with_status ( 101 )
. with_stderr_contains (
" \
2022-02-24 00:36:14 +00:00
error : the - Zhost - config flag requires the - Ztarget - applies - to - host flag to be set
2021-05-01 18:25:57 +00:00
" ,
2022-02-17 18:10:53 +00:00
)
. run ( ) ;
2021-05-01 18:25:57 +00:00
}
2021-04-23 13:23:13 +00:00
#[ cargo_test ]
2022-02-24 00:35:41 +00:00
fn custom_build_linker_host_target_with_bad_host_config ( ) {
2021-04-23 13:23:13 +00:00
let target = rustc_host ( ) ;
let p = project ( )
. file (
" .cargo/config " ,
& format! (
r #"
[ host ]
linker = " /path/to/host/linker "
[ target . { } ]
linker = " /path/to/target/linker "
" #,
target
) ,
)
2022-02-17 18:22:03 +00:00
. file ( " build.rs " , " fn main() {} " )
2021-04-23 13:23:13 +00:00
. file ( " src/lib.rs " , " " )
. build ( ) ;
2022-02-16 23:35:53 +00:00
// build.rs should fail due to bad host linker being set
2022-02-17 18:10:53 +00:00
p . cargo ( " build -Z target-applies-to-host -Z host-config --verbose --target " )
2021-04-23 13:23:13 +00:00
. arg ( & target )
2022-07-16 02:32:23 +00:00
. masquerade_as_nightly_cargo ( & [ " target-applies-to-host " , " host-config " ] )
2021-04-23 13:23:13 +00:00
. with_status ( 101 )
. with_stderr_contains (
" \
[ COMPILING ] foo v0 . 0.1 ( [ CWD ] )
2022-02-16 23:35:53 +00:00
[ RUNNING ] ` rustc - - crate - name build_script_build build . rs [ .. ] - - crate - type bin [ .. ] - C linker = [ .. ] / path / to / host / linker [ .. ] `
[ ERROR ] linker ` [ .. ] / path / to / host / linker ` not found
2021-04-23 13:23:13 +00:00
"
)
. run ( ) ;
}
2021-04-02 03:06:31 +00:00
#[ cargo_test ]
2022-02-24 00:35:41 +00:00
fn custom_build_linker_bad_host ( ) {
2021-04-02 03:06:31 +00:00
let target = rustc_host ( ) ;
let p = project ( )
. file (
" .cargo/config " ,
& format! (
r #"
[ host ]
linker = " /path/to/host/linker "
[ target . { } ]
linker = " /path/to/target/linker "
" #,
target
) ,
)
2022-02-17 18:22:03 +00:00
. file ( " build.rs " , " fn main() {} " )
2021-04-02 03:06:31 +00:00
. file ( " src/lib.rs " , " " )
. build ( ) ;
// build.rs should fail due to bad host linker being set
2022-02-17 18:10:53 +00:00
p . cargo ( " build -Z target-applies-to-host -Z host-config --verbose --target " )
2021-04-21 06:18:30 +00:00
. arg ( & target )
2022-07-16 02:32:23 +00:00
. masquerade_as_nightly_cargo ( & [ " target-applies-to-host " , " host-config " ] )
2021-04-21 06:18:30 +00:00
. with_status ( 101 )
. with_stderr_contains (
" \
2021-04-02 03:06:31 +00:00
[ COMPILING ] foo v0 . 0.1 ( [ CWD ] )
[ RUNNING ] ` rustc - - crate - name build_script_build build . rs [ .. ] - - crate - type bin [ .. ] - C linker = [ .. ] / path / to / host / linker [ .. ] `
[ ERROR ] linker ` [ .. ] / path / to / host / linker ` not found
"
2021-04-21 06:18:30 +00:00
)
. run ( ) ;
2021-04-02 03:06:31 +00:00
}
#[ cargo_test ]
2022-02-24 00:35:41 +00:00
fn custom_build_linker_bad_host_with_arch ( ) {
2021-04-02 03:06:31 +00:00
let target = rustc_host ( ) ;
let p = project ( )
. file (
" .cargo/config " ,
& format! (
r #"
[ host ]
linker = " /path/to/host/linker "
[ host . { } ]
linker = " /path/to/host/arch/linker "
[ target . { } ]
linker = " /path/to/target/linker "
" #,
target , target
) ,
)
2022-02-17 18:22:03 +00:00
. file ( " build.rs " , " fn main() {} " )
2021-04-02 03:06:31 +00:00
. file ( " src/lib.rs " , " " )
. build ( ) ;
// build.rs should fail due to bad host linker being set
2022-02-17 18:10:53 +00:00
p . cargo ( " build -Z target-applies-to-host -Z host-config --verbose --target " )
2021-04-21 06:18:30 +00:00
. arg ( & target )
2022-07-16 02:32:23 +00:00
. masquerade_as_nightly_cargo ( & [ " target-applies-to-host " , " host-config " ] )
2021-04-21 06:18:30 +00:00
. with_status ( 101 )
. with_stderr_contains (
" \
2021-04-02 03:06:31 +00:00
[ COMPILING ] foo v0 . 0.1 ( [ CWD ] )
[ RUNNING ] ` rustc - - crate - name build_script_build build . rs [ .. ] - - crate - type bin [ .. ] - C linker = [ .. ] / path / to / host / arch / linker [ .. ] `
[ ERROR ] linker ` [ .. ] / path / to / host / arch / linker ` not found
"
2021-04-21 06:18:30 +00:00
)
. run ( ) ;
2021-04-02 03:06:31 +00:00
}
#[ cargo_test ]
fn custom_build_env_var_rustc_linker_cross_arch_host ( ) {
let target = rustc_host ( ) ;
let cross_target = cross_compile ::alternate ( ) ;
let p = project ( )
. file (
" .cargo/config " ,
& format! (
r #"
[ host . { } ]
linker = " /path/to/host/arch/linker "
[ target . { } ]
linker = " /path/to/target/linker "
" #,
cross_target , target
) ,
)
. file (
" build.rs " ,
r #"
use std ::env ;
fn main ( ) {
assert! ( env ::var ( " RUSTC_LINKER " ) . unwrap ( ) . ends_with ( " /path/to/target/linker " ) ) ;
}
" #,
)
. file ( " src/lib.rs " , " " )
. build ( ) ;
2022-02-17 18:22:03 +00:00
// build.rs should be built fine since cross target != host target.
// assertion should succeed since it's still passed the target linker
2022-02-17 18:10:53 +00:00
p . cargo ( " build -Z target-applies-to-host -Z host-config --verbose --target " )
. arg ( & target )
2022-07-16 02:32:23 +00:00
. masquerade_as_nightly_cargo ( & [ " target-applies-to-host " , " host-config " ] )
2022-02-17 18:10:53 +00:00
. run ( ) ;
2021-04-02 03:06:31 +00:00
}
#[ cargo_test ]
2022-02-24 00:35:41 +00:00
fn custom_build_linker_bad_cross_arch_host ( ) {
2021-04-02 03:06:31 +00:00
let target = rustc_host ( ) ;
let cross_target = cross_compile ::alternate ( ) ;
let p = project ( )
. file (
" .cargo/config " ,
& format! (
r #"
[ host ]
linker = " /path/to/host/linker "
[ host . { } ]
linker = " /path/to/host/arch/linker "
[ target . { } ]
linker = " /path/to/target/linker "
" #,
cross_target , target
) ,
)
2022-02-17 18:22:03 +00:00
. file ( " build.rs " , " fn main() {} " )
2021-04-02 03:06:31 +00:00
. file ( " src/lib.rs " , " " )
. build ( ) ;
// build.rs should fail due to bad host linker being set
2022-02-17 18:10:53 +00:00
p . cargo ( " build -Z target-applies-to-host -Z host-config --verbose --target " )
2021-04-21 06:18:30 +00:00
. arg ( & target )
2022-07-16 02:32:23 +00:00
. masquerade_as_nightly_cargo ( & [ " target-applies-to-host " , " host-config " ] )
2021-04-21 06:18:30 +00:00
. with_status ( 101 )
. with_stderr_contains (
" \
2021-04-02 03:06:31 +00:00
[ COMPILING ] foo v0 . 0.1 ( [ CWD ] )
[ RUNNING ] ` rustc - - crate - name build_script_build build . rs [ .. ] - - crate - type bin [ .. ] - C linker = [ .. ] / path / to / host / linker [ .. ] `
[ ERROR ] linker ` [ .. ] / path / to / host / linker ` not found
"
2021-04-21 06:18:30 +00:00
)
. run ( ) ;
2021-04-02 03:06:31 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn custom_build_script_wrong_rustc_flags ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2014-10-27 14:13:37 +00:00
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ " wycats@example.com " ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/main.rs " , " fn main() {} " )
2018-08-28 09:20:03 +00:00
. file (
" build.rs " ,
2023-05-30 00:20:54 +00:00
r # "fn main() { println!("cargo::rustc-flags=-aaa -bbb"); }"# ,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2014-10-27 14:13:37 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build " )
. with_status ( 101 )
2018-09-03 09:38:29 +00:00
. with_stderr_contains (
2019-07-13 23:00:47 +00:00
" [ERROR] Only `-l` and `-L` flags are allowed in build script of `foo v0.5.0 ([CWD])`: \
2018-03-14 15:17:44 +00:00
` - aaa - bbb ` " ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-10-27 15:29:03 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn custom_build_script_rustc_flags ( ) {
2018-07-20 14:25:51 +00:00
let p = project ( )
2018-08-29 17:56:48 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2014-10-27 15:29:03 +00:00
2020-09-27 00:59:58 +00:00
name = " bar "
version = " 0.5.0 "
authors = [ " wycats@example.com " ]
2014-10-27 15:29:03 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies . foo ]
path = " foo "
" #,
2019-08-04 18:09:25 +00:00
)
. file ( " src/main.rs " , " fn main() {} " )
2018-08-29 17:56:48 +00:00
. file (
" foo/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2014-10-27 15:29:03 +00:00
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ " wycats@example.com " ]
build = " build.rs "
" #,
2019-08-04 18:09:25 +00:00
)
. file ( " foo/src/lib.rs " , " " )
2018-08-29 17:56:48 +00:00
. file (
" foo/build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-flags=-l nonexistinglib -L /dummy/path1 -L /dummy/path2 " ) ;
2020-09-27 00:59:58 +00:00
}
" #,
2019-08-04 18:09:25 +00:00
)
. build ( ) ;
2014-10-27 15:29:03 +00:00
2018-08-29 17:56:48 +00:00
p . cargo ( " build --verbose " )
. with_stderr (
" \
2019-08-04 18:09:25 +00:00
[ COMPILING ] foo [ .. ]
[ RUNNING ] ` rustc - - crate - name build_script_build foo / build . rs [ .. ]
[ RUNNING ] ` [ .. ] build - script - build `
[ RUNNING ] ` rustc - - crate - name foo foo / src / lib . rs [ .. ] \
- L dependency = [ CWD ] / target / debug / deps \
- L / dummy / path1 - L / dummy / path2 - l nonexistinglib `
[ COMPILING ] bar [ .. ]
[ RUNNING ] ` rustc - - crate - name bar src / main . rs [ .. ] \
- L dependency = [ CWD ] / target / debug / deps \
- - extern foo = [ .. ] libfoo - [ .. ] \
- L / dummy / path1 - L / dummy / path2 `
[ FINISHED ] dev [ .. ]
2018-08-29 17:56:48 +00:00
" ,
2019-08-04 18:09:25 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-10-31 17:49:04 +00:00
2019-08-17 02:25:53 +00:00
#[ cargo_test ]
fn custom_build_script_rustc_flags_no_space ( ) {
let p = project ( )
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2019-08-17 02:25:53 +00:00
2020-09-27 00:59:58 +00:00
name = " bar "
version = " 0.5.0 "
authors = [ " wycats@example.com " ]
2019-08-17 02:25:53 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies . foo ]
path = " foo "
" #,
2019-08-17 02:25:53 +00:00
)
. file ( " src/main.rs " , " fn main() {} " )
. file (
" foo/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2019-08-17 02:25:53 +00:00
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ " wycats@example.com " ]
build = " build.rs "
" #,
2019-08-17 02:25:53 +00:00
)
. file ( " foo/src/lib.rs " , " " )
. file (
" foo/build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-flags=-lnonexistinglib -L/dummy/path1 -L/dummy/path2 " ) ;
2020-09-27 00:59:58 +00:00
}
" #,
2019-08-17 02:25:53 +00:00
)
. build ( ) ;
p . cargo ( " build --verbose " )
. with_stderr (
" \
[ COMPILING ] foo [ .. ]
[ RUNNING ] ` rustc - - crate - name build_script_build foo / build . rs [ .. ]
[ RUNNING ] ` [ .. ] build - script - build `
[ RUNNING ] ` rustc - - crate - name foo foo / src / lib . rs [ .. ] \
- L dependency = [ CWD ] / target / debug / deps \
- L / dummy / path1 - L / dummy / path2 - l nonexistinglib `
2019-08-04 18:09:25 +00:00
[ COMPILING ] bar [ .. ]
[ RUNNING ] ` rustc - - crate - name bar src / main . rs [ .. ] \
- L dependency = [ CWD ] / target / debug / deps \
- - extern foo = [ .. ] libfoo - [ .. ] \
- L / dummy / path1 - L / dummy / path2 `
[ FINISHED ] dev [ .. ]
2018-08-29 17:56:48 +00:00
" ,
2019-08-04 18:09:25 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-10-31 17:49:04 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn links_no_build_cmd ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
links = " a "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2014-10-31 17:49:04 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build " )
. with_status ( 101 )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2019-08-01 16:11:22 +00:00
[ ERROR ] failed to parse manifest at ` [ .. ] / foo / Cargo . toml `
Caused by :
package ` foo v0 . 5.0 ( [ CWD ] ) ` specifies that it links to ` a ` but does \
2014-10-31 17:49:04 +00:00
not have a custom build script
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-10-31 17:49:04 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn links_duplicates ( ) {
2018-01-26 03:50:55 +00:00
// this tests that the links_duplicates are caught at resolver time
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
links = " a "
build = " build.rs "
2017-09-20 19:28:30 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies . a - sys ]
path = " a-sys "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2017-09-20 19:28:30 +00:00
. file ( " build.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" a-sys/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " a-sys "
version = " 0.5.0 "
authors = [ ]
links = " a "
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " a-sys/src/lib.rs " , " " )
2017-07-22 03:12:21 +00:00
. file ( " a-sys/build.rs " , " " )
. build ( ) ;
2017-09-20 19:28:30 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build " ) . with_status ( 101 )
2017-09-20 19:28:30 +00:00
. with_stderr ( " \
2018-02-14 04:11:48 +00:00
error : failed to select a version for ` a - sys ` .
2018-02-15 03:28:59 +00:00
.. . required by package ` foo v0 . 5.0 ( [ .. ] ) `
versions that meet the requirements ` * ` are : 0. 5.0
the package ` a - sys ` links to the native library ` a ` , but it conflicts with a previous package which links to ` a ` as well :
package ` foo v0 . 5.0 ( [ .. ] ) `
2023-11-14 17:26:00 +00:00
Only one package in the dependency graph may specify the same links value . This helps ensure that only one copy of a native library is linked in the final binary . Try to adjust your dependencies so that only one package uses the ` links = \ " a \" ` value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.
2018-02-15 03:28:59 +00:00
failed to select a version for ` a - sys ` which could resolve this conflict
2018-08-28 09:20:03 +00:00
" ).run();
2017-09-20 19:28:30 +00:00
}
2019-08-01 16:11:22 +00:00
#[ cargo_test ]
fn links_duplicates_old_registry ( ) {
// Test old links validator. See `validate_links`.
Package ::new ( " bar " , " 0.1.0 " )
. file (
" Cargo.toml " ,
r #"
[ package ]
name = " bar "
version = " 0.1.0 "
links = " a "
" #,
)
. file ( " build.rs " , " fn main() {} " )
. file ( " src/lib.rs " , " " )
. publish ( ) ;
let p = project ( )
. file (
" Cargo.toml " ,
r #"
[ package ]
name = " foo "
version = " 0.1.0 "
links = " a "
[ dependencies ]
bar = " 0.1 "
" #,
)
. file ( " build.rs " , " fn main() {} " )
. file ( " src/lib.rs " , " " )
. build ( ) ;
p . cargo ( " build " )
. with_status ( 101 )
. with_stderr (
" \
[ UPDATING ] ` [ .. ] ` index
[ DOWNLOADING ] crates .. .
[ DOWNLOADED ] bar v0 . 1.0 ( [ .. ] )
[ ERROR ] multiple packages link to native library ` a ` , \
but a native library can be linked only once
package ` bar v0 . 1.0 `
2021-08-27 16:17:39 +00:00
.. . which satisfies dependency ` bar = \ " ^0.1 \" ` (locked to 0.1.0) of package `foo v0.1.0 ([..]foo)`
2019-08-01 16:11:22 +00:00
links to native library ` a `
package ` foo v0 . 1.0 ( [ .. ] foo ) `
also links to native library ` a `
" ,
)
. run ( ) ;
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2017-09-20 19:28:30 +00:00
fn links_duplicates_deep_dependency ( ) {
2018-01-26 03:50:55 +00:00
// this tests that the links_duplicates are caught at resolver time
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
links = " a "
build = " build.rs "
2014-10-31 17:49:04 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies . a ]
path = " a "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2014-10-31 17:49:04 +00:00
. file ( " build.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" a/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " a "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
2017-09-20 19:28:30 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies . a - sys ]
path = " a-sys "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " a/src/lib.rs " , " " )
2017-09-20 19:28:30 +00:00
. file ( " a/build.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" a/a-sys/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " a-sys "
version = " 0.5.0 "
authors = [ ]
links = " a "
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " a/a-sys/src/lib.rs " , " " )
2017-07-22 03:12:21 +00:00
. file ( " a/a-sys/build.rs " , " " )
. build ( ) ;
2014-10-31 17:49:04 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build " ) . with_status ( 101 )
2016-05-12 17:06:36 +00:00
. with_stderr ( " \
2018-02-14 04:11:48 +00:00
error : failed to select a version for ` a - sys ` .
2018-02-15 03:28:59 +00:00
.. . required by package ` a v0 . 5.0 ( [ .. ] ) `
2021-08-22 16:10:15 +00:00
.. . which satisfies path dependency ` a ` of package ` foo v0 . 5.0 ( [ .. ] ) `
2018-02-15 03:28:59 +00:00
versions that meet the requirements ` * ` are : 0. 5.0
the package ` a - sys ` links to the native library ` a ` , but it conflicts with a previous package which links to ` a ` as well :
package ` foo v0 . 5.0 ( [ .. ] ) `
2023-11-14 17:26:00 +00:00
Only one package in the dependency graph may specify the same links value . This helps ensure that only one copy of a native library is linked in the final binary . Try to adjust your dependencies so that only one package uses the ` links = \ " a \" ` value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.
2018-02-15 03:28:59 +00:00
failed to select a version for ` a - sys ` which could resolve this conflict
2018-08-28 09:20:03 +00:00
" ).run();
2016-05-25 20:55:42 +00:00
}
2014-10-31 17:49:04 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn overrides_and_links ( ) {
2016-05-26 00:06:25 +00:00
let target = rustc_host ( ) ;
2014-10-31 19:25:40 +00:00
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
2014-10-31 19:25:40 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies . a ]
path = " a "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
use std ::env ;
fn main ( ) {
assert_eq! ( env ::var ( " DEP_FOO_FOO " ) . ok ( ) . expect ( " FOO missing " ) ,
" bar " ) ;
assert_eq! ( env ::var ( " DEP_FOO_BAR " ) . ok ( ) . expect ( " BAR missing " ) ,
" baz " ) ;
}
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" .cargo/config " ,
& format! (
r #"
2020-09-27 00:59:58 +00:00
[ target . { } . foo ]
rustc - flags = " -L foo -L bar "
foo = " bar "
bar = " baz "
" #,
2018-03-14 15:17:44 +00:00
target
) ,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" a/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " a "
version = " 0.5.0 "
authors = [ ]
links = " foo "
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " a/src/lib.rs " , " " )
2017-07-22 03:12:21 +00:00
. file ( " a/build.rs " , " not valid rust code " )
. build ( ) ;
2014-10-31 19:25:40 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2014-11-06 17:17:34 +00:00
[ .. ]
[ .. ]
[ .. ]
[ .. ]
[ .. ]
2017-02-08 02:12:48 +00:00
[ RUNNING ] ` rustc - - crate - name foo [ .. ] - L foo - L bar `
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-10-31 22:51:13 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn unused_overrides ( ) {
2016-05-26 00:06:25 +00:00
let target = rustc_host ( ) ;
2014-11-10 17:36:36 +00:00
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2014-11-10 17:36:36 +00:00
. file ( " build.rs " , " fn main() {} " )
2018-03-14 15:17:44 +00:00
. file (
" .cargo/config " ,
& format! (
r #"
2020-09-27 00:59:58 +00:00
[ target . { } . foo ]
rustc - flags = " -L foo -L bar "
foo = " bar "
bar = " baz "
" #,
2018-03-14 15:17:44 +00:00
target
) ,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2014-11-10 17:36:36 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " ) . run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-11-10 17:36:36 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn links_passes_env_vars ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
2014-10-31 22:51:13 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies . a ]
path = " a "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
use std ::env ;
fn main ( ) {
assert_eq! ( env ::var ( " DEP_FOO_FOO " ) . unwrap ( ) , " bar " ) ;
assert_eq! ( env ::var ( " DEP_FOO_BAR " ) . unwrap ( ) , " baz " ) ;
}
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" a/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " a "
version = " 0.5.0 "
authors = [ ]
links = " foo "
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " a/src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" a/build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
use std ::env ;
fn main ( ) {
let lib = env ::var ( " CARGO_MANIFEST_LINKS " ) . unwrap ( ) ;
assert_eq! ( lib , " foo " ) ;
2016-05-17 18:54:43 +00:00
2023-05-30 00:20:54 +00:00
println! ( " cargo::metadata=foo=bar " ) ;
println! ( " cargo::metadata=bar=baz " ) ;
2020-09-27 00:59:58 +00:00
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2014-10-31 22:51:13 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " ) . run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-10-31 19:25:40 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn only_rerun_build_script ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-07-25 00:30:32 +00:00
. file ( " build.rs " , " fn main() {} " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2014-10-31 23:20:13 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " ) . run ( ) ;
2016-05-26 00:06:25 +00:00
p . root ( ) . move_into_the_past ( ) ;
2014-10-31 23:20:13 +00:00
2020-04-17 04:10:11 +00:00
p . change_file ( " some-new-file " , " " ) ;
2016-05-26 00:06:25 +00:00
p . root ( ) . move_into_the_past ( ) ;
2014-10-31 23:20:13 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2022-11-21 17:39:02 +00:00
[ DIRTY ] foo v0 . 5.0 ( [ CWD ] ) : the precalculated components changed
2018-09-08 02:42:26 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ CWD ] )
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` [ .. ] / build - script - build `
2016-11-29 23:11:58 +00:00
[ RUNNING ] ` rustc - - crate - name foo [ .. ] `
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-10-31 23:20:13 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn rebuild_continues_to_pass_env_vars ( ) {
2018-08-28 09:20:03 +00:00
let a = project ( )
. at ( " a " )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " a "
version = " 0.5.0 "
authors = [ ]
links = " foo "
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
use std ::time ::Duration ;
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::metadata=foo=bar " ) ;
println! ( " cargo::metadata=bar=baz " ) ;
2020-09-27 00:59:58 +00:00
std ::thread ::sleep ( Duration ::from_millis ( 500 ) ) ;
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2016-05-26 00:06:25 +00:00
a . root ( ) . move_into_the_past ( ) ;
2014-10-31 23:20:13 +00:00
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
& format! (
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
[ dependencies . a ]
path = ' { } '
" #,
2018-03-14 15:17:44 +00:00
a . root ( ) . display ( )
) ,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
use std ::env ;
fn main ( ) {
assert_eq! ( env ::var ( " DEP_FOO_FOO " ) . unwrap ( ) , " bar " ) ;
assert_eq! ( env ::var ( " DEP_FOO_BAR " ) . unwrap ( ) , " baz " ) ;
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2014-10-31 23:20:13 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " ) . run ( ) ;
2016-05-26 00:06:25 +00:00
p . root ( ) . move_into_the_past ( ) ;
2014-10-31 23:20:13 +00:00
2020-04-17 04:10:11 +00:00
p . change_file ( " some-new-file " , " " ) ;
2016-05-26 00:06:25 +00:00
p . root ( ) . move_into_the_past ( ) ;
2014-10-31 23:20:13 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " ) . run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-11-01 00:36:48 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn testing_and_such ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-07-25 00:30:32 +00:00
. file ( " build.rs " , " fn main() {} " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2014-11-01 00:36:48 +00:00
2015-03-23 18:33:22 +00:00
println! ( " build " ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " ) . run ( ) ;
2016-05-26 00:06:25 +00:00
p . root ( ) . move_into_the_past ( ) ;
2014-11-01 00:36:48 +00:00
2020-04-17 04:10:11 +00:00
p . change_file ( " src/lib.rs " , " " ) ;
2016-05-26 00:06:25 +00:00
p . root ( ) . move_into_the_past ( ) ;
2014-11-01 00:36:48 +00:00
2015-03-23 18:33:22 +00:00
println! ( " test " ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " test -vj1 " )
. with_stderr (
" \
2022-11-21 17:39:02 +00:00
[ DIRTY ] foo v0 . 5.0 ( [ CWD ] ) : the precalculated components changed
2018-09-08 02:42:26 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ CWD ] )
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` [ .. ] / build - script - build `
2016-11-29 23:11:58 +00:00
[ RUNNING ] ` rustc - - crate - name foo [ .. ] `
[ RUNNING ] ` rustc - - crate - name foo [ .. ] `
2019-06-07 18:09:47 +00:00
[ FINISHED ] test [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` [ .. ] / foo - [ .. ] [ EXE ] `
2016-05-19 00:51:07 +00:00
[ DOCTEST ] foo
2019-09-12 17:38:10 +00:00
[ RUNNING ] ` rustdoc [ .. ] - - test [ .. ] ` " ,
2018-12-08 11:19:47 +00:00
)
. with_stdout_contains_n ( " running 0 tests " , 2 )
2018-08-28 09:20:03 +00:00
. run ( ) ;
2014-11-01 00:36:48 +00:00
2015-03-23 18:33:22 +00:00
println! ( " doc " ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " doc -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2018-09-08 02:42:26 +00:00
[ DOCUMENTING ] foo v0 . 5.0 ( [ CWD ] )
2016-05-11 16:55:43 +00:00
[ RUNNING ] ` rustdoc [ .. ] `
2017-01-18 19:37:52 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2023-10-19 15:40:49 +00:00
[ GENERATED ] [ CWD ] / target / doc / foo / index . html
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2018-03-14 15:17:44 +00:00
2020-04-17 04:10:11 +00:00
p . change_file ( " src/main.rs " , " fn main() {} " ) ;
2015-03-23 18:33:22 +00:00
println! ( " run " ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " run " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2018-09-08 02:42:26 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ CWD ] )
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` target / debug / foo [ EXE ] `
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-10-31 23:20:13 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn propagation_of_l_flags ( ) {
2016-05-26 00:06:25 +00:00
let target = rustc_host ( ) ;
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
[ dependencies . a ]
path = " a "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" a/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " a "
version = " 0.5.0 "
authors = [ ]
links = " bar "
build = " build.rs "
2014-11-01 00:36:48 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies . b ]
path = " ../b "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " a/src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
2018-08-28 09:20:03 +00:00
" a/build.rs " ,
2023-05-30 00:20:54 +00:00
r # "fn main() { println!("cargo::rustc-flags=-L bar"); }"# ,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" b/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " b "
version = " 0.5.0 "
authors = [ ]
links = " foo "
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " b/src/lib.rs " , " " )
2014-11-01 00:36:48 +00:00
. file ( " b/build.rs " , " bad file " )
2018-03-14 15:17:44 +00:00
. file (
" .cargo/config " ,
& format! (
r #"
2020-09-27 00:59:58 +00:00
[ target . { } . foo ]
rustc - flags = " -L foo "
" #,
2018-03-14 15:17:44 +00:00
target
) ,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2014-11-01 00:36:48 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v -j1 " )
. with_stderr_contains (
2018-03-14 15:17:44 +00:00
" \
2016-11-29 23:11:58 +00:00
[ RUNNING ] ` rustc - - crate - name a [ .. ] - L bar [ .. ] - L foo [ .. ] `
2018-09-08 02:42:26 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ CWD ] )
2016-11-29 23:11:58 +00:00
[ RUNNING ] ` rustc - - crate - name foo [ .. ] - L bar - L foo `
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-11-01 01:39:39 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn propagation_of_l_flags_new ( ) {
2016-05-26 00:06:25 +00:00
let target = rustc_host ( ) ;
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
[ dependencies . a ]
path = " a "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" a/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " a "
version = " 0.5.0 "
authors = [ ]
links = " bar "
build = " build.rs "
2015-03-10 17:12:47 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies . b ]
path = " ../b "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " a/src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" a/build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-link-search=bar " ) ;
2020-09-27 00:59:58 +00:00
}
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" b/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " b "
version = " 0.5.0 "
authors = [ ]
links = " foo "
build = " build.rs "
" #,
)
2018-12-08 11:19:47 +00:00
. file ( " b/src/lib.rs " , " " )
2015-03-10 17:12:47 +00:00
. file ( " b/build.rs " , " bad file " )
2018-03-14 15:17:44 +00:00
. file (
" .cargo/config " ,
& format! (
r #"
2020-09-27 00:59:58 +00:00
[ target . { } . foo ]
rustc - link - search = [ " foo " ]
" #,
2018-03-14 15:17:44 +00:00
target
) ,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2015-03-10 17:12:47 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v -j1 " )
. with_stderr_contains (
2018-03-14 15:17:44 +00:00
" \
2016-11-29 23:11:58 +00:00
[ RUNNING ] ` rustc - - crate - name a [ .. ] - L bar [ .. ] - L foo [ .. ] `
2018-09-08 02:42:26 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ CWD ] )
2016-11-29 23:11:58 +00:00
[ RUNNING ] ` rustc - - crate - name foo [ .. ] - L bar - L foo `
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-03-10 17:12:47 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn build_deps_simple ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
[ build - dependencies . a ]
path = " a "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
"
2017-08-27 07:10:54 +00:00
#[ allow(unused_extern_crates) ]
2014-11-01 01:39:39 +00:00
extern crate a ;
fn main ( ) { }
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. file ( " a/Cargo.toml " , & basic_manifest ( " a " , " 0.5.0 " ) )
2017-07-22 03:12:21 +00:00
. file ( " a/src/lib.rs " , " " )
. build ( ) ;
2014-11-01 01:39:39 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2018-09-08 02:42:26 +00:00
[ COMPILING ] a v0 . 5.0 ( [ CWD ] / a )
2016-11-29 23:11:58 +00:00
[ RUNNING ] ` rustc - - crate - name a [ .. ] `
2018-09-08 02:42:26 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ CWD ] )
2016-11-29 23:11:58 +00:00
[ RUNNING ] ` rustc [ .. ] build . rs [ .. ] - - extern a = [ .. ] `
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` [ .. ] / foo - [ .. ] / build - script - build `
2016-11-29 23:11:58 +00:00
[ RUNNING ] ` rustc - - crate - name foo [ .. ] `
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-11-01 01:39:39 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn build_deps_not_for_normal ( ) {
2016-05-26 00:06:25 +00:00
let target = rustc_host ( ) ;
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
[ build - dependencies . aaaaa ]
path = " a "
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" src/lib.rs " ,
" #[allow(unused_extern_crates)] extern crate aaaaa; " ,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" build.rs " ,
"
2017-08-27 07:10:54 +00:00
#[ allow(unused_extern_crates) ]
2015-02-09 16:16:08 +00:00
extern crate aaaaa ;
2014-11-01 01:39:39 +00:00
fn main ( ) { }
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. file ( " a/Cargo.toml " , & basic_manifest ( " aaaaa " , " 0.5.0 " ) )
2017-07-22 03:12:21 +00:00
. file ( " a/src/lib.rs " , " " )
. build ( ) ;
2014-11-01 01:39:39 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v --target " )
. arg ( & target )
. with_status ( 101 )
. with_stderr_contains ( " [..]can't find crate for `aaaaa`[..] " )
. with_stderr_contains (
" \
2023-08-09 15:19:59 +00:00
[ ERROR ] could not compile ` foo ` ( lib ) due to 1 previous error
2014-11-01 01:39:39 +00:00
Caused by :
2016-09-14 18:10:30 +00:00
process didn ' t exit successfully : [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-11-01 02:16:39 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn build_cmd_with_a_build_cmd ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
2014-11-01 02:16:39 +00:00
2020-09-27 00:59:58 +00:00
[ build - dependencies . a ]
path = " a "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
"
2017-08-27 07:10:54 +00:00
#[ allow(unused_extern_crates) ]
2014-11-01 02:16:39 +00:00
extern crate a ;
fn main ( ) { }
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" a/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " a "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
2014-11-01 02:16:39 +00:00
2020-09-27 00:59:58 +00:00
[ build - dependencies . b ]
path = " ../b "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " a/src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" a/build.rs " ,
" #[allow(unused_extern_crates)] extern crate b; fn main() {} " ,
2018-12-08 11:19:47 +00:00
)
. file ( " b/Cargo.toml " , & basic_manifest ( " b " , " 0.5.0 " ) )
2017-07-22 03:12:21 +00:00
. file ( " b/src/lib.rs " , " " )
. build ( ) ;
2014-11-01 02:16:39 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2018-09-08 02:42:26 +00:00
[ COMPILING ] b v0 . 5.0 ( [ CWD ] / b )
2016-11-29 23:11:58 +00:00
[ RUNNING ] ` rustc - - crate - name b [ .. ] `
2018-09-08 02:42:26 +00:00
[ COMPILING ] a v0 . 5.0 ( [ CWD ] / a )
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` rustc [ .. ] a / build . rs [ .. ] - - extern b = [ .. ] `
[ RUNNING ] ` [ .. ] / a - [ .. ] / build - script - build `
2019-09-25 01:17:36 +00:00
[ RUNNING ] ` rustc - - crate - name a [ .. ] lib . rs [ .. ] - - crate - type lib \
2022-10-15 15:02:14 +00:00
- - emit = [ .. ] link [ .. ] \
2016-08-02 06:22:29 +00:00
- C metadata = [ .. ] \
2018-08-02 09:18:48 +00:00
- - out - dir [ .. ] target / debug / deps \
- L [ .. ] target / debug / deps `
2018-09-08 02:42:26 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ CWD ] )
2019-09-25 01:17:36 +00:00
[ RUNNING ] ` rustc - - crate - name build_script_build build . rs [ .. ] - - crate - type bin \
2020-04-01 18:41:27 +00:00
- - emit = [ .. ] link [ .. ] \
2022-10-15 15:02:14 +00:00
- C metadata = [ .. ] - - out - dir [ .. ] \
2018-08-02 09:18:48 +00:00
- L [ .. ] target / debug / deps \
Always build libraries into the same location
Previously Cargo would compile a library into a different location depending on
whether it was the "root crate" or not. In the ongoing saga of reducing Cargo's
reliance on the idea of a "root crate" this PR is the next step. With workspaces
the root crate of a compliation changes all the time, so the output needs to be
the same whether a crate is at the root or not.
Fixing this inconsistence in turn fixes bugs like #2855 and #2897 which arise
due to this discrepancy. Additionally, Cargo will no longer recompile a library
when it's used as a "root crate" or not.
This is fixed by taking a few steps:
* Everything is now compiled into the `deps` directory, regardless of whether
it's a root output or not.
* If a "root crate" is being compiled, then the relevant outputs are hard-linked
up one level to where they are today. This means that your binaries, dylibs,
staticlibs, etc, will all show up where they used to.
* The `-C metadata` flag is always omitted for path dependencies now. These
dependencies are always path dependencies and already all have unique crate
names. Additionally, they're the only crates in the DAG without metadata, so
there's no need to provide additional metadata. This in turn means that none
of the file names of the generated crates are mangled.
Closes #2855
2016-07-25 20:27:06 +00:00
- - extern a = [ .. ] liba [ .. ] . rlib `
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` [ .. ] / foo - [ .. ] / build - script - build `
2019-09-25 01:17:36 +00:00
[ RUNNING ] ` rustc - - crate - name foo [ .. ] lib . rs [ .. ] - - crate - type lib \
2023-05-31 10:09:35 +00:00
- - emit = [ .. ] link [ .. ] - C debuginfo = 2 [ .. ] \
2016-08-02 06:22:29 +00:00
- C metadata = [ .. ] \
2017-01-03 21:22:58 +00:00
- - out - dir [ .. ] \
2018-08-02 09:18:48 +00:00
- L [ .. ] target / debug / deps `
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-11-01 18:51:58 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn out_dir_is_preserved ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
use std ::env ;
use std ::fs ::File ;
use std ::path ::Path ;
fn main ( ) {
let out = env ::var ( " OUT_DIR " ) . unwrap ( ) ;
File ::create ( Path ::new ( & out ) . join ( " foo " ) ) . unwrap ( ) ;
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2014-11-01 18:51:58 +00:00
// Make the file
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " ) . run ( ) ;
2014-11-01 18:51:58 +00:00
// Change to asserting that it's there
2020-04-17 04:10:11 +00:00
p . change_file (
" build.rs " ,
r #"
use std ::env ;
use std ::fs ::File ;
use std ::path ::Path ;
fn main ( ) {
let out = env ::var ( " OUT_DIR " ) . unwrap ( ) ;
File ::open ( & Path ::new ( & out ) . join ( " foo " ) ) . unwrap ( ) ;
}
" #,
) ;
p . cargo ( " build -v " )
. with_stderr (
" \
2022-11-21 17:39:02 +00:00
[ DIRTY ] foo [ .. ] : the file ` build . rs ` has changed ( [ .. ] )
2020-04-17 04:10:11 +00:00
[ COMPILING ] foo [ .. ]
[ RUNNING ] ` rustc - - crate - name build_script_build [ .. ]
[ RUNNING ] ` [ .. ] / build - script - build `
[ RUNNING ] ` rustc - - crate - name foo [ .. ]
[ FINISHED ] [ .. ]
" ,
)
. run ( ) ;
2014-11-01 18:51:58 +00:00
// Run a fresh build where file should be preserved
2020-04-17 04:10:11 +00:00
p . cargo ( " build -v " )
. with_stderr (
" \
[ FRESH ] foo [ .. ]
[ FINISHED ] [ .. ]
" ,
)
. run ( ) ;
2014-11-01 18:51:58 +00:00
// One last time to make sure it's still there.
2020-04-17 04:10:11 +00:00
p . change_file ( " foo " , " " ) ;
p . cargo ( " build -v " )
. with_stderr (
" \
2022-11-21 17:39:02 +00:00
[ DIRTY ] foo [ .. ] : the precalculated components changed
2020-04-17 04:10:11 +00:00
[ COMPILING ] foo [ .. ]
[ RUNNING ] ` [ .. ] build - script - build `
[ RUNNING ] ` rustc - - crate - name foo [ .. ]
[ FINISHED ] [ .. ]
" ,
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-11-01 18:51:58 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn output_separate_lines ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-flags=-L foo " ) ;
println! ( " cargo::rustc-flags=-l static=foo " ) ;
2020-09-27 00:59:58 +00:00
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_status ( 101 )
. with_stderr_contains (
2018-03-14 15:17:44 +00:00
" \
2018-09-08 02:42:26 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ CWD ] )
2016-11-29 23:11:58 +00:00
[ RUNNING ] ` rustc [ .. ] build . rs [ .. ] `
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` [ .. ] / foo - [ .. ] / build - script - build `
2016-11-29 23:11:58 +00:00
[ RUNNING ] ` rustc - - crate - name foo [ .. ] - L foo - l static = foo `
2016-05-20 13:22:58 +00:00
[ ERROR ] could not find native static library [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-11-04 07:20:19 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn output_separate_lines_new ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-link-search=foo " ) ;
println! ( " cargo::rustc-link-lib=static=foo " ) ;
println! ( " cargo::rustc-link-lib=bar " ) ;
println! ( " cargo::rustc-link-search=bar " ) ;
2020-09-27 00:59:58 +00:00
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2022-05-01 22:54:20 +00:00
// The order of the arguments passed to rustc is important.
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_status ( 101 )
. with_stderr_contains (
2018-03-14 15:17:44 +00:00
" \
2018-09-08 02:42:26 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ CWD ] )
2016-11-29 23:11:58 +00:00
[ RUNNING ] ` rustc [ .. ] build . rs [ .. ] `
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` [ .. ] / foo - [ .. ] / build - script - build `
2022-05-01 22:54:20 +00:00
[ RUNNING ] ` rustc - - crate - name foo [ .. ] - L foo - L bar - l static = foo - l bar `
2016-05-20 13:22:58 +00:00
[ ERROR ] could not find native static library [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-03-10 17:12:47 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn code_generation ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" src/main.rs " ,
r #"
2020-09-27 00:59:58 +00:00
include! ( concat! ( env! ( " OUT_DIR " ) , " /hello.rs " ) ) ;
2014-11-04 07:20:19 +00:00
2020-09-27 00:59:58 +00:00
fn main ( ) {
println! ( " {} " , message ( ) ) ;
}
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
use std ::env ;
use std ::fs ;
use std ::path ::PathBuf ;
2014-11-04 07:20:19 +00:00
2020-09-27 00:59:58 +00:00
fn main ( ) {
let dst = PathBuf ::from ( env ::var ( " OUT_DIR " ) . unwrap ( ) ) ;
fs ::write ( dst . join ( " hello.rs " ) ,
"
pub fn message ( ) -> & 'static str {
\ " Hello, World! \"
}
" )
. unwrap ( ) ;
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2017-02-15 14:16:41 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " run " )
. with_stderr (
" \
2018-09-08 02:42:26 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ CWD ] )
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2023-05-29 19:01:02 +00:00
[ RUNNING ] ` target / debug / foo [ EXE ] ` " ,
2018-12-08 11:19:47 +00:00
)
. with_stdout ( " Hello, World! " )
2018-08-28 09:20:03 +00:00
. run ( ) ;
2014-11-12 12:12:02 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " test " ) . run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-11-10 17:22:04 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn release_with_build_script ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) { }
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2014-11-10 17:22:04 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v --release " ) . run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-11-11 20:51:27 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn build_script_only ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.0.0 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " build.rs " , r # "fn main() {}"# )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_status ( 101 )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2016-05-11 16:55:43 +00:00
[ ERROR ] failed to parse manifest at ` [ .. ] `
2015-01-16 17:43:28 +00:00
Caused by :
2015-05-17 16:01:50 +00:00
no targets specified in the manifest
2018-03-14 15:17:44 +00:00
either src / lib . rs , src / main . rs , a [ lib ] section , or [ [ bin ] ] section must be present " ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-11-11 19:59:31 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn shared_dep_with_a_build_script ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
2014-11-11 19:59:31 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies . a ]
path = " a "
2014-11-11 19:59:31 +00:00
2020-09-27 00:59:58 +00:00
[ build - dependencies . b ]
path = " b "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2014-11-11 19:59:31 +00:00
. file ( " build.rs " , " fn main() {} " )
2018-03-14 15:17:44 +00:00
. file (
" a/Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " a "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " a/build.rs " , " fn main() {} " )
2014-11-11 19:59:31 +00:00
. file ( " a/src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" b/Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " b "
version = " 0.5.0 "
authors = [ ]
2014-11-11 19:59:31 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies . a ]
path = " ../a "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " b/src/lib.rs " , " " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " ) . run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-11-17 17:35:53 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn transitive_dep_host ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
2014-11-17 17:35:53 +00:00
2020-09-27 00:59:58 +00:00
[ build - dependencies . b ]
path = " b "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2014-11-17 17:35:53 +00:00
. file ( " build.rs " , " fn main() {} " )
2018-03-14 15:17:44 +00:00
. file (
" a/Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " a "
version = " 0.5.0 "
authors = [ ]
links = " foo "
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " a/build.rs " , " fn main() {} " )
2014-11-17 17:35:53 +00:00
. file ( " a/src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" b/Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " b "
version = " 0.5.0 "
authors = [ ]
2014-11-17 17:35:53 +00:00
2020-09-27 00:59:58 +00:00
[ lib ]
name = " b "
plugin = true
2014-11-17 17:35:53 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies . a ]
path = " ../a "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " b/src/lib.rs " , " " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " build " ) . run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-11-17 18:34:27 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn test_a_lib_with_a_build_command ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" src/lib.rs " ,
r #"
2020-09-27 00:59:58 +00:00
include! ( concat! ( env! ( " OUT_DIR " ) , " /foo.rs " ) ) ;
2014-11-17 18:34:27 +00:00
2020-09-27 00:59:58 +00:00
/// ```
/// foo::bar();
/// ```
pub fn bar ( ) {
assert_eq! ( foo ( ) , 1 ) ;
}
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
use std ::env ;
use std ::fs ;
use std ::path ::PathBuf ;
2014-11-17 18:34:27 +00:00
2020-09-27 00:59:58 +00:00
fn main ( ) {
let out = PathBuf ::from ( env ::var ( " OUT_DIR " ) . unwrap ( ) ) ;
fs ::write ( out . join ( " foo.rs " ) , " fn foo() -> i32 { 1 } " ) . unwrap ( ) ;
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " test " ) . run ( ) ;
2016-05-25 20:55:42 +00:00
}
2014-12-08 20:34:31 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn test_dev_dep_build_script ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
2014-12-08 20:34:31 +00:00
2020-09-27 00:59:58 +00:00
[ dev - dependencies . a ]
path = " a "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" a/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " a "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " a/build.rs " , " fn main() {} " )
2017-07-22 03:12:21 +00:00
. file ( " a/src/lib.rs " , " " )
. build ( ) ;
2014-12-08 20:34:31 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " test " ) . run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-01-19 23:46:07 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn build_script_with_dynamic_native_dependency ( ) {
2018-08-28 09:20:03 +00:00
let build = project ( )
2018-11-17 23:42:19 +00:00
. at ( " builder " )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " builder "
version = " 0.0.1 "
authors = [ ]
2015-01-19 23:46:07 +00:00
2020-09-27 00:59:58 +00:00
[ lib ]
name = " builder "
crate - type = [ " dylib " ]
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " #[no_mangle] pub extern fn foo() {} " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2015-01-19 23:46:07 +00:00
2018-08-28 09:20:03 +00:00
let foo = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " foo "
version = " 0.0.1 "
authors = [ ]
build = " build.rs "
2015-01-19 23:46:07 +00:00
2020-09-27 00:59:58 +00:00
[ build - dependencies . bar ]
path = " bar "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " build.rs " , " extern crate bar; fn main() { bar::bar() } " )
2015-01-19 23:46:07 +00:00
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" bar/Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " bar "
version = " 0.0.1 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" bar/build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
use std ::env ;
use std ::fs ;
use std ::path ::PathBuf ;
2015-01-19 23:46:07 +00:00
2020-09-27 00:59:58 +00:00
fn main ( ) {
let out_dir = PathBuf ::from ( env ::var ( " OUT_DIR " ) . unwrap ( ) ) ;
let root = PathBuf ::from ( env ::var ( " BUILDER_ROOT " ) . unwrap ( ) ) ;
let file = format! ( " {} builder {} " ,
env ::consts ::DLL_PREFIX ,
env ::consts ::DLL_SUFFIX ) ;
let src = root . join ( & file ) ;
let dst = out_dir . join ( & file ) ;
fs ::copy ( src , dst ) . unwrap ( ) ;
if cfg! ( target_env = " msvc " ) {
fs ::copy ( root . join ( " builder.dll.lib " ) ,
out_dir . join ( " builder.dll.lib " ) ) . unwrap ( ) ;
}
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-link-search=native= {} " , out_dir . display ( ) ) ;
2018-11-17 23:42:19 +00:00
}
2020-09-27 00:59:58 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" bar/src/lib.rs " ,
r #"
2020-09-27 00:59:58 +00:00
pub fn bar ( ) {
#[ cfg_attr(not(target_env = " msvc " ), link(name = " builder " )) ]
#[ cfg_attr(target_env = " msvc " , link(name = " builder.dll " )) ]
extern { fn foo ( ) ; }
unsafe { foo ( ) }
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2017-05-02 15:34:29 +00:00
2018-08-28 09:20:03 +00:00
build
. cargo ( " build -v " )
2019-01-27 18:34:11 +00:00
. env ( " CARGO_LOG " , " cargo::ops::cargo_rustc " )
2018-08-28 09:20:03 +00:00
. run ( ) ;
2015-01-19 23:46:07 +00:00
2018-11-17 23:42:19 +00:00
let root = build . root ( ) . join ( " target " ) . join ( " debug " ) ;
2018-08-28 09:20:03 +00:00
foo . cargo ( " build -v " )
2018-11-17 23:42:19 +00:00
. env ( " BUILDER_ROOT " , root )
2019-01-27 18:34:11 +00:00
. env ( " CARGO_LOG " , " cargo::ops::cargo_rustc " )
2018-08-28 09:20:03 +00:00
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-02-11 05:03:31 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn profile_and_opt_level_set_correctly ( ) {
2018-07-20 17:41:44 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " foo "
version = " 0.0.1 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
use std ::env ;
2015-02-11 05:03:31 +00:00
2020-09-27 00:59:58 +00:00
fn main ( ) {
assert_eq! ( env ::var ( " OPT_LEVEL " ) . unwrap ( ) , " 3 " ) ;
assert_eq! ( env ::var ( " PROFILE " ) . unwrap ( ) , " release " ) ;
assert_eq! ( env ::var ( " DEBUG " ) . unwrap ( ) , " false " ) ;
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " bench " ) . run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-03-02 17:09:05 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-04-30 17:17:43 +00:00
fn profile_debug_0 ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-04-30 17:17:43 +00:00
. file (
" Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " foo "
version = " 0.0.1 "
2018-04-30 17:17:43 +00:00
2020-09-27 00:59:58 +00:00
[ profile . dev ]
debug = 0
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-04-30 17:17:43 +00:00
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
use std ::env ;
2018-04-30 17:17:43 +00:00
2020-09-27 00:59:58 +00:00
fn main ( ) {
assert_eq! ( env ::var ( " OPT_LEVEL " ) . unwrap ( ) , " 0 " ) ;
assert_eq! ( env ::var ( " PROFILE " ) . unwrap ( ) , " debug " ) ;
assert_eq! ( env ::var ( " DEBUG " ) . unwrap ( ) , " false " ) ;
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " build " ) . run ( ) ;
2018-04-30 17:17:43 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn build_script_with_lto ( ) {
2018-07-20 17:41:44 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " foo "
version = " 0.0.1 "
authors = [ ]
build = " build.rs "
2015-03-02 17:09:05 +00:00
2020-09-27 00:59:58 +00:00
[ profile . dev ]
lto = true
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-07-25 00:30:32 +00:00
. file ( " build.rs " , " fn main() {} " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " build " ) . run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-04-13 18:34:33 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn test_duplicate_deps ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.1.0 "
authors = [ ]
build = " build.rs "
2015-04-13 18:34:33 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies . bar ]
path = " bar "
2015-04-13 18:34:33 +00:00
2020-09-27 00:59:58 +00:00
[ build - dependencies . bar ]
path = " bar "
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" src/main.rs " ,
r #"
2020-09-27 00:59:58 +00:00
extern crate bar ;
fn main ( ) { bar ::do_nothing ( ) }
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
extern crate bar ;
fn main ( ) { bar ::do_nothing ( ) }
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " bar/Cargo.toml " , & basic_manifest ( " bar " , " 0.1.0 " ) )
2017-07-22 03:12:21 +00:00
. file ( " bar/src/lib.rs " , " pub fn do_nothing() {} " )
. build ( ) ;
2015-04-13 18:34:33 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build " ) . run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-04-09 21:35:48 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn cfg_feedback ( ) {
2018-07-20 17:41:44 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " foo "
version = " 0.0.1 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/main.rs " , " #[cfg(foo)] fn main() {} " )
2018-08-28 09:20:03 +00:00
. file (
" build.rs " ,
2023-05-30 00:20:54 +00:00
r # "fn main() { println!("cargo::rustc-cfg=foo"); }"# ,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " ) . run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-04-09 21:35:48 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn cfg_override ( ) {
2016-05-26 00:06:25 +00:00
let target = rustc_host ( ) ;
2015-04-09 21:35:48 +00:00
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
links = " a "
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/main.rs " , " #[cfg(foo)] fn main() {} " )
2015-04-09 21:35:48 +00:00
. file ( " build.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" .cargo/config " ,
& format! (
r #"
2020-09-27 00:59:58 +00:00
[ target . { } . a ]
rustc - cfg = [ " foo " ]
" #,
2018-03-14 15:17:44 +00:00
target
) ,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2015-04-09 21:35:48 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " ) . run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-06-10 02:31:47 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn cfg_test ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " foo "
version = " 0.0.1 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-08-28 09:20:03 +00:00
" build.rs " ,
2023-05-30 00:20:54 +00:00
r # "fn main() { println!("cargo::rustc-cfg=foo"); }"# ,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" src/lib.rs " ,
r #"
2020-09-27 00:59:58 +00:00
///
/// ```
/// extern crate foo;
///
/// fn main() {
/// foo::foo()
/// }
/// ```
///
#[ cfg(foo) ]
pub fn foo ( ) { }
#[ cfg(foo) ]
#[ test ]
fn test_foo ( ) {
foo ( )
}
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " tests/test.rs " , " #[cfg(foo)] #[test] fn test_bar() {} " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " test -v " )
2018-09-03 09:38:29 +00:00
. with_stderr (
2018-08-28 09:20:03 +00:00
" \
2018-09-08 02:42:26 +00:00
[ COMPILING ] foo v0 . 0.1 ( [ CWD ] )
2016-05-11 16:55:43 +00:00
[ RUNNING ] [ .. ] build . rs [ .. ]
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` [ .. ] / build - script - build `
2016-05-11 16:55:43 +00:00
[ RUNNING ] [ .. ] - - cfg foo [ .. ]
[ RUNNING ] [ .. ] - - cfg foo [ .. ]
[ RUNNING ] [ .. ] - - cfg foo [ .. ]
2019-06-07 18:09:47 +00:00
[ FINISHED ] test [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` [ .. ] / foo - [ .. ] [ EXE ] `
[ RUNNING ] ` [ .. ] / test - [ .. ] [ EXE ] `
2016-05-19 00:51:07 +00:00
[ DOCTEST ] foo
2018-03-14 15:17:44 +00:00
[ RUNNING ] [ .. ] - - cfg foo [ .. ] " ,
2018-12-08 11:19:47 +00:00
)
. with_stdout_contains ( " test test_foo ... ok " )
2018-08-28 09:20:03 +00:00
. with_stdout_contains ( " test test_bar ... ok " )
. with_stdout_contains_n ( " test [..] ... ok " , 3 )
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-09 18:37:53 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn cfg_doc ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " foo "
version = " 0.0.1 "
authors = [ ]
build = " build.rs "
2015-10-09 18:37:53 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies . bar ]
path = " bar "
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-08-28 09:20:03 +00:00
" build.rs " ,
2023-05-30 00:20:54 +00:00
r # "fn main() { println!("cargo::rustc-cfg=foo"); }"# ,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " #[cfg(foo)] pub fn foo() {} " )
2018-03-14 15:17:44 +00:00
. file (
" bar/Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " bar "
version = " 0.0.1 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-08-28 09:20:03 +00:00
" bar/build.rs " ,
2023-05-30 00:20:54 +00:00
r # "fn main() { println!("cargo::rustc-cfg=bar"); }"# ,
2018-12-08 11:19:47 +00:00
)
. file ( " bar/src/lib.rs " , " #[cfg(bar)] pub fn bar() {} " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " doc " ) . run ( ) ;
2018-08-29 05:53:01 +00:00
assert! ( p . root ( ) . join ( " target/doc " ) . is_dir ( ) ) ;
2018-08-29 06:11:10 +00:00
assert! ( p . root ( ) . join ( " target/doc/foo/fn.foo.html " ) . is_file ( ) ) ;
assert! ( p . root ( ) . join ( " target/doc/bar/fn.bar.html " ) . is_file ( ) ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-09 18:37:53 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn cfg_override_test ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " foo "
version = " 0.0.1 "
authors = [ ]
build = " build.rs "
links = " a "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " build.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" .cargo/config " ,
& format! (
r #"
2020-09-27 00:59:58 +00:00
[ target . { } . a ]
rustc - cfg = [ " foo " ]
" #,
2018-03-14 15:17:44 +00:00
rustc_host ( )
) ,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" src/lib.rs " ,
r #"
2020-09-27 00:59:58 +00:00
///
/// ```
/// extern crate foo;
///
/// fn main() {
/// foo::foo()
/// }
/// ```
///
#[ cfg(foo) ]
pub fn foo ( ) { }
#[ cfg(foo) ]
#[ test ]
fn test_foo ( ) {
foo ( )
}
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " tests/test.rs " , " #[cfg(foo)] #[test] fn test_bar() {} " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " test -v " )
2018-09-03 09:38:29 +00:00
. with_stderr (
2018-08-28 09:20:03 +00:00
" \
2018-09-08 02:42:26 +00:00
[ COMPILING ] foo v0 . 0.1 ( [ CWD ] )
2016-05-11 16:55:43 +00:00
[ RUNNING ] ` [ .. ] `
[ RUNNING ] ` [ .. ] `
[ RUNNING ] ` [ .. ] `
2019-06-07 18:09:47 +00:00
[ FINISHED ] test [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` [ .. ] / foo - [ .. ] [ EXE ] `
[ RUNNING ] ` [ .. ] / test - [ .. ] [ EXE ] `
2016-05-19 00:51:07 +00:00
[ DOCTEST ] foo
2018-03-14 15:17:44 +00:00
[ RUNNING ] [ .. ] - - cfg foo [ .. ] " ,
2018-12-08 11:19:47 +00:00
)
. with_stdout_contains ( " test test_foo ... ok " )
2018-08-28 09:20:03 +00:00
. with_stdout_contains ( " test test_bar ... ok " )
. with_stdout_contains_n ( " test [..] ... ok " , 3 )
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-09 18:37:53 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn cfg_override_doc ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " foo "
version = " 0.0.1 "
authors = [ ]
build = " build.rs "
links = " a "
2015-10-09 18:37:53 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies . bar ]
path = " bar "
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" .cargo/config " ,
& format! (
r #"
2020-09-27 00:59:58 +00:00
[ target . { target } . a ]
rustc - cfg = [ " foo " ]
[ target . { target } . b ]
rustc - cfg = [ " bar " ]
" #,
2018-03-14 15:17:44 +00:00
target = rustc_host ( )
) ,
2018-12-08 11:19:47 +00:00
)
. file ( " build.rs " , " " )
2018-07-25 00:30:32 +00:00
. file ( " src/lib.rs " , " #[cfg(foo)] pub fn foo() {} " )
2018-03-14 15:17:44 +00:00
. file (
" bar/Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " bar "
version = " 0.0.1 "
authors = [ ]
build = " build.rs "
links = " b "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " bar/build.rs " , " " )
2018-07-25 00:30:32 +00:00
. file ( " bar/src/lib.rs " , " #[cfg(bar)] pub fn bar() {} " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " doc " ) . run ( ) ;
2018-08-29 05:53:01 +00:00
assert! ( p . root ( ) . join ( " target/doc " ) . is_dir ( ) ) ;
2018-08-29 06:11:10 +00:00
assert! ( p . root ( ) . join ( " target/doc/foo/fn.foo.html " ) . is_file ( ) ) ;
assert! ( p . root ( ) . join ( " target/doc/bar/fn.bar.html " ) . is_file ( ) ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-09 18:37:53 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2017-04-17 18:48:56 +00:00
fn env_build ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " foo "
version = " 0.0.1 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" src/main.rs " ,
r #"
2020-09-27 00:59:58 +00:00
const FOO : & 'static str = env! ( " FOO " ) ;
fn main ( ) {
println! ( " {} " , FOO ) ;
}
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-08-28 09:20:03 +00:00
" build.rs " ,
2023-05-30 00:20:54 +00:00
r # "fn main() { println!("cargo::rustc-env=FOO=foo"); }"# ,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " ) . run ( ) ;
p . cargo ( " run -v " ) . with_stdout ( " foo \n " ) . run ( ) ;
2017-04-17 18:48:56 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2017-04-17 18:48:56 +00:00
fn env_test ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " foo "
version = " 0.0.1 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-08-28 09:20:03 +00:00
" build.rs " ,
2023-05-30 00:20:54 +00:00
r # "fn main() { println!("cargo::rustc-env=FOO=foo"); }"# ,
2018-12-08 11:19:47 +00:00
)
. file (
2018-08-28 09:20:03 +00:00
" src/lib.rs " ,
r # "pub const FOO: &'static str = env!("FOO"); "# ,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" tests/test.rs " ,
r #"
2020-09-27 00:59:58 +00:00
extern crate foo ;
2017-04-17 18:48:56 +00:00
2020-09-27 00:59:58 +00:00
#[ test ]
fn test_foo ( ) {
assert_eq! ( " foo " , foo ::FOO ) ;
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " test -v " )
2018-09-03 09:38:29 +00:00
. with_stderr (
2018-08-28 09:20:03 +00:00
" \
2018-09-08 02:42:26 +00:00
[ COMPILING ] foo v0 . 0.1 ( [ CWD ] )
2017-04-17 18:48:56 +00:00
[ RUNNING ] [ .. ] build . rs [ .. ]
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` [ .. ] / build - script - build `
2017-05-13 15:51:40 +00:00
[ RUNNING ] [ .. ] - - crate - name foo [ .. ]
[ RUNNING ] [ .. ] - - crate - name foo [ .. ]
[ RUNNING ] [ .. ] - - crate - name test [ .. ]
2019-06-07 18:09:47 +00:00
[ FINISHED ] test [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` [ .. ] / foo - [ .. ] [ EXE ] `
[ RUNNING ] ` [ .. ] / test - [ .. ] [ EXE ] `
2017-04-17 18:48:56 +00:00
[ DOCTEST ] foo
2018-03-14 15:17:44 +00:00
[ RUNNING ] [ .. ] - - crate - name foo [ .. ] " ,
2018-12-08 11:19:47 +00:00
)
. with_stdout_contains_n ( " running 0 tests " , 2 )
2018-08-28 09:20:03 +00:00
. with_stdout_contains ( " test test_foo ... ok " )
. run ( ) ;
2017-04-17 18:48:56 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2017-05-13 15:51:40 +00:00
fn env_doc ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " foo "
version = " 0.0.1 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" src/main.rs " ,
r #"
2020-09-27 00:59:58 +00:00
const FOO : & 'static str = env! ( " FOO " ) ;
fn main ( ) { }
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-08-28 09:20:03 +00:00
" build.rs " ,
2023-05-30 00:20:54 +00:00
r # "fn main() { println!("cargo::rustc-env=FOO=foo"); }"# ,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " doc -v " ) . run ( ) ;
2017-05-13 15:51:40 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn flags_go_into_tests ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
2015-06-10 02:31:47 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies ]
b = { path = " b " }
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2015-06-10 02:31:47 +00:00
. file ( " tests/foo.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" b/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " b "
version = " 0.5.0 "
authors = [ ]
[ dependencies ]
a = { path = " ../a " }
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " b/src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" a/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " a "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " a/src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" a/build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-link-search=test " ) ;
2020-09-27 00:59:58 +00:00
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2015-06-10 02:31:47 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " test -v --test=foo " )
. with_stderr (
" \
2016-05-11 16:55:43 +00:00
[ COMPILING ] a v0 . 5.0 ( [ .. ]
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` rustc [ .. ] a / build . rs [ .. ] `
[ RUNNING ] ` [ .. ] / build - script - build `
[ RUNNING ] ` rustc [ .. ] a / src / lib . rs [ .. ] - L test [ .. ] `
2016-05-11 16:55:43 +00:00
[ COMPILING ] b v0 . 5.0 ( [ .. ]
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` rustc [ .. ] b / src / lib . rs [ .. ] - L test [ .. ] `
2016-05-11 16:55:43 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ .. ]
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` rustc [ .. ] src / lib . rs [ .. ] - L test [ .. ] `
[ RUNNING ] ` rustc [ .. ] tests / foo . rs [ .. ] - L test [ .. ] `
2019-06-07 18:09:47 +00:00
[ FINISHED ] test [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` [ .. ] / foo - [ .. ] [ EXE ] ` " ,
2018-12-08 11:19:47 +00:00
)
. with_stdout_contains ( " running 0 tests " )
2018-08-28 09:20:03 +00:00
. run ( ) ;
2018-03-14 15:17:44 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " test -v -pb --lib " )
. with_stderr (
" \
2016-05-11 16:55:43 +00:00
[ FRESH ] a v0 . 5.0 ( [ .. ]
[ COMPILING ] b v0 . 5.0 ( [ .. ]
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` rustc [ .. ] b / src / lib . rs [ .. ] - L test [ .. ] `
2019-06-07 18:09:47 +00:00
[ FINISHED ] test [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` [ .. ] / b - [ .. ] [ EXE ] ` " ,
2018-12-08 11:19:47 +00:00
)
. with_stdout_contains ( " running 0 tests " )
2018-08-28 09:20:03 +00:00
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-08 06:26:05 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn diamond_passes_args_only_once ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
2015-10-08 06:26:05 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies ]
a = { path = " a " }
b = { path = " b " }
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2015-10-08 06:26:05 +00:00
. file ( " tests/foo.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" a/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " a "
version = " 0.5.0 "
authors = [ ]
[ dependencies ]
b = { path = " ../b " }
c = { path = " ../c " }
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " a/src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" b/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " b "
version = " 0.5.0 "
authors = [ ]
[ dependencies ]
c = { path = " ../c " }
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " b/src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" c/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " c "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" c/build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-link-search=native=test " ) ;
2020-09-27 00:59:58 +00:00
}
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " c/src/lib.rs " , " " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2015-10-08 06:26:05 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2016-05-11 16:55:43 +00:00
[ COMPILING ] c v0 . 5.0 ( [ .. ]
[ RUNNING ] ` rustc [ .. ] `
[ RUNNING ] ` [ .. ] `
[ RUNNING ] ` rustc [ .. ] `
[ COMPILING ] b v0 . 5.0 ( [ .. ]
[ RUNNING ] ` rustc [ .. ] `
[ COMPILING ] a v0 . 5.0 ( [ .. ]
[ RUNNING ] ` rustc [ .. ] `
[ COMPILING ] foo v0 . 5.0 ( [ .. ]
2019-07-17 19:41:27 +00:00
[ RUNNING ] ` [ .. ] rmeta - L native = test `
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-09 21:15:25 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn adding_an_override_invalidates ( ) {
2016-05-26 00:06:25 +00:00
let target = rustc_host ( ) ;
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
links = " foo "
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2015-10-09 21:15:25 +00:00
. file ( " .cargo/config " , " " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-link-search=native=foo " ) ;
2020-09-27 00:59:58 +00:00
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2015-10-09 21:15:25 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2016-05-11 16:55:43 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ .. ]
[ RUNNING ] ` rustc [ .. ] `
[ RUNNING ] ` [ .. ] `
[ RUNNING ] ` rustc [ .. ] - L native = foo `
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2018-03-14 15:17:44 +00:00
2020-04-17 04:10:11 +00:00
p . change_file (
" .cargo/config " ,
& format! (
"
[ target . { } . foo ]
rustc - link - search = [ \ " native=bar \" ]
" ,
target
) ,
) ;
2018-03-14 15:17:44 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2016-05-11 16:55:43 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ .. ]
[ RUNNING ] ` rustc [ .. ] - L native = bar `
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-09 21:15:25 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn changing_an_override_invalidates ( ) {
2016-05-26 00:06:25 +00:00
let target = rustc_host ( ) ;
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
links = " foo "
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" .cargo/config " ,
& format! (
"
2015-10-09 21:15:25 +00:00
[ target . { } . foo ]
rustc - link - search = [ \ " native=foo \" ]
2018-03-14 15:17:44 +00:00
" ,
target
) ,
2018-12-08 11:19:47 +00:00
)
. file ( " build.rs " , " " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2015-10-09 21:15:25 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2016-05-11 16:55:43 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ .. ]
[ RUNNING ] ` rustc [ .. ] - L native = foo `
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2018-03-14 15:17:44 +00:00
2020-04-17 04:10:11 +00:00
p . change_file (
" .cargo/config " ,
& format! (
"
[ target . { } . foo ]
rustc - link - search = [ \ " native=bar \" ]
" ,
target
) ,
) ;
2018-03-14 15:17:44 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2022-11-21 17:39:02 +00:00
[ DIRTY ] foo v0 . 5.0 ( [ .. ] ) : the precalculated components changed
2016-05-11 16:55:43 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ .. ]
[ RUNNING ] ` rustc [ .. ] - L native = bar `
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-11-11 00:39:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2017-02-08 02:05:10 +00:00
fn fresh_builds_possible_with_link_libs ( ) {
// The bug is non-deterministic. Sometimes you can get a fresh build
let target = rustc_host ( ) ;
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
links = " nativefoo "
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" .cargo/config " ,
& format! (
"
2017-02-08 02:05:10 +00:00
[ target . { } . nativefoo ]
rustc - link - lib = [ \ " a \" ]
rustc - link - search = [ \ " ./b \" ]
rustc - flags = \ " -l z -L ./ \"
2018-03-14 15:17:44 +00:00
" ,
target
) ,
2018-12-08 11:19:47 +00:00
)
. file ( " build.rs " , " " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2017-04-17 18:48:56 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2017-02-08 02:05:10 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ .. ]
[ RUNNING ] ` rustc [ .. ] `
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2018-03-14 15:17:44 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2017-02-08 02:05:10 +00:00
[ FRESH ] foo v0 . 5.0 ( [ .. ] )
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2017-02-08 02:05:10 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2017-02-07 00:13:03 +00:00
fn fresh_builds_possible_with_multiple_metadata_overrides ( ) {
2017-02-06 23:11:46 +00:00
// The bug is non-deterministic. Sometimes you can get a fresh build
let target = rustc_host ( ) ;
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
links = " foo "
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" .cargo/config " ,
& format! (
"
2017-02-06 23:11:46 +00:00
[ target . { } . foo ]
2017-02-07 00:13:03 +00:00
a = \ " \"
b = \ " \"
c = \ " \"
d = \ " \"
e = \ " \"
2018-03-14 15:17:44 +00:00
" ,
target
) ,
2018-12-08 11:19:47 +00:00
)
. file ( " build.rs " , " " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2017-04-17 18:48:56 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2017-02-06 23:11:46 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ .. ]
2017-02-07 00:13:03 +00:00
[ RUNNING ] ` rustc [ .. ] `
2017-02-06 23:11:46 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2018-03-14 15:17:44 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2017-02-06 23:11:46 +00:00
[ FRESH ] foo v0 . 5.0 ( [ .. ] )
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2017-02-06 23:11:46 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2021-04-27 11:25:46 +00:00
fn generate_good_d_files ( ) {
// this is here to stop regression on an issue where build.rs rerun-if-changed paths aren't
// made absolute properly, which in turn interacts poorly with the dep-info-basedir setting,
// and the dep-info files have other-crate-relative paths spat out in them
2021-04-28 04:21:56 +00:00
let p = project ( )
2021-04-27 11:25:46 +00:00
. file (
2021-04-28 04:21:56 +00:00
" awoo/Cargo.toml " ,
2021-04-27 11:25:46 +00:00
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2021-04-27 11:25:46 +00:00
name = " awoo "
version = " 0.5.0 "
build = " build.rs "
" #,
)
2021-04-28 04:21:56 +00:00
. file ( " awoo/src/lib.rs " , " " )
2021-04-27 11:25:46 +00:00
. file (
2021-04-28 04:21:56 +00:00
" awoo/build.rs " ,
2021-04-27 11:25:46 +00:00
r #"
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rerun-if-changed=build.rs " ) ;
println! ( " cargo::rerun-if-changed=barkbarkbark " ) ;
2021-04-27 11:25:46 +00:00
}
" #,
)
. file (
" Cargo.toml " ,
2021-04-28 04:21:56 +00:00
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2021-04-27 11:25:46 +00:00
name = " meow "
version = " 0.5.0 "
[ dependencies ]
2021-04-28 04:21:56 +00:00
awoo = { path = " awoo " }
2021-04-27 11:25:46 +00:00
" #,
)
. file ( " src/main.rs " , " fn main() {} " )
. build ( ) ;
p . cargo ( " build -v " ) . run ( ) ;
let dot_d_path = p . bin ( " meow " ) . with_extension ( " d " ) ;
println! ( " *meow at* {:?} " , dot_d_path ) ;
let dot_d = fs ::read_to_string ( & dot_d_path ) . unwrap ( ) ;
println! ( " *.d file content*: {} " , & dot_d ) ;
2021-06-16 02:23:17 +00:00
assert_match_exact (
" [..]/target/debug/meow[EXE]: [..]/awoo/barkbarkbark [..]/awoo/build.rs[..] " ,
& dot_d ,
2021-04-27 11:25:46 +00:00
) ;
// paths relative to dependency roots should not be allowed
2021-04-28 04:21:56 +00:00
assert! ( ! dot_d
. split_whitespace ( )
. any ( | v | v = = " barkbarkbark " | | v = = " build.rs " ) ) ;
2021-04-27 11:25:46 +00:00
p . change_file (
" .cargo/config.toml " ,
r #"
[ build ]
dep - info - basedir = " . "
" #,
) ;
p . cargo ( " build -v " ) . run ( ) ;
let dot_d = fs ::read_to_string ( & dot_d_path ) . unwrap ( ) ;
println! ( " *.d file content with dep-info-basedir*: {} " , & dot_d ) ;
2021-06-16 02:23:17 +00:00
assert_match_exact (
" target/debug/meow[EXE]: awoo/barkbarkbark awoo/build.rs[..] " ,
& dot_d ,
2021-04-27 11:25:46 +00:00
) ;
// paths relative to dependency roots should not be allowed
2021-04-28 04:21:56 +00:00
assert! ( ! dot_d
. split_whitespace ( )
. any ( | v | v = = " barkbarkbark " | | v = = " build.rs " ) ) ;
2021-04-27 11:25:46 +00:00
}
2022-01-11 08:55:12 +00:00
#[ cargo_test ]
fn generate_good_d_files_for_external_tools ( ) {
// This tests having a relative paths going out of the
// project root in config's dep-info-basedir
let p = project_in ( " rust_things " )
. file (
" awoo/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2022-01-11 08:55:12 +00:00
name = " awoo "
version = " 0.5.0 "
build = " build.rs "
" #,
)
. file ( " awoo/src/lib.rs " , " " )
. file (
" awoo/build.rs " ,
r #"
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rerun-if-changed=build.rs " ) ;
println! ( " cargo::rerun-if-changed=barkbarkbark " ) ;
2022-01-11 08:55:12 +00:00
}
" #,
)
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2022-01-11 08:55:12 +00:00
name = " meow "
version = " 0.5.0 "
[ dependencies ]
awoo = { path = " awoo " }
" #,
)
. file ( " src/main.rs " , " fn main() {} " )
. file (
" .cargo/config.toml " ,
r #"
[ build ]
dep - info - basedir = " ../.. "
" #,
)
. build ( ) ;
p . cargo ( " build -v " ) . run ( ) ;
let dot_d_path = p . bin ( " meow " ) . with_extension ( " d " ) ;
let dot_d = fs ::read_to_string ( & dot_d_path ) . unwrap ( ) ;
println! ( " *.d file content with dep-info-basedir*: {} " , & dot_d ) ;
assert_match_exact (
concat! (
" rust_things/foo/target/debug/meow[EXE]: " ,
" rust_things/foo/awoo/barkbarkbark " ,
" rust_things/foo/awoo/build.rs " ,
" rust_things/foo/awoo/src/lib.rs " ,
" rust_things/foo/src/main.rs " ,
) ,
& dot_d ,
) ;
}
2021-04-27 11:25:46 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn rebuild_only_on_explicit_paths ( ) {
2018-07-20 17:41:44 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rerun-if-changed=foo " ) ;
println! ( " cargo::rerun-if-changed=bar " ) ;
2020-09-27 00:59:58 +00:00
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2015-11-11 00:39:15 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " ) . run ( ) ;
2015-11-11 00:39:15 +00:00
// files don't exist, so should always rerun if they don't exist
println! ( " run without " ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2022-11-21 17:39:02 +00:00
[ DIRTY ] foo v0 . 5.0 ( [ .. ] ) : the file ` foo ` is missing
2018-07-20 17:41:44 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ .. ] )
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` [ .. ] / build - script - build `
[ RUNNING ] ` rustc [ .. ] src / lib . rs [ .. ] `
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2015-11-11 00:39:15 +00:00
2016-05-26 00:06:25 +00:00
sleep_ms ( 1000 ) ;
2020-04-17 04:10:11 +00:00
p . change_file ( " foo " , " " ) ;
p . change_file ( " bar " , " " ) ;
2018-08-21 16:14:45 +00:00
sleep_ms ( 1000 ) ; // make sure the to-be-created outfile has a timestamp distinct from the infiles
2015-11-11 00:39:15 +00:00
// now the exist, so run once, catch the mtime, then shouldn't run again
println! ( " run with " ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2022-11-21 17:39:02 +00:00
[ DIRTY ] foo v0 . 5.0 ( [ .. ] ) : the file ` foo ` has changed ( [ .. ] )
2018-07-20 17:41:44 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ .. ] )
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` [ .. ] / build - script - build `
[ RUNNING ] ` rustc [ .. ] src / lib . rs [ .. ] `
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2015-11-11 00:39:15 +00:00
println! ( " run with2 " ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2018-07-20 17:41:44 +00:00
[ FRESH ] foo v0 . 5.0 ( [ .. ] )
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2015-11-11 00:39:15 +00:00
2016-05-26 00:06:25 +00:00
sleep_ms ( 1000 ) ;
2015-11-11 00:39:15 +00:00
// random other files do not affect freshness
println! ( " run baz " ) ;
2023-12-08 20:32:28 +00:00
p . change_file ( " baz " , " // modified " ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2018-07-20 17:41:44 +00:00
[ FRESH ] foo v0 . 5.0 ( [ .. ] )
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2015-11-11 00:39:15 +00:00
// but changing dependent files does
println! ( " run foo change " ) ;
2023-12-08 20:32:28 +00:00
p . change_file ( " foo " , " // modified " ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2022-11-21 17:39:02 +00:00
[ DIRTY ] foo v0 . 5.0 ( [ .. ] ) : the file ` foo ` has changed ( [ .. ] )
2018-07-20 17:41:44 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ .. ] )
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` [ .. ] / build - script - build `
[ RUNNING ] ` rustc [ .. ] src / lib . rs [ .. ] `
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2015-11-11 00:39:15 +00:00
// .. as does deleting a file
2022-11-21 17:39:02 +00:00
println! ( " run bar delete " ) ;
2015-11-11 00:39:15 +00:00
fs ::remove_file ( p . root ( ) . join ( " bar " ) ) . unwrap ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2022-11-21 17:39:02 +00:00
[ DIRTY ] foo v0 . 5.0 ( [ .. ] ) : the file ` bar ` is missing
2018-07-20 17:41:44 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ .. ] )
2018-08-02 09:18:48 +00:00
[ RUNNING ] ` [ .. ] / build - script - build `
[ RUNNING ] ` rustc [ .. ] src / lib . rs [ .. ] `
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-11-11 00:39:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-04-05 01:45:15 +00:00
fn doctest_receives_build_link_args ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
[ dependencies . a ]
path = " a "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" a/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " a "
version = " 0.5.0 "
authors = [ ]
links = " bar "
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " a/src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" a/build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-link-search=native=bar " ) ;
2020-09-27 00:59:58 +00:00
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2015-12-19 19:44:34 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " test -v " )
. with_stderr_contains (
2021-02-22 19:06:03 +00:00
" [RUNNING] `rustdoc [..]--crate-name foo --test [..]-L native=bar[..]` " ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2016-02-02 19:42:57 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn please_respect_the_dag ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
2016-02-02 19:42:57 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies ]
a = { path = 'a' }
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-link-search=native=foo " ) ;
2020-09-27 00:59:58 +00:00
}
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" a/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " a "
version = " 0.5.0 "
authors = [ ]
links = " bar "
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " a/src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" a/build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-link-search=native=bar " ) ;
2020-09-27 00:59:58 +00:00
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2016-02-02 19:42:57 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr_contains ( " [RUNNING] `rustc [..] -L native=foo -L native=bar[..]` " )
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2016-04-11 17:06:47 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn non_utf8_output ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
use std ::io ::prelude ::* ;
2016-04-11 17:06:47 +00:00
2020-09-27 00:59:58 +00:00
fn main ( ) {
let mut out = std ::io ::stdout ( ) ;
// print something that's not utf8
out . write_all ( b " \xff \xff \n " ) . unwrap ( ) ;
2016-04-11 17:06:47 +00:00
2020-09-27 00:59:58 +00:00
// now print some cargo metadata that's utf8
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-cfg=foo " ) ;
2016-04-11 17:06:47 +00:00
2020-09-27 00:59:58 +00:00
// now print more non-utf8
out . write_all ( b " \xff \xff \n " ) . unwrap ( ) ;
}
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/main.rs " , " #[cfg(foo)] fn main() {} " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2016-04-11 17:06:47 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " ) . run ( ) ;
2016-05-25 20:55:42 +00:00
}
2016-05-16 18:09:52 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn custom_target_dir ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
2016-05-16 18:09:52 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies ]
a = { path = " a " }
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" .cargo/config " ,
r #"
2020-09-27 00:59:58 +00:00
[ build ]
target - dir = ' test '
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" a/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " a "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " a/build.rs " , " fn main() {} " )
2017-07-22 03:12:21 +00:00
. file ( " a/src/lib.rs " , " " )
. build ( ) ;
2016-05-16 18:09:52 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " ) . run ( ) ;
2016-05-25 20:55:42 +00:00
}
2016-05-23 15:44:27 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn panic_abort_with_build_scripts ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
2016-05-23 15:44:27 +00:00
2020-09-27 00:59:58 +00:00
[ profile . release ]
panic = ' abort '
2016-05-23 15:44:27 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies ]
a = { path = " a " }
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" src/lib.rs " ,
" #[allow(unused_extern_crates)] extern crate a; " ,
2018-12-08 11:19:47 +00:00
)
. file ( " build.rs " , " fn main() {} " )
2018-03-14 15:17:44 +00:00
. file (
" a/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " a "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
2016-05-23 15:44:27 +00:00
2020-09-27 00:59:58 +00:00
[ build - dependencies ]
b = { path = " ../b " }
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " a/src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" a/build.rs " ,
" #[allow(unused_extern_crates)] extern crate b; fn main() {} " ,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" b/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " b "
version = " 0.5.0 "
authors = [ ]
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " b/src/lib.rs " , " " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2016-05-23 15:44:27 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v --release " ) . run ( ) ;
2018-06-26 01:00:04 +00:00
2018-07-11 16:27:08 +00:00
p . root ( ) . join ( " target " ) . rm_rf ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " test --release -v " )
2023-02-20 16:13:25 +00:00
. with_stderr_does_not_contain ( " [..]panic=abort[..] " )
2018-08-28 09:20:03 +00:00
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2016-04-12 21:28:52 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-04-12 21:28:52 +00:00
fn warnings_emitted ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::warning=foo " ) ;
println! ( " cargo::warning=bar " ) ;
2020-09-27 00:59:58 +00:00
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2016-04-12 21:28:52 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2016-04-14 06:37:57 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ .. ] )
[ RUNNING ] ` rustc [ .. ] `
[ RUNNING ] ` [ .. ] `
2023-10-10 01:41:18 +00:00
warning : foo @ 0. 5.0 : foo
warning : foo @ 0. 5.0 : bar
2016-04-14 06:37:57 +00:00
[ RUNNING ] ` rustc [ .. ] `
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-04-12 21:28:52 +00:00
}
2020-03-18 17:48:19 +00:00
#[ cargo_test ]
fn warnings_emitted_when_build_script_panics ( ) {
let p = project ( )
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
" #,
2020-03-18 17:48:19 +00:00
)
. file ( " src/lib.rs " , " " )
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::warning=foo " ) ;
println! ( " cargo::warning=bar " ) ;
2020-09-27 00:59:58 +00:00
panic! ( ) ;
}
" #,
2020-03-18 17:48:19 +00:00
)
. build ( ) ;
p . cargo ( " build " )
. with_status ( 101 )
. with_stdout ( " " )
2023-10-10 01:41:18 +00:00
. with_stderr_contains ( " warning: foo@0.5.0: foo \n warning: foo@0.5.0: bar " )
2020-03-18 17:48:19 +00:00
. run ( ) ;
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-04-12 21:28:52 +00:00
fn warnings_hidden_for_upstream ( ) {
Package ::new ( " bar " , " 0.1.0 " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2016-04-12 21:28:52 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::warning=foo " ) ;
println! ( " cargo::warning=bar " ) ;
2016-04-12 21:28:52 +00:00
}
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2016-04-12 21:28:52 +00:00
name = " bar "
version = " 0.1.0 "
authors = [ ]
build = " build.rs "
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. publish ( ) ;
2016-04-12 21:28:52 +00:00
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
2016-04-12 21:28:52 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies ]
bar = " * "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2016-04-12 21:28:52 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2018-09-08 09:23:57 +00:00
[ UPDATING ] ` [ .. ] ` index
2018-09-14 20:33:18 +00:00
[ DOWNLOADING ] crates .. .
[ DOWNLOADED ] bar v0 . 1.0 ( [ .. ] )
2016-02-03 18:54:07 +00:00
[ COMPILING ] bar v0 . 1.0
2016-04-14 06:37:57 +00:00
[ RUNNING ] ` rustc [ .. ] `
[ RUNNING ] ` [ .. ] `
[ RUNNING ] ` rustc [ .. ] `
[ COMPILING ] foo v0 . 5.0 ( [ .. ] )
[ RUNNING ] ` rustc [ .. ] `
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-04-12 21:28:52 +00:00
}
2016-04-12 21:55:19 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-04-12 21:55:19 +00:00
fn warnings_printed_on_vv ( ) {
Package ::new ( " bar " , " 0.1.0 " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2016-04-12 21:55:19 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::warning=foo " ) ;
println! ( " cargo::warning=bar " ) ;
2016-04-12 21:55:19 +00:00
}
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2016-04-12 21:55:19 +00:00
name = " bar "
version = " 0.1.0 "
authors = [ ]
build = " build.rs "
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. publish ( ) ;
2016-04-12 21:55:19 +00:00
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
2016-04-12 21:55:19 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies ]
bar = " * "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2016-04-12 21:55:19 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -vv " )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2018-09-08 09:23:57 +00:00
[ UPDATING ] ` [ .. ] ` index
2018-09-14 20:33:18 +00:00
[ DOWNLOADING ] crates .. .
[ DOWNLOADED ] bar v0 . 1.0 ( [ .. ] )
2016-02-03 18:54:07 +00:00
[ COMPILING ] bar v0 . 1.0
2018-12-27 14:32:34 +00:00
[ RUNNING ] ` [ .. ] rustc [ .. ] `
2016-04-14 06:37:57 +00:00
[ RUNNING ] ` [ .. ] `
2023-10-10 01:41:18 +00:00
warning : bar @ 0. 1.0 : foo
warning : bar @ 0. 1.0 : bar
2018-12-27 14:32:34 +00:00
[ RUNNING ] ` [ .. ] rustc [ .. ] `
2016-04-14 06:37:57 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ .. ] )
2018-12-27 14:32:34 +00:00
[ RUNNING ] ` [ .. ] rustc [ .. ] `
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-04-14 06:37:57 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-04-14 06:37:57 +00:00
fn output_shows_on_vv ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
use std ::io ::prelude ::* ;
2016-04-14 06:37:57 +00:00
2020-09-27 00:59:58 +00:00
fn main ( ) {
std ::io ::stderr ( ) . write_all ( b " stderr \n " ) . unwrap ( ) ;
std ::io ::stdout ( ) . write_all ( b " stdout \n " ) . unwrap ( ) ;
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2016-04-14 06:37:57 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -vv " )
2018-10-09 20:30:13 +00:00
. with_stdout ( " [foo 0.5.0] stdout " )
2018-08-28 09:20:03 +00:00
. with_stderr (
2018-03-14 15:43:41 +00:00
" \
2016-04-14 06:37:57 +00:00
[ COMPILING ] foo v0 . 5.0 ( [ .. ] )
2018-12-27 14:32:34 +00:00
[ RUNNING ] ` [ .. ] rustc [ .. ] `
2016-04-14 06:37:57 +00:00
[ RUNNING ] ` [ .. ] `
2018-10-09 20:30:13 +00:00
[ foo 0. 5.0 ] stderr
2018-12-27 14:32:34 +00:00
[ RUNNING ] ` [ .. ] rustc [ .. ] `
2017-01-12 01:03:36 +00:00
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-04-12 21:55:19 +00:00
}
2016-06-17 11:10:29 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-06-17 11:10:29 +00:00
fn links_with_dots ( ) {
let target = rustc_host ( ) ;
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
links = " a.b "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-link-search=bar " )
2020-09-27 00:59:58 +00:00
}
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" .cargo/config " ,
& format! (
r #"
2020-09-27 00:59:58 +00:00
[ target . { } . ' a . b ' ]
rustc - link - search = [ " foo " ]
" #,
2018-03-14 15:17:44 +00:00
target
) ,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2016-06-17 11:10:29 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr_contains ( " [RUNNING] `rustc --crate-name foo [..] [..] -L foo[..]` " )
. run ( ) ;
2016-06-17 11:10:29 +00:00
}
2016-07-09 17:19:30 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-07-09 17:19:30 +00:00
fn rustc_and_rustdoc_set_correctly ( ) {
2018-07-20 17:41:44 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " foo "
version = " 0.0.1 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
use std ::env ;
2016-07-09 17:19:30 +00:00
2020-09-27 00:59:58 +00:00
fn main ( ) {
assert_eq! ( env ::var ( " RUSTC " ) . unwrap ( ) , " rustc " ) ;
assert_eq! ( env ::var ( " RUSTDOC " ) . unwrap ( ) , " rustdoc " ) ;
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " bench " ) . run ( ) ;
2016-07-09 17:19:30 +00:00
}
2016-10-31 23:20:38 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-10-31 23:20:38 +00:00
fn cfg_env_vars_available ( ) {
2018-07-20 17:41:44 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " foo "
version = " 0.0.1 "
authors = [ ]
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
use std ::env ;
2016-10-31 23:20:38 +00:00
2020-09-27 00:59:58 +00:00
fn main ( ) {
let fam = env ::var ( " CARGO_CFG_TARGET_FAMILY " ) . unwrap ( ) ;
if cfg! ( unix ) {
assert_eq! ( fam , " unix " ) ;
} else {
assert_eq! ( fam , " windows " ) ;
}
2016-10-31 23:20:38 +00:00
}
2020-09-27 00:59:58 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " bench " ) . run ( ) ;
2016-10-31 23:20:38 +00:00
}
2016-11-21 20:32:10 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-11-21 20:32:10 +00:00
fn switch_features_rerun ( ) {
2018-07-20 17:41:44 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " foo "
version = " 0.0.1 "
authors = [ ]
build = " build.rs "
2016-11-21 20:32:10 +00:00
2020-09-27 00:59:58 +00:00
[ features ]
foo = [ ]
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" src/main.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
println! ( include_str! ( concat! ( env! ( " OUT_DIR " ) , " /output " ) ) ) ;
}
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
use std ::env ;
use std ::fs ;
use std ::path ::Path ;
2016-11-21 20:32:10 +00:00
2020-09-27 00:59:58 +00:00
fn main ( ) {
let out_dir = env ::var_os ( " OUT_DIR " ) . unwrap ( ) ;
let output = Path ::new ( & out_dir ) . join ( " output " ) ;
2016-11-21 20:32:10 +00:00
2020-09-27 00:59:58 +00:00
if env ::var_os ( " CARGO_FEATURE_FOO " ) . is_some ( ) {
fs ::write ( output , " foo " ) . unwrap ( ) ;
} else {
fs ::write ( output , " bar " ) . unwrap ( ) ;
}
2016-11-21 20:32:10 +00:00
}
2020-09-27 00:59:58 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2016-11-21 20:32:10 +00:00
2019-01-18 00:39:04 +00:00
p . cargo ( " build -v --features=foo " ) . run ( ) ;
2019-01-18 16:39:25 +00:00
p . rename_run ( " foo " , " with_foo " ) . with_stdout ( " foo \n " ) . run ( ) ;
2019-01-18 00:39:04 +00:00
p . cargo ( " build -v " ) . run ( ) ;
2019-01-24 17:28:21 +00:00
p . rename_run ( " foo " , " without_foo " )
. with_stdout ( " bar \n " )
. run ( ) ;
2019-01-18 00:39:04 +00:00
p . cargo ( " build -v --features=foo " ) . run ( ) ;
2019-01-18 16:39:25 +00:00
p . rename_run ( " foo " , " with_foo2 " ) . with_stdout ( " foo \n " ) . run ( ) ;
2016-11-21 20:32:10 +00:00
}
2016-12-02 04:01:51 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-12-02 04:01:51 +00:00
fn assume_build_script_when_build_rs_present ( ) {
2018-07-20 17:41:44 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" src/main.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
if ! cfg! ( foo ) {
panic! ( " the build script was not run " ) ;
}
2016-12-14 01:18:32 +00:00
}
2020-09-27 00:59:58 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-cfg=foo " ) ;
2020-09-27 00:59:58 +00:00
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2016-12-02 04:01:51 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " run -v " ) . run ( ) ;
2016-12-02 04:01:51 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-12-05 18:02:13 +00:00
fn if_build_set_to_false_dont_treat_build_rs_as_build_script ( ) {
2018-07-20 17:41:44 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2020-09-27 00:59:58 +00:00
[ package ]
name = " foo "
version = " 0.0.1 "
authors = [ ]
build = false
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" src/main.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
if cfg! ( foo ) {
panic! ( " the build script was run " ) ;
}
2016-12-14 01:18:32 +00:00
}
2020-09-27 00:59:58 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-cfg=foo " ) ;
2020-09-27 00:59:58 +00:00
}
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2016-12-02 04:01:51 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " run -v " ) . run ( ) ;
2016-12-02 04:01:51 +00:00
}
2017-04-21 02:36:32 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2017-04-21 02:36:32 +00:00
fn deterministic_rustc_dependency_flags ( ) {
// This bug is non-deterministic hence the large number of dependencies
// in the hopes it will have a much higher chance of triggering it.
Package ::new ( " dep1 " , " 0.1.0 " )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2017-04-21 02:36:32 +00:00
name = " dep1 "
version = " 0.1.0 "
authors = [ ]
build = " build.rs "
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" build.rs " ,
r #"
2017-04-21 02:36:32 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-flags=-L native=test1 " ) ;
2017-04-21 02:36:32 +00:00
}
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. publish ( ) ;
2017-04-21 02:36:32 +00:00
Package ::new ( " dep2 " , " 0.1.0 " )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2017-04-21 02:36:32 +00:00
name = " dep2 "
version = " 0.1.0 "
authors = [ ]
build = " build.rs "
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" build.rs " ,
r #"
2017-04-21 02:36:32 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-flags=-L native=test2 " ) ;
2017-04-21 02:36:32 +00:00
}
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. publish ( ) ;
2017-04-21 02:36:32 +00:00
Package ::new ( " dep3 " , " 0.1.0 " )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2017-04-21 02:36:32 +00:00
name = " dep3 "
version = " 0.1.0 "
authors = [ ]
build = " build.rs "
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" build.rs " ,
r #"
2017-04-21 02:36:32 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-flags=-L native=test3 " ) ;
2017-04-21 02:36:32 +00:00
}
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. publish ( ) ;
2017-04-21 02:36:32 +00:00
Package ::new ( " dep4 " , " 0.1.0 " )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2017-04-21 02:36:32 +00:00
name = " dep4 "
version = " 0.1.0 "
authors = [ ]
build = " build.rs "
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" build.rs " ,
r #"
2017-04-21 02:36:32 +00:00
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-flags=-L native=test4 " ) ;
2017-04-21 02:36:32 +00:00
}
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. publish ( ) ;
2017-04-21 02:36:32 +00:00
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.1.0 "
authors = [ ]
2017-04-21 02:36:32 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies ]
dep1 = " * "
dep2 = " * "
dep3 = " * "
dep4 = " * "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/main.rs " , " fn main() {} " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2017-04-21 02:36:32 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build -v " )
. with_stderr_contains (
2018-03-14 15:17:44 +00:00
" \
2017-04-21 02:36:32 +00:00
[ RUNNING ] ` rustc - - crate - name foo [ .. ] - L native = test1 - L native = test2 \
- L native = test3 - L native = test4 `
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2017-04-21 02:36:32 +00:00
}
2017-12-10 18:14:23 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2017-12-10 18:14:23 +00:00
fn links_duplicates_with_cycle ( ) {
2018-01-26 03:50:55 +00:00
// this tests that the links_duplicates are caught at resolver time
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
links = " a "
build = " build.rs "
2017-12-10 18:14:23 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies . a ]
path = " a "
2017-12-10 18:14:23 +00:00
2020-09-27 00:59:58 +00:00
[ dev - dependencies ]
b = { path = " b " }
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2017-12-10 18:14:23 +00:00
. file ( " build.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" a/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " a "
version = " 0.5.0 "
authors = [ ]
links = " a "
build = " build.rs "
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " a/src/lib.rs " , " " )
2017-12-10 18:14:23 +00:00
. file ( " a/build.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
" b/Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " b "
version = " 0.5.0 "
authors = [ ]
2017-12-10 18:14:23 +00:00
2020-09-27 00:59:58 +00:00
[ dependencies ]
foo = { path = " .. " }
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " b/src/lib.rs " , " " )
2017-12-10 18:14:23 +00:00
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " build " ) . with_status ( 101 )
2017-12-10 18:14:23 +00:00
. with_stderr ( " \
2018-02-14 04:11:48 +00:00
error : failed to select a version for ` a ` .
2018-02-15 03:28:59 +00:00
.. . required by package ` foo v0 . 5.0 ( [ .. ] ) `
versions that meet the requirements ` * ` are : 0. 5.0
the package ` a ` links to the native library ` a ` , but it conflicts with a previous package which links to ` a ` as well :
package ` foo v0 . 5.0 ( [ .. ] ) `
2023-11-14 17:26:00 +00:00
Only one package in the dependency graph may specify the same links value . This helps ensure that only one copy of a native library is linked in the final binary . Try to adjust your dependencies so that only one package uses the ` links = \ " a \" ` value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.
2018-02-15 03:28:59 +00:00
failed to select a version for ` a ` which could resolve this conflict
2018-08-28 09:20:03 +00:00
" ).run();
2017-12-10 18:14:23 +00:00
}
2017-12-14 04:54:01 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2017-12-14 04:54:01 +00:00
fn rename_with_link_search_path ( ) {
2018-11-13 03:41:01 +00:00
_rename_with_link_search_path ( false ) ;
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2022-08-02 19:12:13 +00:00
#[ cfg_attr(
target_os = " macos " ,
ignore = " don't have a cdylib cross target on macos "
) ]
2018-11-13 03:41:01 +00:00
fn rename_with_link_search_path_cross ( ) {
if cross_compile ::disabled ( ) {
return ;
}
_rename_with_link_search_path ( true ) ;
}
fn _rename_with_link_search_path ( cross : bool ) {
let target_arg = if cross {
format! ( " --target= {} " , cross_compile ::alternate ( ) )
} else {
" " . to_string ( )
} ;
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2020-09-27 00:59:58 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
2017-12-14 04:54:01 +00:00
2020-09-27 00:59:58 +00:00
[ lib ]
crate - type = [ " cdylib " ]
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-08-28 09:20:03 +00:00
" src/lib.rs " ,
" #[no_mangle] pub extern fn cargo_test_foo() {} " ,
) ;
2017-12-14 04:54:01 +00:00
let p = p . build ( ) ;
2018-11-13 03:41:01 +00:00
p . cargo ( & format! ( " build {} " , target_arg ) ) . run ( ) ;
2017-12-14 04:54:01 +00:00
2018-08-28 09:20:03 +00:00
let p2 = project ( )
. at ( " bar " )
2018-07-24 22:35:01 +00:00
. file ( " Cargo.toml " , & basic_manifest ( " bar " , " 0.5.0 " ) )
2018-03-14 15:17:44 +00:00
. file (
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
use std ::env ;
use std ::fs ;
use std ::path ::PathBuf ;
2017-12-14 04:54:01 +00:00
2020-09-27 00:59:58 +00:00
fn main ( ) {
// Move the `libfoo.so` from the root of our project into the
// build directory. This way Cargo should automatically manage
// `LD_LIBRARY_PATH` and such.
let root = PathBuf ::from ( env ::var_os ( " CARGO_MANIFEST_DIR " ) . unwrap ( ) ) ;
let file = format! ( " {} foo {} " , env ::consts ::DLL_PREFIX , env ::consts ::DLL_SUFFIX ) ;
let src = root . join ( & file ) ;
let dst_dir = PathBuf ::from ( env ::var_os ( " OUT_DIR " ) . unwrap ( ) ) ;
let dst = dst_dir . join ( & file ) ;
fs ::copy ( & src , & dst ) . unwrap ( ) ;
// handle windows, like below
drop ( fs ::copy ( root . join ( " foo.dll.lib " ) , dst_dir . join ( " foo.dll.lib " ) ) ) ;
2023-05-30 00:20:54 +00:00
println! ( " cargo::rerun-if-changed=build.rs " ) ;
2020-09-27 00:59:58 +00:00
if cfg! ( target_env = " msvc " ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-link-lib=foo.dll " ) ;
2020-09-27 00:59:58 +00:00
} else {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-link-lib=foo " ) ;
2020-09-27 00:59:58 +00:00
}
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-link-search=all= {} " ,
2020-09-27 00:59:58 +00:00
dst . parent ( ) . unwrap ( ) . display ( ) ) ;
2017-12-14 04:54:01 +00:00
}
2020-09-27 00:59:58 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" src/main.rs " ,
r #"
2020-09-27 00:59:58 +00:00
extern {
#[ link_name = " cargo_test_foo " ]
fn foo ( ) ;
}
2017-12-14 04:54:01 +00:00
2020-09-27 00:59:58 +00:00
fn main ( ) {
unsafe { foo ( ) ; }
}
" #,
2018-03-14 15:17:44 +00:00
) ;
2017-12-14 04:54:01 +00:00
let p2 = p2 . build ( ) ;
// Move the output `libfoo.so` into the directory of `p2`, and then delete
2019-02-03 04:01:23 +00:00
// the `p` project. On macOS, the `libfoo.dylib` artifact references the
2017-12-14 04:54:01 +00:00
// original path in `p` so we want to make sure that it can't find it (hence
// the deletion).
2018-11-13 03:41:01 +00:00
let root = if cross {
2018-12-08 11:19:47 +00:00
p . root ( )
. join ( " target " )
. join ( cross_compile ::alternate ( ) )
. join ( " debug " )
. join ( " deps " )
2018-11-13 03:41:01 +00:00
} else {
p . root ( ) . join ( " target " ) . join ( " debug " ) . join ( " deps " )
} ;
2017-12-14 04:54:01 +00:00
let file = format! ( " {} foo {} " , env ::consts ::DLL_PREFIX , env ::consts ::DLL_SUFFIX ) ;
let src = root . join ( & file ) ;
let dst = p2 . root ( ) . join ( & file ) ;
fs ::copy ( & src , & dst ) . unwrap ( ) ;
// copy the import library for windows, if it exists
2018-03-14 15:17:44 +00:00
drop ( fs ::copy (
& root . join ( " foo.dll.lib " ) ,
p2 . root ( ) . join ( " foo.dll.lib " ) ,
) ) ;
2018-08-28 09:20:03 +00:00
remove_dir_all ( p . root ( ) ) . unwrap ( ) ;
2017-12-14 04:54:01 +00:00
// Everything should work the first time
2018-11-13 03:41:01 +00:00
p2 . cargo ( & format! ( " run {} " , target_arg ) ) . run ( ) ;
2017-12-14 04:54:01 +00:00
// Now rename the root directory and rerun `cargo run`. Not only should we
// not build anything but we also shouldn't crash.
let mut new = p2 . root ( ) ;
new . pop ( ) ;
new . push ( " bar2 " ) ;
2018-05-05 18:47:41 +00:00
// For whatever reason on Windows right after we execute a binary it's very
// unlikely that we're able to successfully delete or rename that binary.
// It's not really clear why this is the case or if it's a bug in Cargo
// holding a handle open too long. In an effort to reduce the flakiness of
// this test though we throw this in a loop
//
// For some more information see #5481 and rust-lang/rust#48775
let mut i = 0 ;
loop {
let error = match fs ::rename ( p2 . root ( ) , & new ) {
Ok ( ( ) ) = > break ,
Err ( e ) = > e ,
} ;
i + = 1 ;
if ! cfg! ( windows ) | | error . kind ( ) ! = io ::ErrorKind ::PermissionDenied | | i > 10 {
panic! ( " failed to rename: {} " , error ) ;
}
println! ( " assuming {} is spurious, waiting to try again " , error ) ;
2019-01-24 17:28:21 +00:00
thread ::sleep ( slow_cpu_multiplier ( 100 ) ) ;
2018-05-05 18:47:41 +00:00
}
2018-11-13 03:41:01 +00:00
p2 . cargo ( & format! ( " run {} " , target_arg ) )
2018-08-28 09:20:03 +00:00
. cwd ( & new )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2017-12-14 04:54:01 +00:00
[ FINISHED ] [ .. ]
[ RUNNING ] [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2017-12-14 04:54:01 +00:00
}
2018-05-04 16:19:30 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-05-04 16:19:30 +00:00
fn optional_build_script_dep ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-05-04 16:19:30 +00:00
. file (
" Cargo.toml " ,
r #"
2022-09-22 19:50:54 +00:00
[ package ]
2018-05-04 16:19:30 +00:00
name = " foo "
version = " 0.5.0 "
authors = [ ]
[ dependencies ]
bar = { path = " bar " , optional = true }
[ build - dependencies ]
bar = { path = " bar " , optional = true }
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-08-28 09:20:03 +00:00
" build.rs " ,
r #"
2020-09-27 00:59:58 +00:00
#[ cfg(feature = " bar " ) ]
extern crate bar ;
2018-05-04 16:19:30 +00:00
2020-09-27 00:59:58 +00:00
fn main ( ) {
#[ cfg(feature = " bar " ) ] {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-env=FOO= {} " , bar ::bar ( ) ) ;
2020-09-27 00:59:58 +00:00
return
}
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-env=FOO=0 " ) ;
2018-05-04 16:19:30 +00:00
}
2020-09-27 00:59:58 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file (
2018-05-04 16:19:30 +00:00
" src/main.rs " ,
r #"
#[ cfg(feature = " bar " ) ]
extern crate bar ;
fn main ( ) {
println! ( " {} " , env! ( " FOO " ) ) ;
}
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " bar/Cargo.toml " , & basic_manifest ( " bar " , " 0.5.0 " ) )
2018-07-25 00:30:32 +00:00
. file ( " bar/src/lib.rs " , " pub fn bar() -> u32 { 1 } " ) ;
2018-05-04 16:19:30 +00:00
let p = p . build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " run " ) . with_stdout ( " 0 \n " ) . run ( ) ;
p . cargo ( " run --features bar " ) . with_stdout ( " 1 \n " ) . run ( ) ;
2018-05-04 16:19:30 +00:00
}
2018-05-05 16:04:54 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-05-05 16:04:54 +00:00
fn optional_build_dep_and_required_normal_dep ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-05-05 16:04:54 +00:00
. file (
" Cargo.toml " ,
r #"
[ package ]
name = " foo "
version = " 0.1.0 "
authors = [ ]
[ dependencies ]
bar = { path = " ./bar " , optional = true }
[ build - dependencies ]
bar = { path = " ./bar " }
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " build.rs " , " extern crate bar; fn main() { bar::bar(); } " )
2018-05-05 16:04:54 +00:00
. file (
" src/main.rs " ,
r #"
#[ cfg(feature = " bar " ) ]
extern crate bar ;
fn main ( ) {
#[ cfg(feature = " bar " ) ] {
println! ( " {} " , bar ::bar ( ) ) ;
}
#[ cfg(not(feature = " bar " )) ] {
println! ( " 0 " ) ;
}
}
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " bar/Cargo.toml " , & basic_manifest ( " bar " , " 0.5.0 " ) )
2018-07-25 00:30:32 +00:00
. file ( " bar/src/lib.rs " , " pub fn bar() -> u32 { 1 } " ) ;
2018-05-05 16:04:54 +00:00
let p = p . build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " run " )
. with_stdout ( " 0 " )
. with_stderr (
2018-05-05 16:04:54 +00:00
" \
[ COMPILING ] bar v0 . 5.0 ( [ .. ] )
[ COMPILING ] foo v0 . 1.0 ( [ .. ] )
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
[ RUNNING ] ` [ .. ] foo [ EXE ] ` " ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2018-05-05 16:04:54 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " run --all-features " )
. with_stdout ( " 1 " )
. with_stderr (
2018-05-05 16:04:54 +00:00
" \
2023-01-31 20:57:29 +00:00
[ COMPILING ] bar v0 . 5.0 ( [ .. ] )
2018-05-05 16:04:54 +00:00
[ COMPILING ] foo v0 . 1.0 ( [ .. ] )
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
[ RUNNING ] ` [ .. ] foo [ EXE ] ` " ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2018-05-05 16:04:54 +00:00
}
2019-04-05 19:54:50 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2019-04-05 19:54:50 +00:00
fn using_rerun_if_changed_does_not_rebuild ( ) {
let p = project ( )
. file (
" Cargo.toml " ,
r #"
[ package ]
name = " foo "
version = " 0.1.0 "
authors = [ ]
" #,
)
. file (
" build.rs " ,
r #"
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rerun-if-changed=build.rs " ) ;
2019-04-05 19:54:50 +00:00
}
" #,
)
. file ( " src/lib.rs " , " " )
. build ( ) ;
p . cargo ( " build " ) . run ( ) ;
2019-04-12 01:28:45 +00:00
p . cargo ( " build " ) . with_stderr ( " [FINISHED] [..] " ) . run ( ) ;
2019-04-05 19:54:50 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2019-04-05 19:54:50 +00:00
fn links_interrupted_can_restart ( ) {
// Test for a `links` dependent build script getting canceled and then
// restarted. Steps:
// 1. Build to establish fingerprints.
// 2. Change something (an env var in this case) that triggers the
// dependent build script to run again. Kill the top-level build script
// while it is running (such as hitting Ctrl-C).
// 3. Run the build again, it should re-run the build script.
let bar = project ( )
. at ( " bar " )
. file (
" Cargo.toml " ,
r #"
[ package ]
name = " bar "
version = " 0.5.0 "
authors = [ ]
links = " foo "
build = " build.rs "
" #,
)
. file ( " src/lib.rs " , " " )
. file (
" build.rs " ,
r #"
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rerun-if-env-changed=SOMEVAR " ) ;
2019-04-05 19:54:50 +00:00
}
" #,
)
. build ( ) ;
let p = project ( )
. file (
" Cargo.toml " ,
& format! (
r #"
[ package ]
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
[ dependencies . bar ]
path = ' { } '
" #,
bar . root ( ) . display ( )
) ,
)
. file ( " src/lib.rs " , " " )
. file (
" build.rs " ,
r #"
use std ::env ;
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::metadata=rebuild-if-changed=build.rs " ) ;
2019-04-05 19:54:50 +00:00
if std ::path ::Path ::new ( " abort " ) . exists ( ) {
panic! ( " Crash! " ) ;
}
}
" #,
)
. build ( ) ;
p . cargo ( " build " ) . run ( ) ;
// Simulate the user hitting Ctrl-C during a build.
p . change_file ( " abort " , " " ) ;
// Set SOMEVAR to trigger a rebuild.
p . cargo ( " build " )
. env ( " SOMEVAR " , " 1 " )
. with_stderr_contains ( " [..]Crash![..] " )
. with_status ( 101 )
. run ( ) ;
fs ::remove_file ( p . root ( ) . join ( " abort " ) ) . unwrap ( ) ;
// Try again without aborting the script.
// ***This is currently broken, the script does not re-run.
p . cargo ( " build -v " )
. env ( " SOMEVAR " , " 1 " )
. with_stderr_contains ( " [RUNNING] [..]/foo-[..]/build-script-build[..] " )
. run ( ) ;
}
2019-04-12 01:28:45 +00:00
2020-12-11 17:57:49 +00:00
#[ cargo_test ]
fn dev_dep_with_links ( ) {
let p = project ( )
. file (
" Cargo.toml " ,
r #"
[ package ]
name = " foo "
version = " 0.1.0 "
authors = [ ]
links = " x "
[ dev - dependencies ]
bar = { path = " ./bar " }
" #,
)
. file ( " build.rs " , " fn main() {} " )
. file ( " src/lib.rs " , " " )
. file (
" bar/Cargo.toml " ,
r #"
[ package ]
name = " bar "
version = " 0.1.0 "
authors = [ ]
links = " y "
[ dependencies ]
foo = { path = " .. " }
" #,
)
. file ( " bar/build.rs " , " fn main() {} " )
. file ( " bar/src/lib.rs " , " " )
. build ( ) ;
p . cargo ( " check --tests " ) . run ( )
}
2020-12-12 21:59:51 +00:00
#[ cargo_test ]
fn rerun_if_directory ( ) {
if ! symlink_supported ( ) {
return ;
}
// rerun-if-changed of a directory should rerun if any file in the directory changes.
let p = project ( )
. file ( " Cargo.toml " , & basic_manifest ( " foo " , " 0.1.0 " ) )
. file ( " src/lib.rs " , " " )
. file (
" build.rs " ,
r #"
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rerun-if-changed=somedir " ) ;
2020-12-12 21:59:51 +00:00
}
" #,
)
. build ( ) ;
2022-11-21 17:39:02 +00:00
let dirty = | dirty_line : & str , compile_build_script : bool | {
let mut dirty_line = dirty_line . to_string ( ) ;
if ! dirty_line . is_empty ( ) {
dirty_line . push ( '\n' ) ;
}
let compile_build_script_line = if compile_build_script {
" [RUNNING] `rustc --crate-name build_script_build [..] \n "
} else {
" "
} ;
p . cargo ( " check -v " )
. with_stderr ( format! (
" \
{ dirty_line } \
[ COMPILING ] foo [ .. ]
{ compile_build_script_line } \
[ RUNNING ] ` [ .. ] build - script - build [ .. ] `
[ RUNNING ] ` rustc - - crate - name foo [ .. ]
[ FINISHED ] [ .. ] " ,
) )
2020-12-12 21:59:51 +00:00
. run ( ) ;
} ;
let fresh = | | {
p . cargo ( " check " ) . with_stderr ( " [FINISHED] [..] " ) . run ( ) ;
} ;
// Start with a missing directory.
2022-11-21 17:39:02 +00:00
dirty ( " " , true ) ;
2020-12-12 21:59:51 +00:00
// Because the directory doesn't exist, it will trigger a rebuild every time.
// https://github.com/rust-lang/cargo/issues/6003
2022-11-21 17:39:02 +00:00
dirty (
" [DIRTY] foo v0.1.0 ([..]): the file `somedir` is missing " ,
false ,
) ;
2020-12-12 21:59:51 +00:00
if is_coarse_mtime ( ) {
sleep_ms ( 1000 ) ;
}
// Empty directory.
fs ::create_dir ( p . root ( ) . join ( " somedir " ) ) . unwrap ( ) ;
2022-11-21 17:39:02 +00:00
dirty (
" [DIRTY] foo v0.1.0 ([..]): the file `somedir` has changed ([..]) " ,
false ,
) ;
2020-12-12 21:59:51 +00:00
fresh ( ) ;
if is_coarse_mtime ( ) {
sleep_ms ( 1000 ) ;
}
// Add a file.
p . change_file ( " somedir/foo " , " " ) ;
p . change_file ( " somedir/bar " , " " ) ;
2022-11-21 17:39:02 +00:00
dirty (
" [DIRTY] foo v0.1.0 ([..]): the file `somedir` has changed ([..]) " ,
false ,
) ;
2020-12-12 21:59:51 +00:00
fresh ( ) ;
if is_coarse_mtime ( ) {
sleep_ms ( 1000 ) ;
}
// Add a symlink.
p . symlink ( " foo " , " somedir/link " ) ;
2022-11-21 17:39:02 +00:00
dirty (
" [DIRTY] foo v0.1.0 ([..]): the file `somedir` has changed ([..]) " ,
false ,
) ;
2020-12-12 21:59:51 +00:00
fresh ( ) ;
if is_coarse_mtime ( ) {
sleep_ms ( 1000 ) ;
}
// Move the symlink.
fs ::remove_file ( p . root ( ) . join ( " somedir/link " ) ) . unwrap ( ) ;
p . symlink ( " bar " , " somedir/link " ) ;
2022-11-21 17:39:02 +00:00
dirty (
" [DIRTY] foo v0.1.0 ([..]): the file `somedir` has changed ([..]) " ,
false ,
) ;
2020-12-12 21:59:51 +00:00
fresh ( ) ;
if is_coarse_mtime ( ) {
sleep_ms ( 1000 ) ;
}
// Remove a file.
fs ::remove_file ( p . root ( ) . join ( " somedir/foo " ) ) . unwrap ( ) ;
2022-11-21 17:39:02 +00:00
dirty (
" [DIRTY] foo v0.1.0 ([..]): the file `somedir` has changed ([..]) " ,
false ,
) ;
2020-12-12 21:59:51 +00:00
fresh ( ) ;
}
2021-01-11 18:42:38 +00:00
2023-01-22 15:12:57 +00:00
#[ cargo_test ]
fn rerun_if_published_directory ( ) {
// build script of a dependency contains a `rerun-if-changed` pointing to a directory
Package ::new ( " mylib-sys " , " 1.0.0 " )
. file ( " mylib/balrog.c " , " " )
. file ( " src/lib.rs " , " " )
. file (
" build.rs " ,
r #"
fn main ( ) {
// Changing to mylib/balrog.c will not trigger a rebuild
2023-05-30 00:20:54 +00:00
println! ( " cargo::rerun-if-changed=mylib " ) ;
2023-01-22 15:12:57 +00:00
}
" #,
)
. publish ( ) ;
let p = project ( )
. file (
" Cargo.toml " ,
r #"
[ package ]
name = " foo "
version = " 0.0.1 "
[ dependencies ]
mylib - sys = " 1.0.0 "
" #,
)
. file ( " src/main.rs " , " fn main() {} " )
. build ( ) ;
p . cargo ( " check " ) . run ( ) ;
// Delete regitry src to make directories being recreated with the latest timestamp.
cargo_home ( ) . join ( " registry/src " ) . rm_rf ( ) ;
p . cargo ( " check --verbose " )
. with_stderr (
" \
[ FRESH ] mylib - sys v1 . 0.0
[ FRESH ] foo v0 . 0.1 ( [ CWD ] )
[ FINISHED ] dev [ unoptimized + debuginfo ] target ( s ) in [ .. ]
" ,
)
. run ( ) ;
// Upgrade of a package should still trigger a rebuild
Package ::new ( " mylib-sys " , " 1.0.1 " )
. file ( " mylib/balrog.c " , " " )
. file ( " mylib/balrog.h " , " " )
. file ( " src/lib.rs " , " " )
. file (
" build.rs " ,
r #"
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rerun-if-changed=mylib " ) ;
2023-01-22 15:12:57 +00:00
}
" #,
)
. publish ( ) ;
p . cargo ( " update " ) . run ( ) ;
p . cargo ( " fetch " ) . run ( ) ;
p . cargo ( " check -v " )
. with_stderr ( format! (
" \
[ COMPILING ] mylib - sys [ .. ]
[ RUNNING ] ` rustc - - crate - name build_script_build [ .. ]
[ RUNNING ] ` [ .. ] build - script - build [ .. ] `
[ RUNNING ] ` rustc - - crate - name mylib_sys [ .. ]
[ CHECKING ] foo [ .. ]
[ RUNNING ] ` rustc - - crate - name foo [ .. ]
[ FINISHED ] [ .. ] " ,
) )
. run ( ) ;
}
2021-01-11 18:42:38 +00:00
#[ cargo_test ]
fn test_with_dep_metadata ( ) {
let p = project ( )
. file (
" Cargo.toml " ,
r #"
[ package ]
name = " foo "
version = " 0.1.0 "
[ dependencies ]
bar = { path = ' bar ' }
" #,
)
. file ( " src/lib.rs " , " " )
. file (
" build.rs " ,
r #"
fn main ( ) {
assert_eq! ( std ::env ::var ( " DEP_BAR_FOO " ) . unwrap ( ) , " bar " ) ;
}
" #,
)
. file (
" bar/Cargo.toml " ,
r #"
[ package ]
name = " bar "
version = " 0.1.0 "
links = ' bar '
" #,
)
. file ( " bar/src/lib.rs " , " " )
. file (
" bar/build.rs " ,
r #"
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::metadata=foo=bar " ) ;
2021-01-11 18:42:38 +00:00
}
" #,
)
. build ( ) ;
p . cargo ( " test --lib " ) . run ( ) ;
}
2021-02-02 00:28:23 +00:00
#[ cargo_test ]
fn duplicate_script_with_extra_env ( ) {
// Test where a build script is run twice, that emits different rustc-env
// and rustc-cfg values. In this case, one is run for host, the other for
// target.
if ! cross_compile ::can_run_on_host ( ) {
return ;
}
let target = cross_compile ::alternate ( ) ;
let p = project ( )
. file (
" Cargo.toml " ,
r #"
[ workspace ]
members = [ " foo " , " pm " ]
" #,
)
. file (
" foo/Cargo.toml " ,
r #"
[ package ]
name = " foo "
version = " 0.1.0 "
[ dependencies ]
pm = { path = " ../pm " }
" #,
)
. file (
" foo/src/lib.rs " ,
& r #"
//! ```rust
//! #[cfg(not(mycfg="{target}"))]
//! compile_error!{"expected mycfg set"}
//! assert_eq!(env!("CRATE_TARGET"), "{target}");
//! assert_eq!(std::env::var("CRATE_TARGET").unwrap(), "{target}");
//! ```
#[ test ]
fn check_target ( ) {
#[ cfg(not(mycfg= " {target} " )) ]
compile_error! { " expected mycfg set " }
// Compile-time assertion.
assert_eq! ( env! ( " CRATE_TARGET " ) , " {target} " ) ;
// Run-time assertion.
assert_eq! ( std ::env ::var ( " CRATE_TARGET " ) . unwrap ( ) , " {target} " ) ;
}
" #
. replace ( " {target} " , target ) ,
)
. file (
" foo/build.rs " ,
r #"
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::rustc-env=CRATE_TARGET= {} " , std ::env ::var ( " TARGET " ) . unwrap ( ) ) ;
println! ( " cargo::rustc-cfg=mycfg= \" {} \" " , std ::env ::var ( " TARGET " ) . unwrap ( ) ) ;
2021-02-02 00:28:23 +00:00
}
" #,
)
. file (
" pm/Cargo.toml " ,
r #"
[ package ]
name = " pm "
version = " 0.1.0 "
[ lib ]
proc - macro = true
# This is just here to speed things up .
doctest = false
[ dev - dependencies ]
foo = { path = " ../foo " }
" #,
)
. file ( " pm/src/lib.rs " , " " )
. build ( ) ;
p . cargo ( " test --workspace --target " )
. arg ( & target )
. with_stdout_contains ( " test check_target ... ok " )
. run ( ) ;
if cargo_test_support ::is_nightly ( ) {
p . cargo ( " test --workspace -Z doctest-xcompile --doc --target " )
. arg ( & target )
2022-07-16 02:32:23 +00:00
. masquerade_as_nightly_cargo ( & [ " doctest-xcompile " ] )
2023-06-02 08:26:29 +00:00
. with_stdout_contains ( " test foo/src/lib.rs - (line 2) ... ok " )
2021-02-02 00:28:23 +00:00
. run ( ) ;
}
}
2021-09-11 23:34:09 +00:00
#[ cargo_test ]
fn wrong_output ( ) {
let p = project ( )
. file ( " src/lib.rs " , " " )
. file (
" build.rs " ,
r #"
fn main ( ) {
2023-05-30 00:20:54 +00:00
println! ( " cargo::example " ) ;
2021-09-11 23:34:09 +00:00
}
" #,
)
. build ( ) ;
p . cargo ( " build " )
. with_status ( 101 )
. with_stderr (
" \
[ COMPILING ] foo [ .. ]
2023-05-30 00:20:54 +00:00
error : invalid output in build script of ` foo v0 . 0.1 ( [ ROOT ] / foo ) ` : ` cargo ::example `
Expected a line with ` cargo ::KEY = VALUE ` with an ` = ` character , but none was found .
2023-07-07 01:33:41 +00:00
See https ://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
for more information about build script outputs .
" ,
)
. run ( ) ;
}
2022-10-10 15:43:39 +00:00
#[ cargo_test ]
fn custom_build_closes_stdin ( ) {
// Ensure stdin is closed to prevent deadlock.
// See https://github.com/rust-lang/cargo/issues/11196
let p = project ( )
. file (
" Cargo.toml " ,
r #"
[ package ]
name = " foo "
version = " 0.5.0 "
build = " build.rs "
" #,
)
. file ( " src/main.rs " , " fn main() {} " )
. file (
" build.rs " ,
r #" fn main() {
let mut line = String ::new ( ) ;
std ::io ::stdin ( ) . read_line ( & mut line ) . unwrap ( ) ;
} " #,
)
. build ( ) ;
p . cargo ( " build " ) . run ( ) ;
}
2023-05-30 00:40:41 +00:00
#[ cargo_test ]
fn test_old_syntax ( ) {
let p = project ( )
. file (
" Cargo.toml " ,
r #"
[ package ]
name = " foo "
version = " 0.0.1 "
authors = [ ]
build = " build.rs "
" #,
)
. file (
" src/main.rs " ,
r #"
const FOO : & 'static str = env! ( " FOO " ) ;
fn main ( ) {
println! ( " {} " , FOO ) ;
}
" #,
)
. file (
" build.rs " ,
r #" fn main() {
println! ( " cargo:rustc-env=FOO=foo " ) ;
println! ( " cargo:foo=foo " ) ;
} " #,
)
. build ( ) ;
p . cargo ( " build -v " ) . run ( ) ;
p . cargo ( " run -v " ) . with_stdout ( " foo \n " ) . run ( ) ;
}
#[ cargo_test ]
fn test_invalid_old_syntax ( ) {
// Unexpected metadata value.
let p = project ( )
. file ( " src/lib.rs " , " " )
. file (
" build.rs " ,
r #"
fn main ( ) {
println! ( " cargo:foo " ) ;
}
" #,
)
. build ( ) ;
p . cargo ( " build " )
. with_status ( 101 )
. with_stderr (
" \
[ COMPILING ] foo [ .. ]
error : invalid output in build script of ` foo v0 . 0.1 ( [ ROOT ] / foo ) ` : ` cargo :foo `
Expected a line with ` cargo :KEY = VALUE ` with an ` = ` character , but none was found .
See https ://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
for more information about build script outputs .
" ,
)
. run ( ) ;
}
#[ cargo_test ]
fn test_invalid_new_syntax ( ) {
// Unexpected metadata value.
let p = project ( )
. file ( " src/lib.rs " , " " )
. file (
" build.rs " ,
r #"
fn main ( ) {
println! ( " cargo::metadata=foo " ) ;
}
" #,
)
. build ( ) ;
p . cargo ( " build " )
. with_status ( 101 )
. with_stderr (
" \
[ COMPILING ] foo [ .. ]
error : invalid output in build script of ` foo v0 . 0.1 ( [ ROOT ] / foo ) ` : ` cargo ::metadata = foo `
Expected a line with ` cargo ::metadata = KEY = VALUE ` with an ` = ` character , but none was found .
See https ://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
for more information about build script outputs .
" ,
)
. run ( ) ;
// `cargo::` can not be used with the unknown key.
let p = project ( )
. file ( " src/lib.rs " , " " )
. file (
" build.rs " ,
r #"
fn main ( ) {
println! ( " cargo::foo=bar " ) ;
}
" #,
)
. build ( ) ;
p . cargo ( " build " )
. with_status ( 101 )
. with_stderr (
" \
[ COMPILING ] foo [ .. ]
error : invalid output in build script of ` foo v0 . 0.1 ( [ ROOT ] / foo ) ` : ` cargo ::foo = bar `
Unknown key : ` foo ` .
See https ://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
for more information about build script outputs .
" ,
)
. run ( ) ;
}
2023-12-14 15:06:35 +00:00
#[ cargo_test ]
fn test_new_syntax_with_old_msrv ( ) {
let p = project ( )
. file (
" Cargo.toml " ,
r #"
[ package ]
name = " foo "
version = " 0.5.0 "
authors = [ ]
build = " build.rs "
rust - version = " 1.60.0 "
" #,
)
. file ( " src/lib.rs " , " " )
. file (
" build.rs " ,
r #"
fn main ( ) {
println! ( " cargo::metadata=foo=bar " ) ;
}
" #,
)
. build ( ) ;
p . cargo ( " build " )
. with_status ( 101 )
. with_stderr_contains (
" \
[ COMPILING ] foo [ .. ]
error : the ` cargo ::` syntax for build script output instructions was added in Rust 1.7 7.0 , \
but the minimum supported Rust version of ` foo v0 . 5.0 ( [ ROOT ] / foo ) ` is 1.6 0. 0.
See https ://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
for more information about build script outputs .
" ,
)
. run ( ) ;
}
#[ cargo_test ]
fn test_old_syntax_with_old_msrv ( ) {
let p = project ( )
. file (
" Cargo.toml " ,
r #"
[ package ]
name = " foo "
version = " 0.0.1 "
authors = [ ]
build = " build.rs "
rust - version = " 1.60.0 "
" #,
)
. file (
" src/main.rs " ,
r #"
const FOO : & 'static str = env! ( " FOO " ) ;
fn main ( ) {
println! ( " {} " , FOO ) ;
}
" #,
)
. file (
" build.rs " ,
r #" fn main() {
println! ( " cargo:rustc-env=FOO=foo " ) ;
println! ( " cargo:foo=foo " ) ;
} " #,
)
. build ( ) ;
p . cargo ( " build -v " ) . run ( ) ;
p . cargo ( " run -v " ) . with_stdout ( " foo \n " ) . run ( ) ;
}