fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
03d1d5e4
rust-analyzer
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_flag = [], 25extra_exec_rustc_flags = [ "--cfg=bazel_exec" ], 26tags = [ "manual" ], 27) 28 29with_extra_exec_rustc_flags_cfg ( 30name = "lib_with_singular_exec_flags_do_not_build_directly" , 31srcs = [ "lib_do_not_build_directly" ], 32extra_exec_rustc_flag = [ "--cfg=bazel_exec" ], 33extra_exec_rustc_flags = [], 34tags = [ "manual" ], 35) 36 37with_exec_cfg ( 38name = "lib" , 39srcs = [ "lib_with_exec_flags_do_not_build_directly" ], 40) 41 42with_exec_cfg ( 43name = "lib_singular" , 44srcs = [ "lib_with_singular_exec_flags_do_not_build_directly" ], 45) 46 47# Checks that extra_exec_rustc_flags are not passed in non-exec configurations. 48# lib_no_exec.rs is a sample source file that fails to build if 49# `--cfg=bazel_exec` is present. The targets below are built in non-exec configurations, 50# so they should build just fine with //:extra_exec_rustc_flags=[--cfg=bazel_exec]. 51rust_library ( 52name = "lib_no_exec" , 53srcs = [ "lib_no_exec.rs" ], 54edition = "2018" , 55) 56 57with_extra_exec_rustc_flags_cfg ( 58name = "lib_no_exec_with_extra_build_flags" , 59srcs = [ "lib_no_exec" ], 60extra_exec_rustc_flag = [], 61extra_exec_rustc_flags = [ "--cfg=bazel_exec" ], 62) 63 64with_extra_exec_rustc_flags_cfg ( 65name = "lib_no_exec_with_singular_extra_build_flags" , 66srcs = [ "lib_no_exec" ], 67extra_exec_rustc_flag = [ "--cfg=bazel_exec" ], 68extra_exec_rustc_flags = [], 69) 70 71build_test ( 72name = "lib_build" , 73targets = [ 74":lib" , 75":lib_singular" , 76":lib_no_exec" , 77":lib_no_exec_with_extra_build_flags" , 78":lib_no_exec_with_singular_extra_build_flags" , 79], 80)