10 """Build SwiftShader with CMake.
12 Building SwiftShader works differently from any other Skia third_party lib.
13 See discussion in skia:7671 for more detail.
16 swiftshader_root: root of the SwiftShader checkout.
17 ninja_root: A folder containing a ninja binary
18 cc, cxx: compiler binaries to use
19 out: target directory for libvk_swiftshader.so
22 '-DSWIFTSHADER_BUILD_TESTS=OFF',
23 '-DSWIFTSHADER_WARNINGS_AS_ERRORS=OFF',
24 '-DREACTOR_ENABLE_MEMORY_SANITIZER_INSTRUMENTATION=OFF',
26 cmake_bin = str(api.vars.workdir.join(
'cmake_linux',
'bin'))
30 'PATH':
'%s:%%(PATH)s:%s' % (ninja_root, cmake_bin),
35 'SWIFTSHADER_MSAN_INSTRUMENTED_LIBCXX_PATH':
'/totally/phony/path',
40 if 'MSAN' in extra_tokens:
41 san = (
'msan',
'memory')
45 clang_linux = str(api.vars.workdir.join(
'clang_linux'))
46 libcxx = clang_linux +
'/' + short
52 '-I%s/include' % libcxx,
53 '-I%s/include/c++/v1' % libcxx,
54 '-Wno-unused-command-line-argument'
56 swiftshader_opts.extend([
57 '-DSWIFTSHADER_{}=ON'.
format(short.upper()),
58 '-DCMAKE_C_FLAGS=%s' % cflags,
59 '-DCMAKE_CXX_FLAGS=%s' % cflags,
63 api.file.ensure_directory(
'makedirs swiftshader_out', out)
64 with api.context(cwd=out, env=env):
65 api.run(api.step,
'swiftshader cmake',
66 cmd=[
'cmake'] + swiftshader_opts + [swiftshader_root,
'-GNinja'])
69 api.run(api.step,
'swiftshader ninja', cmd=[
'ninja',
'-C', out,
'vk_swiftshader'])
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',
'')
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'))
84 cc, cxx, ccache =
None,
None,
None
87 args = {
'werror':
'true',
'link_pool_depth':
'2'}
90 with api.context(cwd=skia_dir):
91 api.run(api.step,
'fetch-gn',
92 cmd=[
'python3', skia_dir.join(
'bin',
'fetch-gn')],
95 api.run(api.step,
'fetch-ninja',
96 cmd=[
'python3', skia_dir.join(
'bin',
'fetch-ninja')],
105 XCODE_BUILD_VERSION =
'12c33'
106 if compiler ==
'Xcode11.4.1':
107 XCODE_BUILD_VERSION =
'11e503a'
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')
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',
124 '-xcode-version', XCODE_BUILD_VERSION,
125 '-output-dir', xcode_app_path,
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:
132 env[
'IPHONEOS_DEPLOYMENT_TARGET'] =
'11.0'
133 args[
'ios_min_target'] =
'"11.0"'
136 env[
'MACOSX_DEPLOYMENT_TARGET'] =
'10.13'
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')
144 env[
'CCACHE_MAXSIZE'] =
'75G'
146 ccache = api.vars.workdir.join(
'ccache_mac',
'bin',
'ccache')
149 env[
'CCACHE_MAXSIZE'] =
'50G'
151 args[
'cc_wrapper'] =
'"%s"' % ccache
153 env[
'CCACHE_DIR'] = api.vars.cache_dir.join(
'ccache')
154 env[
'CCACHE_MAXFILES'] =
'0'
158 env[
'CCACHE_COMPILERCHECK'] =
'content'
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'])
171 elif compiler ==
'Clang':
172 cc, cxx =
'clang',
'clang++'
174 if 'Tidy' in extra_tokens:
176 cxx = skia_dir.join(
"tools/clang-tidy.sh")
177 env[
'PATH'] =
'%s:%%(PATH)s' % (clang_linux +
'/bin')
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',
189 if 'Coverage' in extra_tokens:
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')
197 if compiler !=
'MSVC' and configuration ==
'Debug':
198 extra_cflags.append(
'-O1')
199 if compiler !=
'MSVC' and configuration ==
'OptimizeForSize':
202 extra_ldflags.append(
'-Wl,--build-id=sha1')
204 'skia_use_runtime_icu':
'true',
205 'skia_enable_optimize_size':
'true',
206 'skia_use_jpeg_gainmaps':
'false',
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'])
215 if len(extra_tokens) == 1
and extra_tokens[0].startswith(
'SK'):
216 extra_cflags.append(
'-D' + extra_tokens[0])
218 if 'SK_CPU_LIMIT' in extra_tokens[0]:
219 extra_cflags.append(
'-DSKCMS_PORTABLE')
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')
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')
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'),
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'
262 if 'NoGpu' in extra_tokens:
263 args[
'skia_enable_ganesh'] =
'false'
264 if 'NoDEPS' in extra_tokens:
266 'is_official_build':
'true',
267 'skia_enable_fontmgr_empty':
'true',
268 'skia_enable_ganesh':
'true',
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',
285 elif configuration !=
'OptimizeForSize':
287 'skia_use_client_icu':
'true',
288 'skia_use_libgrapheme':
'true',
291 if 'Fontations' in extra_tokens:
292 args[
'skia_use_icu4x'] =
'true'
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'
301 if 'TSAN' in extra_tokens:
302 args[
'skia_use_gl'] =
'true'
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:
313 args[
'skia_ios_identity'] =
'".*83FNP.*"'
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))
324 for t
in extra_tokens:
325 if t.endswith(
'SAN'):
327 if api.vars.is_linux
and t ==
'ASAN':
329 extra_cflags.append(
'-DSK_ENABLE_SCOPED_LSAN_SUPPRESSIONS')
330 if 'SafeStack' in extra_tokens:
331 assert sanitize ==
''
332 sanitize =
'safe-stack'
334 if 'Wuffs' in extra_tokens:
335 args[
'skia_use_wuffs'] =
'true'
337 if 'AVIF' in extra_tokens:
338 args[
'skia_use_libavif'] =
'true'
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 '',
353 args[
'extra_cflags'] = repr(extra_cflags).replace(
"'",
'"')
355 args[
'extra_ldflags'] = repr(extra_ldflags).replace(
"'",
'"')
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')
361 with api.context(cwd=skia_dir):
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])
372 api.run(api.step,
'ccache stats-end', cmd=[ccache,
'-s'])
376 util.copy_listed_files(api, src, dst, util.DEFAULT_BUILD_PRODUCTS)
377 extra_tokens = api.vars.extra_tokens
378 os = api.vars.builder_cfg.get(
'os',
'')
379 configuration = api.vars.builder_cfg.get(
'configuration',
'')
381 if 'SwiftShader' in extra_tokens:
382 util.copy_listed_files(api,
383 src.join(
'swiftshader_out'),
384 api.vars.swarming_out_dir.join(
'swiftshader_out'),
385 util.DEFAULT_BUILD_PRODUCTS)
387 if configuration ==
'OptimizeForSize':
388 util.copy_listed_files(api, src, dst, [
'skottie_tool_cpu',
'skottie_tool_gpu'])
390 if os ==
'Mac' and any(
'SAN' in t
for t
in extra_tokens):
394 xcode_clang_ver_dirs = api.file.listdir(
395 'find XCode Clang version',
396 api.vars.cache_dir.join(
397 'Xcode.app',
'Contents',
'Developer',
'Toolchains',
398 'XcodeDefault.xctoolchain',
'usr',
'lib',
'clang'),
399 test_data=[
'11.0.0'])
400 assert len(xcode_clang_ver_dirs) == 1
401 dylib_dir = xcode_clang_ver_dirs[0].join(
'lib',
'darwin')
402 dylibs = api.file.glob_paths(
'find xSAN dylibs', dylib_dir,
403 'libclang_rt.*san_osx_dynamic.dylib',
405 'libclang_rt.asan_osx_dynamic.dylib',
406 'libclang_rt.tsan_osx_dynamic.dylib',
407 'libclang_rt.ubsan_osx_dynamic.dylib',
410 api.file.copy(
'copy %s' % api.path.basename(f), f, dst)
uint32_t uint32_t * format