1*c8dee2aaSAndroid Build Coastguard Worker--- 2*c8dee2aaSAndroid Build Coastguard Workertitle: 'How to build Skia' 3*c8dee2aaSAndroid Build Coastguard WorkerlinkTitle: 'How to build Skia' 4*c8dee2aaSAndroid Build Coastguard Worker 5*c8dee2aaSAndroid Build Coastguard Workerweight: 20 6*c8dee2aaSAndroid Build Coastguard Worker--- 7*c8dee2aaSAndroid Build Coastguard Worker 8*c8dee2aaSAndroid Build Coastguard WorkerMake sure you have first followed the 9*c8dee2aaSAndroid Build Coastguard Worker[instructions to download Skia](../download). 10*c8dee2aaSAndroid Build Coastguard Worker 11*c8dee2aaSAndroid Build Coastguard WorkerSkia uses [GN](https://chromium.googlesource.com/chromium/src/tools/gn/) to 12*c8dee2aaSAndroid Build Coastguard Workerconfigure its builds. 13*c8dee2aaSAndroid Build Coastguard Worker 14*c8dee2aaSAndroid Build Coastguard Worker## `is_official_build` and Third-party Dependencies 15*c8dee2aaSAndroid Build Coastguard Worker 16*c8dee2aaSAndroid Build Coastguard WorkerMost users of Skia should set `is_official_build=true`, and most developers 17*c8dee2aaSAndroid Build Coastguard Workershould leave it to its `false` default. 18*c8dee2aaSAndroid Build Coastguard Worker 19*c8dee2aaSAndroid Build Coastguard WorkerThis mode configures Skia in a way that's suitable to ship: an optimized build 20*c8dee2aaSAndroid Build Coastguard Workerwith no debug symbols, dynamically linked against its third-party dependencies 21*c8dee2aaSAndroid Build Coastguard Workerusing the ordinary library search path. 22*c8dee2aaSAndroid Build Coastguard Worker 23*c8dee2aaSAndroid Build Coastguard WorkerIn contrast, the developer-oriented default is an unoptimized build with full 24*c8dee2aaSAndroid Build Coastguard Workerdebug symbols and all third-party dependencies built from source and embedded 25*c8dee2aaSAndroid Build Coastguard Workerinto libskia. This is how we do all our manual and automated testing. 26*c8dee2aaSAndroid Build Coastguard Worker 27*c8dee2aaSAndroid Build Coastguard WorkerSkia offers several features that make use of third-party libraries, like 28*c8dee2aaSAndroid Build Coastguard Workerlibpng, libwebp, or libjpeg-turbo to decode images, or ICU and sftnly to subset 29*c8dee2aaSAndroid Build Coastguard Workerfonts. All these third-party dependencies are optional and can be controlled by 30*c8dee2aaSAndroid Build Coastguard Workera GN argument that looks something like `skia_use_foo` for appropriate `foo`. 31*c8dee2aaSAndroid Build Coastguard Worker 32*c8dee2aaSAndroid Build Coastguard WorkerIf `skia_use_foo` is enabled, enabling `skia_use_system_foo` will build and link 33*c8dee2aaSAndroid Build Coastguard WorkerSkia against the headers and libraries found on the system paths. 34*c8dee2aaSAndroid Build Coastguard Worker`is_official_build=true` enables all `skia_use_system_foo` by default. You can 35*c8dee2aaSAndroid Build Coastguard Workeruse `extra_cflags` and `extra_ldflags` to add include or library paths if 36*c8dee2aaSAndroid Build Coastguard Workerneeded. 37*c8dee2aaSAndroid Build Coastguard Worker 38*c8dee2aaSAndroid Build Coastguard Worker## Supported and Preferred Compilers 39*c8dee2aaSAndroid Build Coastguard Worker 40*c8dee2aaSAndroid Build Coastguard WorkerWhile Skia should compile with GCC, MSVC, and other compilers, a number of 41*c8dee2aaSAndroid Build Coastguard Workerroutines in Skia's software backend have been written to run fastest when 42*c8dee2aaSAndroid Build Coastguard Workercompiled with Clang. If you depend on software rasterization, image decoding, or 43*c8dee2aaSAndroid Build Coastguard Workercolor space conversion and compile Skia with a compiler other than Clang, you 44*c8dee2aaSAndroid Build Coastguard Workerwill see dramatically worse performance. This choice was only a matter of 45*c8dee2aaSAndroid Build Coastguard Workerprioritization; there is nothing fundamentally wrong with non-Clang compilers. 46*c8dee2aaSAndroid Build Coastguard WorkerSo if this is a serious issue for you, please let us know on the mailing list. 47*c8dee2aaSAndroid Build Coastguard Worker 48*c8dee2aaSAndroid Build Coastguard WorkerSkia makes use of C++17 language features (compiles with `-std=c++17` flag) and 49*c8dee2aaSAndroid Build Coastguard Workerthus requires a C++17 compatible compiler. Clang 5 and later implement all of 50*c8dee2aaSAndroid Build Coastguard Workerthe features of the c++17 standard. Older compilers that lack C++17 support may 51*c8dee2aaSAndroid Build Coastguard Workerproduce non-obvious compilation errors. You can configure your build to use 52*c8dee2aaSAndroid Build Coastguard Workerspecific executables for `cc` and `cxx` invocations using e.g. 53*c8dee2aaSAndroid Build Coastguard Worker`--args='cc="clang" cxx="clang++"'` GN build arguments, as illustrated in 54*c8dee2aaSAndroid Build Coastguard Worker[Quickstart](#quickstart). This can be useful for building Skia without needing to 55*c8dee2aaSAndroid Build Coastguard Workermodify your machine's default compiler toolchain. 56*c8dee2aaSAndroid Build Coastguard Worker 57*c8dee2aaSAndroid Build Coastguard WorkerIf you do not specify `cc` and `cxx` in your gn arguments, Skia will default to 58*c8dee2aaSAndroid Build Coastguard Worker`cc` and `c++`. This is often GCC by default on many platforms, not Clang. 59*c8dee2aaSAndroid Build Coastguard Worker 60*c8dee2aaSAndroid Build Coastguard Worker## Quickstart 61*c8dee2aaSAndroid Build Coastguard Worker 62*c8dee2aaSAndroid Build Coastguard WorkerRun `gn gen` to generate your build files. As arguments to `gn gen`, pass a name 63*c8dee2aaSAndroid Build Coastguard Workerfor your build directory, and optionally `--args=` to configure the build type. 64*c8dee2aaSAndroid Build Coastguard Worker 65*c8dee2aaSAndroid Build Coastguard WorkerTo build Skia as a static library in a build directory named `out/Static`: 66*c8dee2aaSAndroid Build Coastguard Worker 67*c8dee2aaSAndroid Build Coastguard Worker``` 68*c8dee2aaSAndroid Build Coastguard Workerbin/gn gen out/Static --args='is_official_build=true' 69*c8dee2aaSAndroid Build Coastguard Worker``` 70*c8dee2aaSAndroid Build Coastguard Worker 71*c8dee2aaSAndroid Build Coastguard WorkerTo build Skia as a shared library (DLL) in a build directory named `out/Shared`: 72*c8dee2aaSAndroid Build Coastguard Worker 73*c8dee2aaSAndroid Build Coastguard Worker``` 74*c8dee2aaSAndroid Build Coastguard Workerbin/gn gen out/Shared --args='is_official_build=true is_component_build=true' 75*c8dee2aaSAndroid Build Coastguard Worker``` 76*c8dee2aaSAndroid Build Coastguard Worker 77*c8dee2aaSAndroid Build Coastguard WorkerIf you find that you don't have `bin/gn`, make sure you've run: 78*c8dee2aaSAndroid Build Coastguard Worker 79*c8dee2aaSAndroid Build Coastguard Worker``` 80*c8dee2aaSAndroid Build Coastguard Workerpython3 tools/git-sync-deps 81*c8dee2aaSAndroid Build Coastguard Worker``` 82*c8dee2aaSAndroid Build Coastguard Worker 83*c8dee2aaSAndroid Build Coastguard WorkerFor a list of available build arguments, take a look at `gn/skia.gni`, or run: 84*c8dee2aaSAndroid Build Coastguard Worker 85*c8dee2aaSAndroid Build Coastguard Worker``` 86*c8dee2aaSAndroid Build Coastguard Workerbin/gn args out/Debug --list 87*c8dee2aaSAndroid Build Coastguard Worker``` 88*c8dee2aaSAndroid Build Coastguard Worker 89*c8dee2aaSAndroid Build Coastguard WorkerGN allows multiple build folders to coexist; each build can be configured 90*c8dee2aaSAndroid Build Coastguard Workerseparately as desired. For example: 91*c8dee2aaSAndroid Build Coastguard Worker 92*c8dee2aaSAndroid Build Coastguard Worker``` 93*c8dee2aaSAndroid Build Coastguard Workerbin/gn gen out/Debug 94*c8dee2aaSAndroid Build Coastguard Workerbin/gn gen out/Release --args='is_debug=false' 95*c8dee2aaSAndroid Build Coastguard Workerbin/gn gen out/Clang --args='cc="clang" cxx="clang++"' 96*c8dee2aaSAndroid Build Coastguard Workerbin/gn gen out/Cached --args='cc_wrapper="ccache"' 97*c8dee2aaSAndroid Build Coastguard Workerbin/gn gen out/RTTI --args='extra_cflags_cc=["-frtti"]' 98*c8dee2aaSAndroid Build Coastguard Worker``` 99*c8dee2aaSAndroid Build Coastguard Worker 100*c8dee2aaSAndroid Build Coastguard WorkerOnce you have generated your build files, run Ninja to compile and link all of Skia: 101*c8dee2aaSAndroid Build Coastguard Worker 102*c8dee2aaSAndroid Build Coastguard Worker``` 103*c8dee2aaSAndroid Build Coastguard Workerninja -C out/Static 104*c8dee2aaSAndroid Build Coastguard Worker``` 105*c8dee2aaSAndroid Build Coastguard Worker 106*c8dee2aaSAndroid Build Coastguard WorkerTo avoid building everything, include the target or targets after the ninja command. For example: 107*c8dee2aaSAndroid Build Coastguard Worker 108*c8dee2aaSAndroid Build Coastguard Worker``` 109*c8dee2aaSAndroid Build Coastguard Workerninja -C out/Debug skia 110*c8dee2aaSAndroid Build Coastguard Workerninja -C out/Debug viewer dm 111*c8dee2aaSAndroid Build Coastguard Worker``` 112*c8dee2aaSAndroid Build Coastguard Worker 113*c8dee2aaSAndroid Build Coastguard WorkerNot all targets are available for all sets of build arguments. For a list of all available targets 114*c8dee2aaSAndroid Build Coastguard Workerfor a given build directory, run: 115*c8dee2aaSAndroid Build Coastguard Worker 116*c8dee2aaSAndroid Build Coastguard Worker``` 117*c8dee2aaSAndroid Build Coastguard Workergn ls out/Debug 118*c8dee2aaSAndroid Build Coastguard Worker``` 119*c8dee2aaSAndroid Build Coastguard Worker 120*c8dee2aaSAndroid Build Coastguard WorkerIf some header files are missing, install the corresponding dependencies: 121*c8dee2aaSAndroid Build Coastguard Worker 122*c8dee2aaSAndroid Build Coastguard Worker``` 123*c8dee2aaSAndroid Build Coastguard Workertools/install_dependencies.sh 124*c8dee2aaSAndroid Build Coastguard Worker``` 125*c8dee2aaSAndroid Build Coastguard Worker 126*c8dee2aaSAndroid Build Coastguard WorkerTo pull new changes and rebuild: 127*c8dee2aaSAndroid Build Coastguard Worker 128*c8dee2aaSAndroid Build Coastguard Worker``` 129*c8dee2aaSAndroid Build Coastguard Workergit pull 130*c8dee2aaSAndroid Build Coastguard Workerpython3 tools/git-sync-deps 131*c8dee2aaSAndroid Build Coastguard Workerninja -C out/Static 132*c8dee2aaSAndroid Build Coastguard Worker``` 133*c8dee2aaSAndroid Build Coastguard Worker 134*c8dee2aaSAndroid Build Coastguard Worker## Android 135*c8dee2aaSAndroid Build Coastguard Worker 136*c8dee2aaSAndroid Build Coastguard WorkerTo build Skia for Android you need a recent version of 137*c8dee2aaSAndroid Build Coastguard Worker[Java](https://www.oracle.com/java/technologies/downloads/) and a recent 138*c8dee2aaSAndroid Build Coastguard Worker[Android NDK](https://developer.android.com/ndk/index.html). 139*c8dee2aaSAndroid Build Coastguard Worker 140*c8dee2aaSAndroid Build Coastguard WorkerIf you do not have an NDK and have access to CIPD, you can use one of these 141*c8dee2aaSAndroid Build Coastguard Workercommands to fetch the NDK our bots use: 142*c8dee2aaSAndroid Build Coastguard Worker 143*c8dee2aaSAndroid Build Coastguard Worker``` 144*c8dee2aaSAndroid Build Coastguard Worker./bin/fetch-sk 145*c8dee2aaSAndroid Build Coastguard Worker./bin/sk asset download android_ndk_linux /tmp/ndk # on Linux 146*c8dee2aaSAndroid Build Coastguard Worker./bin/sk asset download android_ndk_darwin /tmp/ndk # on Mac 147*c8dee2aaSAndroid Build Coastguard Worker./bin/sk.exe asset download android_ndk_windows C:/ndk # on Windows 148*c8dee2aaSAndroid Build Coastguard Worker``` 149*c8dee2aaSAndroid Build Coastguard Worker 150*c8dee2aaSAndroid Build Coastguard WorkerWhen generating your GN build files, pass the path to your `ndk` and your 151*c8dee2aaSAndroid Build Coastguard Workerdesired `target_cpu`: 152*c8dee2aaSAndroid Build Coastguard Worker 153*c8dee2aaSAndroid Build Coastguard Worker``` 154*c8dee2aaSAndroid Build Coastguard Workerbin/gn gen out/arm --args='ndk="/tmp/ndk" target_cpu="arm"' 155*c8dee2aaSAndroid Build Coastguard Workerbin/gn gen out/arm64 --args='ndk="/tmp/ndk" target_cpu="arm64"' 156*c8dee2aaSAndroid Build Coastguard Workerbin/gn gen out/x64 --args='ndk="/tmp/ndk" target_cpu="x64"' 157*c8dee2aaSAndroid Build Coastguard Workerbin/gn gen out/x86 --args='ndk="/tmp/ndk" target_cpu="x86"' 158*c8dee2aaSAndroid Build Coastguard Worker``` 159*c8dee2aaSAndroid Build Coastguard Worker 160*c8dee2aaSAndroid Build Coastguard WorkerOther arguments like `is_debug` and `is_component_build` continue to work. 161*c8dee2aaSAndroid Build Coastguard WorkerTweaking `ndk_api` gives you access to newer Android features like Vulkan. 162*c8dee2aaSAndroid Build Coastguard Worker 163*c8dee2aaSAndroid Build Coastguard WorkerTo test on an Android device, push the binary and `resources` over, and run it 164*c8dee2aaSAndroid Build Coastguard Workeras normal. You may find `bin/droid` convenient. 165*c8dee2aaSAndroid Build Coastguard Worker 166*c8dee2aaSAndroid Build Coastguard Worker``` 167*c8dee2aaSAndroid Build Coastguard Workerninja -C out/arm64 168*c8dee2aaSAndroid Build Coastguard Workeradb push out/arm64/dm /data/local/tmp 169*c8dee2aaSAndroid Build Coastguard Workeradb push resources /data/local/tmp 170*c8dee2aaSAndroid Build Coastguard Workeradb shell "cd /data/local/tmp; ./dm --src gm --config gl" 171*c8dee2aaSAndroid Build Coastguard Worker``` 172*c8dee2aaSAndroid Build Coastguard Worker 173*c8dee2aaSAndroid Build Coastguard Worker## ChromeOS 174*c8dee2aaSAndroid Build Coastguard Worker 175*c8dee2aaSAndroid Build Coastguard WorkerTo cross-compile Skia for arm ChromeOS devices the following is needed: 176*c8dee2aaSAndroid Build Coastguard Worker 177*c8dee2aaSAndroid Build Coastguard Worker- Clang 4 or newer 178*c8dee2aaSAndroid Build Coastguard Worker- An armhf sysroot 179*c8dee2aaSAndroid Build Coastguard Worker- The (E)GL lib files on the arm chromebook to link against. 180*c8dee2aaSAndroid Build Coastguard Worker 181*c8dee2aaSAndroid Build Coastguard WorkerTo compile Skia for an x86 ChromeOS device, one only needs Clang and the lib 182*c8dee2aaSAndroid Build Coastguard Workerfiles. 183*c8dee2aaSAndroid Build Coastguard Worker 184*c8dee2aaSAndroid Build Coastguard WorkerIf you have access to CIPD, you can fetch all of these as follows: 185*c8dee2aaSAndroid Build Coastguard Worker 186*c8dee2aaSAndroid Build Coastguard Worker``` 187*c8dee2aaSAndroid Build Coastguard Worker./bin/sk asset download clang_linux /opt/clang 188*c8dee2aaSAndroid Build Coastguard Worker./bin/sk asset download armhf_sysroot /opt/armhf_sysroot 189*c8dee2aaSAndroid Build Coastguard Worker./bin/sk asset download chromebook_arm_gles /opt/chromebook_arm_gles 190*c8dee2aaSAndroid Build Coastguard Worker./bin/sk asset download chromebook_x86_64_gles /opt/chromebook_x86_64_gles 191*c8dee2aaSAndroid Build Coastguard Worker``` 192*c8dee2aaSAndroid Build Coastguard Worker 193*c8dee2aaSAndroid Build Coastguard WorkerIf you don't have authorization to use those assets, then see the README.md 194*c8dee2aaSAndroid Build Coastguard Workerfiles for 195*c8dee2aaSAndroid Build Coastguard Worker[armhf_sysroot](https://skia.googlesource.com/skia/+/main/infra/bots/assets/armhf_sysroot/README.md), 196*c8dee2aaSAndroid Build Coastguard Worker[chromebook_arm_gles](https://skia.googlesource.com/skia/+/main/infra/bots/assets/chromebook_arm_gles/README.md), 197*c8dee2aaSAndroid Build Coastguard Workerand 198*c8dee2aaSAndroid Build Coastguard Worker[chromebook_x86_64_gles](https://skia.googlesource.com/skia/+/main/infra/bots/assets/chromebook_x86_64_gles/README.md) 199*c8dee2aaSAndroid Build Coastguard Workerfor instructions on creating those assets. 200*c8dee2aaSAndroid Build Coastguard Worker 201*c8dee2aaSAndroid Build Coastguard WorkerOnce those files are in place, generate the GN args that resemble the following: 202*c8dee2aaSAndroid Build Coastguard Worker 203*c8dee2aaSAndroid Build Coastguard Worker``` 204*c8dee2aaSAndroid Build Coastguard Worker#ARM 205*c8dee2aaSAndroid Build Coastguard Workercc= "/opt/clang/bin/clang" 206*c8dee2aaSAndroid Build Coastguard Workercxx = "/opt/clang/bin/clang++" 207*c8dee2aaSAndroid Build Coastguard Worker 208*c8dee2aaSAndroid Build Coastguard Workerextra_asmflags = [ 209*c8dee2aaSAndroid Build Coastguard Worker "--target=armv7a-linux-gnueabihf", 210*c8dee2aaSAndroid Build Coastguard Worker "--sysroot=/opt/armhf_sysroot/", 211*c8dee2aaSAndroid Build Coastguard Worker "-march=armv7-a", 212*c8dee2aaSAndroid Build Coastguard Worker "-mfpu=neon", 213*c8dee2aaSAndroid Build Coastguard Worker "-mthumb", 214*c8dee2aaSAndroid Build Coastguard Worker] 215*c8dee2aaSAndroid Build Coastguard Workerextra_cflags=[ 216*c8dee2aaSAndroid Build Coastguard Worker "--target=armv7a-linux-gnueabihf", 217*c8dee2aaSAndroid Build Coastguard Worker "--sysroot=/opt/armhf_sysroot", 218*c8dee2aaSAndroid Build Coastguard Worker "-I/opt/chromebook_arm_gles/include", 219*c8dee2aaSAndroid Build Coastguard Worker "-I/opt/armhf_sysroot/include/", 220*c8dee2aaSAndroid Build Coastguard Worker "-I/opt/armhf_sysroot/include/c++/4.8.4/", 221*c8dee2aaSAndroid Build Coastguard Worker "-I/opt/armhf_sysroot/include/c++/4.8.4/arm-linux-gnueabihf/", 222*c8dee2aaSAndroid Build Coastguard Worker "-DMESA_EGL_NO_X11_HEADERS", 223*c8dee2aaSAndroid Build Coastguard Worker "-funwind-tables", 224*c8dee2aaSAndroid Build Coastguard Worker] 225*c8dee2aaSAndroid Build Coastguard Workerextra_ldflags=[ 226*c8dee2aaSAndroid Build Coastguard Worker "--sysroot=/opt/armhf_sysroot", 227*c8dee2aaSAndroid Build Coastguard Worker "-B/opt/armhf_sysroot/bin", 228*c8dee2aaSAndroid Build Coastguard Worker "-B/opt/armhf_sysroot/gcc-cross", 229*c8dee2aaSAndroid Build Coastguard Worker "-L/opt/armhf_sysroot/gcc-cross", 230*c8dee2aaSAndroid Build Coastguard Worker "-L/opt/armhf_sysroot/lib", 231*c8dee2aaSAndroid Build Coastguard Worker "-L/opt/chromebook_arm_gles/lib", 232*c8dee2aaSAndroid Build Coastguard Worker "--target=armv7a-linux-gnueabihf", 233*c8dee2aaSAndroid Build Coastguard Worker] 234*c8dee2aaSAndroid Build Coastguard Workertarget_cpu="arm" 235*c8dee2aaSAndroid Build Coastguard Workerskia_use_fontconfig = false 236*c8dee2aaSAndroid Build Coastguard Workerskia_use_system_freetype2 = false 237*c8dee2aaSAndroid Build Coastguard Workerskia_use_egl = true 238*c8dee2aaSAndroid Build Coastguard Worker 239*c8dee2aaSAndroid Build Coastguard Worker 240*c8dee2aaSAndroid Build Coastguard Worker# x86_64 241*c8dee2aaSAndroid Build Coastguard Workercc= "/opt/clang/bin/clang" 242*c8dee2aaSAndroid Build Coastguard Workercxx = "/opt/clang/bin/clang++" 243*c8dee2aaSAndroid Build Coastguard Workerextra_cflags=[ 244*c8dee2aaSAndroid Build Coastguard Worker "-I/opt/clang/include/c++/v1/", 245*c8dee2aaSAndroid Build Coastguard Worker "-I/opt/chromebook_x86_64_gles/include", 246*c8dee2aaSAndroid Build Coastguard Worker "-DMESA_EGL_NO_X11_HEADERS", 247*c8dee2aaSAndroid Build Coastguard Worker "-DEGL_NO_IMAGE_EXTERNAL", 248*c8dee2aaSAndroid Build Coastguard Worker] 249*c8dee2aaSAndroid Build Coastguard Workerextra_ldflags=[ 250*c8dee2aaSAndroid Build Coastguard Worker "-stdlib=libc++", 251*c8dee2aaSAndroid Build Coastguard Worker "-fuse-ld=lld", 252*c8dee2aaSAndroid Build Coastguard Worker "-L/opt/chromebook_x86_64_gles/lib", 253*c8dee2aaSAndroid Build Coastguard Worker] 254*c8dee2aaSAndroid Build Coastguard Workertarget_cpu="x64" 255*c8dee2aaSAndroid Build Coastguard Workerskia_use_fontconfig = false 256*c8dee2aaSAndroid Build Coastguard Workerskia_use_system_freetype2 = false 257*c8dee2aaSAndroid Build Coastguard Workerskia_use_egl = true 258*c8dee2aaSAndroid Build Coastguard Worker``` 259*c8dee2aaSAndroid Build Coastguard Worker 260*c8dee2aaSAndroid Build Coastguard WorkerCompile dm (or another executable of your choice) with ninja, as per usual. 261*c8dee2aaSAndroid Build Coastguard Worker 262*c8dee2aaSAndroid Build Coastguard WorkerPush the binary to a chromebook via ssh and 263*c8dee2aaSAndroid Build Coastguard Worker[run dm as normal](/docs/dev/testing/tests) using the gles GPU config. 264*c8dee2aaSAndroid Build Coastguard Worker 265*c8dee2aaSAndroid Build Coastguard WorkerMost chromebooks by default have their home directory partition marked as 266*c8dee2aaSAndroid Build Coastguard Workernoexec. To avoid "permission denied" errors, remember to run something like: 267*c8dee2aaSAndroid Build Coastguard Worker 268*c8dee2aaSAndroid Build Coastguard Worker``` 269*c8dee2aaSAndroid Build Coastguard Workersudo mount -i -o remount,exec /home/chronos 270*c8dee2aaSAndroid Build Coastguard Worker``` 271*c8dee2aaSAndroid Build Coastguard Worker 272*c8dee2aaSAndroid Build Coastguard Worker## Mac 273*c8dee2aaSAndroid Build Coastguard Worker 274*c8dee2aaSAndroid Build Coastguard WorkerMac users may want to pass `--ide=xcode` to `bin/gn gen` to generate an Xcode 275*c8dee2aaSAndroid Build Coastguard Workerproject. 276*c8dee2aaSAndroid Build Coastguard Worker 277*c8dee2aaSAndroid Build Coastguard WorkerMac GN builds assume an Intel CPU by default. If you are building for Apple 278*c8dee2aaSAndroid Build Coastguard WorkerSilicon (M1 and newer) instead, add a gn arg to set `target_cpu="arm64"`: 279*c8dee2aaSAndroid Build Coastguard Worker 280*c8dee2aaSAndroid Build Coastguard Worker``` 281*c8dee2aaSAndroid Build Coastguard Workerbin/gn gen out/AppleSilicon --args='target_cpu="arm64"' 282*c8dee2aaSAndroid Build Coastguard Worker``` 283*c8dee2aaSAndroid Build Coastguard Worker 284*c8dee2aaSAndroid Build Coastguard WorkerGooglers should see [go/skia-corp-xcode](http://go/skia-corp-xcode) for 285*c8dee2aaSAndroid Build Coastguard Workerinstructions on setting up Xcode on a corp machine. 286*c8dee2aaSAndroid Build Coastguard Worker 287*c8dee2aaSAndroid Build Coastguard Worker### Python 288*c8dee2aaSAndroid Build Coastguard Worker 289*c8dee2aaSAndroid Build Coastguard WorkerThe version of Python supplied by Apple is a few versions out of date, 290*c8dee2aaSAndroid Build Coastguard Workerand it is known to interact poorly with our build system. We recommend 291*c8dee2aaSAndroid Build Coastguard Workerinstalling the latest official version of Python from 292*c8dee2aaSAndroid Build Coastguard Workerhttps://www.python.org/downloads/. Then run 293*c8dee2aaSAndroid Build Coastguard Worker"Applications/Python 3.11/Install Certificates.command". 294*c8dee2aaSAndroid Build Coastguard Worker 295*c8dee2aaSAndroid Build Coastguard Worker## iOS 296*c8dee2aaSAndroid Build Coastguard Worker 297*c8dee2aaSAndroid Build Coastguard WorkerRun GN to generate your build files. Set `target_os="ios"` to build for iOS. 298*c8dee2aaSAndroid Build Coastguard WorkerThis defaults to `target_cpu="arm64"`. To use the iOS simulator, set 299*c8dee2aaSAndroid Build Coastguard Worker`ios_use_simulator=true` and set `target_cpu` to your Mac's architecture. 300*c8dee2aaSAndroid Build Coastguard WorkerOn an Intel Mac, setting `target_cpu="x64"` alone will also target the iOS 301*c8dee2aaSAndroid Build Coastguard Workersimulator. 302*c8dee2aaSAndroid Build Coastguard Worker 303*c8dee2aaSAndroid Build Coastguard Worker``` 304*c8dee2aaSAndroid Build Coastguard Workerbin/gn gen out/ios64 --args='target_os="ios"' 305*c8dee2aaSAndroid Build Coastguard Workerbin/gn gen out/ios32 --args='target_os="ios" target_cpu="arm"' 306*c8dee2aaSAndroid Build Coastguard Workerbin/gn gen out/iossim-apple --args='target_os="ios" target_cpu="arm64" ios_use_simulator=true' 307*c8dee2aaSAndroid Build Coastguard Workerbin/gn gen out/iossim-intel --args='target_os="ios" target_cpu="x64"' 308*c8dee2aaSAndroid Build Coastguard Worker``` 309*c8dee2aaSAndroid Build Coastguard Worker 310*c8dee2aaSAndroid Build Coastguard WorkerBy default this will also package (and for non-simulator devices, sign) iOS test binaries. 311*c8dee2aaSAndroid Build Coastguard WorkerIf you wish to skip signing (for testing compilation alone, for example), you can disable it by 312*c8dee2aaSAndroid Build Coastguard Workersetting `skia_ios_use_signing` to `false`. 313*c8dee2aaSAndroid Build Coastguard Worker 314*c8dee2aaSAndroid Build Coastguard WorkerWhen signing, the build defaults to a Google signing identity and provisioning profile. 315*c8dee2aaSAndroid Build Coastguard WorkerTo use a different one 316*c8dee2aaSAndroid Build Coastguard Workerset the GN args `skia_ios_identity` to match your code signing identity and 317*c8dee2aaSAndroid Build Coastguard Worker`skia_ios_profile` to the name of your provisioning profile, e.g. 318*c8dee2aaSAndroid Build Coastguard Worker 319*c8dee2aaSAndroid Build Coastguard Worker``` 320*c8dee2aaSAndroid Build Coastguard Workerskia_ios_identity=".*Jane Doe.*" 321*c8dee2aaSAndroid Build Coastguard Workerskia_ios_profile="iPad Profile"` 322*c8dee2aaSAndroid Build Coastguard Worker``` 323*c8dee2aaSAndroid Build Coastguard Worker 324*c8dee2aaSAndroid Build Coastguard WorkerA list of identities can be found by typing `security find-identity` on the 325*c8dee2aaSAndroid Build Coastguard Workercommand line. The name of the provisioning profile should be available on the 326*c8dee2aaSAndroid Build Coastguard WorkerApple Developer site. Alternatively, you can examine the installed provisioning profile files in the Finder 327*c8dee2aaSAndroid Build Coastguard Workerby going to `~/Library/MobileDevice/Provisioning Profiles`, selecting a `.mobileprovision` file, 328*c8dee2aaSAndroid Build Coastguard Workerand hitting space. The value of `skia_ios_profile` can either be the string 329*c8dee2aaSAndroid Build Coastguard Workergiven at the top of that file or on the Developer site, or the absolute path 330*c8dee2aaSAndroid Build Coastguard Workerto the file. 331*c8dee2aaSAndroid Build Coastguard Worker 332*c8dee2aaSAndroid Build Coastguard WorkerIf you find yourself missing a Google signing identity or provisioning profile, 333*c8dee2aaSAndroid Build Coastguard Workeryou'll want to have a read through go/appledev and go/ios-signing. 334*c8dee2aaSAndroid Build Coastguard Worker 335*c8dee2aaSAndroid Build Coastguard WorkerFor signed packages `ios-deploy` makes installing and running them on a device 336*c8dee2aaSAndroid Build Coastguard Workereasy: 337*c8dee2aaSAndroid Build Coastguard Worker 338*c8dee2aaSAndroid Build Coastguard Worker``` 339*c8dee2aaSAndroid Build Coastguard Workerios-deploy -b out/Debug/dm.app -d --args "--match foo" 340*c8dee2aaSAndroid Build Coastguard Worker``` 341*c8dee2aaSAndroid Build Coastguard Worker 342*c8dee2aaSAndroid Build Coastguard WorkerIf you wish to deploy through Xcode you can generate a project by passing `--ide=xcode` to 343*c8dee2aaSAndroid Build Coastguard Worker`bin/gn gen`. If you are using Xcode version 10 or later, you may need to go to 344*c8dee2aaSAndroid Build Coastguard Worker`Project Settings...` and verify that `Build System:` is set to 345*c8dee2aaSAndroid Build Coastguard Worker`Legacy Build System`. 346*c8dee2aaSAndroid Build Coastguard Worker 347*c8dee2aaSAndroid Build Coastguard WorkerDeploying to a device with an OS older than the current SDK can be done by 348*c8dee2aaSAndroid Build Coastguard Workersetting the `ios_min_target` arg: 349*c8dee2aaSAndroid Build Coastguard Worker 350*c8dee2aaSAndroid Build Coastguard Worker``` 351*c8dee2aaSAndroid Build Coastguard Workerios_min_target = "<major>.<minor>" 352*c8dee2aaSAndroid Build Coastguard Worker``` 353*c8dee2aaSAndroid Build Coastguard Worker 354*c8dee2aaSAndroid Build Coastguard Workerwhere `<major>.<minor>` is the iOS version on the device, e.g., 12.0 or 11.4. 355*c8dee2aaSAndroid Build Coastguard Worker 356*c8dee2aaSAndroid Build Coastguard Worker## Windows 357*c8dee2aaSAndroid Build Coastguard Worker 358*c8dee2aaSAndroid Build Coastguard WorkerSkia can build on Windows with Visual Studio 2017 or 2019. If GN is unable to 359*c8dee2aaSAndroid Build Coastguard Workerlocate either of those, it will print an error message. In that case, you can 360*c8dee2aaSAndroid Build Coastguard Workerpass your `VC` path to GN via `win_vc`. 361*c8dee2aaSAndroid Build Coastguard Worker 362*c8dee2aaSAndroid Build Coastguard WorkerSkia can be compiled with the free 363*c8dee2aaSAndroid Build Coastguard Worker[Build Tools for Visual Studio 2017 or 2019](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2019). 364*c8dee2aaSAndroid Build Coastguard Worker 365*c8dee2aaSAndroid Build Coastguard WorkerThe bots use a packaged 2019 toolchain, which Googlers can download like this: 366*c8dee2aaSAndroid Build Coastguard Worker 367*c8dee2aaSAndroid Build Coastguard Worker``` 368*c8dee2aaSAndroid Build Coastguard Worker./bin/sk.exe asset download win_toolchain C:/toolchain 369*c8dee2aaSAndroid Build Coastguard Worker``` 370*c8dee2aaSAndroid Build Coastguard Worker 371*c8dee2aaSAndroid Build Coastguard WorkerYou can then pass the VC and SDK paths to GN by setting your GN args: 372*c8dee2aaSAndroid Build Coastguard Worker 373*c8dee2aaSAndroid Build Coastguard Worker``` 374*c8dee2aaSAndroid Build Coastguard Workerwin_vc = "C:\toolchain\VC" 375*c8dee2aaSAndroid Build Coastguard Workerwin_sdk = "C:\toolchain\win_sdk" 376*c8dee2aaSAndroid Build Coastguard Worker``` 377*c8dee2aaSAndroid Build Coastguard Worker 378*c8dee2aaSAndroid Build Coastguard WorkerThis toolchain is the only way we support 32-bit builds, by also setting 379*c8dee2aaSAndroid Build Coastguard Worker`target_cpu="x86"`. 380*c8dee2aaSAndroid Build Coastguard Worker 381*c8dee2aaSAndroid Build Coastguard WorkerThe Skia build assumes that the PATHEXT environment variable contains ".EXE". 382*c8dee2aaSAndroid Build Coastguard Worker 383*c8dee2aaSAndroid Build Coastguard Worker### **Highly Recommended**: Build with clang-cl 384*c8dee2aaSAndroid Build Coastguard Worker 385*c8dee2aaSAndroid Build Coastguard WorkerSkia uses generated code that is only optimized when Skia is built with clang. 386*c8dee2aaSAndroid Build Coastguard WorkerOther compilers get generic unoptimized code. 387*c8dee2aaSAndroid Build Coastguard Worker 388*c8dee2aaSAndroid Build Coastguard WorkerSetting the `cc` and `cxx` gn args is _not_ sufficient to build with clang-cl. 389*c8dee2aaSAndroid Build Coastguard WorkerThese variables are ignored on Windows. Instead set the variable `clang_win` to 390*c8dee2aaSAndroid Build Coastguard Workeryour LLVM installation directory. If you installed the prebuilt LLVM downloaded 391*c8dee2aaSAndroid Build Coastguard Workerfrom [here](https://releases.llvm.org/download.html 'LLVM Download') in the 392*c8dee2aaSAndroid Build Coastguard Workerdefault location, that would be: 393*c8dee2aaSAndroid Build Coastguard Worker 394*c8dee2aaSAndroid Build Coastguard Worker``` 395*c8dee2aaSAndroid Build Coastguard Workerclang_win = "C:\Program Files\LLVM" 396*c8dee2aaSAndroid Build Coastguard Worker``` 397*c8dee2aaSAndroid Build Coastguard Worker 398*c8dee2aaSAndroid Build Coastguard WorkerFollow the standard Windows path specification and not MinGW convention (e.g. 399*c8dee2aaSAndroid Build Coastguard Worker`C:\Program Files\LLVM` not ~~`/c/Program Files/LLVM`~~). 400*c8dee2aaSAndroid Build Coastguard Worker 401*c8dee2aaSAndroid Build Coastguard WorkerIf you will be compiling the rest of your program with a compiler other than 402*c8dee2aaSAndroid Build Coastguard WorkerClang, add this GN argument as well: 403*c8dee2aaSAndroid Build Coastguard Worker 404*c8dee2aaSAndroid Build Coastguard Worker``` 405*c8dee2aaSAndroid Build Coastguard Workeris_trivial_abi = false 406*c8dee2aaSAndroid Build Coastguard Worker``` 407*c8dee2aaSAndroid Build Coastguard Worker 408*c8dee2aaSAndroid Build Coastguard Worker### Visual Studio Solutions 409*c8dee2aaSAndroid Build Coastguard Worker 410*c8dee2aaSAndroid Build Coastguard WorkerIf you use Visual Studio, you may want to pass `--ide=vs` to `bin/gn gen` to 411*c8dee2aaSAndroid Build Coastguard Workergenerate `all.sln`. That solution will exist within the GN directory for the 412*c8dee2aaSAndroid Build Coastguard Workerspecific configuration, and will only build/run that configuration. 413*c8dee2aaSAndroid Build Coastguard Worker 414*c8dee2aaSAndroid Build Coastguard WorkerIf you want a Visual Studio Solution that supports multiple GN configurations, 415*c8dee2aaSAndroid Build Coastguard Workerthere is a helper script. It requires that all of your GN directories be inside 416*c8dee2aaSAndroid Build Coastguard Workerthe `out` directory. First, create all of your GN configurations as usual. Pass 417*c8dee2aaSAndroid Build Coastguard Worker`--ide=vs` when running `bin/gn gen` for each one. Then: 418*c8dee2aaSAndroid Build Coastguard Worker 419*c8dee2aaSAndroid Build Coastguard Worker``` 420*c8dee2aaSAndroid Build Coastguard Workerpython3 gn/gn_meta_sln.py 421*c8dee2aaSAndroid Build Coastguard Worker``` 422*c8dee2aaSAndroid Build Coastguard Worker 423*c8dee2aaSAndroid Build Coastguard WorkerThis creates a new dedicated output directory and solution file 424*c8dee2aaSAndroid Build Coastguard Worker`out/sln/skia.sln`. It has one solution configuration for each GN configuration, 425*c8dee2aaSAndroid Build Coastguard Workerand supports building and running any of them. It also adjusts syntax 426*c8dee2aaSAndroid Build Coastguard Workerhighlighting of inactive code blocks based on preprocessor definitions from the 427*c8dee2aaSAndroid Build Coastguard Workerselected solution configuration. 428*c8dee2aaSAndroid Build Coastguard Worker 429*c8dee2aaSAndroid Build Coastguard Worker## Windows ARM64 430*c8dee2aaSAndroid Build Coastguard Worker 431*c8dee2aaSAndroid Build Coastguard WorkerThere is early, experimental support for 432*c8dee2aaSAndroid Build Coastguard Worker[Windows 10 on ARM](https://docs.microsoft.com/en-us/windows/arm/). This 433*c8dee2aaSAndroid Build Coastguard Workercurrently requires (a recent version of) MSVC, and the 434*c8dee2aaSAndroid Build Coastguard Worker`Visual C++ compilers and libraries for ARM64` individual component in the 435*c8dee2aaSAndroid Build Coastguard WorkerVisual Studio Installer. For Googlers, the win_toolchain asset includes the 436*c8dee2aaSAndroid Build Coastguard WorkerARM64 compiler. 437*c8dee2aaSAndroid Build Coastguard Worker 438*c8dee2aaSAndroid Build Coastguard WorkerTo use that toolchain, set the `target_cpu` GN argument to `"arm64"`. Note that 439*c8dee2aaSAndroid Build Coastguard WorkerOpenGL is not supported by Windows 10 on ARM, so Skia's GL backends are stubbed 440*c8dee2aaSAndroid Build Coastguard Workerout, and will not work. ANGLE is supported: 441*c8dee2aaSAndroid Build Coastguard Worker 442*c8dee2aaSAndroid Build Coastguard Worker``` 443*c8dee2aaSAndroid Build Coastguard Workerbin/gn gen out/win-arm64 --args='target_cpu="arm64" skia_use_angle=true' 444*c8dee2aaSAndroid Build Coastguard Worker``` 445*c8dee2aaSAndroid Build Coastguard Worker 446*c8dee2aaSAndroid Build Coastguard WorkerThis will produce a build of Skia that can use the software or ANGLE backends, 447*c8dee2aaSAndroid Build Coastguard Workerin DM. Viewer only works when launched with `--backend angle`, because the 448*c8dee2aaSAndroid Build Coastguard Workersoftware backend tries to use OpenGL to display the window contents. 449*c8dee2aaSAndroid Build Coastguard Worker 450*c8dee2aaSAndroid Build Coastguard Worker## CMake 451*c8dee2aaSAndroid Build Coastguard Worker 452*c8dee2aaSAndroid Build Coastguard WorkerWe have added a GN-to-CMake translator mainly for use with IDEs that like CMake 453*c8dee2aaSAndroid Build Coastguard Workerproject descriptions. This is not meant for any purpose beyond development. 454*c8dee2aaSAndroid Build Coastguard Worker 455*c8dee2aaSAndroid Build Coastguard Worker``` 456*c8dee2aaSAndroid Build Coastguard Workerbin/gn gen out/config --ide=json --json-ide-script=../../gn/gn_to_cmake.py 457*c8dee2aaSAndroid Build Coastguard Worker``` 458