1 stable release

121.0.0 Jan 10, 2024

#187 in Graphics APIs

MIT/Apache

170KB
4.5K SLoC

ckia_sys

This project will take skia and generate rust bindings for it. It also takes care of building skia.

fast compile times is the highest priority. and we do this by:

  1. providing prebuilt static and dynamic libraries, which can be downloaded by build script for common configurations
  2. maintain manual C bindings and use pre-generated bindings, instead of generating bindings at build time. avoids bindgen dependency and 6 seconds of build time.

Generate Bindings

  1. install bindgen with cargo install bindgen
  2. run
# merge extern blocks creates a smaller and denser bindings.rs
# no-layout-tests avoids a lot of tests and makes bindings.rs cleaner. But for sanity, we might generate layout tests first, run cargo test, and then generate bindings without tests to publish. 
# -Iskia is necessary to let clang know where to search for include paths.
bindgen --merge-extern-blocks --default-enum-style rust --no-layout-tests -o bindings.rs skia/ckia/src/sk_all.c -- -Iskia/
  1. Finally, fix the functions which need a different ABI on windows.
    1. gr_vk_get_proc. change its ABI to extern "system", so that it can use __stdcall ABI on windows platforms.

Build

Skia exposes a lot of configuration at build time. To avoid dealing with all the complexity, we will only provide pre-built libraries for common "all-purpose" configuration and expect the users to build from scratch when they need some custom build.

you can force building from scratch by enabling build_from_src feature flag or by setting SKIA_BUILD_FROM_SRC env var.

Dependencies

If you are using the default build and there's a prebuilt binary available, then

  1. curl -> to download the pre-built libs
  2. tar -> to extract the archives after downloading.

Both windows 10 and linux have these by default.

If you are building from source:

  1. git -> to clone skia repo and deps
  2. python -> to download build deps and run build scripts
  3. tar (optional) -> to package libs before copying them to SKIA_COPY_LIBS (see below)
  4. curl -> maybe download something that we need like source code packages from github.
  5. clang and clang++. (LLVM).
  6. sccache or ccache (optional) -> for caching compiled objects, as cargo clean will remove everything from target eventually. highly recommended.
  7. Lots of patience. skia is going through a messy phase of changing build systems from gn to bazel. So, you will probably hit some issues.

If you are building from source, then there are a few env variables you might want to set.

name default purpose
SKIA_CC clang* c compiler. clang is preferred by skia
SKIA_CC_WRAPPER sccache* or ccache* improves compile times by using a global cache. highly recommended
SKIA_CXX clang++* c++ compiler. clang++ is preferred by skia
SKIA_CLANG_WIN (windows only) C:\Program Files\LLVM* path to LLVM installation. required for using clang
SKIA_CLANG_WIN_VERSION (windows only) SKIA_CLANG_WIN/lib/clang/version** version of clang to use. ckia_sys will try to use the most recent version in SKIA_CLANG_WIN/lib/clang/. required for using clang
SKIA_BUILD_FROM_SRC 0 if non-zero, tells ckia_sys to build skia from src. provided for convenience as an alternative to feature build_from_src
SKIA_GN_ARGS (only applies if building from src) "" addditional GN args to pass to skia build for custom builds.
SKIA_COPY_LIBS "" tells ckia_sys build system to copy the built binaries to the directory based on the path set in this var. useful in workflows to distribute libs after building it
SKIA_SRC_DIR "" If set, we will use this as the source for the build.
SKIA_SRC_ARCHIVE_URL "" If set, we will use curl to download this archive (.tar.gz), and extract it in OUT_DIR, and use that as the skia src directory. The archive must have a top level folder, which contains the skia sources

* We will only use that default IF it is avaialable. Otherwise, we will avoid setting that gn arg. eg: we will only use clang for SKIA_CC if clang --version works. otherwise, we would just let skia use the default cc.

** We will look into LLVM/lib/clang directory, read the versions and set the version to latest we can find. Otherwise, we will just skip setting it.

Dependencies