This page assumes you are using a Mac with the M1 chip and want to compile a custom version of the Saito WASM library and have it used by a locally-compiled version of Saito Javascript. If you are trying to compile Saito-WASM on another OS please see our standard installation guide.
PLEASE NOTE: unless you know why you are here you probably don't need to do this! The default version of Saito comes bundled with a pre-compiled version of our WASM library. This bundled version will work out-of-the-box. These steps are only necessary if you want to modify the core Rust software and use or distribute your changes within our standard NodeJS client.
Before starting, ensure:
nodeJS and npm are installed.
homebrew is installed - install
you have cloned the saito repository
brew install llvm
export CC=/opt/homebrew/opt/llvm/bin/clang
cd saito-rust-workspace/saito-wasm
npm i -g wasm-pack
CC=/opt/homebrew/opt/llvm/bin/clang AR=/opt/homebrew/opt/llvm/bin/llvm-ar wasm-pack build --target web --out-dir wasm_build/deps/pkg/
npm install
npm run build
npm link 
If you run into a problem compiling or linking after installing software, please restart your machine. The following may also assist (restart after):
rustup target add wasm32-unknown-unknown
cargo install wasm-pack
cargo install wasm-opt
cd saito-rust-workspace/saito-js
npm install
npm link saito-wasm
npm run build
cd dist
npm link
cd saito-lite-rust
npm install
npm link saito-js
npm run go
If you get a problem when compiling Saito-Lite-Rust, you may need to comment-out the following lines from the file /saito-js/lib/wasm_wrapper.ts. You will then need to recompile saito-js by running npm run build in your saito-js directory as shown in Step 2 above:
export default class WasmWrapper<T> {
  public instance: T;
  private static createdCounter = 0;
  private static deletedCounter = 0;
  // private static registry = new FinalizationRegistry((value: any) => {
  //   // WasmWrapper.deletedCounter++;
  //   // console.log(deleted : ${WasmWrapper.deletedCounter} created : ${WasmWrapper.createdCounter} ptr : ${value.__wbg_ptr});
  //   // @ts-ignore
  //   if (value && !!value.__wbg_ptr) {
  //     value.free();
  //   }
  // });
  constructor(instance: T) {
    this.instance = instance;
    WasmWrapper.createdCounter++;
  }
  // free() {
  //   // @ts-ignore
  //   this.instance.free();
  // }
}
This step is completely optional, but if you're not sure that your machine is using your local copy of saito-js, you can check by looking for the initialize() function in the file /saito-rust-workspace/saito-wasm/src/saitowasm.rs and editing the call to info() somewhere around line 338 to print a custom message such as info!("initializing local copy of saito-wasm!");.
Repeat Steps 1-3 above and when you run Saito-Lite-Rust you should see your log message printed instead of the default.
wasm-unknown-unknown issues - seee https://github.com/briansmith/ring/issues/1824