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.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',
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:
131 if compiler ==
'Xcode11.4.1':
134 env[
'IPHONEOS_DEPLOYMENT_TARGET'] =
'11.0'
135 args[
'ios_min_target'] =
'"11.0"'
137 env[
'IPHONEOS_DEPLOYMENT_TARGET'] =
'13.0'
138 args[
'ios_min_target'] =
'"13.0"'
142 env[
'MACOSX_DEPLOYMENT_TARGET'] =
'10.15'
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')
150 env[
'CCACHE_MAXSIZE'] =
'75G'
152 ccache = api.vars.workdir.join(
'ccache_mac',
'bin',
'ccache')
155 env[
'CCACHE_MAXSIZE'] =
'50G'
157 args[
'cc_wrapper'] =
'"%s"' % ccache
159 env[
'CCACHE_DIR'] = api.vars.cache_dir.join(
'ccache')
160 env[
'CCACHE_MAXFILES'] =
'0'
164 env[
'CCACHE_COMPILERCHECK'] =
'content'
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'])
177 elif compiler ==
'Clang':
178 cc, cxx =
'clang',
'clang++'
180 if 'Tidy' in extra_tokens:
182 cxx = skia_dir.join(
"tools/clang-tidy.sh")
183 env[
'PATH'] =
'%s:%%(PATH)s' % (clang_linux +
'/bin')
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',
195 if 'Coverage' in extra_tokens:
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')
203 if compiler !=
'MSVC' and configuration ==
'Debug':
204 extra_cflags.append(
'-O1')
205 if compiler !=
'MSVC' and configuration ==
'OptimizeForSize':
208 extra_ldflags.append(
'-Wl,--build-id=sha1')
210 'skia_use_runtime_icu':
'true',
211 'skia_enable_optimize_size':
'true',
212 'skia_use_jpeg_gainmaps':
'false',
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'])
221 if len(extra_tokens) == 1
and extra_tokens[0].startswith(
'SK'):
222 extra_cflags.append(
'-D' + extra_tokens[0])
224 if 'SK_CPU_LIMIT' in extra_tokens[0]:
225 extra_cflags.append(
'-DSKCMS_PORTABLE')
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')
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')
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'),
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'
268 if 'NoGpu' in extra_tokens:
269 args[
'skia_enable_ganesh'] =
'false'
270 if 'NoDEPS' in extra_tokens:
272 'is_official_build':
'true',
273 'skia_enable_fontmgr_empty':
'true',
274 'skia_enable_ganesh':
'true',
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',
291 elif configuration !=
'OptimizeForSize':
293 'skia_use_client_icu':
'true',
294 'skia_use_libgrapheme':
'true',
297 if 'Fontations' in extra_tokens:
298 args[
'skia_use_icu4x'] =
'true'
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'
307 if 'TSAN' in extra_tokens:
308 args[
'skia_use_gl'] =
'true'
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:
319 args[
'skia_ios_identity'] =
'".*83FNP.*"'
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))
330 for t
in extra_tokens:
331 if t.endswith(
'SAN'):
333 if api.vars.is_linux
and t ==
'ASAN':
335 extra_cflags.append(
'-DSK_ENABLE_SCOPED_LSAN_SUPPRESSIONS')
336 if 'SafeStack' in extra_tokens:
337 assert sanitize ==
''
338 sanitize =
'safe-stack'
340 if 'Wuffs' in extra_tokens:
341 args[
'skia_use_wuffs'] =
'true'
343 if 'AVIF' in extra_tokens:
344 args[
'skia_use_libavif'] =
'true'
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 '',
359 args[
'extra_cflags'] = repr(extra_cflags).replace(
"'",
'"')
361 args[
'extra_ldflags'] = repr(extra_ldflags).replace(
"'",
'"')
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')
367 with api.context(cwd=skia_dir):
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])
378 api.run(api.step,
'ccache stats-end', cmd=[ccache,
'-s'])
382 util.copy_listed_files(api, src, dst, util.DEFAULT_BUILD_PRODUCTS)
383 extra_tokens = api.vars.extra_tokens
384 os = api.vars.builder_cfg.get(
'os',
'')
385 configuration = api.vars.builder_cfg.get(
'configuration',
'')
387 if 'SwiftShader' in extra_tokens:
388 util.copy_listed_files(api,
389 src.join(
'swiftshader_out'),
390 api.vars.swarming_out_dir.join(
'swiftshader_out'),
391 util.DEFAULT_BUILD_PRODUCTS)
393 if configuration ==
'OptimizeForSize':
394 util.copy_listed_files(api, src, dst, [
'skottie_tool_cpu',
'skottie_tool_gpu'])
396 if os ==
'Mac' and any(
'SAN' in t
for t
in extra_tokens):
400 xcode_clang_ver_dirs = api.file.listdir(
401 'find XCode Clang version',
402 api.vars.cache_dir.join(
403 'Xcode.app',
'Contents',
'Developer',
'Toolchains',
404 'XcodeDefault.xctoolchain',
'usr',
'lib',
'clang'),
405 test_data=[
'11.0.0'])
406 assert len(xcode_clang_ver_dirs) == 1
407 dylib_dir = xcode_clang_ver_dirs[0].
join(
'lib',
'darwin')
408 dylibs = api.file.glob_paths(
'find xSAN dylibs', dylib_dir,
409 'libclang_rt.*san_osx_dynamic.dylib',
411 'libclang_rt.asan_osx_dynamic.dylib',
412 'libclang_rt.tsan_osx_dynamic.dylib',
413 'libclang_rt.ubsan_osx_dynamic.dylib',
416 api.file.copy(
'copy %s' % api.path.basename(f), f, dst)
static void append(char **dst, size_t *count, const char *src, size_t n)
uint32_t uint32_t * format
def compile_swiftshader(api, extra_tokens, swiftshader_root, ninja_root, cc, cxx, out)
def compile_fn(api, checkout_root, out_dir)
def copy_build_products(api, src, dst)
SIT bool any(const Vec< 1, T > &x)
static SkString join(const CommandLineFlags::StringArray &)