fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
a7aba2d0
main
1"""Utilities for llvm targets""" 2 3load ( "@rules_cc//cc:defs.bzl" , "CcInfo" ) 4 5def _cc_stdcc17_transition_impl ( settings , attr ): 6# clang --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 7# msvc --cxxopt=/std:c++17 --host_cxxopt=/std:c++17 8host_opt = settings [ "//command_line_option:host_cxxopt" ] 9tgt_opt = settings [ "//command_line_option:cxxopt" ] 10 11host_opt . extend ( attr . cxxopts ) 12tgt_opt . extend ( attr . cxxopts ) 13 14return { 15"//command_line_option:cxxopt" : tgt_opt , 16"//command_line_option:host_cxxopt" : host_opt , 17} 18 19_cc_stdcc17_transition = transition ( 20implementation = _cc_stdcc17_transition_impl , 21inputs = [ 22"//command_line_option:host_cxxopt" , 23"//command_line_option:cxxopt" , 24], 25outputs = [ 26"//command_line_option:host_cxxopt" , 27"//command_line_option:cxxopt" , 28], 29) 30 31_CXX_OPTS = select ({ 32"@platforms//os:windows" : [ "/std:c++17" ], 33"//conditions:default" : [ "-std=c++17" ], 34}) 35 36_COMMON_ATTRS = { 37"cxxopts" : attr . string_list ( 38doc = "Flags to inject into `--host_cxxopt` and `--cxxopt` command line flags." , 39mandatory = True , 40), 41"target" : attr . label ( 42doc = "The target to transition." , 43mandatory = True , 44), 45} 46 47def _cc_stdcc17_transitioned_target_impl ( ctx ): 48providers = [] 49 50if CcInfo in ctx . attr . target : 51providers . append ( ctx . attr . target [ CcInfo ]) 52 53if DefaultInfo in ctx . attr . target : 54info = ctx . attr . target [ DefaultInfo ] 55kwargs = { 56"files" : info . files , 57"runfiles" : info . default_runfiles , 58} 59 60if info . files_to_run and info . files_to_run . executable : 61exe = info . files_to_run . executable 62kwargs [ "executable" ] = ctx . actions . declare_file ( "{}.{}" . format ( ctx . label . name , exe . extension ). rstrip ( "." )) 63ctx . actions . symlink ( 64output = kwargs [ "executable" ], 65target_file = exe , 66is_executable = True , 67) 68 69providers . append ( DefaultInfo ( ** kwargs )) 70 71if OutputGroupInfo in ctx . attr . target : 72providers . append ( ctx . attr . target [ OutputGroupInfo ]) 73 74return providers 75 76_cc_stdcc17_transitioned_library = rule ( 77doc = "A rule to transition a C++ library to build with stdc++17." , 78implementation = _cc_stdcc17_transitioned_target_impl , 79cfg = _cc_stdcc17_transition , 80attrs = _COMMON_ATTRS , 81) 82 83_cc_stdcc17_transitioned_binary = rule ( 84doc = "A rule to transition a C++ binary to build with stdc++17." , 85implementation = _cc_stdcc17_transitioned_target_impl , 86cfg = _cc_stdcc17_transition , 87attrs = _COMMON_ATTRS , 88executable = True , 89) 90 91def cc_stdcc17_transitioned_library ( name , ** kwargs ): 92_cc_stdcc17_transitioned_library ( 93name = name , 94cxxopts = _CXX_OPTS , 95** kwargs 96) 97 98def cc_stdcc17_transitioned_binary ( name , ** kwargs ): 99_cc_stdcc17_transitioned_binary ( 100name = name , 101cxxopts = _CXX_OPTS , 102** kwargs 103)