diff --git a/.github/workflows/dist.yml b/.github/workflows/dist.yml index b768a2c..8d42e62 100644 --- a/.github/workflows/dist.yml +++ b/.github/workflows/dist.yml @@ -9,5 +9,12 @@ jobs: runs-on: ubuntu-latest steps: - - name: Placeholder - run: true \ No newline at end of file + - uses: actions/checkout@v4 + + - name: Build artifact + run: ./build.sh + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + path: dcraw.wasm.gz \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a7f04db --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +build*/ +libjpeg-turbo*/ +binaryen*/ +wasi-sdk*/ \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..14a9687 --- /dev/null +++ b/build.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +set -Eeuo pipefail + +JVER=3.0.1 +if [ ! -d "libjpeg-turbo-$JVER" ]; then + url="https://downloads.sourceforge.net/project/libjpeg-turbo/$JVER/libjpeg-turbo-$JVER.tar.gz" + curl -#L "$url" | tar xz +fi + +BVER=version_116 +if [ ! -d "binaryen-$BVER" ]; then + url="https://github.com/WebAssembly/binaryen/releases/download/$BVER/binaryen-$BVER-x86_64-linux.tar.gz" + curl -#L "$url" | tar xz +fi +PATH="$PWD/binaryen-$BVER/bin:$PATH" + +WVER=20 +if [ ! -d "wasi-sdk-$WVER.0" ]; then + url="https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$WVER/wasi-sdk-$WVER.0-linux.tar.gz" + curl -#L "$url" | tar xz +fi +WASI_SDK_PREFIX="$PWD/wasi-sdk-$WVER.0" +PATH="$WASI_SDK_PREFIX/bin:$PATH" + +mkdir -p build_wasm +pushd build_wasm +cmake "-DWASI_SDK_PREFIX=$WASI_SDK_PREFIX" "-DCMAKE_TOOLCHAIN_FILE=$WASI_SDK_PREFIX/share/cmake/wasi-sdk.cmake" \ + -G"Unix Makefiles" "../libjpeg-turbo-$JVER" \ + -D"CMAKE_C_FLAGS_RELEASE=-Oz -g0 -DNDEBUG" \ + -D"WITH_SIMD=0" \ + -D"WITH_TURBOJPEG=0" + +make -j jpeg-static +clang --target=wasm32-wasi -g0 -flto \ + -Oz -o dcraw.wasm ../dcraw.c -DNO_JASPER -DNO_LCMS \ + -I. -I"../libjpeg-turbo-$JVER" \ + CMakeFiles/jpeg*-static.dir/*.obj +popd + +wasm-opt build_wasm/dcraw.wasm -O4 -o dcraw.wasm +gzip -9f dcraw.wasm