• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1load("@bazel_skylib//rules:write_file.bzl", "write_file")
2load("//cargo:defs.bzl", "cargo_build_script")
3load("//rust:defs.bzl", "rust_test")
4load(":symlink_exec_root_transition.bzl", "symlink_execroot_cargo_build_script")
5
6###############################################################################
7# Test that the build script can access files in the exec root.
8#
9# All assertions are done in the build script. If it succeeds in execution, the
10# test passes.
11###############################################################################
12
13write_file(
14    name = "cargo_manifest_dir_file",
15    out = "cargo_manifest_dir_file.txt",
16    content = ["This is a file to be found alongside the build script."],
17)
18
19symlink_execroot_cargo_build_script(
20    name = "test_exec_root_access.build.feature_enabled",
21    script = ":test_exec_root_access.build.feature_disabled",
22    target_compatible_with = select({
23        "@platforms//os:windows": ["@platforms//:incompatible"],
24        "//conditions:default": [],
25    }),
26)
27
28cargo_build_script(
29    name = "test_exec_root_access.build.feature_disabled",
30    srcs = ["test_exec_root_access.build.rs"],
31    crate_name = "test_exec_root_access",
32    data = [
33        ":cargo_manifest_dir_file.txt",
34    ],
35    edition = "2021",
36)
37
38# This is an empty test file, it is only needed to trigger the build script.
39write_file(
40    name = "test_exec_root_access_rs",
41    out = "test_exec_root_access.rs",
42    content = [""],
43)
44
45rust_test(
46    name = "test_exec_root_access_feature_enabled",
47    srcs = ["test_exec_root_access.rs"],
48    edition = "2021",
49    deps = [":test_exec_root_access.build.feature_enabled"],
50)
51
52rust_test(
53    name = "test_exec_root_access_feature_disabled",
54    srcs = ["test_exec_root_access.rs"],
55    edition = "2021",
56    deps = [":test_exec_root_access.build.feature_disabled"],
57)
58