diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000000..19bcb5c440e6 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,139 @@ +name: Build +on: push +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [windows-latest, macos-latest, ubuntu-20.04] + mode: [Release, Debug] + arch: [x64, x86, arm64] + exclude: + - os: macos-latest + arch: x86 + - os: windows-latest + arch: arm64 + - os: ubuntu-20.04 + arch: arm64 + steps: + - uses: actions/checkout@v4 + - name: Install Dependencies + shell: bash + run: | + if [[ "${{ runner.os }}" == "Windows" ]] ; then + choco install llvm + choco install zip + elif [[ "${{ runner.os }}" == "macOS" ]] ; then + brew install coreutils + else + sudo apt-get update -qq + sudo apt-get install -y \ + git g++ g++-multilib clang-12 pandoc dpkg-dev \ + libcurl4-openssl-dev libgif-dev libjpeg-dev \ + libz-dev libpng-dev libtinyxml-dev libpixman-1-dev \ + libx11-dev libxcursor-dev ninja-build zip unzip \ + libfontconfig-dev libgl1-mesa-dev + fi + - name: Download depot_tools + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + run: | + git clone 'https://chromium.googlesource.com/chromium/tools/depot_tools.git' + echo "::add-path::${PWD}/depot_tools" + - name: Sync Deps + env: + GIT_SYNC_DEPS_SKIP_EMSDK: true + run: python3 tools/git-sync-deps + - name: Fetch Ninja + run: python3 bin/fetch-ninja + - name: Generating Ninja Files + shell: bash + run: | + if [[ "${{ matrix.mode }}" == "Debug" ]] ; then + export is_debug=true + export is_official=false + else + export is_debug=false + export is_official=true + fi + if [[ "${{ runner.os }}" == "Windows" ]] ; then + export gn_flags='is_trivial_abi=false win_vc="C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC" win_toolchain_version="17.9" win_sdk="C:\\Program Files\\Windows Kits\\10" win_sdk_version="10.0.22621.0" cc="clang" cxx="clang++" clang_win="C:\Program Files\LLVM" clang_win_version="16.0.0"' + if [[ "${{ matrix.mode }}" == "Debug" ]] ; then + export gn_flags="$gn_flags extra_cflags=[\"-MTd\"]" + else + export gn_flags="$gn_flags extra_cflags=[\"-MT\"]" + fi + elif [[ "${{ runner.os }}" == "macOS" ]] ; then + if [[ "${{ matrix.arch }}" == arm64 ]] ; then + export gn_flags='extra_cflags=["-stdlib=libc++", "-mmacosx-version-min=11.0"] extra_cflags_cc=["-frtti"]' + else + export gn_flags='extra_cflags=["-stdlib=libc++", "-mmacosx-version-min=10.9"] extra_cflags_cc=["-frtti"]' + fi + else + export gn_flags='cc="clang-12" cxx="clang++-12"' + fi + gn gen out/${{ matrix.mode }}-${{ matrix.arch }} --args="is_debug=$is_debug is_official_build=$is_official skia_use_system_expat=false skia_use_system_icu=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false skia_use_sfntly=false skia_use_freetype=true skia_use_harfbuzz=true skia_pdf_subset_harfbuzz=true skia_use_system_freetype2=false skia_use_system_harfbuzz=false target_cpu=\"${{ matrix.arch }}\" $gn_flags" + - name: Compiling + run: ninja -C out/${{ matrix.mode }}-${{ matrix.arch }} skia modules + - name: Copying Files + shell: bash + run: | + if [[ "${{ runner.os }}" == "Windows" ]] ; then + export libext=lib + else + export libext=a + fi + if [[ "${{ runner.os }}" == "macOS" ]] ; then + export cp=gcp + else + export cp=cp + fi + export dst=Skia-${{ runner.os }}-${{ matrix.mode }}-${{ matrix.arch }} + mkdir $dst + $cp -R --parents \ + out/${{ matrix.mode }}-${{ matrix.arch }}/*.$libext \ + LICENSE \ + include \ + modules/skcms/*.h \ + modules/skcms/src/*.h \ + modules/skottie/include/*.h \ + modules/skparagraph/include/*.h \ + modules/skplaintexteditor/include/*.h \ + modules/skresources/include/*.h \ + modules/sksg/include/*.h \ + modules/skshaper/include/*.h \ + modules/skunicode/include/*.h \ + modules/svg/include/*.h \ + src/core/*.h \ + src/gpu/ganesh/gl/*.h \ + third_party/externals/angle2/LICENSE \ + third_party/externals/angle2/include \ + third_party/externals/freetype/LICENSE.TXT \ + third_party/externals/freetype/docs/FTL.TXT \ + third_party/externals/freetype/docs/GPLv2.TXT \ + third_party/externals/freetype/include \ + third_party/externals/harfbuzz/COPYING \ + third_party/externals/harfbuzz/src/*.h \ + third_party/externals/icu/LICENSE \ + third_party/externals/icu/flutter/icudtl.dat \ + third_party/externals/libpng/*.h \ + third_party/externals/libpng/LICENSE \ + third_party/externals/libwebp/COPYING \ + third_party/externals/libwebp/PATENTS \ + third_party/externals/libwebp/src/dec/*.h \ + third_party/externals/libwebp/src/dsp/*.h \ + third_party/externals/libwebp/src/enc/*.h \ + third_party/externals/libwebp/src/mux/*.h \ + third_party/externals/libwebp/src/utils/*.h \ + third_party/externals/libwebp/src/webp/*.h \ + third_party/externals/swiftshader/LICENSE.txt \ + third_party/externals/swiftshader/include \ + third_party/externals/zlib/*.h \ + third_party/externals/zlib/LICENSE \ + $dst + - name: Uploading Artifact + uses: actions/upload-artifact@v1 + with: + name: Skia-${{ runner.os }}-${{ matrix.mode }}-${{ matrix.arch }} + path: Skia-${{ runner.os }}-${{ matrix.mode }}-${{ matrix.arch }} diff --git a/README.md b/README.md new file mode 100644 index 000000000000..7863332dffce --- /dev/null +++ b/README.md @@ -0,0 +1,150 @@ +# Skia for Aseprite and laf + +**Pre-built binaries of Skia** in the [releases page](https://github.com/aseprite/skia/releases). + +Skia is a 2D graphic library developed by Google Inc., you can find +the official website in [skia.org](https://skia.org). + +This fork is used to compile Skia automatically for +[laf](https://github.com/aseprite/laf) and +[Aseprite](https://github.com/aseprite/aseprite) using GitHub Actions. + +# Building Skia + +In the following sections you will find straightforward steps to +compile Skia. You can always check the [official Skia +instructions](https://skia.org/docs/user/build) and select the OS you are +building for. [Aseprite](https://github.com/aseprite/aseprite) and +[laf](https://github.com/aseprite/laf) use the **`aseprite-m122`** branch. +So remember to checkout that specific branch. + +These are the platform-specific steps to compile Skia: + +* [Skia on Windows](#skia-on-windows) +* [Skia on macOS](#skia-on-macos) +* [Skia on Linux](#skia-on-linux) + +After this you should have all Skia libraries compiled. After that, +when you compile laf or Aseprite remember to add +`-DSKIA_DIR=$HOME/deps/skia` parameter to your `cmake` call and all +other parameters. + +## Skia on Windows + +Download +[Google depot tools](https://storage.googleapis.com/chrome-infra/depot_tools.zip) +and uncompress it in some place like `C:\deps\depot_tools`. + +[It's recommended to compile Skia with Clang](https://github.com/google/skia/blob/master/site/user/build.md#a-note-on-software-backend-performance) +to get better performance. So you will need to [download Clang](https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.6/LLVM-17.0.6-win64.exe), +and install it on a folder like `C:\deps\llvm` (a folder without whitespaces). + +Open a command prompt window (`cmd.exe`) and call: + + call "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -arch=x64 + +The command above is required while attempting to compile the 64-bit version of skia. When compiling the 32-bit version, it is possible to open a [developer command prompt](https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs) instead. + +Then: + + set PATH=C:\deps\depot_tools;%PATH% + cd C:\deps\depot_tools + gclient sync + +(The `gclient` command might print an error like +`Error: client not configured; see 'gclient config'`. +Just ignore it.) + + cd C:\deps + git clone -b aseprite-m122 https://github.com/aseprite/skia.git + cd skia + set GIT_EXECUTABLE=git.bat + python3 tools/git-sync-deps + python3 bin/fetch-ninja + +(The `tools/git-sync-deps` will take some minutes because it downloads +a lot of packages, please wait and re-run the same command in case it +fails.) + +Finally, if you've downloaded Clang, use this command: + + set PATH=C:\deps\llvm\bin;%PATH% + gn gen out/Release-x64 --args="is_debug=false is_official_build=true is_trivial_abi=false skia_use_system_expat=false skia_use_system_icu=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false skia_use_sfntly=false skia_use_freetype=true skia_use_harfbuzz=true skia_pdf_subset_harfbuzz=true skia_use_system_freetype2=false skia_use_system_harfbuzz=false target_cpu=""x64"" cc=""clang"" cxx=""clang++"" clang_win=""c:\deps\llvm"" clang_win_version=""17.0.6"" win_vc=""C:\Program Files\Microsoft Visual Studio\2022\Community\VC"" extra_cflags=[""-MT""]" + ninja -C out/Release-x64 skia modules + +If you haven't installed Clang, and want to compile Skia with MSVC +(anyway it's not recommended because the performance penalty is too +big), you can use the following commands instead: + + gn gen out/Release-x64 --args="is_debug=false is_official_build=true is_trivial_abi=false skia_use_system_expat=false skia_use_system_icu=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false skia_use_sfntly=false skia_use_freetype=true skia_use_harfbuzz=true skia_pdf_subset_harfbuzz=true skia_use_system_freetype2=false skia_use_system_harfbuzz=false target_cpu=""x64"" win_vc=""C:\Program Files\Microsoft Visual Studio\2022\Community\VC"" extra_cflags=[""-MT""]" + ninja -C out/Release-x64 skia modules + +### For debugging + +For debugging purposes you can compile the debug version of the +library, e.g. for LLVM: + + set PATH=C:\deps\llvm\bin;%PATH% + gn gen out/Debug-x64 --args="is_debug=true is_official_build=false is_trivial_abi=false skia_use_system_expat=false skia_use_system_icu=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false skia_use_sfntly=false skia_use_freetype=true skia_use_harfbuzz=true skia_pdf_subset_harfbuzz=true skia_use_system_freetype2=false skia_use_system_harfbuzz=false target_cpu=""x64"" cc=""clang"" cxx=""clang++"" clang_win=""c:\deps\llvm"" clang_win_version=""17.0.6"" win_vc=""C:\Program Files\Microsoft Visual Studio\2022\Community\VC"" extra_cflags=[""-MTd""]" + ninja -C out/Debug-x64 skia modules + +## Skia on macOS + +These steps will create a `deps` folder in your home directory with a +couple of subdirectories needed to build Skia (you can change the +`$HOME/deps` with other directory). Some of these commands will take +several minutes to finish: + + mkdir $HOME/deps + cd $HOME/deps + git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git + git clone -b aseprite-m122 https://github.com/aseprite/skia.git + export PATH="${PWD}/depot_tools:${PATH}" + cd skia + python3 tools/git-sync-deps + python3 bin/fetch-ninja + gn gen out/Release-x64 --args="is_debug=false is_official_build=true skia_use_system_expat=false skia_use_system_icu=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false skia_use_sfntly=false skia_use_freetype=true skia_use_harfbuzz=true skia_pdf_subset_harfbuzz=true skia_use_system_freetype2=false skia_use_system_harfbuzz=false target_cpu=\"x64\" extra_cflags=[\"-stdlib=libc++\", \"-mmacosx-version-min=10.9\"] extra_cflags_cc=[\"-frtti\"]" + ninja -C out/Release-x64 skia modules + +### Skia on macOS for Apple Silicon + +If you want to compile Skia for Apple Silicon (e.g. M1), you have to +specify the `arm64` CPU architecture: + + gn gen out/Release-arm64 --args="is_debug=false is_official_build=true skia_use_system_expat=false skia_use_system_icu=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false skia_use_sfntly=false skia_use_freetype=true skia_use_harfbuzz=true skia_pdf_subset_harfbuzz=true skia_use_system_freetype2=false skia_use_system_harfbuzz=false target_cpu=\"arm64\" extra_cflags=[\"-stdlib=libc++\", \"-mmacosx-version-min=11.0\"] extra_cflags_cc=[\"-frtti\"]" + ninja -C out/Release-arm64 skia modules + +## Skia on Linux + +These steps will create a `deps` folder in your home directory with a +couple of subdirectories needed to build Skia (you can change the +`$HOME/deps` with other directory). Some of these commands will take +several minutes to finish: + + mkdir $HOME/deps + cd $HOME/deps + git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git + git clone -b aseprite-m122 https://github.com/aseprite/skia.git + export PATH="${PWD}/depot_tools:${PATH}" + cd skia + python3 tools/git-sync-deps + python3 bin/fetch-ninja + gn gen out/Release-x64 --args="is_debug=false is_official_build=true skia_use_system_expat=false skia_use_system_icu=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false skia_use_sfntly=false skia_use_freetype=true skia_use_harfbuzz=true skia_pdf_subset_harfbuzz=true skia_use_system_freetype2=false skia_use_system_harfbuzz=false" + ninja -C out/Release-x64 skia modules + +# Internal Details + +* `is_trivial_abi`: As we are mixing MSVC/Clang, the Windows + compilation needs the `is_trivial_abi=false` option as indicated + [here](https://groups.google.com/g/skia-discuss/c/ze-_PUljtkk/m/sdTNWL3rAQAJ), + in other case we can get an infinite loop `SkOnce::operator()` + +* `-MT`: We are creating a static-linked version of Skia library, + that's why we have the `extra_cflags=["-MTd"]` option, so we don't + need to distribute the MSVC C++ runtime DLLs. + +* `-frtti`: On macOS we've detected a [strange bug](https://bugs.llvm.org/show_bug.cgi?id=37487) + where linking object files compiled with `-frtti` and `-fno-rtti` + (the default Skia option) breaks the normal function of + `std::exception` hierarchy. That's why we're compiling with run-time + type information `extra_cflags_cc=["-frtti"]`. diff --git a/gn/skia/BUILD.gn b/gn/skia/BUILD.gn index 80ca91799c15..e2a1f82fa5c7 100644 --- a/gn/skia/BUILD.gn +++ b/gn/skia/BUILD.gn @@ -297,15 +297,15 @@ config("default") { } else { asmflags += [ "-target", - "x86_64-apple-macos10.13", + "x86_64-apple-macos10.9", ] cflags += [ "-target", - "x86_64-apple-macos10.13", + "x86_64-apple-macos10.9", ] ldflags += [ "-target", - "x86_64-apple-macos10.13", + "x86_64-apple-macos10.9", ] } } diff --git a/gn/toolchain/BUILD.gn b/gn/toolchain/BUILD.gn index 4d4abc952f59..fe75264423b3 100644 --- a/gn/toolchain/BUILD.gn +++ b/gn/toolchain/BUILD.gn @@ -91,10 +91,10 @@ template("msvc_toolchain") { if (toolchain_target_cpu == "x86") { # Toolchain asset includes a script that configures for x86 building. # We don't support x86 builds with local MSVC installations. - env_setup = "$shell $win_sdk/bin/SetEnv.cmd /x86 && " + #env_setup = "$shell $win_sdk/bin/SetEnv.cmd /x86 && " } else if (toolchain_target_cpu == "arm64") { # ARM64 compiler is incomplete - it relies on DLLs located in the host toolchain directory. - env_setup = "$shell set \"PATH=%PATH%;$win_vc\\Tools\\MSVC\\$win_toolchain_version\\bin\\HostX64\\x64\" && " + #env_setup = "$shell set \"PATH=%PATH%;$win_vc\\Tools\\MSVC\\$win_toolchain_version\\bin\\HostX64\\x64\" && " } cl_m32_flag = "" diff --git a/third_party/harfbuzz/BUILD.gn b/third_party/harfbuzz/BUILD.gn index 5b39dc213ef2..9d99b2f25907 100644 --- a/third_party/harfbuzz/BUILD.gn +++ b/third_party/harfbuzz/BUILD.gn @@ -25,8 +25,9 @@ if (skia_use_system_harfbuzz) { ".", _src, ] + include_dirs = [ "../externals/freetype/include" ] defines = [ - #"HAVE_FREETYPE", + "HAVE_FREETYPE", #"HAVE_ICU", #"HAVE_ICU_BUILTIN", "HAVE_OT", @@ -198,6 +199,8 @@ if (skia_use_system_harfbuzz) { "$_src/hb-face.hh", "$_src/hb-font.cc", "$_src/hb-font.hh", + "$_src/hb-ft.cc", + "$_src/hb-ft.h", "$_src/hb-iter.hh", "$_src/hb-kern.hh", "$_src/hb-limits.hh",