Skip to content
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
15 changes: 13 additions & 2 deletions .github/actions/install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ inputs:
description: 'OS used to select the v8 lib'
required: false
default: 'linux'
target-env:
description: 'TARGET_ENVIRONMENT used to select the v8 lib, only for ios build'
required: false
default: 'simulator'
zig-v8:
description: 'zig v8 version to install'
required: false
default: 'v0.1.33'
default: 'v0.1.34'
v8:
description: 'v8 version to install'
required: false
Expand Down Expand Up @@ -51,13 +55,20 @@ runs:
path: ${{ inputs.cache-dir }}/v8
key: libc_v8_${{ inputs.v8 }}_${{ inputs.os }}_${{ inputs.arch }}_${{ inputs.zig-v8 }}.a

- if: ${{ steps.cache-v8.outputs.cache-hit != 'true' }}
- if: ${{ steps.cache-v8.outputs.cache-hit != 'true' && inputs.os != 'ios' }}
shell: bash
run: |
mkdir -p ${{ inputs.cache-dir }}/v8

wget -O ${{ inputs.cache-dir }}/v8/libc_v8.a https://github.com/lightpanda-io/zig-v8-fork/releases/download/${{ inputs.zig-v8 }}/libc_v8_${{ inputs.v8 }}_${{ inputs.os }}_${{ inputs.arch }}.a

- if: ${{ steps.cache-v8.outputs.cache-hit != 'true' && inputs.os == 'ios' }}
shell: bash
run: |
mkdir -p ${{ inputs.cache-dir }}/v8

wget -O ${{ inputs.cache-dir }}/v8/libc_v8.a https://github.com/lightpanda-io/zig-v8-fork/releases/download/${{ inputs.zig-v8 }}/libc_v8_${{ inputs.v8 }}_${{ inputs.os }}_${{ inputs.target-env }}_${{ inputs.arch }}.a

- name: install v8
shell: bash
run: |
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,43 @@ jobs:
allowUpdates: true
artifacts: lightpanda-${{ env.ARCH }}-${{ env.OS }}
tag: nightly

build-aarch64-ios:
env:
OS: ios
ARCH: aarch64
TARGET_ENVIRONMENT: simulator

# macos-15 runs on arm CPU. see
# https://github.com/actions/runner-images?tab=readme-ov-file
runs-on: macos-15
timeout-minutes: 15

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
# fetch submodules recusively, to get zig-js-runtime submodules also.
submodules: recursive

- uses: ./.github/actions/install
with:
os: ${{env.OS}}
arch: ${{env.ARCH}}
target-env: ${{env.TARGET_ENVIRONMENT}}

# zig uses macos instead of ios as target. But install created ios dir.
# here we link v8 build in macos path too.
- name: fix ios/macos pathes
run: |
# v8
cd v8/out; ln -s ${{ env.OS }} macos; cd -
# libiconv
cd vendor/libiconv/out; ln -s ${{env.OS}}-${{env.ARCH}} macos-${{env.ARCH}}; cd -
# netsurf
cd vendor/netsurf/out; ln -s ${{env.OS}}-${{env.ARCH}} macos-${{env.ARCH}}; cd -
# mimalloc
cd vendor/mimalloc/out; ln -s ${{env.OS}}-${{env.ARCH}} macos-${{env.ARCH}}; cd -

- name: zig build
run: zig build --release=safe -Doptimize=ReleaseSafe -Dgit_commit=$(git rev-parse --short ${{ github.sha }}) static-lib
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARG MINISIG=0.12
ARG ZIG=0.15.2
ARG ZIG_MINISIG=RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U
ARG V8=14.0.365.4
ARG ZIG_V8=v0.1.33
ARG ZIG_V8=v0.1.34
ARG TARGETPLATFORM

RUN apt-get update -yq && \
Expand Down
77 changes: 42 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,29 @@ F=
# OS and ARCH
kernel = $(shell uname -ms)
ifeq ($(kernel), Darwin arm64)
OS := macos
ARCH := aarch64
OS ?= macos
ARCH ?= aarch64
else ifeq ($(kernel), Darwin x86_64)
OS := macos
ARCH := x86_64
OS ?= macos
ARCH ?= x86_64
else ifeq ($(kernel), Linux aarch64)
OS := linux
ARCH := aarch64
OS ?= linux
ARCH ?= aarch64
else ifeq ($(kernel), Linux arm64)
OS := linux
ARCH := aarch64
OS ?= linux
ARCH ?= aarch64
else ifeq ($(kernel), Linux x86_64)
OS := linux
ARCH := x86_64
OS ?= linux
ARCH ?= x86_64
else
$(error "Unhandled kernel: $(kernel)")
endif

MAKE ?= make
CMAKE ?= cmake
AUTOCONF_FLAGS ?=
CFLAGS ?=
LDFLAGS ?=

# Infos
# -----
Expand Down Expand Up @@ -156,38 +161,40 @@ _install-netsurf: clean-netsurf
mkdir -p $(BC_NS) && \
cp -R vendor/netsurf/share $(BC_NS) && \
export PREFIX=$(BC_NS) && \
export OPTLDFLAGS="-L$(ICONV)/lib" && \
export OPTCFLAGS="$(OPTCFLAGS) -I$(ICONV)/include" && \
export OPTLDFLAGS="$(LDFLAGS) -L$(ICONV)/lib" && \
export OPTCFLAGS="$(CFLAGS) $(OPTCFLAGS) -I$(ICONV)/include" && \
printf "\e[33mInstalling libwapcaplet...\e[0m\n" && \
cd vendor/netsurf/libwapcaplet && \
BUILDDIR=$(BC_NS)/build/libwapcaplet make install && \
BUILDDIR=$(BC_NS)/build/libwapcaplet $(MAKE) install && \
cd ../libparserutils && \
printf "\e[33mInstalling libparserutils...\e[0m\n" && \
BUILDDIR=$(BC_NS)/build/libparserutils make install && \
BUILDDIR=$(BC_NS)/build/libparserutils $(MAKE) install && \
cd ../libhubbub && \
printf "\e[33mInstalling libhubbub...\e[0m\n" && \
BUILDDIR=$(BC_NS)/build/libhubbub make install && \
BUILDDIR=$(BC_NS)/build/libhubbub $(MAKE) install && \
rm src/treebuilder/autogenerated-element-type.c && \
cd ../libdom && \
printf "\e[33mInstalling libdom...\e[0m\n" && \
BUILDDIR=$(BC_NS)/build/libdom make install && \
printf "\e[33mRunning libdom example...\e[0m\n" && \
cd examples && \
$(ZIG) cc \
-I$(ICONV)/include \
-I$(BC_NS)/include \
-L$(ICONV)/lib \
-L$(BC_NS)/lib \
-liconv \
-ldom \
-lhubbub \
-lparserutils \
-lwapcaplet \
-o a.out \
dom-structure-dump.c \
$(ICONV)/lib/libiconv.a && \
./a.out > /dev/null && \
rm a.out && \
BUILDDIR=$(BC_NS)/build/libdom $(MAKE) install && \
if [ -z "$${SKIP_EXAMPLES}" ]; then \
printf "\e[33mRunning libdom example...\e[0m\n" && \
cd examples && \
$(ZIG) cc \
-I$(ICONV)/include \
-I$(BC_NS)/include \
-L$(ICONV)/lib \
-L$(BC_NS)/lib \
-liconv \
-ldom \
-lhubbub \
-lparserutils \
-lwapcaplet \
-o a.out \
dom-structure-dump.c \
$(ICONV)/lib/libiconv.a && \
./a.out > /dev/null && \
rm a.out; \
fi && \
printf "\e[36mDone NetSurf $(OS)\e[0m\n"

clean-netsurf:
Expand All @@ -211,7 +218,7 @@ endif

build-libiconv: clean-libiconv
@cd vendor/libiconv/libiconv-1.17 && \
./configure --prefix=$(ICONV) --enable-static && \
./configure --prefix=$(ICONV) --enable-static $(AUTOCONF_FLAGS) && \
make && make install

install-libiconv: download-libiconv build-libiconv
Expand All @@ -231,7 +238,7 @@ MIMALLOC := $(BC)vendor/mimalloc/out/$(OS)-$(ARCH)
_build_mimalloc: clean-mimalloc
@mkdir -p $(MIMALLOC)/build && \
cd $(MIMALLOC)/build && \
cmake -DMI_BUILD_SHARED=OFF -DMI_BUILD_OBJECT=OFF -DMI_BUILD_TESTS=OFF -DMI_OVERRIDE=OFF $(OPTS) ../../.. && \
$(CMAKE) -DMI_BUILD_SHARED=OFF -DMI_BUILD_OBJECT=OFF -DMI_BUILD_TESTS=OFF -DMI_OVERRIDE=OFF $(OPTS) ../../.. && \
make && \
mkdir -p $(MIMALLOC)/lib

Expand Down
74 changes: 66 additions & 8 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,25 @@ pub fn build(b: *Build) !void {
const build_step = b.step("build-v8", "Build v8");
build_step.dependOn(&build_v8.step);
}

{
// static lib
// -------
const static_lib_module = b.addModule("lightpanda", .{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.link_libcpp = true,
});
try addDependencies(b, static_lib_module, opts);

const lib = b.addLibrary(.{ .name = "lightpanda", .root_module = static_lib_module, .use_llvm = true, .linkage = .static });
lib.bundle_compiler_rt = true;
const install_artifact = b.addInstallArtifact(lib, .{});
const build_step = b.step("static-lib", "Build static lib");
build_step.dependOn(&install_artifact.step);
}
}

fn addDependencies(b: *Build, mod: *Build.Module, opts: *Build.Step.Options) !void {
Expand Down Expand Up @@ -176,6 +195,7 @@ fn addDependencies(b: *Build, mod: *Build.Module, opts: *Build.Step.Options) !vo
const os = switch (target.result.os.tag) {
.linux => "linux",
.macos => "macos",
.ios => "ios",
else => return error.UnsupportedPlatform,
};
var lib_path = try std.fmt.allocPrint(
Expand All @@ -199,6 +219,12 @@ fn addDependencies(b: *Build, mod: *Build.Module, opts: *Build.Step.Options) !vo
mod.addSystemFrameworkPath(.{ .cwd_relative = "/System/Library/Frameworks" });
mod.linkFramework("CoreFoundation", .{});
},
.ios => {
const sdk_path = try std.process.getEnvVarOwned(mod.owner.allocator, "SDK");
const framework_path = try std.fmt.allocPrint(mod.owner.allocator, "{s}/System/Library/Frameworks", .{sdk_path});
mod.addSystemFrameworkPath(.{ .cwd_relative = framework_path });
mod.linkFramework("CoreFoundation", .{});
},
else => {},
}
}
Expand Down Expand Up @@ -393,26 +419,47 @@ fn addDependencies(b: *Build, mod: *Build.Module, opts: *Build.Step.Options) !vo
mod.linkFramework("CoreFoundation", .{});
mod.linkFramework("SystemConfiguration", .{});
},
.ios => {
const sdk_path = try std.process.getEnvVarOwned(mod.owner.allocator, "SDK");
const framework_path = try std.fmt.allocPrint(mod.owner.allocator, "{s}/System/Library/Frameworks", .{sdk_path});
mod.addSystemFrameworkPath(.{ .cwd_relative = framework_path });
mod.linkFramework("CoreFoundation", .{});
mod.linkFramework("SystemConfiguration", .{});
},
else => {},
}
}
}

fn moduleNetSurf(b: *Build, mod: *Build.Module) !void {
const target = mod.resolved_target.?;
const os = target.result.os.tag;
const arch = target.result.cpu.arch;
const os = switch (target.result.os.tag) {
.linux => "linux",
.macos => "macos",
.ios => switch (target.result.abi) {
.simulator => "iphonesimulator",
else => return error.UnsupportedPlatform,
},
else => return error.UnsupportedPlatform,
};
const arch = switch (target.result.os.tag) {
.ios => switch (target.result.cpu.arch) {
.aarch64 => "arm64",
else => @tagName(target.result.cpu.arch),
},
else => @tagName(target.result.cpu.arch),
};

// iconv
const libiconv_lib_path = try std.fmt.allocPrint(
b.allocator,
"vendor/libiconv/out/{s}-{s}/lib/libiconv.a",
.{ @tagName(os), @tagName(arch) },
.{ os, arch },
);
const libiconv_include_path = try std.fmt.allocPrint(
b.allocator,
"vendor/libiconv/out/{s}-{s}/lib/libiconv.a",
.{ @tagName(os), @tagName(arch) },
.{ os, arch },
);
mod.addObjectFile(b.path(libiconv_lib_path));
mod.addIncludePath(b.path(libiconv_include_path));
Expand All @@ -423,7 +470,7 @@ fn moduleNetSurf(b: *Build, mod: *Build.Module) !void {
const lib_path = try std.fmt.allocPrint(
b.allocator,
mimalloc ++ "/out/{s}-{s}/lib/libmimalloc.a",
.{ @tagName(os), @tagName(arch) },
.{ os, arch },
);
mod.addObjectFile(b.path(lib_path));
mod.addIncludePath(b.path(mimalloc ++ "/include"));
Expand All @@ -434,7 +481,7 @@ fn moduleNetSurf(b: *Build, mod: *Build.Module) !void {
const ns_include_path = try std.fmt.allocPrint(
b.allocator,
ns ++ "/out/{s}-{s}/include",
.{ @tagName(os), @tagName(arch) },
.{ os, arch },
);
mod.addIncludePath(b.path(ns_include_path));

Expand All @@ -448,7 +495,7 @@ fn moduleNetSurf(b: *Build, mod: *Build.Module) !void {
const ns_lib_path = try std.fmt.allocPrint(
b.allocator,
ns ++ "/out/{s}-{s}/lib/" ++ lib ++ ".a",
.{ @tagName(os), @tagName(arch) },
.{ os, arch },
);
mod.addObjectFile(b.path(ns_lib_path));
mod.addIncludePath(b.path(ns ++ "/" ++ lib ++ "/src"));
Expand Down Expand Up @@ -521,7 +568,12 @@ fn buildMbedtls(b: *Build, m: *Build.Module) !void {
mbedtls.addIncludePath(b.path(root ++ "include"));
mbedtls.addIncludePath(b.path(root ++ "library"));

mbedtls.addCSourceFiles(.{ .flags = &.{}, .files = &.{
const flags: []const []const u8 = if (m.resolved_target.?.result.os.tag == .ios)
&.{"-Wno-nullability-completeness"}
else
&.{};

mbedtls.addCSourceFiles(.{ .flags = flags, .files = &.{
root ++ "library/aes.c",
root ++ "library/aesni.c",
root ++ "library/aesce.c",
Expand Down Expand Up @@ -675,6 +727,12 @@ fn buildNghttp2(b: *Build, m: *Build.Module) !void {
}

fn buildCurl(b: *Build, m: *Build.Module) !void {
if (m.resolved_target.?.result.os.tag == .ios) {
const sdk_path = try std.process.getEnvVarOwned(b.allocator, "SDK");
const include_path = try std.fmt.allocPrint(b.allocator, "{s}/usr/include", .{sdk_path});
m.addIncludePath(.{ .cwd_relative = include_path });
}

const curl = b.addLibrary(.{
.name = "curl",
.root_module = m,
Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/84cdca7cd9065f67c7933388f2091810fc485bc6.tar.gz",
.hash = "v8-0.0.0-xddH67vcAwCuN2gBsAO8TBzEw523KMroIKGrdZwc-Q-y",
},
//.v8 = .{ .path = "../zig-v8-fork" }
//.v8 = .{ .path = "../zig-v8-fork" },
.@"ada-singleheader" = .{
.url = "https://github.com/ada-url/ada/releases/download/v3.3.0/singleheader.zip",
.hash = "N-V-__8AAPmhFAAw64ALjlzd5YMtzpSrmZ6KymsT84BKfB4s",
Expand Down
Loading