fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
03a70796
0.7.0
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 ( 15name = "lib_do_not_build_directly" , 16srcs = [ "lib.rs" ], 17edition = "2018" , 18tags = [ "manual" ], 19) 20 21with_extra_exec_rustc_flags_cfg ( 22name = "lib_with_exec_flags_do_not_build_directly" , 23srcs = [ "lib_do_not_build_directly" ], 24extra_exec_rustc_flags = [ "--cfg=bazel_exec" ], 25tags = [ "manual" ], 26) 27 28with_exec_cfg ( 29name = "lib" , 30srcs = [ "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 ( 38name = "lib_no_exec" , 39srcs = [ "lib_no_exec.rs" ], 40edition = "2018" , 41) 42 43with_extra_exec_rustc_flags_cfg ( 44name = "lib_no_exec_with_extra_build_flags" , 45srcs = [ "lib_no_exec" ], 46extra_exec_rustc_flags = [ "--cfg=bazel_exec" ], 47) 48 49build_test ( 50name = "lib_build" , 51targets = [ 52":lib" , 53":lib_no_exec" , 54":lib_no_exec_with_extra_build_flags" , 55], 56)