Flutter Engine
The Flutter Engine
Functions
build.default Namespace Reference

Functions

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)
 

Function Documentation

◆ compile_fn()

def 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.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 # "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 if compiler == 'Xcode11.4.1':
132 # Ganesh has a lower minimum iOS version than Graphite but there are dedicated jobs that
133 # test with the lower SDK.
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 # We have some machines on 10.15.
142 env['MACOSX_DEPLOYMENT_TARGET'] = '10.15'
143
144 # ccache + clang-tidy.sh chokes on the argument list.
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 # As of 2020-02-07, the sum of each Debian10-Clang-x86
149 # non-flutter/android/chromebook build takes less than 75G cache space.
150 env['CCACHE_MAXSIZE'] = '75G'
151 else:
152 ccache = api.vars.workdir.join('ccache_mac', 'bin', 'ccache')
153 # As of 2020-02-10, the sum of each Build-Mac-Clang- non-android build
154 # takes ~30G cache space.
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 # Compilers are unpacked from cipd with bogus timestamps, only contribute
162 # compiler content to hashes. If Ninja ever uses absolute paths to changing
163 # directories we'll also need to set a CCACHE_BASEDIR.
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 # Swap in clang-tidy.sh for clang++, but update PATH so it can find clang++.
182 cxx = skia_dir.join("tools/clang-tidy.sh")
183 env['PATH'] = '%s:%%(PATH)s' % (clang_linux + '/bin')
184 # Increase ClangTidy code coverage by enabling features.
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 # See https://clang.llvm.org/docs/SourceBasedCodeCoverage.html for
197 # more info on using llvm to gather coverage information.
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 # build IDs are required for Bloaty if we want to use strip to ignore debug symbols.
207 # https://github.com/google/bloaty/blob/master/doc/using.md#debugging-stripped-binaries
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 # If we're limiting Skia at all, drop skcms to portable code.
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 # Swiftshader will need to make ninja be on the path
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' # we compare with freetype in tests
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 # When running TSAN with Vulkan on NVidia, we experienced some timeouts. We found
306 # a workaround (in GrContextFactory) that requires GL (in addition to Vulkan).
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 # Bots use Chromium signing cert.
319 args['skia_ios_identity'] = '".*83FNP.*"'
320 # Get mobileprovision via the CIPD package.
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 # skia:8712 and skia:8713
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)
Definition: editor.cpp:211
def compile_swiftshader(api, extra_tokens, swiftshader_root, ninja_root, cc, cxx, out)
Definition: default.py:9
def compile_fn(api, checkout_root, out_dir)
Definition: default.py:72
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741

◆ compile_swiftshader()

def 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()

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

Definition at line 381 of file default.py.

381def copy_build_products(api, src, dst):
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', '')
386
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)
392
393 if configuration == 'OptimizeForSize':
394 util.copy_listed_files(api, src, dst, ['skottie_tool_cpu', 'skottie_tool_gpu'])
395
396 if os == 'Mac' and any('SAN' in t for t in extra_tokens):
397 # The XSAN dylibs are in
398 # Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib
399 # /clang/11.0.0/lib/darwin, where 11.0.0 could change in future versions.
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',
410 test_data=[
411 'libclang_rt.asan_osx_dynamic.dylib',
412 'libclang_rt.tsan_osx_dynamic.dylib',
413 'libclang_rt.ubsan_osx_dynamic.dylib',
414 ])
415 for f in dylibs:
416 api.file.copy('copy %s' % api.path.basename(f), f, dst)
def copy_build_products(api, src, dst)
Definition: default.py:381
SIT bool any(const Vec< 1, T > &x)
Definition: SkVx.h:530