commit 1b11c573499002ec2f26ab68dcde742f0b63bb7e
parent 71cbe2cef0e6ea8e1173912c5b161f24d73fe2d7
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date: Mon, 7 Jul 2025 12:28:56 -0300
build: support building rasterizer
Diffstat:
1 file changed, 24 insertions(+), 16 deletions(-)
diff --git a/build_libs.sh b/build_libs.sh
@@ -4,19 +4,19 @@
# by the Odin binding code. It relies on the zig toolchain for easy
# cross compilation. Feel free to use clang natively with a couple
# of tweaks.
+#
+# nanosvg contains only the parsing logic.
+# nanosvgrast additionally contains a simple cpu rasterizer.
set -xe
BASE=bin
-# Copy header to source file for compilation.
-cp ./nanosvg/src/nanosvg.h nanosvg.c;
-
# Prepare the bin folder per target.
mkdir -p $BASE/{macos,macos-arm64,windows,linux,wasm}
# Setup common args.
-COMMON_ARGS="-DNANOSVG_IMPLEMENTATION -static -fPIC -ffreestanding"
+COMMON_ARGS="-DNANOSVG_IMPLEMENTATION -DNANOSVGRAST_IMPLEMENTATION -static -fPIC -ffreestanding -I./nanosvg/src"
DEBUG_ARGS=" -g -O0"
RELEASE_ARGS=" -O3"
@@ -33,21 +33,29 @@ case "$1" in
;;
esac
-# Use zig cc for easy cross compilation.
+build_lib() {
+ # Copy header to source file for compilation.
+ cp ./nanosvg/src/$1.h $1.c;
+
+ # Use zig cc for easy cross compilation.
+
+ # Intel Mac
+ zig cc -c -o $1.o -target x86_64-macos-none $COMMON_ARGS $1.c && ar r $BASE/macos/$1.a $1.o;
-# Intel Mac
-zig cc -c -o nanosvg.o -target x86_64-macos-none $COMMON_ARGS nanosvg.c && ar r $BASE/macos/nanosvg.a nanosvg.o;
+ # ARM Mac
+ zig cc -c -o $1.o -target aarch64-macos-none $COMMON_ARGS $1.c && ar r $BASE/macos-arm64/$1.a $1.o;
-# ARM Mac
-zig cc -c -o nanosvg.o -target aarch64-macos-none $COMMON_ARGS nanosvg.c && ar r $BASE/macos-arm64/nanosvg.a nanosvg.o;
+ # Linux
+ zig cc -c -o $1.o -target aarch64-linux-musl $COMMON_ARGS $1.c && ar r $BASE/linux/$1.a $1.o;
-# Linux
-zig cc -c -o nanosvg.o -target aarch64-linux-musl $COMMON_ARGS nanosvg.c && ar r $BASE/linux/nanosvg.a nanosvg.o;
+ # WASM
+ zig cc -c -o $1.o -target wasm32-wasi-musl $COMMON_ARGS $1.c && cp $1.o $BASE/wasm/$1.o;
-# WASM
-zig cc -c -o nanosvg.o -target wasm32-wasi-musl $COMMON_ARGS nanosvg.c && cp nanosvg.o $BASE/wasm/nanosvg.o;
+ # x64 Windows
+ zig cc -c -o $1.o -target x86_64-windows $COMMON_ARGS -fuse-ld=llvm-lib $1.c && cp $1.o $BASE/windows/$1.lib;
+}
-# x64 Windows
-zig cc -c -o nanosvg.o -target x86_64-windows $COMMON_ARGS -fuse-ld=llvm-lib nanosvg.c && cp nanosvg.o $BASE/windows/nanosvg.lib;
+build_lib nanosvg
+build_lib nanosvgrast
-rm nanosvg.{o,c} || true;
+rm *.{o,c} || true;