build.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/sh
  2. set -ex
  3. BASEDIR="$(dirname "$0")"
  4. TARGET_VERSION="0.1.2"
  5. cd "$BASEDIR/.."
  6. git clean -fdx
  7. mkdir -p vendor
  8. cd vendor
  9. get_tgz () {
  10. TARGET_PLATFORM="$1"
  11. TARGET="node-v$TARGET_VERSION-$TARGET_PLATFORM-x64"
  12. ARCHIVE="$TARGET.tar.gz"
  13. URL="https://nodejs.org/dist/v$TARGET_VERSION/$ARCHIVE"
  14. TARGET_NODE="$TARGET/bin/node"
  15. wget "$URL"
  16. tar -xvf "$ARCHIVE" "$TARGET_NODE"
  17. rm -f "$ARCHIVE"
  18. }
  19. get_zip () {
  20. TARGET_PLATFORM="$1"
  21. TARGET="node-v$TARGET_VERSION-$TARGET_PLATFORM-x64"
  22. ARCHIVE="$TARGET.zip"
  23. URL="https://nodejs.org/dist/v$TARGET_VERSION/$ARCHIVE"
  24. TARGET_NODE="$TARGET/node.exe"
  25. wget "$URL"
  26. unzip "$ARCHIVE" "$TARGET_NODE"
  27. rm -f "$ARCHIVE"
  28. }
  29. get_tgz darwin
  30. get_tgz linux
  31. get_zip win
  32. cd ..
  33. # Avoid building anything from source.
  34. npm ci --only=prod --ignore-scripts --no-audit --no-fund
  35. # More trouble than it's worth :)
  36. rm -rf ./node_modules/sharp
  37. export GOARCH="amd64"
  38. # Darwin (shell script)
  39. export GOOS="darwin"
  40. OUTFILE="oasis-$GOOS-$GOARCH"
  41. go build -ldflags "-X main.node=vendor/node-v$TARGET_VERSION-darwin-x64/bin/node" -o "$OUTFILE" scripts/oasis.go
  42. chmod +x "$OUTFILE"
  43. # Linux (ELF executable)
  44. export GOOS="linux"
  45. OUTFILE="oasis-$GOOS-$GOARCH"
  46. go build -ldflags "-X main.node=vendor/node-v$TARGET_VERSION-linux-x64/bin/node" -o "$OUTFILE" scripts/oasis.go
  47. chmod +x "$OUTFILE"
  48. # Windows (batch file)
  49. export GOOS="windows"
  50. OUTFILE="oasis-$GOOS-$GOARCH.exe"
  51. go build -ldflags "-X main.node=vendor\\node-v$TARGET_VERSION-win-x64\\bin\\node" -o "$OUTFILE" scripts/oasis.go
  52. chmod +x "$OUTFILE"
  53. # I think if the zip already exists it's adding files to the existing archive?
  54. ZIP_PATH="/tmp/oasis-x64.zip"
  55. rm -f "$ZIP_PATH"
  56. zip -r "$ZIP_PATH" . -x ".git/**"
  57. git clean -fdx