odin-nanosvg

Odin bindings to nanosvg
Log | Files | Refs | Submodules | README | LICENSE

build_libs.sh (1637B)


      1 #!/usr/bin/env bash
      2 
      3 # This script builds nanosvg into static libraries for consumption
      4 # by the Odin binding code. It relies on the zig toolchain for easy
      5 # cross compilation. Feel free to use clang natively with a couple
      6 # of tweaks.
      7 #
      8 # nanosvg contains only the parsing logic.
      9 # nanosvgrast additionally contains a simple cpu rasterizer.
     10 
     11 set -xe
     12 
     13 BASE=bin
     14 
     15 # Prepare the bin folder per target.
     16 mkdir -p $BASE/{macos,macos-arm64,windows,linux,wasm}
     17 
     18 # Setup common args.
     19 COMMON_ARGS="-DNANOSVG_IMPLEMENTATION -DNANOSVGRAST_IMPLEMENTATION -static -fPIC -ffreestanding -I./nanosvg/src"
     20 DEBUG_ARGS=" -g -O0"
     21 RELEASE_ARGS=" -O3"
     22 
     23 # Configure args based on build type: {release,debug}.
     24 case "$1" in
     25   debug)
     26     COMMON_ARGS=$COMMON_ARGS$DEBUG_ARGS
     27   ;;
     28   release)
     29     COMMON_ARGS=$COMMON_ARGS$RELEASE_ARGS
     30   ;;
     31   *)
     32     COMMON_ARGS=$COMMON_ARGS$RELEASE_ARGS
     33   ;;
     34 esac
     35 
     36 build_lib() {
     37   # Copy header to source file for compilation.
     38   cp ./nanosvg/src/$1.h $1.c;
     39 
     40   # Use zig cc for easy cross compilation.
     41 
     42   # Intel Mac
     43   zig cc -c -o $1.o -target x86_64-macos-none  $COMMON_ARGS $1.c && ar r $BASE/macos/$1.a $1.o;
     44 
     45   # ARM Mac
     46   zig cc -c -o $1.o -target aarch64-macos-none $COMMON_ARGS $1.c && ar r $BASE/macos-arm64/$1.a $1.o;
     47 
     48   # Linux
     49   zig cc -c -o $1.o -target aarch64-linux-musl $COMMON_ARGS $1.c && ar r $BASE/linux/$1.a $1.o;
     50 
     51   # WASM
     52   zig cc -c -o $1.o -target wasm32-wasi-musl   $COMMON_ARGS $1.c && cp $1.o $BASE/wasm/$1.o;
     53 
     54   # x64 Windows
     55   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;
     56 }
     57 
     58 build_lib nanosvg
     59 build_lib nanosvgrast
     60 
     61 rm *.{o,c} || true;