fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
d83c8658
cleanup
1"""Bootstrap rustc process wrapper""" 2 3load ( "@bazel_skylib//rules:common_settings.bzl" , "BuildSettingInfo" ) 4 5def _bootstrap_process_wrapper_impl_unix ( ctx ): 6output = ctx . actions . declare_file ( "{}.sh" . format ( ctx . label . name )) 7 8setting = ctx . attr . _use_sh_toolchain_for_bootstrap_process_wrapper [ BuildSettingInfo ]. value 9sh_toolchain = ctx . toolchains [ "@bazel_tools//tools/sh:toolchain_type" ] 10if setting and sh_toolchain : 11shebang = "#!{}".format(sh_toolchain.path) 12ctx . actions . expand_template ( 13output = output , 14template = ctx . file . _bash , 15substitutions = { 16# Replace the shebang with one constructed from the configured 17# shell toolchain. 18 "#!/usr/bin/env bash": shebang, 19}, 20) 21else : 22ctx . actions . symlink ( 23output = output , 24target_file = ctx . file . _bash , 25is_executable = True , 26) 27 28return [ DefaultInfo ( 29files = depset ([ output ]), 30executable = output , 31)] 32 33def _bootstrap_process_wrapper_impl_windows ( ctx ): 34output = ctx . actions . declare_file ( "{}.bat" . format ( ctx . label . name )) 35ctx . actions . symlink ( 36output = output , 37target_file = ctx . file . _batch , 38is_executable = True , 39) 40 41return [ DefaultInfo ( 42files = depset ([ output ]), 43executable = output , 44)] 45 46def _bootstrap_process_wrapper_impl ( ctx ): 47if ctx . attr . is_windows : 48return _bootstrap_process_wrapper_impl_windows ( ctx ) 49return _bootstrap_process_wrapper_impl_unix ( ctx ) 50 51bootstrap_process_wrapper = rule ( 52doc = "A rule which produces a bootstrapping script for the rustc process wrapper." , 53implementation = _bootstrap_process_wrapper_impl , 54attrs = { 55"is_windows" : attr . bool ( 56doc = "Indicate whether or not the target platform is windows." , 57mandatory = True , 58), 59"_bash" : attr . label ( 60allow_single_file = True , 61default = Label ( "//util/process_wrapper/private:process_wrapper.sh" ), 62), 63"_batch" : attr . label ( 64allow_single_file = True , 65default = Label ( "//util/process_wrapper/private:process_wrapper.bat" ), 66), 67"_use_sh_toolchain_for_bootstrap_process_wrapper" : attr . label ( 68default = Label ( "//rust/settings:experimental_use_sh_toolchain_for_bootstrap_process_wrapper" ), 69), 70}, 71toolchains = [ config_common . toolchain_type ( "@bazel_tools//tools/sh:toolchain_type" , mandatory = False )], 72executable = True , 73)