cargo/tests/testsuite/build_script.rs

5234 lines
133 KiB
Rust
Raw Normal View History

2019-11-25 02:42:45 +00:00
//! Tests for build.rs scripts.
use cargo_test_support::compare::assert_match_exact;
use cargo_test_support::install::cargo_home;
use cargo_test_support::paths::CargoPathExt;
use cargo_test_support::registry::Package;
use cargo_test_support::tools;
use cargo_test_support::{
basic_manifest, cargo_exe, cross_compile, is_coarse_mtime, project, project_in,
};
use cargo_test_support::{rustc_host, sleep_ms, slow_cpu_multiplier, symlink_supported};
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;
#[cargo_test]
fn custom_build_script_failed() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
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() {}")
.file("build.rs", "fn main() { std::process::exit(101); }")
.build();
p.cargo("build -v")
.with_status(101)
.with_stderr(
2018-03-14 15:17:44 +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`
[ERROR] failed to run custom build command for `foo v0.5.0 ([CWD])`
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])`
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 [..]
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])`
Caused by:
process didn't exit successfully: `[..]/build-script-build` (exit [..]: 101)",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[cargo_test]
fn custom_build_env_vars() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.5.0"
authors = ["wycats@example.com"]
2020-09-27 00:59:58 +00:00
[features]
bar_feat = ["bar/foo"]
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#"
[package]
2020-09-27 00:59:58 +00:00
name = "bar"
version = "0.5.0"
authors = ["wycats@example.com"]
build = "build.rs"
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() {}");
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!(
r##"
2015-02-06 07:27:53 +00:00
use std::env;
use std::path::Path;
fn main() {{
2015-02-13 04:10:07 +00:00
let _target = env::var("TARGET").unwrap();
let _ncpus = env::var("NUM_JOBS").unwrap();
let _dir = env::var("CARGO_MANIFEST_DIR").unwrap();
2015-02-13 04:10:07 +00:00
let opt = env::var("OPT_LEVEL").unwrap();
assert_eq!(opt, "0");
2015-02-13 04:10:07 +00:00
let opt = env::var("PROFILE").unwrap();
assert_eq!(opt, "debug");
2015-02-13 04:10:07 +00:00
let debug = env::var("DEBUG").unwrap();
assert_eq!(debug, "true");
2015-02-13 04:10:07 +00:00
let out = env::var("OUT_DIR").unwrap();
assert!(out.starts_with(r"{0}"));
assert!(Path::new(&out).is_dir());
2015-02-13 04:10:07 +00:00
let _host = env::var("HOST").unwrap();
2015-02-13 04:10:07 +00:00
let _feat = env::var("CARGO_FEATURE_FOO").unwrap();
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}"#);
}}
let rustc = env::var("RUSTC").unwrap();
assert_eq!(rustc, "rustc");
let rustdoc = env::var("RUSTDOC").unwrap();
assert_eq!(rustdoc, "rustdoc");
assert!(env::var("RUSTC_WRAPPER").is_err());
assert!(env::var("RUSTC_WORKSPACE_WRAPPER").is_err());
assert!(env::var("RUSTC_LINKER").is_err());
2021-06-29 19:08:50 +00:00
assert!(env::var("RUSTFLAGS").is_err());
let rustflags = env::var("CARGO_ENCODED_RUSTFLAGS").unwrap();
assert_eq!(rustflags, "");
}}
"##,
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
);
let p = p.file("bar/build.rs", &file_content).build();
p.cargo("build --features bar_feat").run();
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();
}
#[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());
let x;
#[cfg(special)]
2021-06-29 19:08:50 +00:00
{{ assert_eq!(env::var("CARGO_ENCODED_RUSTFLAGS").unwrap(), "{}"); x = String::new(); }}
#[cfg(notspecial)]
2021-06-29 19:08:50 +00:00
{{ assert_eq!(env::var("CARGO_ENCODED_RUSTFLAGS").unwrap(), "{}"); x = String::new(); }}
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();
}
#[cargo_test]
fn custom_build_env_var_rustc_wrapper() {
let wrapper = tools::echo_wrapper();
let p = project()
.file(
"build.rs",
r#"
use std::env;
fn main() {{
assert_eq!(
env::var("RUSTC_WRAPPER").unwrap(),
env::var("CARGO_RUSTC_WRAPPER_CHECK").unwrap()
);
}}
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("check")
.env("CARGO_BUILD_RUSTC_WRAPPER", &wrapper)
.env("CARGO_RUSTC_WRAPPER_CHECK", &wrapper)
.run();
}
#[cargo_test]
fn custom_build_env_var_rustc_workspace_wrapper() {
let wrapper = tools::echo_wrapper();
// Workspace wrapper should be set for any crate we're operating directly on.
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();
// 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();
}
#[cargo_test]
fn custom_build_env_var_rustc_linker() {
if cross_compile::disabled() {
return;
}
let target = cross_compile::alternate();
let p = project()
.file(
".cargo/config",
&format!(
r#"
[target.{}]
linker = "/path/to/linker"
"#,
target
),
2018-12-08 11:19:47 +00:00
)
.file(
"build.rs",
r#"
use std::env;
fn main() {
assert!(env::var("RUSTC_LINKER").unwrap().ends_with("/path/to/linker"));
}
"#,
2018-12-08 11:19:47 +00:00
)
.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();
}
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();
}
#[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
),
)
.file("build.rs", "fn main() {}")
.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#"
target-applies-to-host = false
[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.
p.cargo("build -Z target-applies-to-host --target")
.arg(&target)
.masquerade_as_nightly_cargo(&["target-applies-to-host"])
.run();
}
#[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.
p.cargo("build -Z target-applies-to-host --target")
.env("CARGO_TARGET_APPLIES_TO_HOST", "false")
.arg(&target)
.masquerade_as_nightly_cargo(&["target-applies-to-host"])
.run();
}
#[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
),
)
.file("build.rs", "fn main() {}")
.file("src/lib.rs", "")
.build();
// build.rs should fail due to -Zhost-config being set without -Ztarget-applies-to-host
p.cargo("build -Z host-config --target")
.arg(&target)
.masquerade_as_nightly_cargo(&["host-config"])
.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
",
)
.run();
}
#[cargo_test]
fn custom_build_linker_host_target_with_bad_host_config() {
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
),
)
.file("build.rs", "fn main() {}")
.file("src/lib.rs", "")
.build();
// build.rs should fail due to bad host linker being set
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
.arg(&target)
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
.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/host/linker [..]`
[ERROR] linker `[..]/path/to/host/linker` not found
"
)
.run();
}
#[cargo_test]
fn custom_build_linker_bad_host() {
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
),
)
.file("build.rs", "fn main() {}")
.file("src/lib.rs", "")
.build();
// build.rs should fail due to bad host linker being set
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
.arg(&target)
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
.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/host/linker [..]`
[ERROR] linker `[..]/path/to/host/linker` not found
"
)
.run();
}
#[cargo_test]
fn custom_build_linker_bad_host_with_arch() {
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
),
)
.file("build.rs", "fn main() {}")
.file("src/lib.rs", "")
.build();
// build.rs should fail due to bad host linker being set
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
.arg(&target)
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
.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/host/arch/linker [..]`
[ERROR] linker `[..]/path/to/host/arch/linker` not found
"
)
.run();
}
#[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();
// build.rs should be built fine since cross target != host target.
// assertion should succeed since it's still passed the target linker
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
.arg(&target)
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
.run();
}
#[cargo_test]
fn custom_build_linker_bad_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/linker"
[host.{}]
linker = "/path/to/host/arch/linker"
[target.{}]
linker = "/path/to/target/linker"
"#,
cross_target, target
),
)
.file("build.rs", "fn main() {}")
.file("src/lib.rs", "")
.build();
// build.rs should fail due to bad host linker being set
p.cargo("build -Z target-applies-to-host -Z host-config --verbose --target")
.arg(&target)
.masquerade_as_nightly_cargo(&["target-applies-to-host", "host-config"])
.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/host/linker [..]`
[ERROR] linker `[..]/path/to/host/linker` not found
"
)
.run();
}
#[cargo_test]
fn custom_build_script_wrong_rustc_flags() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
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() {}")
.file(
"build.rs",
r#"fn main() { println!("cargo:rustc-flags=-aaa -bbb"); }"#,
2018-12-08 11:19:47 +00:00
)
.build();
p.cargo("build")
.with_status(101)
.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();
}
#[cargo_test]
fn custom_build_script_rustc_flags() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "bar"
version = "0.5.0"
authors = ["wycats@example.com"]
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() {}")
.file(
"foo/Cargo.toml",
r#"
[package]
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", "")
.file(
"foo/build.rs",
r#"
2020-09-27 00:59:58 +00:00
fn main() {
println!("cargo:rustc-flags=-l nonexistinglib -L /dummy/path1 -L /dummy/path2");
}
"#,
2019-08-04 18:09:25 +00:00
)
.build();
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 [..]
",
2019-08-04 18:09:25 +00:00
)
.run();
}
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#"
[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#"
[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() {
println!("cargo:rustc-flags=-lnonexistinglib -L/dummy/path1 -L/dummy/path2");
}
"#,
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 [..]
",
2019-08-04 18:09:25 +00:00
)
.run();
}
#[cargo_test]
fn links_no_build_cmd() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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", "")
.build();
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 \
not have a custom build script
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[cargo_test]
fn links_duplicates() {
2018-01-26 03:50:55 +00:00
// this tests that the links_duplicates are caught at resolver time
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.5.0"
authors = []
links = "a"
build = "build.rs"
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", "")
.file("build.rs", "")
2018-03-14 15:17:44 +00:00
.file(
"a-sys/Cargo.toml",
r#"
[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", "")
.file("a-sys/build.rs", "")
.build();
p.cargo("build").with_status(101)
.with_stderr("\
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 ([..])`
2021-06-10 07:12:19 +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-sys' 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
").run();
}
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`
... 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();
}
#[cargo_test]
fn links_duplicates_deep_dependency() {
2018-01-26 03:50:55 +00:00
// this tests that the links_duplicates are caught at resolver time
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.5.0"
authors = []
links = "a"
build = "build.rs"
2020-09-27 00:59:58 +00:00
[dependencies.a]
path = "a"
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "")
.file("build.rs", "")
2018-03-14 15:17:44 +00:00
.file(
"a/Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "a"
version = "0.5.0"
authors = []
build = "build.rs"
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", "")
.file("a/build.rs", "")
2018-03-14 15:17:44 +00:00
.file(
"a/a-sys/Cargo.toml",
r#"
[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", "")
.file("a/a-sys/build.rs", "")
.build();
p.cargo("build").with_status(101)
2016-05-12 17:06:36 +00:00
.with_stderr("\
error: failed to select a version for `a-sys`.
2018-02-15 03:28:59 +00:00
... required by package `a v0.5.0 ([..])`
... 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 ([..])`
2021-06-10 07:12:19 +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-sys' 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
").run();
}
#[cargo_test]
fn overrides_and_links() {
let target = rustc_host();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.5.0"
authors = []
build = "build.rs"
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#"
[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", "")
.file("a/build.rs", "not valid rust code")
.build();
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[..]
[..]
[..]
[..]
[..]
[RUNNING] `rustc --crate-name foo [..] -L foo -L bar`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[cargo_test]
fn unused_overrides() {
let target = rustc_host();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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", "")
.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();
p.cargo("build -v").run();
}
#[cargo_test]
fn links_passes_env_vars() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.5.0"
authors = []
build = "build.rs"
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#"
[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");
2020-09-27 00:59:58 +00:00
println!("cargo:foo=bar");
println!("cargo:bar=baz");
}
"#,
2018-12-08 11:19:47 +00:00
)
.build();
p.cargo("build -v").run();
}
#[cargo_test]
fn only_rerun_build_script() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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", "")
.file("build.rs", "fn main() {}")
.build();
p.cargo("build -v").run();
p.root().move_into_the_past();
p.change_file("some-new-file", "");
p.root().move_into_the_past();
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[DIRTY] foo v0.5.0 ([CWD]): the precalculated components changed
[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 [..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[cargo_test]
fn rebuild_continues_to_pass_env_vars() {
let a = project()
.at("a")
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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() {
println!("cargo:foo=bar");
println!("cargo:bar=baz");
std::thread::sleep(Duration::from_millis(500));
}
"#,
2018-12-08 11:19:47 +00:00
)
.build();
a.root().move_into_the_past();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
&format!(
r#"
[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();
p.cargo("build -v").run();
p.root().move_into_the_past();
p.change_file("some-new-file", "");
p.root().move_into_the_past();
p.cargo("build -v").run();
}
#[cargo_test]
fn testing_and_such() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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", "")
.file("build.rs", "fn main() {}")
.build();
2015-03-23 18:33:22 +00:00
println!("build");
p.cargo("build -v").run();
p.root().move_into_the_past();
p.change_file("src/lib.rs", "");
p.root().move_into_the_past();
2015-03-23 18:33:22 +00:00
println!("test");
p.cargo("test -vj1")
.with_stderr(
"\
[DIRTY] foo v0.5.0 ([CWD]): the precalculated components changed
[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 [..]`
[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)
.run();
2015-03-23 18:33:22 +00:00
println!("doc");
p.cargo("doc -v")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[DOCUMENTING] foo v0.5.0 ([CWD])
[RUNNING] `rustdoc [..]`
2017-01-18 19:37:52 +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
p.change_file("src/main.rs", "fn main() {}");
2015-03-23 18:33:22 +00:00
println!("run");
p.cargo("run")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[COMPILING] foo v0.5.0 ([CWD])
[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();
}
#[cargo_test]
fn propagation_of_l_flags() {
let target = rustc_host();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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#"
[package]
2020-09-27 00:59:58 +00:00
name = "a"
version = "0.5.0"
authors = []
links = "bar"
build = "build.rs"
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#"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#"
[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", "")
.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();
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[..]`
[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();
}
#[cargo_test]
fn propagation_of_l_flags_new() {
let target = rustc_host();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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#"
[package]
2020-09-27 00:59:58 +00:00
name = "a"
version = "0.5.0"
authors = []
links = "bar"
build = "build.rs"
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() {
println!("cargo:rustc-link-search=bar");
}
"#,
2018-12-08 11:19:47 +00:00
)
.file(
2018-03-14 15:17:44 +00:00
"b/Cargo.toml",
r#"
[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", "")
.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();
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[..]`
[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();
}
#[cargo_test]
fn build_deps_simple() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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",
"
#[allow(unused_extern_crates)]
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"))
.file("a/src/lib.rs", "")
.build();
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[COMPILING] a v0.5.0 ([CWD]/a)
2016-11-29 23:11:58 +00:00
[RUNNING] `rustc --crate-name a [..]`
[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 [..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[cargo_test]
fn build_deps_not_for_normal() {
let target = rustc_host();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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",
"
#[allow(unused_extern_crates)]
2015-02-09 16:16:08 +00:00
extern crate aaaaa;
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"))
.file("a/src/lib.rs", "")
.build();
p.cargo("build -v --target")
.arg(&target)
.with_status(101)
.with_stderr_contains("[..]can't find crate for `aaaaa`[..]")
.with_stderr_contains(
"\
[ERROR] could not compile `foo` (lib) due to previous error
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();
}
#[cargo_test]
fn build_cmd_with_a_build_cmd() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.5.0"
authors = []
build = "build.rs"
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",
"
#[allow(unused_extern_crates)]
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#"
[package]
2020-09-27 00:59:58 +00:00
name = "a"
version = "0.5.0"
authors = []
build = "build.rs"
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"))
.file("b/src/lib.rs", "")
.build();
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[COMPILING] b v0.5.0 ([CWD]/b)
2016-11-29 23:11:58 +00:00
[RUNNING] `rustc --crate-name b [..]`
[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 \
--emit=[..]link[..] \
-C metadata=[..] \
2018-08-02 09:18:48 +00:00
--out-dir [..]target/debug/deps \
-L [..]target/debug/deps`
[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 \
Add support for `-Cembed-bitcode=no` This commit is the Cargo half of support necessary for rust-lang/rust#70458. Today the compiler emits embedded bytecode in rlibs by default, but compresses it. This is both extraneous disk space and wasted build time for almost all builds, so the PR in question there is changing rustc to have a `-Cembed-bitcode` flag which, when enabled, places the bitcode in the object file rather than an auxiliary file (no extra compression), but also enables `-Cembed-bitcode=no` to disable bitcode emission entirely. This Cargo support changes Cargo to pass `-Cembed-bitcode=no` for almost all compilations. Cargo will keep `lto = true` and such working by not passing this flag (and thus allowing bitcode to get embedded), but by default `cargo build` and `cargo build --release` will no longer have any bitcode in rlibs which should result in speedier builds! Most of the changes here were around the test suite and various assertions about the `rustc` command lines we spit out. One test was hard-disabled until we can get `-Cembed-bitcode=no` into nightly, and then we can make it a nightly-only test. The test will then be stable again once `-Cembed-bitcode=no` hits stable. Note that this is intended to land before the upstream `-Cembed-bitcode` change. The thinking is that we'll land everything in rust-lang/rust all at once so there's no build time regressions for anyone. If we were to land the `-Cembed-bitcode` PR first then there would be a build time regression until we land Cargo changes because rustc would be emitting uncompressed bitcode by default and Cargo wouldn't be turning it off.
2020-04-01 18:41:27 +00:00
--emit=[..]link[..]\
-C metadata=[..] --out-dir [..] \
2018-08-02 09:18:48 +00:00
-L [..]target/debug/deps \
--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 \
--emit=[..]link[..]-C debuginfo=2 [..]\
-C metadata=[..] \
2017-01-03 21:22:58 +00:00
--out-dir [..] \
2018-08-02 09:18:48 +00:00
-L [..]target/debug/deps`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[cargo_test]
fn out_dir_is_preserved() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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();
// Make the file
p.cargo("build -v").run();
// Change to asserting that it's there
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(
"\
[DIRTY] foo [..]: the file `build.rs` has changed ([..])
[COMPILING] foo [..]
[RUNNING] `rustc --crate-name build_script_build [..]
[RUNNING] `[..]/build-script-build`
[RUNNING] `rustc --crate-name foo [..]
[FINISHED] [..]
",
)
.run();
// Run a fresh build where file should be preserved
p.cargo("build -v")
.with_stderr(
"\
[FRESH] foo [..]
[FINISHED] [..]
",
)
.run();
// One last time to make sure it's still there.
p.change_file("foo", "");
p.cargo("build -v")
.with_stderr(
"\
[DIRTY] foo [..]: the precalculated components changed
[COMPILING] foo [..]
[RUNNING] `[..]build-script-build`
[RUNNING] `rustc --crate-name foo [..]
[FINISHED] [..]
",
)
.run();
}
#[cargo_test]
fn output_separate_lines() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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() {
println!("cargo:rustc-flags=-L foo");
println!("cargo:rustc-flags=-l static=foo");
}
"#,
2018-12-08 11:19:47 +00:00
)
.build();
p.cargo("build -v")
.with_status(101)
.with_stderr_contains(
2018-03-14 15:17:44 +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();
}
#[cargo_test]
fn output_separate_lines_new() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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() {
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();
// The order of the arguments passed to rustc is important.
p.cargo("build -v")
.with_status(101)
.with_stderr_contains(
2018-03-14 15:17:44 +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`
[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();
}
#[cargo_test]
fn code_generation() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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"));
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;
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();
p.cargo("run")
.with_stderr(
"\
[COMPILING] foo v0.5.0 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[RUNNING] `target/debug/foo[EXE]`",
2018-12-08 11:19:47 +00:00
)
.with_stdout("Hello, World!")
.run();
p.cargo("test").run();
}
#[cargo_test]
fn release_with_build_script() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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();
p.cargo("build -v --release").run();
}
#[cargo_test]
fn build_script_only() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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() {}"#)
.build();
p.cargo("build -v")
.with_status(101)
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[ERROR] failed to parse manifest at `[..]`
Caused by:
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();
}
#[cargo_test]
fn shared_dep_with_a_build_script() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.5.0"
authors = []
build = "build.rs"
2020-09-27 00:59:58 +00:00
[dependencies.a]
path = "a"
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", "")
.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() {}")
.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 = []
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", "")
.build();
p.cargo("build -v").run();
}
#[cargo_test]
fn transitive_dep_host() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.5.0"
authors = []
build = "build.rs"
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", "")
.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() {}")
.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 = []
2020-09-27 00:59:58 +00:00
[lib]
name = "b"
plugin = true
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", "")
.build();
p.cargo("build").run();
}
#[cargo_test]
fn test_a_lib_with_a_build_command() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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"));
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;
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();
p.cargo("test").run();
}
#[cargo_test]
fn test_dev_dep_build_script() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.5.0"
authors = []
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#"
[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() {}")
.file("a/src/lib.rs", "")
.build();
p.cargo("test").run();
}
#[cargo_test]
fn build_script_with_dynamic_native_dependency() {
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 = []
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() {}")
.build();
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"
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() }")
.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;
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();
}
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();
build
.cargo("build -v")
.env("CARGO_LOG", "cargo::ops::cargo_rustc")
.run();
2018-11-17 23:42:19 +00:00
let root = build.root().join("target").join("debug");
foo.cargo("build -v")
2018-11-17 23:42:19 +00:00
.env("BUILDER_ROOT", root)
.env("CARGO_LOG", "cargo::ops::cargo_rustc")
.run();
}
#[cargo_test]
fn profile_and_opt_level_set_correctly() {
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;
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();
p.cargo("bench").run();
}
#[cargo_test]
fn profile_debug_0() {
let p = project()
.file(
"Cargo.toml",
r#"
2020-09-27 00:59:58 +00:00
[package]
name = "foo"
version = "0.0.1"
2020-09-27 00:59:58 +00:00
[profile.dev]
debug = 0
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "")
.file(
"build.rs",
r#"
2020-09-27 00:59:58 +00:00
use std::env;
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();
p.cargo("build").run();
}
#[cargo_test]
fn build_script_with_lto() {
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"
2020-09-27 00:59:58 +00:00
[profile.dev]
lto = true
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "")
.file("build.rs", "fn main() {}")
.build();
p.cargo("build").run();
}
#[cargo_test]
fn test_duplicate_deps() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.1.0"
authors = []
build = "build.rs"
2020-09-27 00:59:58 +00:00
[dependencies.bar]
path = "bar"
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"))
.file("bar/src/lib.rs", "pub fn do_nothing() {}")
.build();
p.cargo("build").run();
}
#[cargo_test]
fn cfg_feedback() {
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() {}")
.file(
"build.rs",
r#"fn main() { println!("cargo:rustc-cfg=foo"); }"#,
2018-12-08 11:19:47 +00:00
)
.build();
p.cargo("build -v").run();
}
#[cargo_test]
fn cfg_override() {
let target = rustc_host();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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() {}")
.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();
p.cargo("build -v").run();
}
#[cargo_test]
fn cfg_test() {
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(
"build.rs",
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() {}")
.build();
p.cargo("test -v")
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] [..] build.rs [..]
2018-08-02 09:18:48 +00:00
[RUNNING] `[..]/build-script-build`
[RUNNING] [..] --cfg foo[..]
[RUNNING] [..] --cfg foo[..]
[RUNNING] [..] --cfg foo[..]
[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")
.with_stdout_contains("test test_bar ... ok")
.with_stdout_contains_n("test [..] ... ok", 3)
.run();
}
#[cargo_test]
fn cfg_doc() {
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"
2020-09-27 00:59:58 +00:00
[dependencies.bar]
path = "bar"
"#,
2018-12-08 11:19:47 +00:00
)
.file(
"build.rs",
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(
"bar/build.rs",
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() {}")
.build();
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());
}
#[cargo_test]
fn cfg_override_test() {
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() {}")
.build();
p.cargo("test -v")
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `[..]`
[RUNNING] `[..]`
[RUNNING] `[..]`
[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")
.with_stdout_contains("test test_bar ... ok")
.with_stdout_contains_n("test [..] ... ok", 3)
.run();
}
#[cargo_test]
fn cfg_override_doc() {
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"
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", "")
.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", "")
.file("bar/src/lib.rs", "#[cfg(bar)] pub fn bar() {}")
.build();
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());
}
#[cargo_test]
2017-04-17 18:48:56 +00:00
fn env_build() {
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(
"build.rs",
r#"fn main() { println!("cargo:rustc-env=FOO=foo"); }"#,
2018-12-08 11:19:47 +00:00
)
.build();
p.cargo("build -v").run();
p.cargo("run -v").with_stdout("foo\n").run();
2017-04-17 18:48:56 +00:00
}
#[cargo_test]
2017-04-17 18:48:56 +00:00
fn env_test() {
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(
"build.rs",
r#"fn main() { println!("cargo:rustc-env=FOO=foo"); }"#,
2018-12-08 11:19:47 +00:00
)
.file(
"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();
p.cargo("test -v")
.with_stderr(
"\
[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`
[RUNNING] [..] --crate-name foo[..]
[RUNNING] [..] --crate-name foo[..]
[RUNNING] [..] --crate-name test[..]
[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)
.with_stdout_contains("test test_foo ... ok")
.run();
2017-04-17 18:48:56 +00:00
}
#[cargo_test]
fn env_doc() {
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(
"build.rs",
r#"fn main() { println!("cargo:rustc-env=FOO=foo"); }"#,
2018-12-08 11:19:47 +00:00
)
.build();
p.cargo("doc -v").run();
}
#[cargo_test]
fn flags_go_into_tests() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.5.0"
authors = []
2020-09-27 00:59:58 +00:00
[dependencies]
b = { path = "b" }
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "")
.file("tests/foo.rs", "")
2018-03-14 15:17:44 +00:00
.file(
"b/Cargo.toml",
r#"
[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#"
[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() {
println!("cargo:rustc-link-search=test");
}
"#,
2018-12-08 11:19:47 +00:00
)
.build();
p.cargo("test -v --test=foo")
.with_stderr(
"\
[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[..]`
[COMPILING] b v0.5.0 ([..]
2018-08-02 09:18:48 +00:00
[RUNNING] `rustc [..] b/src/lib.rs [..] -L test[..]`
[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[..]`
[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")
.run();
2018-03-14 15:17:44 +00:00
p.cargo("test -v -pb --lib")
.with_stderr(
"\
[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[..]`
[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")
.run();
}
#[cargo_test]
fn diamond_passes_args_only_once() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.5.0"
authors = []
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", "")
.file("tests/foo.rs", "")
2018-03-14 15:17:44 +00:00
.file(
"a/Cargo.toml",
r#"
[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#"
[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#"
[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() {
println!("cargo:rustc-link-search=native=test");
}
"#,
2018-12-08 11:19:47 +00:00
)
.file("c/src/lib.rs", "")
.build();
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +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 ([..]
[RUNNING] `[..]rmeta -L native=test`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[cargo_test]
fn adding_an_override_invalidates() {
let target = rustc_host();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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", "")
.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() {
println!("cargo:rustc-link-search=native=foo");
}
"#,
2018-12-08 11:19:47 +00:00
)
.build();
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[COMPILING] foo v0.5.0 ([..]
[RUNNING] `rustc [..]`
[RUNNING] `[..]`
[RUNNING] `rustc [..] -L native=foo`
[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
p.change_file(
".cargo/config",
&format!(
"
[target.{}.foo]
rustc-link-search = [\"native=bar\"]
",
target
),
);
2018-03-14 15:17:44 +00:00
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[COMPILING] foo v0.5.0 ([..]
[RUNNING] `rustc [..] -L native=bar`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[cargo_test]
fn changing_an_override_invalidates() {
let target = rustc_host();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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!(
"
[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", "")
.build();
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[COMPILING] foo v0.5.0 ([..]
[RUNNING] `rustc [..] -L native=foo`
[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
p.change_file(
".cargo/config",
&format!(
"
[target.{}.foo]
rustc-link-search = [\"native=bar\"]
",
target
),
);
2018-03-14 15:17:44 +00:00
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[DIRTY] foo v0.5.0 ([..]): the precalculated components changed
[COMPILING] foo v0.5.0 ([..]
[RUNNING] `rustc [..] -L native=bar`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[cargo_test]
fn fresh_builds_possible_with_link_libs() {
// The bug is non-deterministic. Sometimes you can get a fresh build
let target = rustc_host();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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!(
"
[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", "")
.build();
2017-04-17 18:48:56 +00:00
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +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
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +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();
}
#[cargo_test]
fn fresh_builds_possible_with_multiple_metadata_overrides() {
// The bug is non-deterministic. Sometimes you can get a fresh build
let target = rustc_host();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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!(
"
[target.{}.foo]
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", "")
.build();
2017-04-17 18:48:56 +00:00
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +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
p.cargo("build -v")
.env("CARGO_LOG", "cargo::ops::cargo_rustc::fingerprint=info")
.with_stderr(
2018-03-14 15:17:44 +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();
}
#[cargo_test]
Fix dep-info files emitting paths relative to deps' roots Sample `shoo.d` file prior to this change is below, note the `build.rs` at the end, which was not from my package. From booping the debugger, I found this was coming from `compiler_builtins`. This is not really their bug though: if a build.rs asks for rerun-if-changed on some crate relative path, this will happen in general. So I've fixed it in Cargo and added a test to prevent it regressing. ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s build.rs ``` This change fixes it so it's like: ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.39/build.rs /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/build.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s ```
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()
Fix dep-info files emitting paths relative to deps' roots Sample `shoo.d` file prior to this change is below, note the `build.rs` at the end, which was not from my package. From booping the debugger, I found this was coming from `compiler_builtins`. This is not really their bug though: if a build.rs asks for rerun-if-changed on some crate relative path, this will happen in general. So I've fixed it in Cargo and added a test to prevent it regressing. ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s build.rs ``` This change fixes it so it's like: ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.39/build.rs /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/build.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s ```
2021-04-27 11:25:46 +00:00
.file(
2021-04-28 04:21:56 +00:00
"awoo/Cargo.toml",
Fix dep-info files emitting paths relative to deps' roots Sample `shoo.d` file prior to this change is below, note the `build.rs` at the end, which was not from my package. From booping the debugger, I found this was coming from `compiler_builtins`. This is not really their bug though: if a build.rs asks for rerun-if-changed on some crate relative path, this will happen in general. So I've fixed it in Cargo and added a test to prevent it regressing. ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s build.rs ``` This change fixes it so it's like: ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.39/build.rs /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/build.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s ```
2021-04-27 11:25:46 +00:00
r#"
[package]
Fix dep-info files emitting paths relative to deps' roots Sample `shoo.d` file prior to this change is below, note the `build.rs` at the end, which was not from my package. From booping the debugger, I found this was coming from `compiler_builtins`. This is not really their bug though: if a build.rs asks for rerun-if-changed on some crate relative path, this will happen in general. So I've fixed it in Cargo and added a test to prevent it regressing. ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s build.rs ``` This change fixes it so it's like: ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.39/build.rs /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/build.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s ```
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", "")
Fix dep-info files emitting paths relative to deps' roots Sample `shoo.d` file prior to this change is below, note the `build.rs` at the end, which was not from my package. From booping the debugger, I found this was coming from `compiler_builtins`. This is not really their bug though: if a build.rs asks for rerun-if-changed on some crate relative path, this will happen in general. So I've fixed it in Cargo and added a test to prevent it regressing. ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s build.rs ``` This change fixes it so it's like: ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.39/build.rs /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/build.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s ```
2021-04-27 11:25:46 +00:00
.file(
2021-04-28 04:21:56 +00:00
"awoo/build.rs",
Fix dep-info files emitting paths relative to deps' roots Sample `shoo.d` file prior to this change is below, note the `build.rs` at the end, which was not from my package. From booping the debugger, I found this was coming from `compiler_builtins`. This is not really their bug though: if a build.rs asks for rerun-if-changed on some crate relative path, this will happen in general. So I've fixed it in Cargo and added a test to prevent it regressing. ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s build.rs ``` This change fixes it so it's like: ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.39/build.rs /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/build.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s ```
2021-04-27 11:25:46 +00:00
r#"
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=barkbarkbark");
}
"#,
)
.file(
"Cargo.toml",
2021-04-28 04:21:56 +00:00
r#"
[package]
Fix dep-info files emitting paths relative to deps' roots Sample `shoo.d` file prior to this change is below, note the `build.rs` at the end, which was not from my package. From booping the debugger, I found this was coming from `compiler_builtins`. This is not really their bug though: if a build.rs asks for rerun-if-changed on some crate relative path, this will happen in general. So I've fixed it in Cargo and added a test to prevent it regressing. ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s build.rs ``` This change fixes it so it's like: ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.39/build.rs /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/build.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s ```
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" }
Fix dep-info files emitting paths relative to deps' roots Sample `shoo.d` file prior to this change is below, note the `build.rs` at the end, which was not from my package. From booping the debugger, I found this was coming from `compiler_builtins`. This is not really their bug though: if a build.rs asks for rerun-if-changed on some crate relative path, this will happen in general. So I've fixed it in Cargo and added a test to prevent it regressing. ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s build.rs ``` This change fixes it so it's like: ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.39/build.rs /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/build.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s ```
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);
assert_match_exact(
"[..]/target/debug/meow[EXE]: [..]/awoo/barkbarkbark [..]/awoo/build.rs[..]",
&dot_d,
Fix dep-info files emitting paths relative to deps' roots Sample `shoo.d` file prior to this change is below, note the `build.rs` at the end, which was not from my package. From booping the debugger, I found this was coming from `compiler_builtins`. This is not really their bug though: if a build.rs asks for rerun-if-changed on some crate relative path, this will happen in general. So I've fixed it in Cargo and added a test to prevent it regressing. ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s build.rs ``` This change fixes it so it's like: ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.39/build.rs /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/build.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s ```
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"));
Fix dep-info files emitting paths relative to deps' roots Sample `shoo.d` file prior to this change is below, note the `build.rs` at the end, which was not from my package. From booping the debugger, I found this was coming from `compiler_builtins`. This is not really their bug though: if a build.rs asks for rerun-if-changed on some crate relative path, this will happen in general. So I've fixed it in Cargo and added a test to prevent it regressing. ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s build.rs ``` This change fixes it so it's like: ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.39/build.rs /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/build.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s ```
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);
assert_match_exact(
"target/debug/meow[EXE]: awoo/barkbarkbark awoo/build.rs[..]",
&dot_d,
Fix dep-info files emitting paths relative to deps' roots Sample `shoo.d` file prior to this change is below, note the `build.rs` at the end, which was not from my package. From booping the debugger, I found this was coming from `compiler_builtins`. This is not really their bug though: if a build.rs asks for rerun-if-changed on some crate relative path, this will happen in general. So I've fixed it in Cargo and added a test to prevent it regressing. ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s build.rs ``` This change fixes it so it's like: ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.39/build.rs /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/build.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s ```
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"));
Fix dep-info files emitting paths relative to deps' roots Sample `shoo.d` file prior to this change is below, note the `build.rs` at the end, which was not from my package. From booping the debugger, I found this was coming from `compiler_builtins`. This is not really their bug though: if a build.rs asks for rerun-if-changed on some crate relative path, this will happen in general. So I've fixed it in Cargo and added a test to prevent it regressing. ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s build.rs ``` This change fixes it so it's like: ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.39/build.rs /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/build.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s ```
2021-04-27 11:25:46 +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#"
[package]
name = "awoo"
version = "0.5.0"
build = "build.rs"
"#,
)
.file("awoo/src/lib.rs", "")
.file(
"awoo/build.rs",
r#"
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=barkbarkbark");
}
"#,
)
.file(
"Cargo.toml",
r#"
[package]
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,
);
}
Fix dep-info files emitting paths relative to deps' roots Sample `shoo.d` file prior to this change is below, note the `build.rs` at the end, which was not from my package. From booping the debugger, I found this was coming from `compiler_builtins`. This is not really their bug though: if a build.rs asks for rerun-if-changed on some crate relative path, this will happen in general. So I've fixed it in Cargo and added a test to prevent it regressing. ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s build.rs ``` This change fixes it so it's like: ``` target/riscv64imac-mu-shoo-elf/release/shoo: /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.39/build.rs /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/build.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/core_arch_docs.md /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/mod.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd.rs /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/simd_llvm.rs crates/build_bits/src/lib.rs shoo/src/main.rs shoo/src/task.rs shoo/src/vectors.s ```
2021-04-27 11:25:46 +00:00
#[cargo_test]
fn rebuild_only_on_explicit_paths() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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() {
println!("cargo:rerun-if-changed=foo");
println!("cargo:rerun-if-changed=bar");
}
"#,
2018-12-08 11:19:47 +00:00
)
.build();
p.cargo("build -v").run();
// files don't exist, so should always rerun if they don't exist
println!("run without");
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[DIRTY] foo v0.5.0 ([..]): the file `foo` is missing
[COMPILING] foo v0.5.0 ([..])
2018-08-02 09:18:48 +00:00
[RUNNING] `[..]/build-script-build`
[RUNNING] `rustc [..] src/lib.rs [..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
sleep_ms(1000);
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
// now the exist, so run once, catch the mtime, then shouldn't run again
println!("run with");
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[DIRTY] foo v0.5.0 ([..]): the file `foo` has changed ([..])
[COMPILING] foo v0.5.0 ([..])
2018-08-02 09:18:48 +00:00
[RUNNING] `[..]/build-script-build`
[RUNNING] `rustc [..] src/lib.rs [..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
println!("run with2");
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +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();
sleep_ms(1000);
// random other files do not affect freshness
println!("run baz");
p.change_file("baz", "");
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +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();
// but changing dependent files does
println!("run foo change");
p.change_file("foo", "");
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[DIRTY] foo v0.5.0 ([..]): the file `foo` has changed ([..])
[COMPILING] foo v0.5.0 ([..])
2018-08-02 09:18:48 +00:00
[RUNNING] `[..]/build-script-build`
[RUNNING] `rustc [..] src/lib.rs [..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
// .. as does deleting a file
println!("run bar delete");
fs::remove_file(p.root().join("bar")).unwrap();
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[DIRTY] foo v0.5.0 ([..]): the file `bar` is missing
[COMPILING] foo v0.5.0 ([..])
2018-08-02 09:18:48 +00:00
[RUNNING] `[..]/build-script-build`
[RUNNING] `rustc [..] src/lib.rs [..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[cargo_test]
2018-04-05 01:45:15 +00:00
fn doctest_receives_build_link_args() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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#"
[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() {
println!("cargo:rustc-link-search=native=bar");
}
"#,
2018-12-08 11:19:47 +00:00
)
.build();
p.cargo("test -v")
.with_stderr_contains(
"[RUNNING] `rustdoc [..]--crate-name foo --test [..]-L native=bar[..]`",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[cargo_test]
fn please_respect_the_dag() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.5.0"
authors = []
build = "build.rs"
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() {
println!("cargo:rustc-link-search=native=foo");
}
"#,
2018-12-08 11:19:47 +00:00
)
.file(
2018-03-14 15:17:44 +00:00
"a/Cargo.toml",
r#"
[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() {
println!("cargo:rustc-link-search=native=bar");
}
"#,
2018-12-08 11:19:47 +00:00
)
.build();
p.cargo("build -v")
.with_stderr_contains("[RUNNING] `rustc [..] -L native=foo -L native=bar[..]`")
.run();
}
#[cargo_test]
fn non_utf8_output() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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::*;
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();
2020-09-27 00:59:58 +00:00
// now print some cargo metadata that's utf8
println!("cargo:rustc-cfg=foo");
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() {}")
.build();
p.cargo("build -v").run();
}
#[cargo_test]
fn custom_target_dir() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.5.0"
authors = []
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#"
[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() {}")
.file("a/src/lib.rs", "")
.build();
p.cargo("build -v").run();
}
#[cargo_test]
fn panic_abort_with_build_scripts() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.5.0"
authors = []
2020-09-27 00:59:58 +00:00
[profile.release]
panic = 'abort'
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#"
[package]
2020-09-27 00:59:58 +00:00
name = "a"
version = "0.5.0"
authors = []
build = "build.rs"
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#"
[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", "")
.build();
p.cargo("build -v --release").run();
p.root().join("target").rm_rf();
p.cargo("test --release -v")
.with_stderr_does_not_contain("[..]panic=abort[..]")
.run();
}
#[cargo_test]
fn warnings_emitted() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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() {
println!("cargo:warning=foo");
println!("cargo:warning=bar");
}
"#,
2018-12-08 11:19:47 +00:00
)
.build();
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[COMPILING] foo v0.5.0 ([..])
[RUNNING] `rustc [..]`
[RUNNING] `[..]`
warning: foo@0.5.0: foo
warning: foo@0.5.0: bar
[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();
}
#[cargo_test]
fn warnings_emitted_when_build_script_panics() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.5.0"
authors = []
build = "build.rs"
"#,
)
.file("src/lib.rs", "")
.file(
"build.rs",
r#"
2020-09-27 00:59:58 +00:00
fn main() {
println!("cargo:warning=foo");
println!("cargo:warning=bar");
panic!();
}
"#,
)
.build();
p.cargo("build")
.with_status(101)
.with_stdout("")
.with_stderr_contains("warning: foo@0.5.0: foo\nwarning: foo@0.5.0: bar")
.run();
}
#[cargo_test]
fn warnings_hidden_for_upstream() {
Package::new("bar", "0.1.0")
2018-03-14 15:17:44 +00:00
.file(
"build.rs",
r#"
fn main() {
println!("cargo:warning=foo");
println!("cargo:warning=bar");
}
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#"
[package]
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();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.5.0"
authors = []
2020-09-27 00:59:58 +00:00
[dependencies]
bar = "*"
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "")
.build();
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[UPDATING] `[..]` index
2018-09-14 20:33:18 +00:00
[DOWNLOADING] crates ...
[DOWNLOADED] bar v0.1.0 ([..])
Implement source redirection This commit implements a scheme for .cargo/config files where sources can be redirected to other sources. The purpose of this will be to override crates.io for a few use cases: * Replace it with a mirror site that is sync'd to crates.io * Replace it with a "directory source" or some other local source This major feature of this redirection, however, is that none of it is encoded into the lock file. If one source is redirected to another then it is assumed that packages from both are exactly the same (e.g. `foo v0.0.1` is the same in both location). The lock file simply encodes the canonical soure (e.g. crates.io) rather than the replacement source. In the end this means that Cargo.lock files can be generated from any replacement source and shipped to other locations without the lockfile oscillating about where packages came from. Eventually this support will be extended to `Cargo.toml` itself (which will be encoded into the lock file), but that support is not implemented today. The syntax for what was implemented today looks like: # .cargo/config [source.my-awesome-registry] registry = 'https://example.com/path/to/index' [source.crates-io] replace-with = 'my-awesome-registry' Each source will have a canonical name and will be configured with the various keys underneath it (today just 'registry' and 'directory' will be accepted). The global `crates-io` source represents crates from the standard registry, and this can be replaced with other mirror sources. All tests have been modified to use this new infrastructure instead of the old `registry.index` configuration. This configuration is now also deprecated and will emit an unconditional warning about how it will no longer be used in the future. Finally, all subcommands now use this "source map" except for `cargo publish`, which will always publish to the default registry (in this case crates.io).
2016-02-03 18:54:07 +00:00
[COMPILING] bar v0.1.0
[RUNNING] `rustc [..]`
[RUNNING] `[..]`
[RUNNING] `rustc [..]`
[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();
}
#[cargo_test]
fn warnings_printed_on_vv() {
Package::new("bar", "0.1.0")
2018-03-14 15:17:44 +00:00
.file(
"build.rs",
r#"
fn main() {
println!("cargo:warning=foo");
println!("cargo:warning=bar");
}
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#"
[package]
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();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.5.0"
authors = []
2020-09-27 00:59:58 +00:00
[dependencies]
bar = "*"
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "")
.build();
p.cargo("build -vv")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[UPDATING] `[..]` index
2018-09-14 20:33:18 +00:00
[DOWNLOADING] crates ...
[DOWNLOADED] bar v0.1.0 ([..])
Implement source redirection This commit implements a scheme for .cargo/config files where sources can be redirected to other sources. The purpose of this will be to override crates.io for a few use cases: * Replace it with a mirror site that is sync'd to crates.io * Replace it with a "directory source" or some other local source This major feature of this redirection, however, is that none of it is encoded into the lock file. If one source is redirected to another then it is assumed that packages from both are exactly the same (e.g. `foo v0.0.1` is the same in both location). The lock file simply encodes the canonical soure (e.g. crates.io) rather than the replacement source. In the end this means that Cargo.lock files can be generated from any replacement source and shipped to other locations without the lockfile oscillating about where packages came from. Eventually this support will be extended to `Cargo.toml` itself (which will be encoded into the lock file), but that support is not implemented today. The syntax for what was implemented today looks like: # .cargo/config [source.my-awesome-registry] registry = 'https://example.com/path/to/index' [source.crates-io] replace-with = 'my-awesome-registry' Each source will have a canonical name and will be configured with the various keys underneath it (today just 'registry' and 'directory' will be accepted). The global `crates-io` source represents crates from the standard registry, and this can be replaced with other mirror sources. All tests have been modified to use this new infrastructure instead of the old `registry.index` configuration. This configuration is now also deprecated and will emit an unconditional warning about how it will no longer be used in the future. Finally, all subcommands now use this "source map" except for `cargo publish`, which will always publish to the default registry (in this case crates.io).
2016-02-03 18:54:07 +00:00
[COMPILING] bar v0.1.0
[RUNNING] `[..] rustc [..]`
[RUNNING] `[..]`
warning: bar@0.1.0: foo
warning: bar@0.1.0: bar
[RUNNING] `[..] rustc [..]`
[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();
}
#[cargo_test]
fn output_shows_on_vv() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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::*;
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();
p.cargo("build -vv")
.with_stdout("[foo 0.5.0] stdout")
.with_stderr(
2018-03-14 15:43:41 +00:00
"\
[COMPILING] foo v0.5.0 ([..])
[RUNNING] `[..] rustc [..]`
[RUNNING] `[..]`
[foo 0.5.0] stderr
[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();
}
#[cargo_test]
fn links_with_dots() {
let target = rustc_host();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[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() {
println!("cargo:rustc-link-search=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.{}.'a.b']
rustc-link-search = ["foo"]
"#,
2018-03-14 15:17:44 +00:00
target
),
2018-12-08 11:19:47 +00:00
)
.build();
p.cargo("build -v")
.with_stderr_contains("[RUNNING] `rustc --crate-name foo [..] [..] -L foo[..]`")
.run();
}
#[cargo_test]
fn rustc_and_rustdoc_set_correctly() {
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;
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();
p.cargo("bench").run();
}
#[cargo_test]
fn cfg_env_vars_available() {
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;
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");
}
}
2020-09-27 00:59:58 +00:00
"#,
2018-12-08 11:19:47 +00:00
)
.build();
p.cargo("bench").run();
}
#[cargo_test]
fn switch_features_rerun() {
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"
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;
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");
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();
}
}
2020-09-27 00:59:58 +00:00
"#,
2018-12-08 11:19:47 +00:00
)
.build();
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();
p.cargo("build -v").run();
p.rename_run("foo", "without_foo")
.with_stdout("bar\n")
.run();
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-12-02 04:01:51 +00:00
#[cargo_test]
2016-12-02 04:01:51 +00:00
fn assume_build_script_when_build_rs_present() {
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");
}
}
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() {
println!("cargo:rustc-cfg=foo");
}
"#,
2018-12-08 11:19:47 +00:00
)
.build();
2016-12-02 04:01:51 +00:00
p.cargo("run -v").run();
2016-12-02 04:01:51 +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() {
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");
}
}
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() {
println!("cargo:rustc-cfg=foo");
}
"#,
2018-12-08 11:19:47 +00:00
)
.build();
2016-12-02 04:01:51 +00:00
p.cargo("run -v").run();
2016-12-02 04:01:51 +00:00
}
#[cargo_test]
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#"
[package]
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#"
fn main() {
println!("cargo:rustc-flags=-L native=test1");
}
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();
Package::new("dep2", "0.1.0")
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
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#"
fn main() {
println!("cargo:rustc-flags=-L native=test2");
}
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();
Package::new("dep3", "0.1.0")
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
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#"
fn main() {
println!("cargo:rustc-flags=-L native=test3");
}
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();
Package::new("dep4", "0.1.0")
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
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#"
fn main() {
println!("cargo:rustc-flags=-L native=test4");
}
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();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.1.0"
authors = []
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() {}")
.build();
p.cargo("build -v")
.with_stderr_contains(
2018-03-14 15:17:44 +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();
}
#[cargo_test]
fn links_duplicates_with_cycle() {
2018-01-26 03:50:55 +00:00
// this tests that the links_duplicates are caught at resolver time
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.5.0"
authors = []
links = "a"
build = "build.rs"
2020-09-27 00:59:58 +00:00
[dependencies.a]
path = "a"
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", "")
.file("build.rs", "")
2018-03-14 15:17:44 +00:00
.file(
"a/Cargo.toml",
r#"
[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", "")
.file("a/build.rs", "")
2018-03-14 15:17:44 +00:00
.file(
"b/Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "b"
version = "0.5.0"
authors = []
2020-09-27 00:59:58 +00:00
[dependencies]
foo = { path = ".." }
"#,
2018-12-08 11:19:47 +00:00
)
.file("b/src/lib.rs", "")
.build();
p.cargo("build").with_status(101)
.with_stderr("\
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 ([..])`
2021-06-10 07:12:19 +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
").run();
}
#[cargo_test]
fn rename_with_link_search_path() {
_rename_with_link_search_path(false);
}
#[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"
)]
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()
};
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.5.0"
authors = []
2020-09-27 00:59:58 +00:00
[lib]
crate-type = ["cdylib"]
"#,
2018-12-08 11:19:47 +00:00
)
.file(
"src/lib.rs",
"#[no_mangle] pub extern fn cargo_test_foo() {}",
);
let p = p.build();
p.cargo(&format!("build{}", target_arg)).run();
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;
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")));
println!("cargo:rerun-if-changed=build.rs");
if cfg!(target_env = "msvc") {
println!("cargo:rustc-link-lib=foo.dll");
} else {
println!("cargo:rustc-link-lib=foo");
}
println!("cargo:rustc-link-search=all={}",
dst.parent().unwrap().display());
}
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();
}
2020-09-27 00:59:58 +00:00
fn main() {
unsafe { foo(); }
}
"#,
2018-03-14 15:17:44 +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
// original path in `p` so we want to make sure that it can't find it (hence
// the deletion).
let root = if cross {
2018-12-08 11:19:47 +00:00
p.root()
.join("target")
.join(cross_compile::alternate())
.join("debug")
.join("deps")
} else {
p.root().join("target").join("debug").join("deps")
};
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"),
));
remove_dir_all(p.root()).unwrap();
// Everything should work the first time
p2.cargo(&format!("run{}", target_arg)).run();
// 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");
// 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);
thread::sleep(slow_cpu_multiplier(100));
}
p2.cargo(&format!("run{}", target_arg))
.cwd(&new)
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[FINISHED] [..]
[RUNNING] [..]
2018-03-14 15:17:44 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[cargo_test]
fn optional_build_script_dep() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
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(
"build.rs",
r#"
2020-09-27 00:59:58 +00:00
#[cfg(feature = "bar")]
extern crate bar;
2020-09-27 00:59:58 +00:00
fn main() {
#[cfg(feature = "bar")] {
println!("cargo:rustc-env=FOO={}", bar::bar());
return
}
println!("cargo:rustc-env=FOO=0");
}
2020-09-27 00:59:58 +00:00
"#,
2018-12-08 11:19:47 +00:00
)
.file(
"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"))
.file("bar/src/lib.rs", "pub fn bar() -> u32 { 1 }");
let p = p.build();
p.cargo("run").with_stdout("0\n").run();
p.cargo("run --features bar").with_stdout("1\n").run();
}
#[cargo_test]
fn optional_build_dep_and_required_normal_dep() {
let p = project()
.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(); }")
.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"))
.file("bar/src/lib.rs", "pub fn bar() -> u32 { 1 }");
let p = p.build();
p.cargo("run")
.with_stdout("0")
.with_stderr(
"\
[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();
p.cargo("run --all-features")
.with_stdout("1")
.with_stderr(
"\
[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();
}
Remove `Freshness` from `DependencyQueue` Ever since the inception of Cargo and the advent of incremental compilation at the crate level via Cargo, Cargo has tracked whether it needs to recompile something at a unit level in its "dependency queue" which manages when items are ready for execution. Over time we've fixed lots and lots of bugs related to incremental compilation, and perhaps one of the most impactful realizations was that the model Cargo started with fundamentally doesn't handle interrupting Cargo halfway through and resuming the build later. The previous model relied upon implicitly propagating "dirtiness" based on whether the one of the dependencies of a build was rebuilt or not. This information is not available, however, if Cargo is interrupted and resumed (or performs a subset of steps and then later performs more). We've fixed this in a number of places historically but the purpose of this commit is to put a nail in this coffin once and for all. Implicit propagation of whether a unit is fresh or dirty is no longer present at all. Instead Cargo should always know, irrespective of it's in-memory state, whether a unit needs to be recompiled or not. This commit actually turns up a few bugs in the test suite, so later commits will be targeted at fixing this. Note that this required a good deal of work on the `fingerprint` module to fix some longstanding bugs (like #6780) and some serious hoops had to be jumped through for others (like #6779). While these were fallout from this change they weren't necessarily the primary motivation, but rather to help make `fingerprints` a bit more straightforward in what's an already confusing system! Closes #6780
2019-04-05 19:54:50 +00:00
#[cargo_test]
Remove `Freshness` from `DependencyQueue` Ever since the inception of Cargo and the advent of incremental compilation at the crate level via Cargo, Cargo has tracked whether it needs to recompile something at a unit level in its "dependency queue" which manages when items are ready for execution. Over time we've fixed lots and lots of bugs related to incremental compilation, and perhaps one of the most impactful realizations was that the model Cargo started with fundamentally doesn't handle interrupting Cargo halfway through and resuming the build later. The previous model relied upon implicitly propagating "dirtiness" based on whether the one of the dependencies of a build was rebuilt or not. This information is not available, however, if Cargo is interrupted and resumed (or performs a subset of steps and then later performs more). We've fixed this in a number of places historically but the purpose of this commit is to put a nail in this coffin once and for all. Implicit propagation of whether a unit is fresh or dirty is no longer present at all. Instead Cargo should always know, irrespective of it's in-memory state, whether a unit needs to be recompiled or not. This commit actually turns up a few bugs in the test suite, so later commits will be targeted at fixing this. Note that this required a good deal of work on the `fingerprint` module to fix some longstanding bugs (like #6780) and some serious hoops had to be jumped through for others (like #6779). While these were fallout from this change they weren't necessarily the primary motivation, but rather to help make `fingerprints` a bit more straightforward in what's an already confusing system! Closes #6780
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() {
println!("cargo:rerun-if-changed=build.rs");
}
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("build").run();
p.cargo("build").with_stderr("[FINISHED] [..]").run();
Remove `Freshness` from `DependencyQueue` Ever since the inception of Cargo and the advent of incremental compilation at the crate level via Cargo, Cargo has tracked whether it needs to recompile something at a unit level in its "dependency queue" which manages when items are ready for execution. Over time we've fixed lots and lots of bugs related to incremental compilation, and perhaps one of the most impactful realizations was that the model Cargo started with fundamentally doesn't handle interrupting Cargo halfway through and resuming the build later. The previous model relied upon implicitly propagating "dirtiness" based on whether the one of the dependencies of a build was rebuilt or not. This information is not available, however, if Cargo is interrupted and resumed (or performs a subset of steps and then later performs more). We've fixed this in a number of places historically but the purpose of this commit is to put a nail in this coffin once and for all. Implicit propagation of whether a unit is fresh or dirty is no longer present at all. Instead Cargo should always know, irrespective of it's in-memory state, whether a unit needs to be recompiled or not. This commit actually turns up a few bugs in the test suite, so later commits will be targeted at fixing this. Note that this required a good deal of work on the `fingerprint` module to fix some longstanding bugs (like #6780) and some serious hoops had to be jumped through for others (like #6779). While these were fallout from this change they weren't necessarily the primary motivation, but rather to help make `fingerprints` a bit more straightforward in what's an already confusing system! Closes #6780
2019-04-05 19:54:50 +00:00
}
#[cargo_test]
Remove `Freshness` from `DependencyQueue` Ever since the inception of Cargo and the advent of incremental compilation at the crate level via Cargo, Cargo has tracked whether it needs to recompile something at a unit level in its "dependency queue" which manages when items are ready for execution. Over time we've fixed lots and lots of bugs related to incremental compilation, and perhaps one of the most impactful realizations was that the model Cargo started with fundamentally doesn't handle interrupting Cargo halfway through and resuming the build later. The previous model relied upon implicitly propagating "dirtiness" based on whether the one of the dependencies of a build was rebuilt or not. This information is not available, however, if Cargo is interrupted and resumed (or performs a subset of steps and then later performs more). We've fixed this in a number of places historically but the purpose of this commit is to put a nail in this coffin once and for all. Implicit propagation of whether a unit is fresh or dirty is no longer present at all. Instead Cargo should always know, irrespective of it's in-memory state, whether a unit needs to be recompiled or not. This commit actually turns up a few bugs in the test suite, so later commits will be targeted at fixing this. Note that this required a good deal of work on the `fingerprint` module to fix some longstanding bugs (like #6780) and some serious hoops had to be jumped through for others (like #6779). While these were fallout from this change they weren't necessarily the primary motivation, but rather to help make `fingerprints` a bit more straightforward in what's an already confusing system! Closes #6780
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() {
println!("cargo:rerun-if-env-changed=SOMEVAR");
}
"#,
)
.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() {
println!("cargo:rebuild-if-changed=build.rs");
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();
}
#[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()
}
#[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() {
println!("cargo:rerun-if-changed=somedir");
}
"#,
)
.build();
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] [..]",
))
.run();
};
let fresh = || {
p.cargo("check").with_stderr("[FINISHED] [..]").run();
};
// Start with a missing directory.
dirty("", true);
// Because the directory doesn't exist, it will trigger a rebuild every time.
// https://github.com/rust-lang/cargo/issues/6003
dirty(
"[DIRTY] foo v0.1.0 ([..]): the file `somedir` is missing",
false,
);
if is_coarse_mtime() {
sleep_ms(1000);
}
// Empty directory.
fs::create_dir(p.root().join("somedir")).unwrap();
dirty(
"[DIRTY] foo v0.1.0 ([..]): the file `somedir` has changed ([..])",
false,
);
fresh();
if is_coarse_mtime() {
sleep_ms(1000);
}
// Add a file.
p.change_file("somedir/foo", "");
p.change_file("somedir/bar", "");
dirty(
"[DIRTY] foo v0.1.0 ([..]): the file `somedir` has changed ([..])",
false,
);
fresh();
if is_coarse_mtime() {
sleep_ms(1000);
}
// Add a symlink.
p.symlink("foo", "somedir/link");
dirty(
"[DIRTY] foo v0.1.0 ([..]): the file `somedir` has changed ([..])",
false,
);
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");
dirty(
"[DIRTY] foo v0.1.0 ([..]): the file `somedir` has changed ([..])",
false,
);
fresh();
if is_coarse_mtime() {
sleep_ms(1000);
}
// Remove a file.
fs::remove_file(p.root().join("somedir/foo")).unwrap();
dirty(
"[DIRTY] foo v0.1.0 ([..]): the file `somedir` has changed ([..])",
false,
);
fresh();
}
#[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
println!("cargo:rerun-if-changed=mylib");
}
"#,
)
.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() {
println!("cargo:rerun-if-changed=mylib");
}
"#,
)
.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();
}
#[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() {
println!("cargo:foo=bar");
}
"#,
)
.build();
p.cargo("test --lib").run();
}
#[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() {
println!("cargo:rustc-env=CRATE_TARGET={}", std::env::var("TARGET").unwrap());
println!("cargo:rustc-cfg=mycfg=\"{}\"", std::env::var("TARGET").unwrap());
}
"#,
)
.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)
.masquerade_as_nightly_cargo(&["doctest-xcompile"])
.with_stdout_contains("test foo/src/lib.rs - (line 2) ... ok")
.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() {
println!("cargo:example");
}
"#,
)
.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:example`
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 wrong_syntax_with_two_colons() {
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: unsupported output in build script of `foo v0.0.1 ([ROOT]/foo)`: `cargo::foo=bar`
Found a `cargo::key=value` build directive which is reserved for future use.
Either change the directive to `cargo:key=value` syntax (note the single `:`) or upgrade your version of Rust.
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 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();
}