build.sh 2.5 KB

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