Skip to content

Building on Linux

Matthew Leibowitz edited this page Mar 25, 2018 · 42 revisions

SkiaSharp v1.60.1 has not yet been released, thus some commands may not work properly - specifically the v1.60.1 branch. To build now, use the xamarin-mobile-bindings branch.

As of v1.60.1, building libSkiaSharp.so is very easy and does not even require the mono/SkiaSharp repository. However, it is best to just clone the mono/SkiaSharp repository as it also pulls down additional tools used to build skia, namely depot_tools.

Prior to v1.60.1, use the "Building on Linux (LEGACY)" guide.

Downloading

The first step is to clone the mono/skia repository:

git clone https://github.com/mono/skia.git -b v1.60.1

To build the current master, check out xamarin-mobile-bindings as this is the Xamarin "master" - the master branch is reserved for the Google "master".

In order to build libSkiaSharp, Google's depot_tools is also required:

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

Building

Once skia and depot_tools are cloned, building happens in 3 steps (before anything happens, make sure you are working in the directory that you cloned skia into):

First, synchronize the skia dependencies:

python tools/git-sync-deps

Next, create the build (ninja) files using various arguments:

./bin/gn 'out/Linux/x64' --args='
    is_official_build=true skia_enable_tools=false
    target_os="linux" target_cpu="x64"
    skia_use_icu=false skia_use_sfntly=false skia_use_piex=true
    skia_use_system_expat=false skia_use_system_freetype2=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false
    skia_enable_gpu=true
    extra_cflags=[ "-DSKIA_C_DLL" ]
    linux_soname_version="60.1.0"'

Finally, build the native libSkiaSharp.so binary:

../depot_tools/ninja 'SkiaSharp' -C 'out/Linux/x64'

Once the build completes, there will be a file located at out/Linux/x64/libSkiaSharp.so.60.1.0 which can be renamed to libSkiaSharp.so and used for SkiaSharp apps.

Customizing

To build other types of linux-y binaries, you can tweak the --args value. Some example are:

  • disable GPU: --args='... skia_enable_gpu=false ...'
  • customize the compilers: --args='... cc="gcc" cxx="g++" ar="ar" ...'
  • adding C/C++ flags: --args='... extra_cflags_c=[ "..." ] extra_cflags_cc=[ "..." ] ...'
  • adding linker flags: --args='... extra_ldflags=[ "..." ] ...'
  • adding assembler flags: --args='... extra_asmflags=[ "..." ] ...'