build.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env bash
  2. # Idempotent build script for the steamworks.js vote-support patch. Safe to re-run: every step
  3. # checks whether it already happened before doing anything.
  4. #
  5. # Usage: ./build.sh [path-to-projects-dir]
  6. # Defaults to ~/projects/private if no argument is given (matches this project's usual layout).
  7. # STEAMWORKSJS_BUILD=build makes a release build instead of the default debug one.
  8. set -euo pipefail
  9. PROJECTS_DIR="${1:-$HOME/projects/private}"
  10. PATCHES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  11. STEAMWORKS_RS="$PROJECTS_DIR/steamworks-rs"
  12. STEAMWORKSJS="$PROJECTS_DIR/steamworksjs"
  13. PINNED_REV="fbb79635b06b4feea8261e5ca3e8ea3ef42facf9"
  14. echo "==> Rust toolchain"
  15. if ! command -v cargo >/dev/null 2>&1; then
  16. curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
  17. fi
  18. # shellcheck disable=SC1091
  19. [ -f "$HOME/.cargo/env" ] && source "$HOME/.cargo/env"
  20. cargo --version
  21. echo "==> Cloning steamworks-rs (skipped if already present)"
  22. if [ ! -d "$STEAMWORKS_RS" ]; then
  23. git clone https://github.com/Noxime/steamworks-rs "$STEAMWORKS_RS"
  24. fi
  25. git -C "$STEAMWORKS_RS" checkout --quiet "$PINNED_REV"
  26. echo "==> Cloning steamworks.js (skipped if already present)"
  27. if [ ! -d "$STEAMWORKSJS" ]; then
  28. git clone https://github.com/ceifa/steamworks.js "$STEAMWORKSJS"
  29. fi
  30. echo "==> Applying steamworks-rs patch (skipped if already applied)"
  31. if grep -q "vote_up_item" "$STEAMWORKS_RS/src/ugc.rs"; then
  32. echo " already applied"
  33. else
  34. git -C "$STEAMWORKS_RS" apply "$PATCHES_DIR/steamworks-rs-ugc.patch"
  35. fi
  36. echo "==> Applying steamworks.js patch (skipped if already applied)"
  37. if grep -q "vote_item" "$STEAMWORKSJS/src/api/workshop.rs"; then
  38. echo " already applied"
  39. else
  40. git -C "$STEAMWORKSJS" apply "$PATCHES_DIR/steamworks-js-workshop.patch"
  41. fi
  42. echo "==> Pointing steamworks.js's Cargo.toml at the local patched steamworks-rs (skipped if already done)"
  43. if grep -qF 'Noxime/steamworks-rs' "$STEAMWORKSJS/Cargo.toml" && grep -q '\[patch\.' "$STEAMWORKSJS/Cargo.toml"; then
  44. echo " already present"
  45. else
  46. {
  47. printf '\n[patch."https://github.com/Noxime/steamworks-rs/"]\n'
  48. printf 'steamworks = { path = "../steamworks-rs" }\n'
  49. } >> "$STEAMWORKSJS/Cargo.toml"
  50. fi
  51. echo "==> Building steamworks.js (this runs cargo + napi, may take a minute)"
  52. cd "$STEAMWORKSJS"
  53. npm install
  54. npm run "${STEAMWORKSJS_BUILD:-build:debug}"
  55. echo ""
  56. echo "==> Done. Built artifact:"
  57. ls -la "$STEAMWORKSJS/dist/linux64/steamworksjs.linux-x64-gnu.node"
  58. echo ""
  59. echo "Next: wire it into we_manager with:"
  60. echo " cd /path/to/we_manager"
  61. echo " npm pkg set dependencies.steamworks.js=\"file:$STEAMWORKSJS\""
  62. echo " npm install && npm run build"