xref: /aosp_15_r20/external/skia/docker/skia-with-swift-shader-base/build-with-swift-shader-and-run (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1*c8dee2aaSAndroid Build Coastguard Worker#!/usr/bin/python
2*c8dee2aaSAndroid Build Coastguard Worker
3*c8dee2aaSAndroid Build Coastguard Workerimport subprocess
4*c8dee2aaSAndroid Build Coastguard Workerimport os
5*c8dee2aaSAndroid Build Coastguard Workerimport argparse
6*c8dee2aaSAndroid Build Coastguard Worker
7*c8dee2aaSAndroid Build Coastguard Worker
8*c8dee2aaSAndroid Build Coastguard Worker# This script compiles and runs a skia app using Swiftshader in a docker container, making it easy
9*c8dee2aaSAndroid Build Coastguard Worker# to use Swiftshade w/o having to over-write /usr/local/lib/libEGL.so and related on the
10*c8dee2aaSAndroid Build Coastguard Worker# host development machine.
11*c8dee2aaSAndroid Build Coastguard Worker
12*c8dee2aaSAndroid Build Coastguard Worker# The Skia repo to be compiled will be the one on the host machine, which will
13*c8dee2aaSAndroid Build Coastguard Worker# default to the one specified by the environment variable $SKIA_ROOT with a fallback to the
14*c8dee2aaSAndroid Build Coastguard Worker# current working directory.
15*c8dee2aaSAndroid Build Coastguard Worker
16*c8dee2aaSAndroid Build Coastguard Worker# Example usage
17*c8dee2aaSAndroid Build Coastguard Worker
18*c8dee2aaSAndroid Build Coastguard Worker# Prove SwiftShader is really being used:
19*c8dee2aaSAndroid Build Coastguard Worker#   build-with-swift-shader-and-run "out/with-swift-shader/fuzz --gpuInfo -t api -n NativeGLCanvas"
20*c8dee2aaSAndroid Build Coastguard Worker
21*c8dee2aaSAndroid Build Coastguard Worker# Notice the output says GL_RENDERER Google SwiftShader
22*c8dee2aaSAndroid Build Coastguard Worker# After running the above, feel free to check out $SKIA_OUT/out/with-swift-shader. It has binaries
23*c8dee2aaSAndroid Build Coastguard Worker# but if you try to run out/with-swift-shader/fuzz --gpuInfo -t api -n NativeGLCanvas w/o using
24*c8dee2aaSAndroid Build Coastguard Worker# Docker, it will use the host's GPU (e.g. GL_VENDOR NVIDIA Corporation).
25*c8dee2aaSAndroid Build Coastguard Worker
26*c8dee2aaSAndroid Build Coastguard Worker# Reproduce a fuzzer bug in SwiftShader:
27*c8dee2aaSAndroid Build Coastguard Worker# First, copy the test case into $SKIA_ROOT, say $SKIA_ROOT/skbug_1234
28*c8dee2aaSAndroid Build Coastguard Worker#    build-with-swift-shader-and-run "out/with-swift-shader/fuzz -t filter_fuzz -b /skia/skbug_1234"
29*c8dee2aaSAndroid Build Coastguard Worker
30*c8dee2aaSAndroid Build Coastguard Worker# $SKIA_ROOT gets mapped to /skia - other than that, the docker container does not have
31*c8dee2aaSAndroid Build Coastguard Worker# access to the host file system.
32*c8dee2aaSAndroid Build Coastguard Worker
33*c8dee2aaSAndroid Build Coastguard Worker
34*c8dee2aaSAndroid Build Coastguard WorkerIMAGE = 'gcr.io/skia-public/skia-with-swift-shader-base:prod'
35*c8dee2aaSAndroid Build Coastguard Worker
36*c8dee2aaSAndroid Build Coastguard WorkerBUILD_SCRIPT_PATH = '/skia/docker/skia-with-swift-shader-base/build.sh'
37*c8dee2aaSAndroid Build Coastguard WorkerEXECUTABLE_DIR = 'out/with-swift-shader/'
38*c8dee2aaSAndroid Build Coastguard Worker
39*c8dee2aaSAndroid Build Coastguard Workerparser = argparse.ArgumentParser()
40*c8dee2aaSAndroid Build Coastguard Workerparser.add_argument('--sync_deps', action='store_true', help='Sync the deps before building?')
41*c8dee2aaSAndroid Build Coastguard Workerparser.add_argument('command', help='A string containing the command to be run '
42*c8dee2aaSAndroid Build Coastguard Worker                                    '(e.g. out/with-swift-shader/fuzz --help)')
43*c8dee2aaSAndroid Build Coastguard Workerargs = parser.parse_args()
44*c8dee2aaSAndroid Build Coastguard Worker
45*c8dee2aaSAndroid Build Coastguard Workerskia_root = os.environ['SKIA_ROOT'] or os.getcwd()
46*c8dee2aaSAndroid Build Coastguard Worker
47*c8dee2aaSAndroid Build Coastguard Workerprint 'Assuming SKIA_ROOT to be %s' % skia_root
48*c8dee2aaSAndroid Build Coastguard Worker
49*c8dee2aaSAndroid Build Coastguard Workerbuild_cmd = ['docker', 'run', '--rm', '-v', '%s:/skia' % skia_root, IMAGE, BUILD_SCRIPT_PATH]
50*c8dee2aaSAndroid Build Coastguard Workerif args.sync_deps:
51*c8dee2aaSAndroid Build Coastguard Worker    build_cmd += ['sync-deps']
52*c8dee2aaSAndroid Build Coastguard Worker
53*c8dee2aaSAndroid Build Coastguard Workerprint 'Compiling executables to %s/%s' % (skia_root, EXECUTABLE_DIR)
54*c8dee2aaSAndroid Build Coastguard Worker
55*c8dee2aaSAndroid Build Coastguard Workerprint subprocess.check_output(build_cmd)
56*c8dee2aaSAndroid Build Coastguard Worker
57*c8dee2aaSAndroid Build Coastguard Workersupplied_cmd = args.command.split(' ')
58*c8dee2aaSAndroid Build Coastguard Workerprint 'Running supplied command %s' % supplied_cmd
59*c8dee2aaSAndroid Build Coastguard Workerrun_cmd = ['docker', 'run', '--rm', '-w=/skia', '-v', '%s:/skia' % skia_root, IMAGE] + supplied_cmd
60*c8dee2aaSAndroid Build Coastguard Worker
61*c8dee2aaSAndroid Build Coastguard Workerprint subprocess.check_output(run_cmd)