6
6
# of this source tree.
7
7
8
8
load ("@prelude//:paths.bzl" , "paths" )
9
+ load (
10
+ "@prelude//cxx:compile_types.bzl" ,
11
+ "AsmExtensions" ,
12
+ "CxxCompileCommand" ,
13
+ "CxxCompileCommandOutput" ,
14
+ "CxxCompileFlavor" ,
15
+ "CxxCompileOutput" ,
16
+ "CxxExtension" ,
17
+ "CxxSrcCompileCommand" ,
18
+ "CxxSrcPrecompileCommand" ,
19
+ "DepFileType" ,
20
+ "HeaderExtension" ,
21
+ "HeadersDepFiles" ,
22
+ )
9
23
load ("@prelude//cxx:cxx_toolchain_types.bzl" , "CxxToolchainInfo" )
10
24
load ("@prelude//cxx:cxx_utility.bzl" , "cxx_attrs_get_allow_cache_upload" )
11
25
load (
@@ -47,155 +61,6 @@ load(
47
61
"get_flags_for_compiler_type" ,
48
62
)
49
63
50
- # Supported assembly extensions
51
- AsmExtensions = enum (
52
- ".s" ,
53
- ".sx" ,
54
- ".S" ,
55
- ".asm" ,
56
- ".asmpp" ,
57
- )
58
-
59
- # Supported Cxx file extensions
60
- CxxExtension = enum (
61
- ".cpp" ,
62
- ".cc" ,
63
- ".cl" ,
64
- ".cxx" ,
65
- ".c++" ,
66
- ".c" ,
67
- ".m" ,
68
- ".mm" ,
69
- ".cu" ,
70
- ".hip" ,
71
- ".h" ,
72
- ".hpp" ,
73
- ".hh" ,
74
- ".h++" ,
75
- ".hxx" ,
76
- ".bc" ,
77
- * AsmExtensions .values ()
78
- )
79
-
80
- # Header files included in compilation databases
81
- HeaderExtension = enum (
82
- ".h" ,
83
- ".hpp" ,
84
- ".hh" ,
85
- ".h++" ,
86
- ".hxx" ,
87
- ".cuh" ,
88
- )
89
-
90
- # File types for dep files
91
- DepFileType = enum (
92
- "cpp" ,
93
- "c" ,
94
- "cuda" ,
95
- "asm" ,
96
- )
97
-
98
- _HeadersDepFiles = record (
99
- # An executable to wrap the actual command with for post-processing of dep
100
- # files into the format that Buck2 recognizes (i.e. one artifact per line).
101
- processor = field (cmd_args ),
102
- # The tag that was added to headers.
103
- tag = field (ArtifactTag ),
104
- # A function that produces new cmd_args to append to the compile command to
105
- # get it to emit the dep file. This will receive the output dep file as an
106
- # input.
107
- mk_flags = field (typing .Callable ),
108
- # Dependency tracking mode to know how to generate dep file
109
- dep_tracking_mode = field (DepTrackingMode ),
110
- )
111
-
112
- # Information about how to compile a source file of particular extension.
113
- _CxxCompileCommand = record (
114
- # The compiler and any args which are independent of the rule.
115
- base_compile_cmd = field (cmd_args ),
116
- # The argsfile of arguments from the rule and it's dependencies.
117
- argsfile = field (CompileArgsfile ),
118
- # The argsfile to use for Xcode integration.
119
- xcode_argsfile = field (CompileArgsfile ),
120
- # The argsfile containing header units args.
121
- header_units_argsfile = field (CompileArgsfile | None ),
122
- headers_dep_files = field ([_HeadersDepFiles , None ]),
123
- compiler_type = field (str ),
124
- # The action category
125
- category = field (str ),
126
- allow_cache_upload = field (bool ),
127
- )
128
-
129
- # Information about how to compile a source file.
130
- CxxSrcCompileCommand = record (
131
- # Source file to compile.
132
- src = field (Artifact ),
133
- # If we have multiple source entries with same files but different flags,
134
- # specify an index so we can differentiate them. Otherwise, use None.
135
- index = field ([int , None ], None ),
136
- # The CxxCompileCommand to use to compile this file.
137
- cxx_compile_cmd = field (_CxxCompileCommand ),
138
- # Arguments specific to the source file.
139
- args = field (list [typing .Any ]),
140
- # Is this a header file?
141
- is_header = field (bool , False ),
142
- # The index store factory to use to generate index store for this source file.
143
- index_store_factory = field (typing .Callable | None , None ),
144
- error_handler = field ([typing .Callable , None ], None ),
145
- )
146
-
147
- _CxxSrcPrecompileCommand = record (
148
- # Source file to compile.
149
- src = field (Artifact ),
150
- # The CxxCompileCommand to use to compile this file.
151
- cxx_compile_cmd = field (_CxxCompileCommand ),
152
- # Arguments specific to the source file.
153
- args = field (list [typing .Any ]),
154
- # Extra argsfile to include after any other header units argsfile but before the
155
- # main argsfiles.
156
- extra_argsfile = field ([CompileArgsfile , None ], None ),
157
- )
158
-
159
- # Output of creating compile commands for Cxx source files.
160
- CxxCompileCommandOutput = record (
161
- # List of compile commands for each source file.
162
- src_compile_cmds = field (list [CxxSrcCompileCommand ], default = []),
163
- # Base compile commands for each source file extension.
164
- base_compile_cmds = field (dict [CxxExtension , _CxxCompileCommand ], default = {}),
165
- # Argsfiles generated for compiling these source files.
166
- argsfiles = field (CompileArgsfiles , default = CompileArgsfiles ()),
167
- # List of compile commands for use in compilation database generation.
168
- comp_db_compile_cmds = field (list [CxxSrcCompileCommand ], default = []),
169
- )
170
-
171
- CxxCompileOutput = record (
172
- # The compiled `.o` file.
173
- object = field (Artifact ),
174
- object_format = field (CxxObjectFormat , CxxObjectFormat ("native" )),
175
- object_has_external_debug_info = field (bool , False ),
176
- # Externally referenced debug info, which doesn't get linked with the
177
- # object (e.g. the above `.o` when using `-gsplit-dwarf=single` or the
178
- # the `.dwo` when using `-gsplit-dwarf=split`).
179
- external_debug_info = field (Artifact | None , None ),
180
- clang_remarks = field (Artifact | None , None ),
181
- clang_trace = field (Artifact | None , None ),
182
- gcno_file = field (Artifact | None , None ),
183
- index_store = field (Artifact | None , None ),
184
- assembly = field (Artifact | None , None ),
185
- diagnostics = field (Artifact | None , None ),
186
- preproc = field (Artifact | None , None ),
187
- )
188
-
189
- CxxCompileFlavor = enum (
190
- # Default compilation witout alterations
191
- "default" ,
192
- # Produces position independent compile outputs
193
- "pic" ,
194
- # Produces position independent compile outputs
195
- # using optimization flags from toolchain
196
- "pic_optimized" ,
197
- )
198
-
199
64
def get_source_extension_for_header (header_extension : str , default : CxxExtension ) -> CxxExtension :
200
65
"""
201
66
Which source file extension to use to get compiler flags for the header.
@@ -347,7 +212,7 @@ def create_compile_cmds(
347
212
348
213
src_compile_cmds = []
349
214
hdr_compile_cmds = []
350
- cxx_compile_cmd_by_ext = {} # type: dict[CxxExtension, _CxxCompileCommand ]
215
+ cxx_compile_cmd_by_ext = {} # type: dict[CxxExtension, CxxCompileCommand ]
351
216
argsfile_by_ext = {} # type: dict[str, CompileArgsfile]
352
217
xcode_argsfile_by_ext = {} # type: dict[str, CompileArgsfile]
353
218
@@ -775,7 +640,7 @@ def _create_precompile_cmd(
775
640
header_group : str | None ,
776
641
group_name : str ,
777
642
extra_preprocessors : list [CPreprocessor ],
778
- cmd : _CxxCompileCommand ) -> _CxxSrcPrecompileCommand :
643
+ cmd : CxxCompileCommand ) -> CxxSrcPrecompileCommand :
779
644
include_dirs = flatten ([x .include_dirs for x in preprocessors ])
780
645
converted_headers = [
781
646
_convert_raw_header (ctx , raw_header , include_dirs )
@@ -852,7 +717,7 @@ module "{}" {{
852
717
args .extend (["-Xclang" , cmd_args (input_header , format = "-fmodules-embed-file={}" )])
853
718
args .extend (["--precompile" , input_header ])
854
719
855
- return _CxxSrcPrecompileCommand (
720
+ return CxxSrcPrecompileCommand (
856
721
src = src_dir ,
857
722
cxx_compile_cmd = cmd ,
858
723
args = args ,
@@ -863,7 +728,7 @@ def _precompile_single_cxx(
863
728
ctx : AnalysisContext ,
864
729
impl_params : CxxRuleConstructorParams ,
865
730
group_name : str ,
866
- src_compile_cmd : _CxxSrcPrecompileCommand ) -> HeaderUnit :
731
+ src_compile_cmd : CxxSrcPrecompileCommand ) -> HeaderUnit :
867
732
identifier = src_compile_cmd .src .short_path
868
733
869
734
filename = "{}.pcm" .format (identifier )
@@ -1287,7 +1152,7 @@ def _generate_base_compile_command(
1287
1152
pre : CPreprocessorInfo ,
1288
1153
headers_tag : ArtifactTag ,
1289
1154
ext : CxxExtension ,
1290
- filename_prefix : str = "" ) -> _CxxCompileCommand :
1155
+ filename_prefix : str = "" ) -> CxxCompileCommand :
1291
1156
"""
1292
1157
Generate a common part of a compile command that is shared by all sources
1293
1158
with a given extension.
@@ -1303,7 +1168,7 @@ def _generate_base_compile_command(
1303
1168
tracking_mode = _get_dep_tracking_mode (toolchain , dep_file_file_type_hint )
1304
1169
mk_dep_files_flags = get_headers_dep_files_flags_factory (tracking_mode )
1305
1170
if mk_dep_files_flags :
1306
- headers_dep_files = _HeadersDepFiles (
1171
+ headers_dep_files = HeadersDepFiles (
1307
1172
processor = cmd_args (toolchain .internal_tools .dep_file_processor ),
1308
1173
mk_flags = mk_dep_files_flags ,
1309
1174
tag = headers_tag ,
@@ -1315,7 +1180,7 @@ def _generate_base_compile_command(
1315
1180
header_units_argsfile = _mk_header_units_argsfile (ctx , compiler_info , pre , ext , filename_prefix )
1316
1181
1317
1182
allow_cache_upload = cxx_attrs_get_allow_cache_upload (ctx .attrs , default = compiler_info .allow_cache_upload )
1318
- return _CxxCompileCommand (
1183
+ return CxxCompileCommand (
1319
1184
base_compile_cmd = base_compile_cmd ,
1320
1185
argsfile = argsfile ,
1321
1186
xcode_argsfile = xcode_argsfile ,
0 commit comments