1+ load ("//misc/bazel:os.bzl" , "os_select" )
2+
3+ # TODO: make a shared library with the internal repos for transitions
4+ # unfortunately github.com/fmeum/rules_meta doesn't work any more with latest bazel
5+
6+ def _transition_impl (settings , attr ):
7+ return {
8+ "macos" : {
9+ "//command_line_option:copt" : [
10+ "-fno-rtti" ,
11+ # we currently cannot built the swift extractor for ARM
12+ "-arch" ,
13+ "x86_64" ,
14+ ],
15+ "//command_line_option:cxxopt" : [
16+ "-std=c++20" ,
17+ # we currently cannot built the swift extractor for ARM
18+ "-arch" ,
19+ "x86_64" ,
20+ ],
21+ "//command_line_option:linkopt" : [
22+ # we currently cannot built the swift extractor for ARM
23+ "-arch" ,
24+ "x86_64" ,
25+ ],
26+ },
27+ "linux" : {
28+ "//command_line_option:copt" : [
29+ "-fno-rtti" ,
30+ ],
31+ "//command_line_option:cxxopt" : [
32+ "-std=c++20" ,
33+ ],
34+ },
35+ "windows" : {
36+ "//command_line_option:cxxopt" : [
37+ "/std:c++20" ,
38+ "--cxxopt=/Zc:preprocessor" ,
39+ ],
40+ },
41+ }[attr .os ]
42+
43+ _transition = transition (
44+ implementation = _transition_impl ,
45+ inputs = [],
46+ outputs = ["//command_line_option:copt" , "//command_line_option:cxxopt" , "//command_line_option:linkopt" ],
47+ )
48+
49+ def _cc_transition_impl (ctx ):
50+ src = ctx .attr .src [0 ]
51+ default_info = src [DefaultInfo ]
52+ executable = default_info .files_to_run .executable
53+ runfiles = default_info .default_runfiles
54+ direct = []
55+ if executable :
56+ original_executable = executable
57+ executable = ctx .actions .declare_file (original_executable .basename )
58+ command = "cp %s %s" % (original_executable .path , executable .path )
59+
60+ ctx .actions .run_shell (
61+ inputs = [original_executable ],
62+ outputs = [executable ],
63+ command = command ,
64+ )
65+
66+ # costly, but no other way to remove the internal exe from the runfiles
67+ files = runfiles .files .to_list ()
68+ files .remove (original_executable )
69+ files .append (executable )
70+ runfiles = ctx .runfiles (files )
71+
72+ direct = [executable ]
73+
74+ providers = [
75+ DefaultInfo (
76+ files = depset (direct ),
77+ runfiles = runfiles ,
78+ executable = executable ,
79+ ),
80+ ]
81+ for p in (OutputGroupInfo , CcInfo ):
82+ if p in src :
83+ providers .append (src [p ])
84+
85+ return providers
86+
87+ _cc_transition = rule (
88+ implementation = _cc_transition_impl ,
89+ attrs = {
90+ "_allowlist_function_transition" : attr .label (
91+ default = "@bazel_tools//tools/allowlists/function_transition_allowlist" ,
92+ ),
93+ "src" : attr .label (mandatory = True , cfg = _transition ),
94+ "os" : attr .string (),
95+ },
96+ )
97+
198def _add_args (kwargs , kwarg , value ):
299 kwargs [kwarg ] = kwargs .get (kwarg , []) + value
3100
4101def _wrap_cc (rule , kwargs ):
5- _add_args (kwargs , "copts" , [
6- # Required by LLVM/Swift
7- "-fno-rtti" ,
8- ])
102+ name = kwargs .pop ("name" )
103+ visibility = kwargs .pop ("visibility" , None )
9104 _add_args (kwargs , "features" , [
10105 # temporary, before we do universal merging
11106 "-universal_binaries" ,
@@ -17,7 +112,13 @@ def _wrap_cc(rule, kwargs):
17112 "@platforms//os:macos" : [],
18113 "//conditions:default" : ["@platforms//:incompatible" ],
19114 }))
20- rule (** kwargs )
115+ rule (name = "internal/" + name , visibility = ["//visibility:private" ], ** kwargs )
116+ _cc_transition (
117+ name = name ,
118+ visibility = visibility ,
119+ src = ":internal/" + name ,
120+ os = os_select (linux = "linux" , macos = "macos" , windows = "windows" ),
121+ )
21122
22123def swift_cc_binary (** kwargs ):
23124 _wrap_cc (native .cc_binary , kwargs )
0 commit comments