Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux Support #2

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 27 additions & 36 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,74 +1,65 @@
name: Build Zig package
on: [push]
on:
push:
workflow_dispatch:

jobs:
mingw64-x64:
name: Build Skia with MinGW Clang
clang-x64:
name: Build Skia

runs-on: windows-latest
runs-on: ubuntu-latest

defaults:
run:
shell: bash

steps:
- uses: actions/checkout@v4

- uses: msys2/setup-msys2@v2
id: msys2
with:
msystem: MINGW64
update: true
install: mingw-w64-x86_64-clang mingw-w64-x86_64-lld

- name: Install skia dependency
run: |
sudo apt update
sudo apt install -y fontconfig libfreetype-dev libjpeg-turbo8-dev libpng-dev zlib1g-dev libwebp-dev vulkan-tools libvulkan-dev vulkan-validationlayers-dev spirv-tools
- name: "Clone skia"
run: git clone --depth 1 https://github.com/mono/skia.git skia_repo
- uses: mlugg/setup-zig@v1
with:
version: 0.13.0
- name: "Build skia"
run: |
"${{ steps.msys2.outputs.msys2-location }}/mingw64/bin/clang" --version

cd skia_repo
python3 tools/git-sync-deps
python3 bin/fetch-ninja
bin/gn gen out/lib --args='
target_os="win"
target_os="linux"
target_cpu="x64"
is_debug=false
is_component_build=false
is_static_skiasharp=true
is_official_build=true
skia_enable_fontmgr_win=true
skia_use_system_harfbuzz=false
skia_use_system_libpng=true
skia_enable_gpu=true
skia_enable_pdf=true
skia_use_system_libjpeg_turbo=false
skia_use_system_libpng=false
skia_use_system_libwebp=false
skia_use_system_zlib=false
skia_enable_discrete_gpu=true
skia_use_harfbuzz=false
skia_use_icu=false
skia_enable_tools=false
skia_use_expat=false
skia_enable_skottie=false
skia_use_gl=true
clang_win="${{ steps.msys2.outputs.msys2-location }}/mingw64"
clang_win_version=18
cc="${{ steps.msys2.outputs.msys2-location }}/mingw64/bin/clang"
cxx="${{ steps.msys2.outputs.msys2-location }}/mingw64/bin/clang++"
skia_use_vulkan=true
cc="zig cc"
cxx="zig c++"
extra_cflags=[
"-mevex512",
"-mavx",
"-mavx512f",
]
'
third_party/ninja/ninja -C out/lib skia

mkdir -p ../skia/lib/win-x86_64
mkdir -p ../skia/lib
cp --recursive include ../skia/include
cp --recursive out/lib/*.lib ../skia/lib/win-x86_64/
cp --recursive out/lib/*.a ../skia/lib

cd ..
rm -rf skia_repo
rm -rf .*
find -maxdepth 1 -name ".*" ! -name "." ! -name ".." -exec rm -rf {} +
ls -lah
- uses: mlugg/setup-zig@v1
with:
version: 0.13.0
- name: "Generate zig source"
run: sh generate.sh
- name: Archive the build
Expand Down
23 changes: 11 additions & 12 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ pub fn build(b: *std.Build) !void {
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});

if (target.result.os.tag == .windows and target.result.abi != .msvc) {
std.debug.print("Error: Skia requires the `msvc` abi on Windows. Please specify the abi using the build command (e.g. `zig build -Dtarget=x86_64-windows-msvc`) or force it by requesting it in the default_target of b.standardTargetOptions.", .{});
//return error.SkiaRequiresMSVConWin; // Temporarily disabled as this breaks ZLS
}

// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
Expand All @@ -26,13 +21,17 @@ pub fn build(b: *std.Build) !void {
.root_source_file = b.path("src/main.zig"),
});

switch (target.result.os.tag) {
.windows => {
var path: [128:0]u8 = undefined;
module.addLibraryPath(b.path(try std.fmt.bufPrint(&path, "skia/lib/win-{s}", .{@tagName(target.result.cpu.arch)})));
},
else => return error.PlatformNotSupported,
}
var path: [128:0]u8 = undefined;
module.addLibraryPath(b.path(try std.fmt.bufPrint(&path, "skia/lib/", .{})));

module.linkSystemLibrary("skia", .{ .preferred_link_mode = .static });
module.linkSystemLibrary("libjpeg", .{});
module.linkSystemLibrary("libpng", .{});
module.linkSystemLibrary("fontconfig", .{});
module.linkSystemLibrary("freetype", .{});
module.linkSystemLibrary("libwebp", .{});
module.linkSystemLibrary("libwebpdemux", .{});
module.linkSystemLibrary("zlib", .{});
module.linkSystemLibrary("vulkan", .{});
module.link_libc = true;
}