release.sh raw

   1  #!/bin/bash
   2  set -e
   3  
   4  VERSION=$(git describe --tags --abbrev=0)
   5  if [ -z "$VERSION" ]; then
   6      echo "error: no git tag found" >&2
   7      exit 1
   8  fi
   9  
  10  if ! git diff --quiet HEAD --; then
  11      echo "warning: working tree is dirty" >&2
  12  fi
  13  
  14  ARCH=$(uname -m)
  15  case "$ARCH" in
  16      x86_64) ARCH=amd64 ;;
  17      aarch64) ARCH=arm64 ;;
  18      *) echo "error: unsupported arch $ARCH" >&2; exit 1 ;;
  19  esac
  20  
  21  OS=linux
  22  NAME="moxie-${VERSION}-${OS}-${ARCH}"
  23  STAGE="/tmp/${NAME}"
  24  TARBALL="/tmp/${NAME}.tar.gz"
  25  
  26  echo "building release $NAME ..." >&2
  27  
  28  # build fixpoint binary
  29  ./build.sh
  30  
  31  # verify fixpoint: compiling the source with the binary produces the same binary
  32  echo "verifying fixpoint ..." >&2
  33  MOXIEROOT="$(pwd)"
  34  export MOXIEROOT
  35  export LLVM_GLUE_PATH="$MOXIEROOT/llvm-glue/libmoxie-llvm-glue.so"
  36  rm -rf ~/.cache/moxie/pkg
  37  ./moxie build -o moxie-verify ./_mxc_stage4/
  38  if ! cmp -s moxie moxie-verify; then
  39      echo "error: fixpoint verification failed - binary not reproducible" >&2
  40      echo "  run another stage: MOXIE=./moxie ./build.sh" >&2
  41      rm -f moxie-verify
  42      exit 1
  43  fi
  44  rm -f moxie-verify
  45  echo "fixpoint verified" >&2
  46  
  47  rm -rf "$STAGE"
  48  mkdir -p "$STAGE/bin"
  49  mkdir -p "$STAGE/compiler"
  50  
  51  cp moxie "$STAGE/bin/moxie"
  52  strip "$STAGE/bin/moxie" 2>/dev/null || true
  53  
  54  # sysroot - precompiled runtime, stdlib, libs
  55  cp -a sysroot "$STAGE/sysroot"
  56  
  57  # stdlib source
  58  cp -a src "$STAGE/src"
  59  
  60  # jsruntime - WASM browser shims
  61  cp -a jsruntime "$STAGE/jsruntime"
  62  
  63  # llvm glue
  64  mkdir -p "$STAGE/llvm-glue"
  65  cp llvm-glue/libmoxie-llvm-glue.so "$STAGE/llvm-glue/"
  66  cp llvm-glue/build.sh "$STAGE/llvm-glue/"
  67  cp llvm-glue/*.cpp "$STAGE/llvm-glue/" 2>/dev/null || true
  68  
  69  # compiler source - for rebuilding from source
  70  cp _mxc_stage4/*.mx "$STAGE/compiler/"
  71  cp _mxc_stage4/host.c "$STAGE/compiler/"
  72  cp _mxc_stage4/host.bc "$STAGE/compiler/"
  73  
  74  # build script
  75  cp build.sh "$STAGE/"
  76  
  77  # SHA256 of the fixpoint binary for verification
  78  sha256sum moxie | cut -d' ' -f1 > "$STAGE/SHA256"
  79  
  80  echo "creating tarball ..." >&2
  81  tar czf "$TARBALL" -C /tmp "$NAME"
  82  
  83  SIZE=$(du -h "$TARBALL" | cut -f1)
  84  SHA=$(sha256sum "$TARBALL" | cut -d' ' -f1)
  85  echo "tarball: $TARBALL ($SIZE)" >&2
  86  echo "sha256:  $SHA" >&2
  87  
  88  # install versioned binary to ~/.local/bin
  89  BINDIR="$HOME/.local/bin"
  90  VNUM="${VERSION#v}"
  91  mkdir -p "$BINDIR"
  92  cp moxie "$BINDIR/moxie-${VNUM}"
  93  ln -sf "moxie-${VNUM}" "$BINDIR/moxie"
  94  echo "installed: $BINDIR/moxie-${VNUM} (symlink: $BINDIR/moxie)" >&2
  95  
  96  rm -rf "$STAGE"
  97  echo "release $VERSION ready at $TARBALL" >&2
  98