fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
c7cb5bd7
0.9.0
1"""A custom rule that generates a .rs file in a different configuration.""" 2 3def _change_cfg_impl ( _settings , _attr ): 4return { "//test/generated_inputs:change_cfg" : True } 5 6change_cfg_transition = transition ( 7implementation = _change_cfg_impl , 8inputs = [], 9outputs = [ "//test/generated_inputs:change_cfg" ], 10) 11 12def _input_from_different_cfg_impl ( ctx ): 13rs_file = ctx . actions . declare_file ( ctx . label . name + ".rs" ) 14 15ctx . actions . write ( 16output = rs_file , 17content = """ 18pub fn generated_fn() -> String { 19"Generated".to_owned() 20} 21 22#[cfg(test)] 23mod tests { 24#[test] 25fn test_generated() { 26assert_eq!(super::generated_fn(), "Generated".to_owned()); 27} 28} 29""" , 30) 31 32return OutputGroupInfo ( generated_file = depset ([ rs_file ])) 33 34input_from_different_cfg = rule ( 35implementation = _input_from_different_cfg_impl , 36attrs = { 37"_allowlist_function_transition" : attr . label ( 38default = Label ( "@bazel_tools//tools/allowlists/function_transition_allowlist" ), 39), 40}, 41cfg = change_cfg_transition , 42)