blob: 6efb98c1f973b0710c65f0dc114c3b49afef7b97 [file] [log] [blame]
"""Tests for the cargo_build_script rule"""
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("//cargo:defs.bzl", "cargo_build_script")
load("//rust:defs.bzl", "rust_library", "rust_test")
# Test that tools are built in the exec configuration.
cargo_build_script(
name = "tools_exec_build_rs",
srcs = ["build.rs"],
build_script_env = {
# Note that cargo_build_script working directories are not
# guaranteed to be the execroot. Thus, the expanded value
# is resolved to an absolute path with the help of it's
# process wrapper resolving `${pwd}`.
"EXPANDED_TOOLCHAIN_VAR": "$${pwd}/$(RUSTC)",
"TOOL": "$(execpath :tool)",
},
edition = "2018",
# Add a flag to test that they're exposed to the build script
rustc_flags = ["--verbose"],
toolchains = ["//rust/toolchain:current_rust_toolchain"],
tools = [":tool"],
)
write_file(
name = "tool",
out = "tool-file",
content = [""],
)
rust_test(
name = "tools_exec",
srcs = ["tools_exec.rs"],
edition = "2018",
deps = [":tools_exec_build_rs"],
)
environment_group(
name = "foo_environment",
defaults = [":foo"],
environments = [
":foo",
":bar",
],
)
environment(
name = "foo",
)
environment(
name = "bar",
)
rust_library(
name = "build_script_dep_without_compatible_with",
srcs = ["lib.rs"],
edition = "2018",
)
cargo_build_script(
name = "empty_build_script",
srcs = ["do_nothing.rs"],
compatible_with = [":bar"],
edition = "2018",
deps = [":build_script_dep_without_compatible_with"],
)
rust_test(
name = "test_compatible_with",
srcs = ["lib.rs"],
compatible_with = [":bar"],
edition = "2018",
deps = [":empty_build_script"],
)