mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-16 08:18:59 +00:00
Add support for building on iOS
This commit is contained in:
committed by
Pierre Tachoire
parent
3f2f56d603
commit
8568c821fa
77
Makefile
77
Makefile
@@ -9,24 +9,29 @@ F=
|
|||||||
# OS and ARCH
|
# OS and ARCH
|
||||||
kernel = $(shell uname -ms)
|
kernel = $(shell uname -ms)
|
||||||
ifeq ($(kernel), Darwin arm64)
|
ifeq ($(kernel), Darwin arm64)
|
||||||
OS := macos
|
OS ?= macos
|
||||||
ARCH := aarch64
|
ARCH ?= aarch64
|
||||||
else ifeq ($(kernel), Darwin x86_64)
|
else ifeq ($(kernel), Darwin x86_64)
|
||||||
OS := macos
|
OS ?= macos
|
||||||
ARCH := x86_64
|
ARCH ?= x86_64
|
||||||
else ifeq ($(kernel), Linux aarch64)
|
else ifeq ($(kernel), Linux aarch64)
|
||||||
OS := linux
|
OS ?= linux
|
||||||
ARCH := aarch64
|
ARCH ?= aarch64
|
||||||
else ifeq ($(kernel), Linux arm64)
|
else ifeq ($(kernel), Linux arm64)
|
||||||
OS := linux
|
OS ?= linux
|
||||||
ARCH := aarch64
|
ARCH ?= aarch64
|
||||||
else ifeq ($(kernel), Linux x86_64)
|
else ifeq ($(kernel), Linux x86_64)
|
||||||
OS := linux
|
OS ?= linux
|
||||||
ARCH := x86_64
|
ARCH ?= x86_64
|
||||||
else
|
else
|
||||||
$(error "Unhandled kernel: $(kernel)")
|
$(error "Unhandled kernel: $(kernel)")
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
MAKE ?= make
|
||||||
|
CMAKE ?= cmake
|
||||||
|
AUTOCONF_FLAGS ?=
|
||||||
|
CFLAGS ?=
|
||||||
|
LDFLAGS ?=
|
||||||
|
|
||||||
# Infos
|
# Infos
|
||||||
# -----
|
# -----
|
||||||
@@ -156,38 +161,40 @@ _install-netsurf: clean-netsurf
|
|||||||
mkdir -p $(BC_NS) && \
|
mkdir -p $(BC_NS) && \
|
||||||
cp -R vendor/netsurf/share $(BC_NS) && \
|
cp -R vendor/netsurf/share $(BC_NS) && \
|
||||||
export PREFIX=$(BC_NS) && \
|
export PREFIX=$(BC_NS) && \
|
||||||
export OPTLDFLAGS="-L$(ICONV)/lib" && \
|
export OPTLDFLAGS="$(LDFLAGS) -L$(ICONV)/lib" && \
|
||||||
export OPTCFLAGS="$(OPTCFLAGS) -I$(ICONV)/include" && \
|
export OPTCFLAGS="$(CFLAGS) $(OPTCFLAGS) -I$(ICONV)/include" && \
|
||||||
printf "\e[33mInstalling libwapcaplet...\e[0m\n" && \
|
printf "\e[33mInstalling libwapcaplet...\e[0m\n" && \
|
||||||
cd vendor/netsurf/libwapcaplet && \
|
cd vendor/netsurf/libwapcaplet && \
|
||||||
BUILDDIR=$(BC_NS)/build/libwapcaplet make install && \
|
BUILDDIR=$(BC_NS)/build/libwapcaplet $(MAKE) install && \
|
||||||
cd ../libparserutils && \
|
cd ../libparserutils && \
|
||||||
printf "\e[33mInstalling libparserutils...\e[0m\n" && \
|
printf "\e[33mInstalling libparserutils...\e[0m\n" && \
|
||||||
BUILDDIR=$(BC_NS)/build/libparserutils make install && \
|
BUILDDIR=$(BC_NS)/build/libparserutils $(MAKE) install && \
|
||||||
cd ../libhubbub && \
|
cd ../libhubbub && \
|
||||||
printf "\e[33mInstalling libhubbub...\e[0m\n" && \
|
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 && \
|
rm src/treebuilder/autogenerated-element-type.c && \
|
||||||
cd ../libdom && \
|
cd ../libdom && \
|
||||||
printf "\e[33mInstalling libdom...\e[0m\n" && \
|
printf "\e[33mInstalling libdom...\e[0m\n" && \
|
||||||
BUILDDIR=$(BC_NS)/build/libdom make install && \
|
BUILDDIR=$(BC_NS)/build/libdom $(MAKE) install && \
|
||||||
printf "\e[33mRunning libdom example...\e[0m\n" && \
|
if [ -z "$${SKIP_EXAMPLES}" ]; then \
|
||||||
cd examples && \
|
printf "\e[33mRunning libdom example...\e[0m\n" && \
|
||||||
$(ZIG) cc \
|
cd examples && \
|
||||||
-I$(ICONV)/include \
|
$(ZIG) cc \
|
||||||
-I$(BC_NS)/include \
|
-I$(ICONV)/include \
|
||||||
-L$(ICONV)/lib \
|
-I$(BC_NS)/include \
|
||||||
-L$(BC_NS)/lib \
|
-L$(ICONV)/lib \
|
||||||
-liconv \
|
-L$(BC_NS)/lib \
|
||||||
-ldom \
|
-liconv \
|
||||||
-lhubbub \
|
-ldom \
|
||||||
-lparserutils \
|
-lhubbub \
|
||||||
-lwapcaplet \
|
-lparserutils \
|
||||||
-o a.out \
|
-lwapcaplet \
|
||||||
dom-structure-dump.c \
|
-o a.out \
|
||||||
$(ICONV)/lib/libiconv.a && \
|
dom-structure-dump.c \
|
||||||
./a.out > /dev/null && \
|
$(ICONV)/lib/libiconv.a && \
|
||||||
rm a.out && \
|
./a.out > /dev/null && \
|
||||||
|
rm a.out; \
|
||||||
|
fi && \
|
||||||
printf "\e[36mDone NetSurf $(OS)\e[0m\n"
|
printf "\e[36mDone NetSurf $(OS)\e[0m\n"
|
||||||
|
|
||||||
clean-netsurf:
|
clean-netsurf:
|
||||||
@@ -211,7 +218,7 @@ endif
|
|||||||
|
|
||||||
build-libiconv: clean-libiconv
|
build-libiconv: clean-libiconv
|
||||||
@cd vendor/libiconv/libiconv-1.17 && \
|
@cd vendor/libiconv/libiconv-1.17 && \
|
||||||
./configure --prefix=$(ICONV) --enable-static && \
|
./configure --prefix=$(ICONV) --enable-static $(AUTOCONF_FLAGS) && \
|
||||||
make && make install
|
make && make install
|
||||||
|
|
||||||
install-libiconv: download-libiconv build-libiconv
|
install-libiconv: download-libiconv build-libiconv
|
||||||
@@ -231,7 +238,7 @@ MIMALLOC := $(BC)vendor/mimalloc/out/$(OS)-$(ARCH)
|
|||||||
_build_mimalloc: clean-mimalloc
|
_build_mimalloc: clean-mimalloc
|
||||||
@mkdir -p $(MIMALLOC)/build && \
|
@mkdir -p $(MIMALLOC)/build && \
|
||||||
cd $(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 && \
|
make && \
|
||||||
mkdir -p $(MIMALLOC)/lib
|
mkdir -p $(MIMALLOC)/lib
|
||||||
|
|
||||||
|
|||||||
96
build.zig
96
build.zig
@@ -62,28 +62,36 @@ pub fn build(b: *Build) !void {
|
|||||||
try addDependencies(b, lightpanda_module, opts);
|
try addDependencies(b, lightpanda_module, opts);
|
||||||
|
|
||||||
{
|
{
|
||||||
// browser
|
// static lib
|
||||||
// -------
|
// ----------
|
||||||
|
|
||||||
// compile and install
|
const lib = b.addLibrary(.{ .name = "lightpanda", .root_module = lightpanda_module, .use_llvm = true, .linkage = .static });
|
||||||
const exe = b.addExecutable(.{
|
b.installArtifact(lib);
|
||||||
.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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// {
|
||||||
|
// // 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
|
// tests
|
||||||
// ----
|
// ----
|
||||||
@@ -176,6 +184,7 @@ fn addDependencies(b: *Build, mod: *Build.Module, opts: *Build.Step.Options) !vo
|
|||||||
const os = switch (target.result.os.tag) {
|
const os = switch (target.result.os.tag) {
|
||||||
.linux => "linux",
|
.linux => "linux",
|
||||||
.macos => "macos",
|
.macos => "macos",
|
||||||
|
.ios => "ios",
|
||||||
else => return error.UnsupportedPlatform,
|
else => return error.UnsupportedPlatform,
|
||||||
};
|
};
|
||||||
var lib_path = try std.fmt.allocPrint(
|
var lib_path = try std.fmt.allocPrint(
|
||||||
@@ -199,6 +208,12 @@ fn addDependencies(b: *Build, mod: *Build.Module, opts: *Build.Step.Options) !vo
|
|||||||
mod.addSystemFrameworkPath(.{ .cwd_relative = "/System/Library/Frameworks" });
|
mod.addSystemFrameworkPath(.{ .cwd_relative = "/System/Library/Frameworks" });
|
||||||
mod.linkFramework("CoreFoundation", .{});
|
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 => {},
|
else => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -393,6 +408,13 @@ fn addDependencies(b: *Build, mod: *Build.Module, opts: *Build.Step.Options) !vo
|
|||||||
mod.linkFramework("CoreFoundation", .{});
|
mod.linkFramework("CoreFoundation", .{});
|
||||||
mod.linkFramework("SystemConfiguration", .{});
|
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 => {},
|
else => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -400,19 +422,33 @@ fn addDependencies(b: *Build, mod: *Build.Module, opts: *Build.Step.Options) !vo
|
|||||||
|
|
||||||
fn moduleNetSurf(b: *Build, mod: *Build.Module) !void {
|
fn moduleNetSurf(b: *Build, mod: *Build.Module) !void {
|
||||||
const target = mod.resolved_target.?;
|
const target = mod.resolved_target.?;
|
||||||
const os = target.result.os.tag;
|
const os = switch (target.result.os.tag) {
|
||||||
const arch = target.result.cpu.arch;
|
.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
|
// iconv
|
||||||
const libiconv_lib_path = try std.fmt.allocPrint(
|
const libiconv_lib_path = try std.fmt.allocPrint(
|
||||||
b.allocator,
|
b.allocator,
|
||||||
"vendor/libiconv/out/{s}-{s}/lib/libiconv.a",
|
"vendor/libiconv/out/{s}-{s}/lib/libiconv.a",
|
||||||
.{ @tagName(os), @tagName(arch) },
|
.{ os, arch },
|
||||||
);
|
);
|
||||||
const libiconv_include_path = try std.fmt.allocPrint(
|
const libiconv_include_path = try std.fmt.allocPrint(
|
||||||
b.allocator,
|
b.allocator,
|
||||||
"vendor/libiconv/out/{s}-{s}/lib/libiconv.a",
|
"vendor/libiconv/out/{s}-{s}/lib/libiconv.a",
|
||||||
.{ @tagName(os), @tagName(arch) },
|
.{ os, arch },
|
||||||
);
|
);
|
||||||
mod.addObjectFile(b.path(libiconv_lib_path));
|
mod.addObjectFile(b.path(libiconv_lib_path));
|
||||||
mod.addIncludePath(b.path(libiconv_include_path));
|
mod.addIncludePath(b.path(libiconv_include_path));
|
||||||
@@ -423,7 +459,7 @@ fn moduleNetSurf(b: *Build, mod: *Build.Module) !void {
|
|||||||
const lib_path = try std.fmt.allocPrint(
|
const lib_path = try std.fmt.allocPrint(
|
||||||
b.allocator,
|
b.allocator,
|
||||||
mimalloc ++ "/out/{s}-{s}/lib/libmimalloc.a",
|
mimalloc ++ "/out/{s}-{s}/lib/libmimalloc.a",
|
||||||
.{ @tagName(os), @tagName(arch) },
|
.{ os, arch },
|
||||||
);
|
);
|
||||||
mod.addObjectFile(b.path(lib_path));
|
mod.addObjectFile(b.path(lib_path));
|
||||||
mod.addIncludePath(b.path(mimalloc ++ "/include"));
|
mod.addIncludePath(b.path(mimalloc ++ "/include"));
|
||||||
@@ -434,7 +470,7 @@ fn moduleNetSurf(b: *Build, mod: *Build.Module) !void {
|
|||||||
const ns_include_path = try std.fmt.allocPrint(
|
const ns_include_path = try std.fmt.allocPrint(
|
||||||
b.allocator,
|
b.allocator,
|
||||||
ns ++ "/out/{s}-{s}/include",
|
ns ++ "/out/{s}-{s}/include",
|
||||||
.{ @tagName(os), @tagName(arch) },
|
.{ os, arch },
|
||||||
);
|
);
|
||||||
mod.addIncludePath(b.path(ns_include_path));
|
mod.addIncludePath(b.path(ns_include_path));
|
||||||
|
|
||||||
@@ -448,7 +484,7 @@ fn moduleNetSurf(b: *Build, mod: *Build.Module) !void {
|
|||||||
const ns_lib_path = try std.fmt.allocPrint(
|
const ns_lib_path = try std.fmt.allocPrint(
|
||||||
b.allocator,
|
b.allocator,
|
||||||
ns ++ "/out/{s}-{s}/lib/" ++ lib ++ ".a",
|
ns ++ "/out/{s}-{s}/lib/" ++ lib ++ ".a",
|
||||||
.{ @tagName(os), @tagName(arch) },
|
.{ os, arch },
|
||||||
);
|
);
|
||||||
mod.addObjectFile(b.path(ns_lib_path));
|
mod.addObjectFile(b.path(ns_lib_path));
|
||||||
mod.addIncludePath(b.path(ns ++ "/" ++ lib ++ "/src"));
|
mod.addIncludePath(b.path(ns ++ "/" ++ lib ++ "/src"));
|
||||||
@@ -521,7 +557,7 @@ fn buildMbedtls(b: *Build, m: *Build.Module) !void {
|
|||||||
mbedtls.addIncludePath(b.path(root ++ "include"));
|
mbedtls.addIncludePath(b.path(root ++ "include"));
|
||||||
mbedtls.addIncludePath(b.path(root ++ "library"));
|
mbedtls.addIncludePath(b.path(root ++ "library"));
|
||||||
|
|
||||||
mbedtls.addCSourceFiles(.{ .flags = &.{}, .files = &.{
|
mbedtls.addCSourceFiles(.{ .flags = &.{"-Wno-nullability-completeness"}, .files = &.{
|
||||||
root ++ "library/aes.c",
|
root ++ "library/aes.c",
|
||||||
root ++ "library/aesni.c",
|
root ++ "library/aesni.c",
|
||||||
root ++ "library/aesce.c",
|
root ++ "library/aesce.c",
|
||||||
@@ -675,6 +711,12 @@ fn buildNghttp2(b: *Build, m: *Build.Module) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn buildCurl(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(.{
|
const curl = b.addLibrary(.{
|
||||||
.name = "curl",
|
.name = "curl",
|
||||||
.root_module = m,
|
.root_module = m,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/84cdca7cd9065f67c7933388f2091810fc485bc6.tar.gz",
|
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/84cdca7cd9065f67c7933388f2091810fc485bc6.tar.gz",
|
||||||
.hash = "v8-0.0.0-xddH67vcAwCuN2gBsAO8TBzEw523KMroIKGrdZwc-Q-y",
|
.hash = "v8-0.0.0-xddH67vcAwCuN2gBsAO8TBzEw523KMroIKGrdZwc-Q-y",
|
||||||
},
|
},
|
||||||
//.v8 = .{ .path = "../zig-v8-fork" }
|
//.v8 = .{ .path = "../zig-v8-fork" },
|
||||||
.@"ada-singleheader" = .{
|
.@"ada-singleheader" = .{
|
||||||
.url = "https://github.com/ada-url/ada/releases/download/v3.3.0/singleheader.zip",
|
.url = "https://github.com/ada-url/ada/releases/download/v3.3.0/singleheader.zip",
|
||||||
.hash = "N-V-__8AAPmhFAAw64ALjlzd5YMtzpSrmZ6KymsT84BKfB4s",
|
.hash = "N-V-__8AAPmhFAAw64ALjlzd5YMtzpSrmZ6KymsT84BKfB4s",
|
||||||
|
|||||||
@@ -98,6 +98,11 @@ fn getAndMakeAppDir(allocator: Allocator) ?[]const u8 {
|
|||||||
if (@import("builtin").is_test) {
|
if (@import("builtin").is_test) {
|
||||||
return allocator.dupe(u8, "/tmp") catch unreachable;
|
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| {
|
const app_dir_path = std.fs.getAppDataDir(allocator, "lightpanda") catch |err| {
|
||||||
log.warn(.app, "get data dir", .{ .err = err });
|
log.warn(.app, "get data dir", .{ .err = err });
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -75,8 +75,17 @@ pub const Server = struct {
|
|||||||
self.listener = listener;
|
self.listener = listener;
|
||||||
|
|
||||||
try posix.setsockopt(listener, posix.SOL.SOCKET, posix.SO.REUSEADDR, &std.mem.toBytes(@as(c_int, 1)));
|
try posix.setsockopt(listener, posix.SOL.SOCKET, posix.SO.REUSEADDR, &std.mem.toBytes(@as(c_int, 1)));
|
||||||
if (@hasDecl(posix.TCP, "NODELAY")) {
|
switch (builtin.os.tag) {
|
||||||
try posix.setsockopt(listener, posix.IPPROTO.TCP, posix.TCP.NODELAY, &std.mem.toBytes(@as(c_int, 1)));
|
.ios => {
|
||||||
|
// TCP.NODELAY is not defined for iOS in posix module
|
||||||
|
const TCP_NODELAY = 0x01;
|
||||||
|
try posix.setsockopt(listener, posix.IPPROTO.TCP, TCP_NODELAY, &std.mem.toBytes(@as(c_int, 1)));
|
||||||
|
},
|
||||||
|
else => {
|
||||||
|
if (@hasDecl(posix.TCP, "NODELAY")) {
|
||||||
|
try posix.setsockopt(listener, posix.IPPROTO.TCP, posix.TCP.NODELAY, &std.mem.toBytes(@as(c_int, 1)));
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
try posix.bind(listener, &address.any, address.getOsSockLen());
|
try posix.bind(listener, &address.any, address.getOsSockLen());
|
||||||
|
|||||||
Reference in New Issue
Block a user