#!/bin/sh
# Rebuilds one2json.wasm from one2json-1.0.0-source.tar.xz: our MPL-2.0 wrapper (one2json) plus the
# unmodified onenote_parser 2.0.0 source (github.com/msiemens/onenote.rs, commit 42c8acef2bf88f3f5ccbb2a0bd691599adfa862c).
# Needs Rust stable (built with rustc 1.99.1) and the wasm32-unknown-unknown target.
# Cargo hashes the absolute path of path dependencies, so the build always runs in /tmp/one2json-build
# to give a byte-identical wasm.
set -e
here=$(pwd)
rm -rf /tmp/one2json-build && mkdir -p /tmp/one2json-build
tar -xJf one2json-1.0.0-source.tar.xz -C /tmp/one2json-build
cd /tmp/one2json-build/one2json-src/one2json
RUSTFLAGS="--remap-path-prefix=/tmp/one2json-build/one2json-src=/src --remap-path-prefix=${CARGO_HOME:-$HOME/.cargo}=/cargo" \
  cargo build --release --locked --lib --target wasm32-unknown-unknown
cp target/wasm32-unknown-unknown/release/one2json.wasm "$here/one2json.wasm"
