1# Copyright 2018 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5DOCKER_IMAGE = 'gcr.io/skia-public/canvaskit-emsdk:3.1.26_v2' 6INNER_BUILD_SCRIPT = '/SRC/skia/infra/canvaskit/build_canvaskit.sh' 7 8 9def compile_fn(api, checkout_root, _ignore): 10 skia_dir = checkout_root.joinpath('skia') 11 out_dir = api.vars.cache_dir.joinpath('docker', 'canvaskit') 12 configuration = api.vars.builder_cfg.get('configuration', '') 13 extra = api.vars.builder_cfg.get('extra_config', '') 14 15 # We want to make sure the directories exist and were created by chrome-bot, 16 # because if that isn't the case, docker will make them and they will be 17 # owned by root, which causes mysterious failures. To mitigate this risk 18 # further, we don't use the same out_dir as everyone else (thus the _ignore) 19 # param. Instead, we use a "canvaskit" subdirectory in the "docker" named_cache. 20 api.file.ensure_directory('mkdirs out_dir', out_dir, mode=0o777) 21 22 # Download the emsdk binaries (we won't actually use the ones on the Docker 23 # image anymore, now that we have proper GN support) 24 with api.context(cwd=skia_dir): 25 api.run(api.step, 'activate-emsdk', 26 cmd=['python3', skia_dir.joinpath('bin', 'activate-emsdk')], 27 infra_step=True) 28 29 # This uses the emscripten sdk docker image and says "run the 30 # build_canvaskit.sh helper script in there". Additionally, it binds two 31 # folders: the Skia checkout to /SRC and the output directory to /OUT 32 # The called helper script will make the compile happen and put the 33 # output in the right spot. The neat thing is that since the Skia checkout 34 # (and, by extension, the build script) is not a part of the image, but 35 # bound in at runtime, we don't have to re-build the image, except when the 36 # toolchain changes. 37 # Of note, the wasm build doesn't re-use any intermediate steps from the 38 # previous builds, so it's essentially a build from scratch every time. 39 cmd = ['docker', 'run', '--rm', '--volume', '%s:/SRC' % checkout_root, 40 '--volume', '%s:/OUT' % out_dir, 41 DOCKER_IMAGE, INNER_BUILD_SCRIPT] 42 43 # The compile.sh script defaults to "gpu" which means Ganesh + WebGL. The other options are 44 # "cpu" (no GPU backend) and "webgpu" (Graphite + WebGPU). 45 if 'CPU' in extra: 46 cmd.append('cpu') 47 if 'WebGPU' in extra: 48 cmd.append('webgpu') 49 50 if configuration == 'Debug': 51 cmd.append('debug') # It defaults to Release 52 # Override DOCKER_CONFIG set by Kitchen. 53 env = {'DOCKER_CONFIG': '/home/chrome-bot/.docker'} 54 with api.env(env): 55 api.run( 56 api.step, 57 'Build CanvasKit with Docker', 58 cmd=cmd) 59 60 61CANVASKIT_BUILD_PRODUCTS = [ 62 'canvaskit.*' 63] 64 65 66def copy_build_products(api, _ignore, dst): 67 out_dir = api.vars.cache_dir.joinpath('docker', 'canvaskit') 68 # We don't use the normal copy_listed_files because it uses 69 # shutil.move, which attempts to delete the previous file, which 70 # doesn't work because the docker created outputs are read-only and 71 # owned by root (aka only docker images). It's likely safe to change 72 # the shutil.move in the original script to a non-deleting thing 73 # (like copy or copyfile), but there's some subtle behavior differences 74 # especially with directories, that kjlubick felt it best not to risk it. 75 script = api.build.resource('copy_build_products_no_delete.py') 76 api.step( 77 name='copy wasm output', 78 cmd=['python3', script, out_dir, dst, ','.join(CANVASKIT_BUILD_PRODUCTS)], 79 infra_step=True) 80