Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
24 changes: 24 additions & 0 deletions cargo/tests/build_env/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load("//cargo:defs.bzl", "cargo_build_script")
load("//rust:rust_test.bzl", "rust_test")

rust_test(
# Intentionally uses a mix of -s and _s because those normalisations are part of what is being tested.
name = "cargo_env-vars_test",
srcs = ["tests/cargo.rs"],
edition = "2018",
deps = [":cargo_build_script_env-vars_bs"],
)

rust_test(
name = "cargo-env-vars-custom-crate-name-test",
srcs = ["tests/custom_crate_name.rs"],
crate_name = "custom_crate_name",
edition = "2018",
deps = [":cargo_build_script_env-vars_bs"],
)

cargo_build_script(
name = "cargo_build_script_env-vars_bs",
srcs = ["src/build.rs"],
edition = "2018",
)
File renamed without changes.
1 change: 1 addition & 0 deletions cargo/tests/build_env/src/manifest_dir_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file tests that CARGO_MANIFEST_DIR is set for the build environment
File renamed without changes.
8 changes: 8 additions & 0 deletions cargo/tests/build_env/tests/custom_crate_name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[test]
fn cargo_env_vars() {
assert_eq!(
env!("CARGO_PKG_NAME"),
"cargo-env-vars-custom-crate-name-test"
);
assert_eq!(env!("CARGO_CRATE_NAME"), "custom_crate_name");
}
10 changes: 10 additions & 0 deletions cargo/tests/build_env/tests/manifest_dir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#[test]
pub fn test_manifest_dir() {
let actual = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/src/manifest_dir_file.txt"
))
.trim_end();
let expected = "This file tests that CARGO_MANIFEST_DIR is set for the build environment";
assert_eq!(actual, expected);
}
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def cargo_build_script_with_extra_cc_compile_flags(
)
with_extra_toolchains(
name = name,
extra_toolchains = ["//test/cargo_build_script/cc_args_and_env:%s/test_cc_toolchain" % name],
extra_toolchains = ["//%s:%s/test_cc_toolchain" % (native.package_name(), name)],
target = "%s/cargo_build_script_impl" % name,
tags = ["manual"],
)
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[test]
pub fn test_data_rootpath() {
assert_eq!(
"test/cargo_build_script/location_expansion/target_data.txt",
"cargo/tests/cargo_build_script/location_expansion/target_data.txt",
env!("DATA_ROOTPATH")
);
}
Expand All @@ -11,9 +11,9 @@ pub fn test_data_rlocation() {
assert!(
[
// workspace
"rules_rust/test/cargo_build_script/location_expansion/target_data.txt",
"rules_rust/cargo/tests/cargo_build_script/location_expansion/target_data.txt",
// bzlmod
"_main/test/cargo_build_script/location_expansion/target_data.txt",
"_main/cargo/tests/cargo_build_script/location_expansion/target_data.txt",
]
.contains(&env!("DATA_RLOCATIONPATH")),
concat!("Unexpected rlocationpath: ", env!("DATA_RLOCATIONPATH"))
Expand All @@ -23,7 +23,7 @@ pub fn test_data_rlocation() {
#[test]
pub fn test_tool_rootpath() {
assert_eq!(
"test/cargo_build_script/location_expansion/exec_data.txt",
"cargo/tests/cargo_build_script/location_expansion/exec_data.txt",
env!("TOOL_ROOTPATH")
);
}
Expand All @@ -33,9 +33,9 @@ pub fn test_tool_rlocationpath() {
assert!(
[
// workspace
"rules_rust/test/cargo_build_script/location_expansion/exec_data.txt",
"rules_rust/cargo/tests/cargo_build_script/location_expansion/exec_data.txt",
// bzlmod
"_main/test/cargo_build_script/location_expansion/exec_data.txt",
"_main/cargo/tests/cargo_build_script/location_expansion/exec_data.txt",
]
.contains(&env!("TOOL_RLOCATIONPATH")),
concat!("Unexpected rlocationpath: ", env!("TOOL_RLOCATIONPATH"))
Expand Down Expand Up @@ -83,10 +83,10 @@ pub fn test_execpath() {

assert_eq!(
data_short_path,
"test/cargo_build_script/location_expansion/target_data.txt"
"cargo/tests/cargo_build_script/location_expansion/target_data.txt"
);
assert_eq!(
tool_short_path,
"test/cargo_build_script/location_expansion/exec_data.txt"
"cargo/tests/cargo_build_script/location_expansion/exec_data.txt"
);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() {
let contents = std::fs::read_to_string("test/cargo_build_script/run_from_exec_root/data.txt")
let contents = std::fs::read_to_string("cargo/tests/cargo_build_script/run_from_exec_root/data.txt")
.expect("Failed to read data file");
println!("cargo:rustc-env=DATA={}", contents);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added cargo/tests/unit/BUILD.bazel
Empty file.
28 changes: 0 additions & 28 deletions test/build_env/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
load(
"//cargo:defs.bzl",
"cargo_build_script",
)
load("//rust:defs.bzl", "rust_library", "rust_test")

package(default_visibility = ["//visibility:public"])

rust_test(
name = "conflicting_deps_test",
srcs = ["tests/manifest_dir.rs"],
Expand Down Expand Up @@ -54,25 +48,3 @@ rust_test(
"USER_DEFINED_KEY": "USER_DEFINED_VALUE",
},
)

rust_test(
# Intentionally uses a mix of -s and _s because those normalisations are part of what is being tested.
name = "cargo_env-vars_test",
srcs = ["tests/cargo.rs"],
edition = "2018",
deps = [":cargo_build_script_env-vars_bs"],
)

rust_test(
name = "cargo-env-vars-custom-crate-name-test",
srcs = ["tests/custom_crate_name.rs"],
crate_name = "custom_crate_name",
edition = "2018",
deps = [":cargo_build_script_env-vars_bs"],
)

cargo_build_script(
name = "cargo_build_script_env-vars_bs",
srcs = ["src/build.rs"],
edition = "2018",
)
Loading