2
2
# Use of this source code is governed by a BSD-style license that can be
3
3
# found in the LICENSE file.
4
4
5
+ import (" //build/toolchain/rbe.gni" )
6
+ import (" //build/toolchain/win/win_toolchain_data.gni" )
7
+
5
8
default_clang_base_path = " //buildtools/windows-x64/clang"
6
9
7
10
declare_args () {
@@ -31,23 +34,18 @@ assert(is_win)
31
34
# This tool will is used as a wrapper for various commands below.
32
35
tool_wrapper_path = rebase_path (" tool_wrapper.py" , root_build_dir )
33
36
34
- toolchain_data = exec_script (" setup_toolchain.py" ,
35
- [
36
- visual_studio_path ,
37
- windows_sdk_path ,
38
- visual_studio_runtime_dirs ,
39
- current_cpu ,
40
- ],
41
- " scope" )
42
-
43
- if (vc_bin_dir == " " ) {
44
- vc_bin_dir = toolchain_data .vc_bin_dir
45
- }
46
-
47
37
if (use_goma ) {
48
- goma_prefix = " $goma_dir /gomacc.exe "
38
+ compiler_prefix = " $goma_dir /gomacc.exe "
39
+ asm_prefix = " $goma_dir /gomacc.exe "
40
+ } else if (use_rbe ) {
41
+ compiler_args = rewrapper_command + [
42
+ " --labels=type=compile,compiler=clang-cl,lang=cpp " ,
43
+ ]
44
+ compiler_prefix = string_join (" " , compiler_args )
45
+ asm_prefix = " "
49
46
} else {
50
- goma_prefix = " "
47
+ compiler_prefix = " "
48
+ asm_prefix = " "
51
49
}
52
50
53
51
if (current_toolchain == default_toolchain ) {
@@ -80,48 +78,73 @@ template("msvc_toolchain") {
80
78
}
81
79
}
82
80
81
+ # TODO(zanderso ): Assert that clang is always used or remove this logic.
82
+ if (defined (toolchain_args .is_clang )) {
83
+ toolchain_is_clang = toolchain_args .is_clang
84
+ } else {
85
+ toolchain_is_clang = is_clang
86
+ }
87
+
83
88
env = invoker .environment
89
+ env_path = " $root_out_dir /$env "
90
+ print (env_path )
91
+ env_file = read_file (env_path , " string" )
92
+ print (env_file )
84
93
85
94
cl = invoker .cl
86
95
87
96
# Make these apply to all tools below.
88
97
lib_switch = " "
89
98
lib_dir_switch = " /LIBPATH:"
90
99
91
- tool (" cc" ) {
92
- rspfile = " {{output}}.rsp"
100
+ # If possible, pass system includes as flags to the compiler. When that's
101
+ # not possible, load a full environment file (containing %INCLUDE% and
102
+ # %PATH%) -- e.g. 32-bit MSVS builds require %PATH% to be set and just
103
+ # passing in a list of include directories isn't enough.
104
+ if (defined (invoker .sys_include_flags )) {
105
+ assert (toolchain_is_clang )
106
+ env_wrapper = " "
107
+ sys_include_flags =
108
+ " ${ invoker.sys_include_flags } " # Note trailing space.
109
+ } else {
110
+ # clang-cl doesn't need this env hoop, so omit it there.
111
+ assert (! toolchain_is_clang )
112
+ env_wrapper = " ninja -t msvc -e $env -- " # Note trailing space.
113
+ sys_include_flags = " "
114
+ }
93
115
94
- # TODO(brettw) enable this when GN support in the binary has been rolled.
95
- # precompiled_header_type = "msvc"
96
- pdbname = " {{target_out_dir}}/{{target_output_name}}_c.pdb"
97
- command = " ninja -t msvc -e $env -- $cl /nologo /showIncludes @$rspfile /c {{source}} /Fo{{output}} /Fd$pdbname "
116
+ tool (" cc" ) {
117
+ precompiled_header_type = " msvc"
118
+ pdbname = " {{target_out_dir}}/{{label_name}}_c.pdb"
98
119
depsformat = " msvc"
99
120
description = " CC {{output}}"
100
- outputs = [
101
- " {{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj" ,
102
- ]
103
- rspfile_content = " {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
121
+ outputs = [ " {{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj" ]
122
+
123
+ # Label names may have spaces in them so the pdbname must be quoted. The
124
+ # source and output don't need to be quoted because GN knows they're a
125
+ # full file name and will quote automatically when necessary.
126
+ command = " $env_wrapper$cl /c {{source}} /nologo /showIncludes:user $sys_include_flags {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} /Fo{{output}} /Fd\" $pdbname \" "
104
127
}
105
128
106
129
tool (" cxx" ) {
107
- rspfile = " {{output}}.rsp"
108
-
109
- # TODO(brettw) enable this when GN support in the binary has been rolled.
110
- # precompiled_header_type = "msvc"
130
+ precompiled_header_type = " msvc"
111
131
112
132
# The PDB name needs to be different between C and C++ compiled files.
113
- pdbname = " {{target_out_dir}}/{{target_output_name}}_cc.pdb"
133
+ pdbname = " {{target_out_dir}}/{{label_name}}_cc.pdb"
134
+
135
+ # TODO(zanderso ): This logic should be moved to be with the other compiler
136
+ # flag logic in build/config/compiler/BUILD.gn or so.
114
137
flags = " "
115
138
if (is_clang && invoker .current_cpu == " x86" ) {
116
139
flags = " -m32"
117
140
}
118
- command = " ninja -t msvc -e $env -- $cl $flags /nologo /showIncludes @ $rspfile /c {{source}} /Fo{{output}} /Fd $pdbname "
141
+
119
142
depsformat = " msvc"
120
143
description = " CXX {{output}}"
121
- outputs = [
122
- " {{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj " ,
123
- ]
124
- rspfile_content = " {{ defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
144
+ outputs = [ " {{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj " ]
145
+
146
+ # See comment in CC tool about quoting.
147
+ command = " $env_wrapper$cl /c {{source}} /Fo{{output}} $flags /nologo /showIncludes:user $sys_include_flags {{ defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} /Fd \" $pdbname \" "
125
148
}
126
149
127
150
tool (" rc" ) {
@@ -141,7 +164,7 @@ template("msvc_toolchain") {
141
164
} else if (toolchain_args .current_cpu == " arm64" ) {
142
165
is_msvc_assembler = false
143
166
prefix = rebase_path (" $clang_base_path /bin" , root_build_dir )
144
- ml = " ${ goma_prefix } ${ prefix } /clang-cl.exe --target=arm64-windows"
167
+ ml = " ${ compiler_prefix } ${ prefix } /clang-cl.exe --target=arm64-windows"
145
168
x64 = " "
146
169
} else {
147
170
ml = " ml.exe"
@@ -175,14 +198,11 @@ template("msvc_toolchain") {
175
198
}
176
199
177
200
tool (" solink" ) {
178
- dllname = " {{root_out_dir}}/{{target_output_name}}{{output_extension}}" # e.g.
179
- # foo.dll
180
- libname = " {{root_out_dir}}/{{target_output_name}}{{output_extension}}.lib" # e.g.
181
- # foo.dll.lib
182
- expname = " {{root_out_dir}}/{{target_output_name}}{{output_extension}}.exp" # e.g.
183
- # foo.dll.exp
184
- pdbname = " {{root_out_dir}}/{{target_output_name}}{{output_extension}}.pdb" # e.g.
185
- # foo.dll.pdb
201
+ # E.g. "foo.dll":
202
+ dllname = " {{root_out_dir}}/{{target_output_name}}{{output_extension}}"
203
+ libname = " ${ dllname } .lib" # e.g. foo.dll.lib
204
+ expname = " ${ dllname } .exp"
205
+ pdbname = " ${ dllname } .pdb"
186
206
rspfile = " ${ dllname } .rsp"
187
207
188
208
link_command = " $python_path $tool_wrapper_path link-wrapper $env False link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:${ dllname } .pdb @$rspfile "
@@ -253,21 +273,22 @@ template("win_toolchains") {
253
273
assert (defined (invoker .toolchain_arch ))
254
274
toolchain_arch = invoker .toolchain_arch
255
275
256
- msvc_toolchain (target_name ) {
257
- environment = " environment." + toolchain_arch
258
- cl = " ${ goma_prefix } \" ${ vc_bin_dir } /cl.exe\" "
259
- toolchain_args = {
260
- if (defined (invoker .toolchain_args )) {
261
- forward_variables_from (invoker .toolchain_args , " *" )
262
- }
263
- current_cpu = toolchain_arch
264
- is_clang = false
265
- }
276
+ # The toolchain data for `msvc_toolchain()`.
277
+ if (toolchain_arch == " x86" ) {
278
+ win_toolchain_data = win_toolchain_data_x86
279
+ } else if (toolchain_arch == " x64" ) {
280
+ win_toolchain_data = win_toolchain_data_x64
281
+ } else if (toolchain_arch == " arm64" ) {
282
+ win_toolchain_data = win_toolchain_data_arm64
283
+ } else {
284
+ error (" Unsupported toolchain_arch, add it to win_toolchain_data.gni" )
266
285
}
286
+
267
287
msvc_toolchain (" clang_" + target_name ) {
268
288
environment = " environment." + toolchain_arch
269
289
prefix = rebase_path (" $clang_base_path /bin" , root_build_dir )
270
- cl = " ${ goma_prefix } $prefix /clang-cl.exe"
290
+ cl = " ${ compiler_prefix } $prefix /clang-cl.exe"
291
+ sys_include_flags = " ${ win_toolchain_data.include_flags_imsvc } "
271
292
toolchain_args = {
272
293
if (defined (invoker .toolchain_args )) {
273
294
forward_variables_from (invoker .toolchain_args , " *" )
0 commit comments