Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
build.default Namespace Reference

Functions

 compile_swiftshader (api, extra_tokens, swiftshader_root, ninja_root, cc, cxx, out)
 
 compile_fn (api, checkout_root, out_dir)
 
 copy_build_products (api, src, dst)
 

Function Documentation

◆ compile_fn()

build.default.compile_fn (   api,
  checkout_root,
  out_dir 
)

Definition at line 72 of file default.py.

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 # XCode build is listed in parentheses after the version at
101 # https://developer.apple.com/news/releases/, or on Wikipedia here:
102 # https://en.wikipedia.org/wiki/Xcode#Version_comparison_table
103 # Use lowercase letters.
104 # https://chrome-infra-packages.appspot.com/p/infra_internal/ios/xcode
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 # Copied from
114 # https://chromium.googlesource.com/chromium/tools/build/+/e19b7d9390e2bb438b566515b141ed2b9ed2c7c2/scripts/slave/recipe_modules/ios/api.py#322
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 # "ios" is needed for simulator builds
122 # (Build-Mac-Clang-x64-Release-iOS).
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 # Our current min-spec for Skia is iOS 11
132 env['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
133 args['ios_min_target'] = '"11.0"'
134 else:
135 # We have some bots on 10.13.
136 env['MACOSX_DEPLOYMENT_TARGET'] = '10.13'
137
138 # ccache + clang-tidy.sh chokes on the argument list.
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 # As of 2020-02-07, the sum of each Debian10-Clang-x86
143 # non-flutter/android/chromebook build takes less than 75G cache space.
144 env['CCACHE_MAXSIZE'] = '75G'
145 else:
146 ccache = api.vars.workdir.join('ccache_mac', 'bin', 'ccache')
147 # As of 2020-02-10, the sum of each Build-Mac-Clang- non-android build
148 # takes ~30G cache space.
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 # Compilers are unpacked from cipd with bogus timestamps, only contribute
156 # compiler content to hashes. If Ninja ever uses absolute paths to changing
157 # directories we'll also need to set a CCACHE_BASEDIR.
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 # Swap in clang-tidy.sh for clang++, but update PATH so it can find clang++.
176 cxx = skia_dir.join("tools/clang-tidy.sh")
177 env['PATH'] = '%s:%%(PATH)s' % (clang_linux + '/bin')
178 # Increase ClangTidy code coverage by enabling features.
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 # See https://clang.llvm.org/docs/SourceBasedCodeCoverage.html for
191 # more info on using llvm to gather coverage information.
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 # build IDs are required for Bloaty if we want to use strip to ignore debug symbols.
201 # https://github.com/google/bloaty/blob/master/doc/using.md#debugging-stripped-binaries
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 # If we're limiting Skia at all, drop skcms to portable code.
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 # Swiftshader will need to make ninja be on the path
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' # we compare with freetype in tests
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 # When running TSAN with Vulkan on NVidia, we experienced some timeouts. We found
300 # a workaround (in GrContextFactory) that requires GL (in addition to Vulkan).
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 # Bots use Chromium signing cert.
313 args['skia_ios_identity'] = '".*83FNP.*"'
314 # Get mobileprovision via the CIPD package.
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 # skia:8712 and skia:8713
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)
Definition editor.cpp:211

◆ compile_swiftshader()

build.default.compile_swiftshader (   api,
  extra_tokens,
  swiftshader_root,
  ninja_root,
  cc,
  cxx,
  out 
)
Build SwiftShader with CMake.

Building SwiftShader works differently from any other Skia third_party lib.
See discussion in skia:7671 for more detail.

Args:
  swiftshader_root: root of the SwiftShader checkout.
  ninja_root: A folder containing a ninja binary
  cc, cxx: compiler binaries to use
  out: target directory for libvk_swiftshader.so

Definition at line 9 of file default.py.

9def compile_swiftshader(api, extra_tokens, swiftshader_root, ninja_root, cc, cxx, out):
10 """Build SwiftShader with CMake.
11
12 Building SwiftShader works differently from any other Skia third_party lib.
13 See discussion in skia:7671 for more detail.
14
15 Args:
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
20 """
21 swiftshader_opts = [
22 '-DSWIFTSHADER_BUILD_TESTS=OFF',
23 '-DSWIFTSHADER_WARNINGS_AS_ERRORS=OFF',
24 '-DREACTOR_ENABLE_MEMORY_SANITIZER_INSTRUMENTATION=OFF', # Way too slow.
25 ]
26 cmake_bin = str(api.vars.workdir.join('cmake_linux', 'bin'))
27 env = {
28 'CC': cc,
29 'CXX': cxx,
30 'PATH': '%s:%%(PATH)s:%s' % (ninja_root, cmake_bin),
31 # We arrange our MSAN/TSAN prebuilts a little differently than
32 # SwiftShader's CMakeLists.txt expects, so we'll just keep our custom
33 # setup (everything mentioning libcxx below) and point SwiftShader's
34 # CMakeLists.txt at a harmless non-existent path.
35 'SWIFTSHADER_MSAN_INSTRUMENTED_LIBCXX_PATH': '/totally/phony/path',
36 }
37
38 # Extra flags for MSAN/TSAN, if necessary.
39 san = None
40 if 'MSAN' in extra_tokens:
41 san = ('msan','memory')
42
43 if san:
44 short,full = san
45 clang_linux = str(api.vars.workdir.join('clang_linux'))
46 libcxx = clang_linux + '/' + short
47 cflags = ' '.join([
48 '-fsanitize=' + full,
49 '-stdlib=libc++',
50 '-L%s/lib' % libcxx,
51 '-lc++abi',
52 '-I%s/include' % libcxx,
53 '-I%s/include/c++/v1' % libcxx,
54 '-Wno-unused-command-line-argument' # Are -lc++abi and -Llibcxx/lib always unused?
55 ])
56 swiftshader_opts.extend([
57 '-DSWIFTSHADER_{}=ON'.format(short.upper()),
58 '-DCMAKE_C_FLAGS=%s' % cflags,
59 '-DCMAKE_CXX_FLAGS=%s' % cflags,
60 ])
61
62 # Build SwiftShader.
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'])
67 # See https://swiftshader-review.googlesource.com/c/SwiftShader/+/56452 for when the
68 # deprecated targets were added. See skbug.com/12386 for longer-term plans.
69 api.run(api.step, 'swiftshader ninja', cmd=['ninja', '-C', out, 'vk_swiftshader'])
70
71
uint32_t uint32_t * format

◆ copy_build_products()

build.default.copy_build_products (   api,
  src,
  dst 
)

Definition at line 375 of file default.py.

375def copy_build_products(api, src, dst):
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', '')
380
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)
386
387 if configuration == 'OptimizeForSize':
388 util.copy_listed_files(api, src, dst, ['skottie_tool_cpu', 'skottie_tool_gpu'])
389
390 if os == 'Mac' and any('SAN' in t for t in extra_tokens):
391 # The XSAN dylibs are in
392 # Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib
393 # /clang/11.0.0/lib/darwin, where 11.0.0 could change in future versions.
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',
404 test_data=[
405 'libclang_rt.asan_osx_dynamic.dylib',
406 'libclang_rt.tsan_osx_dynamic.dylib',
407 'libclang_rt.ubsan_osx_dynamic.dylib',
408 ])
409 for f in dylibs:
410 api.file.copy('copy %s' % api.path.basename(f), f, dst)