fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
15572051
patching
1load ( "@bazel_skylib//rules:common_settings.bzl" , "bool_flag" ) 2load ( "@bazel_skylib//rules:write_file.bzl" , "write_file" ) 3load ( "@rules_rust//rust:defs.bzl" , "rust_binary" , "rust_library" , "rust_test" ) 4load ( ":input_from_different_cfg.bzl" , "input_from_different_cfg" ) 5 6write_file ( 7name = "gen_src" , 8out = "src.rs" , 9content = """ 10#[cfg(not(generated_file_as_root))] 11pub fn forty_two() -> i32 { 42 } 12 13#[cfg(generated_file_as_root)] 14mod lib_for_src; 15 16#[cfg(generated_file_as_root)] 17pub fn get_forty_two_as_string() -> String { 18format!("{}", lib_for_src::forty_two()) 19} 20""" . splitlines (), 21newline = "unix" , 22) 23 24write_file ( 25name = "gen_src_generated" , 26out = "src/generated.rs" , 27content = """ 28mod submodule; 29 30#[cfg(test)] 31#[test] 32fn test_foo() { 33assert_eq!(submodule::foo(), "foo"); 34} 35""" . splitlines (), 36newline = "unix" , 37) 38 39rust_library ( 40name = "libgensrc" , 41srcs = [ 42"lib.rs" , 43"submodule/mod.rs" , 44":src.rs" , 45], 46edition = "2018" , 47tags = [ "norustfmt" ], 48) 49 50rust_library ( 51name = "libgensrc_with_crate_root" , 52srcs = [ 53"lib.rs" , 54"submodule/mod.rs" , 55":src.rs" , 56], 57crate_root = "lib.rs" , 58edition = "2018" , 59tags = [ "norustfmt" ], 60visibility = [ "//visibility:public" ], 61) 62 63rust_library ( 64name = "libgensrc_as_crate_root" , 65srcs = [ 66"lib.rs" , 67"lib_for_src.rs" , 68":src.rs" , 69], 70crate_root = ":src.rs" , 71edition = "2018" , 72rustc_flags = [ "--cfg=generated_file_as_root" ], 73tags = [ "norustfmt" ], 74) 75 76rust_library ( 77name = "lib_with_crate_root_in_subdir" , 78srcs = [ 79"src/generated.rs" , 80"src/generated/submodule.rs" , 81"src/lib.rs" , 82], 83crate_root = "src/lib.rs" , 84edition = "2018" , 85tags = [ "norustfmt" ], 86) 87 88rust_test ( 89name = "lib_with_srcs_in_subdir_test" , 90srcs = [ 91"src/generated.rs" , 92"src/generated/submodule.rs" , 93"src/lib.rs" , 94], 95edition = "2018" , 96tags = [ "norustfmt" ], 97) 98 99rust_test ( 100name = "lib_with_crate_root_in_subdir_test" , 101crate = "lib_with_crate_root_in_subdir" , 102edition = "2018" , 103tags = [ "norustfmt" ], 104) 105 106# When no lib.rs, main.rs file exists, we try to use the file that carries 107# the target's name as a crate_root. 108rust_library ( 109name = "src" , 110srcs = [ 111"lib_for_src.rs" , 112":src.rs" , 113], 114edition = "2018" , 115rustc_flags = [ "--cfg=generated_file_as_root" ], 116tags = [ "norustfmt" ], 117) 118 119rust_test ( 120name = "gensrc_test" , 121crate = ":libgensrc_with_crate_root" , 122edition = "2018" , 123tags = [ "norustfmt" ], 124) 125 126rust_binary ( 127name = "print_42" , 128srcs = [ 129"main.rs" , 130":src.rs" , 131], 132edition = "2018" , 133tags = [ "norustfmt" ], 134) 135 136input_from_different_cfg ( 137name = "generated_in_different_cfg" , 138) 139 140filegroup ( 141name = "input_from_different_cfg" , 142srcs = [ ":generated_in_different_cfg" ], 143output_group = "generated_file" , 144) 145 146rust_library ( 147name = "gen_src_in_different_cfg_as_root" , 148srcs = [ ":input_from_different_cfg" ], 149edition = "2018" , 150tags = [ "norustfmt" ], 151) 152 153rust_test ( 154name = "gen_src_in_different_cfg_as_root_test" , 155crate = "gen_src_in_different_cfg_as_root" , 156edition = "2018" , 157tags = [ "norustfmt" ], 158) 159 160rust_library ( 161name = "gen_src_in_different_cfg" , 162srcs = [ 163"root.rs" , 164":input_from_different_cfg" , 165], 166crate_root = "root.rs" , 167edition = "2018" , 168tags = [ "norustfmt" ], 169) 170 171rust_test ( 172name = "gen_src_in_different_cfg_test" , 173crate = "gen_src_in_different_cfg" , 174edition = "2018" , 175tags = [ "norustfmt" ], 176) 177 178bool_flag ( 179name = "change_cfg" , 180build_setting_default = False , 181) 182 183rust_test ( 184name = "gen_inputs_external_repo_test" , 185# This is regression testing a specific failure case for generated files _not_ in the root 186# of an external repository. 187crate = "@generated_inputs_in_external_repo//lib:generated_inputs_external_repo" , 188edition = "2021" , 189)