fork/rules_rust

git clone https://git.julia.blue/fork/rules_rust

David TolnayOutside of examples, fill in all `edition` attrs (#1257)03a70796

0.7.0
1.8 KiB56 linesraw
1load("@bazel_skylib//rules:build_test.bzl", "build_test")
2load("@rules_rust//rust:defs.bzl", "rust_library")
3load("defs.bzl", "with_exec_cfg", "with_extra_exec_rustc_flags_cfg")
4
5package(default_visibility = ["//test:__subpackages__"])
6
7# Checks that extra_exec_rustc_flags are passed in exec configuration.
8# lib.rs is a sample source file that requires a `--cfg=bazel_exec` flag to build.
9# These targets set up transitions so that building :lib triggers building
10# lib.rs in exec configuration with //:extra_exec_rustc_flags=[--cfg=bazel_exec].
11# The intermediate targets are tagged "manual" as they are not meant to be built
12# on their own.
13
14rust_library(
15    name = "lib_do_not_build_directly",
16    srcs = ["lib.rs"],
17    edition = "2018",
18    tags = ["manual"],
19)
20
21with_extra_exec_rustc_flags_cfg(
22    name = "lib_with_exec_flags_do_not_build_directly",
23    srcs = ["lib_do_not_build_directly"],
24    extra_exec_rustc_flags = ["--cfg=bazel_exec"],
25    tags = ["manual"],
26)
27
28with_exec_cfg(
29    name = "lib",
30    srcs = ["lib_with_exec_flags_do_not_build_directly"],
31)
32
33# Checks that extra_exec_rustc_flags are not passed in non-exec configurations.
34# lib_no_exec.rs is a sample source file that fails to build if
35# `--cfg=bazel_exec` is present. The targets below are built in non-exec configurations,
36# so they should build just fine with //:extra_exec_rustc_flags=[--cfg=bazel_exec].
37rust_library(
38    name = "lib_no_exec",
39    srcs = ["lib_no_exec.rs"],
40    edition = "2018",
41)
42
43with_extra_exec_rustc_flags_cfg(
44    name = "lib_no_exec_with_extra_build_flags",
45    srcs = ["lib_no_exec"],
46    extra_exec_rustc_flags = ["--cfg=bazel_exec"],
47)
48
49build_test(
50    name = "lib_build",
51    targets = [
52        ":lib",
53        ":lib_no_exec",
54        ":lib_no_exec_with_extra_build_flags",
55    ],
56)