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