Merge pull request #291 from lightpanda-io/multi_build

Multi build
This commit is contained in:
Francis Bouvier
2024-11-06 18:17:24 +01:00
committed by GitHub
4 changed files with 105 additions and 59 deletions

4
.gitignore vendored
View File

@@ -1,7 +1,5 @@
zig-cache zig-cache
/.zig-cache/ /.zig-cache/
zig-out zig-out
/vendor/netsurf/build/ /vendor/netsurf/out
/vendor/netsurf/lib/
/vendor/netsurf/include/
/vendor/libiconv/ /vendor/libiconv/

View File

@@ -55,7 +55,8 @@ RUN cd vendor/zig-js-runtime && \
git submodule init && \ git submodule init && \
git submodule update --recursive git submodule update --recursive
RUN make install-netsurf && \ RUN make install-libiconv && \
make install-netsurf && \
make install-mimalloc make install-mimalloc
# download and install v8 # download and install v8

View File

@@ -4,6 +4,25 @@
ZIG := zig ZIG := zig
BC := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) BC := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
# OS and ARCH
kernel = $(shell uname -ms)
ifeq ($(kernel), Darwin arm64)
OS := macos
ARCH := aarch64
else ifeq ($(kernel), Linux aarch64)
OS := linux
ARCH := aarch64
else ifeq ($(kernel), Linux arm64)
OS := linux
ARCH := aarch64
else ifeq ($(kernel), Linux x86_64)
OS := linux
ARCH := x86_64
else
$(error "Unhandled kernel: $(kernel)")
endif
# Infos # Infos
# ----- # -----
.PHONY: help .PHONY: help
@@ -26,30 +45,11 @@ help:
.PHONY: build build-dev run run-release shell test bench download-zig wpt .PHONY: build build-dev run run-release shell test bench download-zig wpt
zig_version = $(shell grep 'recommended_zig_version = "' "vendor/zig-js-runtime/build.zig" | cut -d'"' -f2) zig_version = $(shell grep 'recommended_zig_version = "' "vendor/zig-js-runtime/build.zig" | cut -d'"' -f2)
kernel = $(shell uname -ms)
## Download the zig recommended version ## Download the zig recommended version
download-zig: download-zig:
ifeq ($(kernel), Darwin x86_64) $(eval url = "https://ziglang.org/builds/zig-$(OS)-$(ARCH)-$(zig_version).tar.xz")
$(eval target="macos") $(eval dest = "/tmp/zig-$(OS)-$(ARCH)-$(zig_version).tar.xz")
$(eval arch="x86_64")
else ifeq ($(kernel), Darwin arm64)
$(eval target="macos")
$(eval arch="aarch64")
else ifeq ($(kernel), Linux aarch64)
$(eval target="linux")
$(eval arch="aarch64")
else ifeq ($(kernel), Linux arm64)
$(eval target="linux")
$(eval arch="aarch64")
else ifeq ($(kernel), Linux x86_64)
$(eval target="linux")
$(eval arch="x86_64")
else
$(error "Unhandled kernel: $(kernel)")
endif
$(eval url = "https://ziglang.org/builds/zig-$(target)-$(arch)-$(zig_version).tar.xz")
$(eval dest = "/tmp/zig-$(target)-$(arch)-$(zig_version).tar.xz")
@printf "\e[36mDownload zig version $(zig_version)...\e[0m\n" @printf "\e[36mDownload zig version $(zig_version)...\e[0m\n"
@curl -o "$(dest)" -L "$(url)" || (printf "\e[33mBuild ERROR\e[0m\n"; exit 1;) @curl -o "$(dest)" -L "$(url)" || (printf "\e[33mBuild ERROR\e[0m\n"; exit 1;)
@printf "\e[33mDownloaded $(dest)\e[0m\n" @printf "\e[33mDownloaded $(dest)\e[0m\n"
@@ -100,10 +100,10 @@ test:
.PHONY: install-dev install .PHONY: install-dev install
## Install and build dependencies for release ## Install and build dependencies for release
install: install-submodule install-zig-js-runtime install-netsurf install-mimalloc install: install-submodule install-zig-js-runtime install-libiconv install-netsurf install-mimalloc
## Install and build dependencies for dev ## Install and build dependencies for dev
install-dev: install-submodule install-zig-js-runtime-dev install-netsurf-dev install-mimalloc-dev install-dev: install-submodule install-zig-js-runtime-dev install-libiconv install-netsurf-dev install-mimalloc-dev
install-netsurf-dev: _install-netsurf install-netsurf-dev: _install-netsurf
install-netsurf-dev: OPTCFLAGS := -O0 -g -DNDEBUG install-netsurf-dev: OPTCFLAGS := -O0 -g -DNDEBUG
@@ -111,14 +111,16 @@ install-netsurf-dev: OPTCFLAGS := -O0 -g -DNDEBUG
install-netsurf: _install-netsurf install-netsurf: _install-netsurf
install-netsurf: OPTCFLAGS := -DNDEBUG install-netsurf: OPTCFLAGS := -DNDEBUG
BC_NS := $(BC)vendor/netsurf BC_NS := $(BC)vendor/netsurf/out/$(OS)-$(ARCH)
ICONV := $(BC)vendor/libiconv ICONV := $(BC)vendor/libiconv/out/$(OS)-$(ARCH)
# TODO: add Linux iconv path (I guess it depends on the distro) # TODO: add Linux iconv path (I guess it depends on the distro)
# TODO: this way of linking libiconv is not ideal. We should have a more generic way # TODO: this way of linking libiconv is not ideal. We should have a more generic way
# and stick to a specif version. Maybe build from source. Anyway not now. # and stick to a specif version. Maybe build from source. Anyway not now.
_install-netsurf: install-libiconv _install-netsurf: clean-netsurf
@printf "\e[36mInstalling NetSurf...\e[0m\n" && \ @printf "\e[36mInstalling NetSurf...\e[0m\n" && \
ls $(ICONV) 1> /dev/null || (printf "\e[33mERROR: you need to install libiconv in your system (on MacOS on with Homebrew)\e[0m\n"; exit 1;) && \ ls $(ICONV)/lib/libiconv.a 1> /dev/null || (printf "\e[33mERROR: you need to execute 'make install-libiconv'\e[0m\n"; exit 1;) && \
mkdir -p $(BC_NS) && \
cp -R vendor/netsurf/share $(BC_NS) && \
export PREFIX=$(BC_NS) && \ export PREFIX=$(BC_NS) && \
export OPTLDFLAGS="-L$(ICONV)/lib" && \ export OPTLDFLAGS="-L$(ICONV)/lib" && \
export OPTCFLAGS="$(OPTCFLAGS) -I$(ICONV)/include" && \ export OPTCFLAGS="$(OPTCFLAGS) -I$(ICONV)/include" && \
@@ -156,10 +158,7 @@ _install-netsurf: install-libiconv
clean-netsurf: clean-netsurf:
@printf "\e[36mCleaning NetSurf build...\e[0m\n" && \ @printf "\e[36mCleaning NetSurf build...\e[0m\n" && \
cd vendor/netsurf && \ rm -Rf $(BC_NS)
rm -R build && \
rm -R lib && \
rm -R include
test-netsurf: test-netsurf:
@printf "\e[36mTesting NetSurf...\e[0m\n" && \ @printf "\e[36mTesting NetSurf...\e[0m\n" && \
@@ -169,14 +168,22 @@ test-netsurf:
cd vendor/netsurf/libdom && \ cd vendor/netsurf/libdom && \
BUILDDIR=$(BC_NS)/build/libdom make test BUILDDIR=$(BC_NS)/build/libdom make test
install-libiconv: download-libiconv:
ifeq ("$(wildcard vendor/libiconv/lib/libiconv.a)","") ifeq ("$(wildcard vendor/libiconv/libiconv-1.17)","")
@mkdir -p vendor/libiconv @mkdir -p vendor/libiconv
@cd vendor/libiconv && \ @cd vendor/libiconv && \
curl https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.17.tar.gz | tar -xvzf - curl https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.17.tar.gz | tar -xvzf -
endif
install-libiconv: download-libiconv clean-libiconv
@cd vendor/libiconv/libiconv-1.17 && \ @cd vendor/libiconv/libiconv-1.17 && \
./configure --prefix=$(BC)vendor/libiconv --enable-static && \ ./configure --prefix=$(ICONV) --enable-static && \
make && make install make && make install
clean-libiconv:
ifneq ("$(wildcard vendor/libiconv/libiconv-1.17/Makefile)","")
@cd vendor/libiconv/libiconv-1.17 && \
make clean
endif endif
install-zig-js-runtime-dev: install-zig-js-runtime-dev:
@@ -188,24 +195,28 @@ install-zig-js-runtime:
make install make install
.PHONY: _build_mimalloc .PHONY: _build_mimalloc
_build_mimalloc:
@cd vendor/mimalloc && \ MIMALLOC := $(BC)vendor/mimalloc/out/$(OS)-$(ARCH)
mkdir -p out/include && \ _build_mimalloc: clean-mimalloc
cp include/mimalloc.h out/include/ && \ @mkdir -p $(MIMALLOC)/build && \
cd out && \ 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
install-mimalloc-dev: _build_mimalloc install-mimalloc-dev: _build_mimalloc
install-mimalloc-dev: OPTS=-DCMAKE_BUILD_TYPE=Debug install-mimalloc-dev: OPTS=-DCMAKE_BUILD_TYPE=Debug
install-mimalloc-dev: install-mimalloc-dev:
@cd vendor/mimalloc/out && \ @cd $(MIMALLOC) && \
mv libmimalloc-debug.a libmimalloc.a mv build/libmimalloc-debug.a lib/libmimalloc.a
install-mimalloc: _build_mimalloc install-mimalloc: _build_mimalloc
install-mimalloc:
@cd $(MIMALLOC) && \
mv build/libmimalloc.a lib/libmimalloc.a
clean-mimalloc: clean-mimalloc:
@rm -fr vendor/mimalloc/lib/* @rm -Rf $(MIMALLOC)/build
## Init and update git submodule ## Init and update git submodule
install-submodule: install-submodule:

View File

@@ -146,15 +146,16 @@ fn common(
step: *std.Build.Step.Compile, step: *std.Build.Step.Compile,
options: jsruntime.Options, options: jsruntime.Options,
) !void { ) !void {
const target = step.root_module.resolved_target.?;
const jsruntimemod = try jsruntime_pkgs.module( const jsruntimemod = try jsruntime_pkgs.module(
b, b,
options, options,
step.root_module.optimize.?, step.root_module.optimize.?,
step.root_module.resolved_target.?, target,
); );
step.root_module.addImport("jsruntime", jsruntimemod); step.root_module.addImport("jsruntime", jsruntimemod);
const netsurf = moduleNetSurf(b); const netsurf = try moduleNetSurf(b, target);
netsurf.addImport("jsruntime", jsruntimemod); netsurf.addImport("jsruntime", jsruntimemod);
step.root_module.addImport("netsurf", netsurf); step.root_module.addImport("netsurf", netsurf);
@@ -164,20 +165,40 @@ fn common(
step.root_module.addImport("tls", tlsmod); step.root_module.addImport("tls", tlsmod);
} }
fn moduleNetSurf(b: *std.Build) *std.Build.Module { fn moduleNetSurf(b: *std.Build, target: std.Build.ResolvedTarget) !*std.Build.Module {
const mod = b.addModule("netsurf", .{ const mod = b.addModule("netsurf", .{
.root_source_file = b.path("src/netsurf/netsurf.zig"), .root_source_file = b.path("src/netsurf/netsurf.zig"),
.target = target,
}); });
const os = target.result.os.tag;
const arch = target.result.cpu.arch;
// iconv // iconv
mod.addObjectFile(b.path("vendor/libiconv/lib/libiconv.a")); const libiconv_lib_path = try std.fmt.allocPrint(
mod.addIncludePath(b.path("vendor/libiconv/include")); mod.owner.allocator,
"vendor/libiconv/out/{s}-{s}/lib/libiconv.a",
.{ @tagName(os), @tagName(arch) },
);
const libiconv_include_path = try std.fmt.allocPrint(
mod.owner.allocator,
"vendor/libiconv/out/{s}-{s}/lib/libiconv.a",
.{ @tagName(os), @tagName(arch) },
);
mod.addObjectFile(b.path(libiconv_lib_path));
mod.addIncludePath(b.path(libiconv_include_path));
// mimalloc // mimalloc
mod.addImport("mimalloc", moduleMimalloc(b)); mod.addImport("mimalloc", (try moduleMimalloc(b, target)));
// netsurf libs // netsurf libs
const ns = "vendor/netsurf"; const ns = "vendor/netsurf";
mod.addIncludePath(b.path(ns ++ "/include")); const ns_include_path = try std.fmt.allocPrint(
mod.owner.allocator,
ns ++ "/out/{s}-{s}/include",
.{ @tagName(os), @tagName(arch) },
);
mod.addIncludePath(b.path(ns_include_path));
const libs: [4][]const u8 = .{ const libs: [4][]const u8 = .{
"libdom", "libdom",
@@ -186,20 +207,35 @@ fn moduleNetSurf(b: *std.Build) *std.Build.Module {
"libwapcaplet", "libwapcaplet",
}; };
inline for (libs) |lib| { inline for (libs) |lib| {
mod.addObjectFile(b.path(ns ++ "/lib/" ++ lib ++ ".a")); const ns_lib_path = try std.fmt.allocPrint(
mod.owner.allocator,
ns ++ "/out/{s}-{s}/lib/" ++ lib ++ ".a",
.{ @tagName(os), @tagName(arch) },
);
mod.addObjectFile(b.path(ns_lib_path));
mod.addIncludePath(b.path(ns ++ "/" ++ lib ++ "/src")); mod.addIncludePath(b.path(ns ++ "/" ++ lib ++ "/src"));
} }
return mod; return mod;
} }
fn moduleMimalloc(b: *std.Build) *std.Build.Module { fn moduleMimalloc(b: *std.Build, target: std.Build.ResolvedTarget) !*std.Build.Module {
const mod = b.addModule("mimalloc", .{ const mod = b.addModule("mimalloc", .{
.root_source_file = b.path("src/mimalloc/mimalloc.zig"), .root_source_file = b.path("src/mimalloc/mimalloc.zig"),
.target = target,
}); });
mod.addObjectFile(b.path("vendor/mimalloc/out/libmimalloc.a")); const os = target.result.os.tag;
mod.addIncludePath(b.path("vendor/mimalloc/out/include")); const arch = target.result.cpu.arch;
const mimalloc = "vendor/mimalloc";
const lib_path = try std.fmt.allocPrint(
mod.owner.allocator,
mimalloc ++ "/out/{s}-{s}/lib/libmimalloc.a",
.{ @tagName(os), @tagName(arch) },
);
mod.addObjectFile(b.path(lib_path));
mod.addIncludePath(b.path(mimalloc ++ "/include"));
return mod; return mod;
} }