diff --git a/scripts/build.sh b/scripts/build.sh index 8b7607c..6832570 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -2,39 +2,45 @@ set -ex - BASEDIR="$(dirname "$0")" cd "$BASEDIR/.." TARGET_VERSION="12.16.1" -TARGET_PLATFORM="$1" -TARGET_ARCH="$2" - -echo "Target version: $TARGET_VERSION" -echo "Target platform: $TARGET_PLATFORM" -echo "Target arch: $TARGET_ARCH" - -if [ "$TARGET_ARCH" == "x64" ]; then - GCC_ARCH="x86-64" -else - echo "Unsupported architecture: $TARGET_ARCH" - exit 1 -fi git clean -fdx mkdir -p vendor cd vendor -TARGET="node-v$TARGET_VERSION-$TARGET_PLATFORM-$TARGET_ARCH" -TARBALL="$TARGET.tar.gz" -URL="https://nodejs.org/dist/v$TARGET_VERSION/$TARBALL" -TARGET_NODE="$TARGET/bin/node" +get_tgz () { + TARGET_PLATFORM="$1" + TARGET="node-v$TARGET_VERSION-$TARGET_PLATFORM-x64" + ARCHIVE="$TARGET.tar.gz" + URL="https://nodejs.org/dist/v$TARGET_VERSION/$ARCHIVE" + TARGET_NODE="$TARGET/bin/node" + + wget "$URL" + tar -xvf "$ARCHIVE" "$TARGET_NODE" + rm -rf "$ARCHIVE" +} + +get_zip () { + TARGET_PLATFORM="$1" + TARGET="node-v$TARGET_VERSION-$TARGET_PLATFORM-x64" + ARCHIVE="$TARGET.zip" + URL="https://nodejs.org/dist/v$TARGET_VERSION/$ARCHIVE" + TARGET_NODE="$TARGET/node.exe" + + wget "$URL" + unzip "$ARCHIVE" "$TARGET_NODE" + rm -rf "$ARCHIVE" +} + +get_tgz darwin +get_tgz linux +get_zip win -wget "$URL" -tar -xvf "$TARBALL" "$TARGET_NODE" -rm -rf "$TARBALL" cd .. # Avoid building anything from source. @@ -42,19 +48,31 @@ npm ci --only=prod --ignore-scripts --no-audit --no-fund # More trouble than it's worth :) rm -rf ./node_modules/sharp -BINARY_NAME="oasis" +# Darwin (shell script) +cat << EOF > oasis-darwin-x64 +#!/bin/sh +exec vendor/node-v$TARGET_VERSION-darwin-x64/bin/node src "\$@" +EOF +chmod +x oasis-darwin-x64 -VENDOR_NODE="vendor/$TARGET_NODE" +# Linux (ELF executable) +clang scripts/oasis.c -Wall -g -no-pie -o "oasis-linux-x64" --target=x86_64-linux-unknown -D "NODE=\"vendor/node-v$TARGET_VERSION-linux-x64/bin/node\"" +chmod +x oasis-linux-x64 -gcc scripts/oasis.c -Wall -g -no-pie -o "$BINARY_NAME" -march="$GCC_ARCH" -D "NODE=\"$VENDOR_NODE\"" +# Windows (batch file) +cat << EOF > oasis-win-x64.bat +vendor\\node-v$TARGET_VERSION-darwin-x64\\bin\\node src "\$@" +EOF -chmod +x "$BINARY_NAME" +chmod +x oasis-win-x64.bat # I think if the zip already exists it's adding files to the existing archive? -ZIP_PATH="/tmp/oasis-$TARGET_PLATFORM-$TARGET_ARCH.zip" +ZIP_PATH="/tmp/oasis-x64.zip" rm -f "$ZIP_PATH" zip -r "$ZIP_PATH" . -x ".git/**" -rm -f oasis +rm -f oasis-darwin-x64 +rm -f oasis-linux-x64 +rm -f oasis-win-x64.bat rm -rf vendor