Skip to content
Closed
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
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 @@ -149,38 +154,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 @@ -204,7 +211,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 @@ -224,7 +231,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
102 changes: 77 additions & 25 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,46 @@ pub fn build(b: *Build) !void {
try addDependencies(b, lightpanda_module, opts);

{
// browser
// -------
// static lib
// ----------

// compile and install
const exe = b.addExecutable(.{
.name = "lightpanda",
.use_llvm = true,
.root_module = lightpanda_module,
const liblightpanda_module = b.addModule("lightpanda", .{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.link_libcpp = true,
});
b.installArtifact(exe);
try addDependencies(b, liblightpanda_module, opts);

// run
const run_cmd = b.addRunArtifact(exe);
if (b.args) |args| {
run_cmd.addArgs(args);
}

// step
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const lib = b.addLibrary(.{ .name = "lightpanda", .root_module = liblightpanda_module, .use_llvm = true, .linkage = .static });
lib.bundle_compiler_rt = true;
b.installArtifact(lib);
}

// {
// // browser
// // -------

// // compile and install
// const exe = b.addExecutable(.{
// .name = "lightpanda",
// .use_llvm = true,
// .root_module = lightpanda_module,
// });
// b.installArtifact(exe);

// // run
// const run_cmd = b.addRunArtifact(exe);
// if (b.args) |args| {
// run_cmd.addArgs(args);
// }

// // step
// const run_step = b.step("run", "Run the app");
// run_step.dependOn(&run_cmd.step);
// }

{
// tests
// ----
Expand Down Expand Up @@ -176,6 +194,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 +218,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 @@ -390,26 +415,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 @@ -420,7 +466,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 @@ -431,7 +477,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 @@ -445,7 +491,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 @@ -494,7 +540,7 @@ fn buildMbedtls(b: *Build, m: *Build.Module) !void {
mbedtls.addIncludePath(b.path(root ++ "include"));
mbedtls.addIncludePath(b.path(root ++ "library"));

mbedtls.addCSourceFiles(.{ .flags = &.{}, .files = &.{
mbedtls.addCSourceFiles(.{ .flags = &.{"-Wno-nullability-completeness"}, .files = &.{
root ++ "library/aes.c",
root ++ "library/aesni.c",
root ++ "library/aesce.c",
Expand Down Expand Up @@ -648,6 +694,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
10 changes: 5 additions & 5 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
.version = "0.0.0",
.fingerprint = 0xda130f3af836cea0,
.dependencies = .{
.v8 = .{
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/7177ee1ae267a44751a0e7e012e257177699a375.tar.gz",
.hash = "v8-0.0.0-xddH63TCAwC1D1hEiOtbEnLBbtz9ZPHrdiGWLcBcYQB7",
},
// .v8 = .{ .path = "../zig-v8-fork" }
// .v8 = .{
// .url = "https://github.com/lightpanda-io/zig-v8-fork/archive/7177ee1ae267a44751a0e7e012e257177699a375.tar.gz",
// .hash = "v8-0.0.0-xddH63TCAwC1D1hEiOtbEnLBbtz9ZPHrdiGWLcBcYQB7",
// },
.v8 = .{ .path = "../zig-v8-fork" },
},
}
27 changes: 27 additions & 0 deletions include/lightpanda.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef _LIGHTPANDA_H
#define _LIGHTPANDA_H

void* lightpanda_app_init();
void lightpanda_app_deinit(void* app_ptr);

void* lightpanda_browser_init(void* app_ptr);
void lightpanda_browser_deinit(void* browser_ptr);

void* lightpanda_browser_new_session(void* browser_ptr);

void* lightpanda_session_create_page(void* session_ptr);
void* lightpanda_session_page(void* session_ptr);

void lightpanda_page_navigate(void* page_ptr, const char *url);

void* lightpanda_cdp_init(void* app_ptr, void (*handler_fn)(void*, const char *), void* ctx);
void lightpanda_cdp_deinit(void* cdp_ptr);
const char* lightpanda_cdp_create_browser_context(void* cdp_ptr);
void* lightpanda_cdp_browser(void* cdp_ptr);
void lightpanda_cdp_process_message(void* cdp_ptr, const char *msg);
void* lightpanda_cdp_browser_context(void* cdp_ptr);
int lightpanda_cdp_page_wait(void* cdp_ptr, int ms);

void* lightpanda_browser_context_session(void* browser_context_ptr);

#endif
4 changes: 4 additions & 0 deletions include/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module lightpanda {
umbrella header "lightpanda.h"
export *
}
Binary file added src/.DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions src/app.zig
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ fn getAndMakeAppDir(allocator: Allocator) ?[]const u8 {
if (@import("builtin").is_test) {
return allocator.dupe(u8, "/tmp") catch unreachable;
}

if (@import("builtin").os.tag == .ios) {
return null; // getAppDataDir is not available on iOS
}

const app_dir_path = std.fs.getAppDataDir(allocator, "lightpanda") catch |err| {
log.warn(.app, "get data dir", .{ .err = err });
return null;
Expand Down
5 changes: 5 additions & 0 deletions src/browser/dom/document_fragment.zig
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ pub const DocumentFragment = struct {
const e = try parser.nodeGetElementById(@ptrCast(@alignCast(self)), id) orelse return null;
return try Element.toInterface(e);
}

pub fn get_firstElementChild(self: *parser.DocumentFragment) !?ElementUnion {
var children = try get_children(self);
return try children._item(0);
}
};

const testing = @import("../../testing.zig");
Expand Down
8 changes: 8 additions & 0 deletions src/browser/netsurf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,14 @@ pub fn mutationEventPrevValue(evt: *MutationEvent) !?[]const u8 {
return strToData(s.?);
}

pub fn mutationEventNewValue(evt: *MutationEvent) !?[]const u8 {
var s: ?*String = null;
const err = c._dom_mutation_event_get_new_value(evt, &s);
try DOMErr(err);
if (s == null) return null;
return strToData(s.?);
}

pub fn mutationEventRelatedNode(evt: *MutationEvent) !?*Node {
var n: NodeExternal = undefined;
const err = c._dom_mutation_event_get_related_node(evt, &n);
Expand Down
Loading
Loading