• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1How to build Skia
2=================
3
4Make sure you have first followed the [instructions to download
5Skia](./download).
6
7Skia uses [GN](https://chromium.googlesource.com/chromium/src/tools/gn/) to
8configure its builds.
9
10`is_official_build` and Third-party Dependencies
11------------------------------------------------
12
13Most users of Skia should set `is_official_build=true`, and most developers
14should leave it to its `false` default.
15
16This mode configures Skia in a way that's suitable to ship: an optimized build
17with no debug symbols, dynamically linked against its third-party dependencies
18using the ordinary library search path.
19
20In contrast, the developer-oriented default is an unoptimized build with full
21debug symbols and all third-party dependencies built from source and embedded
22into libskia.  This is how we do all our manual and automated testing.
23
24Skia offers several features that make use of third-party libraries, like
25libpng, libwebp, or libjpeg-turbo to decode images, or ICU and sftnly to subset
26fonts.  All these third-party dependencies are optional and can be controlled
27by a GN argument that looks something like `skia_use_foo` for appropriate
28`foo`.
29
30If `skia_use_foo` is enabled, enabling `skia_use_system_foo` will build and
31link Skia against the headers and libaries found on the system paths.
32`is_official_build=true` enables all `skia_use_system_foo` by default.  You can
33use `extra_cflags` and `extra_ldflags` to add include or library paths if
34needed.
35
36Quickstart
37----------
38
39Run GN to generate your build files.
40
41    bin/gn gen out/Static --args='is_official_build=true'
42    bin/gn gen out/Shared --args='is_official_build=true is_component_build=true'
43
44If you find you don't have `bin/gn`, make sure you've run
45
46    python tools/git-sync-deps
47
48GN allows fine-grained settings for developers and special situations.
49
50    bin/gn gen out/Debug
51    bin/gn gen out/Release  --args='is_debug=false'
52    bin/gn gen out/Clang    --args='cc="clang" cxx="clang++"'
53    bin/gn gen out/Cached   --args='cc_wrapper="ccache"'
54    bin/gn gen out/RTTI     --args='extra_cflags_cc=["-frtti"]'
55
56To see all the arguments available, you can run
57
58    bin/gn args out/Debug --list
59
60Having generated your build files, run Ninja to compile and link Skia.
61
62    ninja -C out/Static
63    ninja -C out/Shared
64    ninja -C out/Debug
65    ninja -C out/Release
66    ninja -C out/Clang
67    ninja -C out/Cached
68    ninja -C out/RTTI
69
70Android
71-------
72
73To build Skia for Android you need an [Android
74NDK](https://developer.android.com/ndk/index.html).
75
76If you do not have an NDK and have access to CIPD, you
77can use one of these commands to fetch the NDK our bots use:
78
79    python infra/bots/assets/android_ndk_linux/download.py  -t /tmp/ndk
80    python infra/bots/assets/android_ndk_darwin/download.py -t /tmp/ndk
81    python infra/bots/assets/android_ndk_windows/download.py -t C:/ndk
82
83When generating your GN build files, pass the path to your `ndk` and your
84desired `target_cpu`:
85
86    bin/gn gen out/arm   --args='ndk="/tmp/ndk" target_cpu="arm"'
87    bin/gn gen out/arm64 --args='ndk="/tmp/ndk" target_cpu="arm64"'
88    bin/gn gen out/x64   --args='ndk="/tmp/ndk" target_cpu="x64"'
89    bin/gn gen out/x86   --args='ndk="/tmp/ndk" target_cpu="x86"'
90
91Other arguments like `is_debug` and `is_component_build` continue to work.
92Tweaking `ndk_api` gives you access to newer Android features like Vulkan.
93
94To test on an Android device, push the binary and `resources` over,
95and run it as normal.  You may find `bin/droid` convenient.
96
97    ninja -C out/arm64
98    adb push out/arm64/dm /data/local/tmp
99    adb push resources /data/local/tmp
100    adb shell "cd /data/local/tmp; ./dm --src gm --config gl"
101
102
103ChromeOS
104--------------
105To cross-compile Skia for arm ChromeOS devices the following is needed:
106
107  - Clang 4 or newer
108  - An armhf sysroot
109  - The (E)GL lib files on the arm chromebook to link against.
110
111To compile Skia for an x86 ChromeOS device, one only needs Clang and the lib files.
112
113If you have access to CIPD, you can fetch all of these as follows:
114
115    python infra/bots/assets/clang_linux/download.py  -t /opt/clang
116    python infra/bots/assets/armhf_sysroot/download.py -t /opt/armhf_sysroot
117    python infra/bots/assets/chromebook_arm_gles/download.py -t /opt/chromebook_arm_gles
118    python infra/bots/assets/chromebook_x86_64_gles/download.py -t /opt/chromebook_x86_64_gles
119
120If you don't have authorization to use those assets, then see the README.md files for
121[armhf_sysroot](https://skia.googlesource.com/skia/+/master/infra/bots/assets/armhf_sysroot/README.md),
122[chromebook_arm_gles](https://skia.googlesource.com/skia/+/master/infra/bots/assets/chromebook_arm_gles/README.md), and
123[chromebook_x86_64_gles](https://skia.googlesource.com/skia/+/master/infra/bots/assets/chromebook_x86_64_gles/README.md)
124for instructions on creating those assets.
125
126Once those files are in place, generate the GN args that resemble the following:
127
128    #ARM
129    cc= "/opt/clang/bin/clang"
130    cxx = "/opt/clang/bin/clang++"
131
132    extra_asmflags = [
133        "--target=armv7a-linux-gnueabihf",
134        "--sysroot=/opt/armhf_sysroot/",
135        "-march=armv7-a",
136        "-mfpu=neon",
137        "-mthumb",
138    ]
139    extra_cflags=[
140        "--target=armv7a-linux-gnueabihf",
141        "--sysroot=/opt/armhf_sysroot",
142        "-I/opt/chromebook_arm_gles/include",
143        "-I/opt/armhf_sysroot/include/",
144        "-I/opt/armhf_sysroot/include/c++/4.8.4/",
145        "-I/opt/armhf_sysroot/include/c++/4.8.4/arm-linux-gnueabihf/",
146        "-DMESA_EGL_NO_X11_HEADERS",
147        "-funwind-tables",
148    ]
149    extra_ldflags=[
150        "--sysroot=/opt/armhf_sysroot",
151        "-B/opt/armhf_sysroot/bin",
152        "-B/opt/armhf_sysroot/gcc-cross",
153        "-L/opt/armhf_sysroot/gcc-cross",
154        "-L/opt/armhf_sysroot/lib",
155        "-L/opt/chromebook_arm_gles/lib",
156        "--target=armv7a-linux-gnueabihf",
157    ]
158    target_cpu="arm"
159    skia_use_fontconfig = false
160    skia_use_system_freetype2 = false
161    skia_use_egl = true
162
163
164    # x86_64
165    cc= "/opt/clang/bin/clang"
166    cxx = "/opt/clang/bin/clang++"
167    extra_cflags=[
168        "-I/opt/clang/include/c++/v1/",
169        "-I/opt/chromebook_x86_64_gles/include",
170        "-DMESA_EGL_NO_X11_HEADERS",
171        "-DEGL_NO_IMAGE_EXTERNAL",
172    ]
173    extra_ldflags=[
174        "-stdlib=libc++",
175        "-fuse-ld=lld",
176        "-L/opt/chromebook_x86_64_gles/lib",
177    ]
178    target_cpu="x64"
179    skia_use_fontconfig = false
180    skia_use_system_freetype2 = false
181    skia_use_egl = true
182
183Compile dm (or another executable of your choice) with ninja, as per usual.
184
185Push the binary to a chromebook via ssh and [run dm as normal](https://skia.org/dev/testing/tests)
186using the gles GPU config.
187
188Most chromebooks by default have their home directory partition marked as noexec.
189To avoid "permission denied" errors, remember to run something like:
190
191    sudo mount -i -o remount,exec /home/chronos
192
193Mac
194---
195
196Mac users may want to pass `--ide=xcode` to `bin/gn gen` to generate an Xcode project.
197
198iOS
199---
200
201Run GN to generate your build files.  Set `target_os="ios"` to build for iOS.
202This defaults to `target_cpu="arm64"`.  Choosing `x64` targets the iOS simulator.
203
204    bin/gn gen out/ios64  --args='target_os="ios"'
205    bin/gn gen out/ios32  --args='target_os="ios" target_cpu="arm"'
206    bin/gn gen out/iossim --args='target_os="ios" target_cpu="x64"'
207
208This will also package (and for devices, sign) iOS test binaries. This defaults to a
209Google signing identity and provisioning profile. To use a different one set `skia_ios_identity`
210to match your code signing identity and `skia_ios_profile` to the name of your provisioning
211profile, e.g. `skia_ios_identity=".*Jane Doe.*" skia_ios_profile="iPad Profile"`. A list of
212identities can be found by typing `security find-identity` on the command line. The name of the
213provisioning profile should be available on the Apple Developer site.
214
215For signed packages `ios-deploy` makes installing and running them on a device easy:
216
217    ios-deploy -b out/Debug/dm.app -d --args "--match foo"
218
219Alternatively you can generate an Xcode project by passing `--ide=xcode` to `bin/gn gen`.
220
221If you find yourself missing a Google signing identity or provisioning profile,
222you'll want to have a read through go/appledev.
223
224Deploying to a device with an OS older than the current SDK doesn't currently work through Xcode,
225but can be done on the command line by setting the environment variable IPHONEOS_DEPLOYMENT_TARGET
226to the desired OS version.
227
228Windows
229-------
230
231Skia can build on Windows with Visual Studio 2017 or Visual Studio 2015 Update 3.
232If GN is unable to locate either of those, it will print an error message. In that
233case, you can pass your `VC` path to GN via `win_vc`.
234
235The bots use a packaged 2017 toolchain, which Googlers can download like this:
236
237    python infra/bots/assets/win_toolchain/download.py -t C:/toolchain
238
239You can then pass the VC and SDK paths to GN by setting your GN args:
240
241    win_vc = "C:\toolchain\depot_tools\win_toolchain\vs_files\a9e1098bba66d2acccc377d5ee81265910f29272\VC"
242    win_sdk = "C:\toolchain\depot_tools\win_toolchain\vs_files\a9e1098bba66d2acccc377d5ee81265910f29272\win_sdk"
243
244This toolchain is the only way we support 32-bit builds, by also setting `target_cpu="x86"`.
245There is also a corresponding 2015 toolchain, downloaded via `infra/bots/assets/win_toolchain_2015`.
246
247### Visual Studio Solutions
248
249If you use Visual Studio, you may want to pass `--ide=vs` to `bin/gn gen` to
250generate `all.sln`.  That solution will exist within the GN directory for the
251specific configuration, and will only build/run that configuration.
252
253If you want a Visual Studio Solution that supports multiple GN configurations,
254there is a helper script. It requires that all of your GN directories be inside
255the `out` directory. First, create all of your GN configurations as usual.
256Pass `--ide=vs` when running `bin/gn gen` for each one. Then:
257
258    python gn/gn_meta_sln.py
259
260This creates a new dedicated output directory and solution file
261`out/sln/skia.sln`. It has one solution configuration for each GN configuration,
262and supports building and running any of them. It also adjusts syntax highlighting
263of inactive code blocks based on preprocessor definitions from the selected
264solution configuration.
265
266CMake
267-----
268
269We have added a GN-to-CMake translator mainly for use with IDEs that like CMake
270project descriptions.  This is not meant for any purpose beyond development.
271
272    bin/gn gen out/config --ide=json --json-ide-script=../../gn/gn_to_cmake.py
273