#!/bin/bash
[% INCLUDE 'build_common' %]

# We already packed compiler-rt alongside clang.
# Just let the build system know it's there.
touch build/compiler-rt.BUILT

make \
  LLVM_PROJ_DIR=$LLVM_HOME \
  PREFIX=/wasi \
  build/libcxx.BUILT \
  NINJA_FLAGS='-j[% c("num_procs") %]'

mv build/install/wasi/share/wasi-sysroot/* $distdir/
# Add wasip1 directories to wasi sysroot and compiler-rt.
# See firefox commit 630a929dcf8de5f46d3affe52607ed588276393a
cp -r $distdir/lib/wasm32-wasi $distdir/lib/wasm32-wasip1

cd /var/tmp/dist
[% c('tar', {
        tar_src => [ project ],
        tar_args => '-caf ' _ dest_dir _ '/' _ c('filename'),
    }) %]
