73 skia_dir = checkout_root.join('skia')
74 compiler = api.vars.builder_cfg.get('compiler', '')
75 configuration = api.vars.builder_cfg.get('configuration', '')
76 extra_tokens = api.vars.extra_tokens
77 os = api.vars.builder_cfg.get('os', '')
78 target_arch = api.vars.builder_cfg.get('target_arch', '')
79
80 clang_linux = str(api.vars.workdir.join('clang_linux'))
81 win_toolchain = str(api.vars.workdir.join('win_toolchain'))
82 dwritecore = str(api.vars.workdir.join('dwritecore'))
83
84 cc, cxx, ccache = None, None, None
85 extra_cflags = []
86 extra_ldflags = []
87 args = {'werror': 'true', 'link_pool_depth':'2'}
88 env = {}
89
90 with api.context(cwd=skia_dir):
91 api.run(api.step, 'fetch-gn',
92 cmd=['python3', skia_dir.join('bin', 'fetch-gn')],
93 infra_step=True)
94
95 api.run(api.step, 'fetch-ninja',
96 cmd=['python3', skia_dir.join('bin', 'fetch-ninja')],
97 infra_step=True)
98
99 if os == 'Mac':
100
101
102
103
104
105 XCODE_BUILD_VERSION = '12c33'
106 if compiler == 'Xcode11.4.1':
107 XCODE_BUILD_VERSION = '11e503a'
108 extra_cflags.append(
109 '-DREBUILD_IF_CHANGED_xcode_build_version=%s' % XCODE_BUILD_VERSION)
110 mac_toolchain_cmd = api.vars.workdir.join(
111 'mac_toolchain', 'mac_toolchain')
112 xcode_app_path = api.vars.cache_dir.join('Xcode.app')
113
114
115 with api.step.nest('ensure xcode') as step_result:
116 step_result.step_summary_text = (
117 'Ensuring Xcode version %s in %s' % (
118 XCODE_BUILD_VERSION, xcode_app_path))
119 install_xcode_cmd = [
120 mac_toolchain_cmd, 'install',
121
122
123 '-kind', 'ios',
124 '-xcode-version', XCODE_BUILD_VERSION,
125 '-output-dir', xcode_app_path,
126 ]
127 api.step('install xcode', install_xcode_cmd)
128 api.step('select xcode', [
129 'sudo', 'xcode-select', '-switch', xcode_app_path])
130 if 'iOS' in extra_tokens:
131 if compiler == 'Xcode11.4.1':
132
133
134 env['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
135 args['ios_min_target'] = '"11.0"'
136 else:
137 env['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
138 args['ios_min_target'] = '"13.0"'
139
140 else:
141
142 env['MACOSX_DEPLOYMENT_TARGET'] = '10.15'
143
144
145 if (api.vars.is_linux or os == 'Mac' or os == 'Mac10.15.5' or os == 'Mac10.15.7') and 'Tidy' not in extra_tokens:
146 if api.vars.is_linux:
147 ccache = api.vars.workdir.join('ccache_linux', 'bin', 'ccache')
148
149
150 env['CCACHE_MAXSIZE'] = '75G'
151 else:
152 ccache = api.vars.workdir.join('ccache_mac', 'bin', 'ccache')
153
154
155 env['CCACHE_MAXSIZE'] = '50G'
156
157 args['cc_wrapper'] = '"%s"' % ccache
158
159 env['CCACHE_DIR'] = api.vars.cache_dir.join('ccache')
160 env['CCACHE_MAXFILES'] = '0'
161
162
163
164 env['CCACHE_COMPILERCHECK'] = 'content'
165
166 if compiler == 'Clang' and api.vars.is_linux:
167 cc = clang_linux + '/bin/clang'
168 cxx = clang_linux + '/bin/clang++'
169 extra_cflags .
append(
'-B%s/bin' % clang_linux)
170 extra_ldflags.append('-B%s/bin' % clang_linux)
171 extra_ldflags.append('-fuse-ld=lld')
172 extra_cflags.append('-DPLACEHOLDER_clang_linux_version=%s' %
173 api.run.asset_version('clang_linux', skia_dir))
174 if 'Static' in extra_tokens:
175 extra_ldflags.extend(['-static-libstdc++', '-static-libgcc'])
176
177 elif compiler == 'Clang':
178 cc, cxx = 'clang', 'clang++'
179
180 if 'Tidy' in extra_tokens:
181
182 cxx = skia_dir.join("tools/clang-tidy.sh")
183 env['PATH'] = '%s:%%(PATH)s' % (clang_linux + '/bin')
184
185 args.update({
186 'skia_enable_fontmgr_empty': 'true',
187 'skia_enable_graphite': 'true',
188 'skia_enable_pdf': 'true',
189 'skia_use_dawn': 'true',
190 'skia_use_expat': 'true',
191 'skia_use_freetype': 'true',
192 'skia_use_vulkan': 'true',
193 })
194
195 if 'Coverage' in extra_tokens:
196
197
198 extra_cflags.append('-fprofile-instr-generate')
199 extra_cflags.append('-fcoverage-mapping')
200 extra_ldflags.append('-fprofile-instr-generate')
201 extra_ldflags.append('-fcoverage-mapping')
202
203 if compiler != 'MSVC' and configuration == 'Debug':
204 extra_cflags.append('-O1')
205 if compiler != 'MSVC' and configuration == 'OptimizeForSize':
206
207
208 extra_ldflags.append('-Wl,--build-id=sha1')
209 args.update({
210 'skia_use_runtime_icu': 'true',
211 'skia_enable_optimize_size': 'true',
212 'skia_use_jpeg_gainmaps': 'false',
213 })
214
215 if 'Exceptions' in extra_tokens:
216 extra_cflags.append('/EHsc')
217 if 'Fast' in extra_tokens:
218 extra_cflags.extend(['-march=native', '-fomit-frame-pointer', '-O3',
219 '-ffp-contract=off'])
220
221 if len(extra_tokens) == 1
and extra_tokens[0].startswith(
'SK'):
222 extra_cflags.append('-D' + extra_tokens[0])
223
224 if 'SK_CPU_LIMIT' in extra_tokens[0]:
225 extra_cflags.append('-DSKCMS_PORTABLE')
226
227 if 'MSAN' in extra_tokens:
228 extra_ldflags.append('-L' + clang_linux + '/msan')
229 elif 'TSAN' in extra_tokens:
230 extra_ldflags.append('-L' + clang_linux + '/tsan')
231 elif api.vars.is_linux:
232 extra_ldflags.append('-L' + clang_linux + '/lib')
233
234 if configuration != 'Debug':
235 args['is_debug'] = 'false'
236 if 'Dawn' in extra_tokens:
237 util.set_dawn_args_and_env(args, env, api, extra_tokens, skia_dir)
238 if 'ANGLE' in extra_tokens:
239 args['skia_use_angle'] = 'true'
240 if 'SwiftShader' in extra_tokens:
241 swiftshader_root = skia_dir.join('third_party', 'externals', 'swiftshader')
242
243 ninja_root = skia_dir.join('third_party', 'ninja')
244 swiftshader_out = out_dir.join('swiftshader_out')
245 compile_swiftshader(api, extra_tokens, swiftshader_root, ninja_root, cc, cxx, swiftshader_out)
246 args['skia_use_vulkan'] = 'true'
247 extra_cflags.extend(['-DSK_GPU_TOOLS_VK_LIBRARY_NAME=%s' %
248 api.vars.swarming_out_dir.join('swiftshader_out', 'libvk_swiftshader.so'),
249 ])
250 if 'MSAN' in extra_tokens:
251 args['skia_use_fontconfig'] = 'false'
252 if 'ASAN' in extra_tokens:
253 args['skia_enable_spirv_validation'] = 'false'
254 if 'NoPrecompile' in extra_tokens:
255 args['skia_enable_precompile'] = 'false'
256 if 'Graphite' in extra_tokens:
257 args['skia_enable_graphite'] = 'true'
258 if 'Vello' in extra_tokens:
259 args['skia_enable_vello_shaders'] = 'true'
260 if 'Fontations' in extra_tokens:
261 args['skia_use_fontations'] = 'true'
262 args['skia_use_freetype'] = 'true'
263 args['skia_use_system_freetype2'] = 'false'
264 if 'FreeType' in extra_tokens:
265 args['skia_use_freetype'] = 'true'
266 args['skia_use_system_freetype2'] = 'false'
267
268 if 'NoGpu' in extra_tokens:
269 args['skia_enable_ganesh'] = 'false'
270 if 'NoDEPS' in extra_tokens:
271 args.update({
272 'is_official_build': 'true',
273 'skia_enable_fontmgr_empty': 'true',
274 'skia_enable_ganesh': 'true',
275
276 'skia_enable_pdf': 'false',
277 'skia_use_expat': 'false',
278 'skia_use_freetype': 'false',
279 'skia_use_harfbuzz': 'false',
280 'skia_use_icu': 'false',
281 'skia_use_libjpeg_turbo_decode': 'false',
282 'skia_use_libjpeg_turbo_encode': 'false',
283 'skia_use_libpng_decode': 'false',
284 'skia_use_libpng_encode': 'false',
285 'skia_use_libwebp_decode': 'false',
286 'skia_use_libwebp_encode': 'false',
287 'skia_use_vulkan': 'false',
288 'skia_use_wuffs': 'false',
289 'skia_use_zlib': 'false',
290 })
291 elif configuration != 'OptimizeForSize':
292 args.update({
293 'skia_use_client_icu': 'true',
294 'skia_use_libgrapheme': 'true',
295 })
296
297 if 'Fontations' in extra_tokens:
298 args['skia_use_icu4x'] = 'true'
299
300 if 'Shared' in extra_tokens:
301 args['is_component_build'] = 'true'
302 if 'Vulkan' in extra_tokens and not 'Android' in extra_tokens and not 'Dawn' in extra_tokens:
303 args['skia_use_vulkan'] = 'true'
304 args['skia_enable_vulkan_debug_layers'] = 'true'
305
306
307 if 'TSAN' in extra_tokens:
308 args['skia_use_gl'] = 'true'
309 else:
310 args['skia_use_gl'] = 'false'
311 if 'Direct3D' in extra_tokens and not 'Dawn' in extra_tokens:
312 args['skia_use_direct3d'] = 'true'
313 args['skia_use_gl'] = 'false'
314 if 'Metal' in extra_tokens and not 'Dawn' in extra_tokens:
315 args['skia_use_metal'] = 'true'
316 args['skia_use_gl'] = 'false'
317 if 'iOS' in extra_tokens:
318
319 args['skia_ios_identity'] = '".*83FNP.*"'
320
321 args['skia_ios_profile'] = '"%s"' % api.vars.workdir.join(
322 'provisioning_profile_ios',
323 'Upstream_Testing_Provisioning_Profile.mobileprovision')
324 if compiler == 'Clang' and 'Win' in os:
325 args['clang_win'] = '"%s"' % api.vars.workdir.join('clang_win')
326 extra_cflags.append('-DPLACEHOLDER_clang_win_version=%s' %
327 api.run.asset_version('clang_win', skia_dir))
328
329 sanitize = ''
330 for t in extra_tokens:
331 if t.endswith('SAN'):
332 sanitize = t
333 if api.vars.is_linux and t == 'ASAN':
334
335 extra_cflags.append('-DSK_ENABLE_SCOPED_LSAN_SUPPRESSIONS')
336 if 'SafeStack' in extra_tokens:
337 assert sanitize == ''
338 sanitize = 'safe-stack'
339
340 if 'Wuffs' in extra_tokens:
341 args['skia_use_wuffs'] = 'true'
342
343 if 'AVIF' in extra_tokens:
344 args['skia_use_libavif'] = 'true'
345
346 for (k,v) in {
347 'cc': cc,
348 'cxx': cxx,
349 'sanitize': sanitize,
350 'target_cpu': target_arch,
351 'target_os': 'ios' if 'iOS' in extra_tokens else '',
352 'win_sdk': win_toolchain + '/win_sdk' if 'Win' in os else '',
353 'win_vc': win_toolchain + '/VC' if 'Win' in os else '',
354 'skia_dwritecore_sdk': dwritecore if 'DWriteCore' in extra_tokens else '',
355 }.items():
356 if v:
357 args[k] = '"%s"' % v
358 if extra_cflags:
359 args['extra_cflags'] = repr(extra_cflags).replace("'", '"')
360 if extra_ldflags:
361 args['extra_ldflags'] = repr(extra_ldflags).replace("'", '"')
362
363 gn_args =
' '.
join(
'%s=%s' % (k,v)
for (k,v)
in sorted(args.items()))
364 gn = skia_dir.join('bin', 'gn')
365 ninja = skia_dir.join('third_party', 'ninja', 'ninja')
366
367 with api.context(cwd=skia_dir):
368 with api.env(env):
369 if ccache:
370 api.run(api.step, 'ccache stats-start', cmd=[ccache, '-s'])
371 api.run(api.step, 'gn gen',
372 cmd=[gn, 'gen', out_dir, '--args=' + gn_args])
373 if 'Fontations' in extra_tokens:
374 api.run(api.step, 'gn clean',
375 cmd=[gn, 'clean', out_dir])
376 api.run(api.step, 'ninja', cmd=[ninja, '-C', out_dir])
377 if ccache:
378 api.run(api.step, 'ccache stats-end', cmd=[ccache, '-s'])
379
380
static void append(char **dst, size_t *count, const char *src, size_t n)
def compile_swiftshader(api, extra_tokens, swiftshader_root, ninja_root, cc, cxx, out)
def compile_fn(api, checkout_root, out_dir)
static SkString join(const CommandLineFlags::StringArray &)