build.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env bash
  2. # Idempotent build script for the steamworks.js vote and favorites 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. # A clone patched before favorites were added has only the vote half, so anything short of the
  31. # full patch is reset to upstream first and patched again.
  32. apply_patch() {
  33. local repo="$1" file="$2" marker="$3" patch="$4"
  34. if grep -q "$marker" "$repo/$file"; then
  35. echo " already applied"
  36. return
  37. fi
  38. git -C "$repo" checkout -- "$file"
  39. git -C "$repo" apply "$patch"
  40. }
  41. echo "==> Applying steamworks-rs patch (skipped if already applied)"
  42. apply_patch "$STEAMWORKS_RS" src/ugc.rs add_item_to_favorites "$PATCHES_DIR/steamworks-rs-ugc.patch"
  43. echo "==> Applying steamworks.js patch (skipped if already applied)"
  44. apply_patch "$STEAMWORKSJS" src/api/workshop.rs add_favorite "$PATCHES_DIR/steamworks-js-workshop.patch"
  45. echo "==> Pointing steamworks.js's Cargo.toml at the local patched steamworks-rs (skipped if already done)"
  46. if grep -qF 'Noxime/steamworks-rs' "$STEAMWORKSJS/Cargo.toml" && grep -q '\[patch\.' "$STEAMWORKSJS/Cargo.toml"; then
  47. echo " already present"
  48. else
  49. {
  50. printf '\n[patch."https://github.com/Noxime/steamworks-rs/"]\n'
  51. printf 'steamworks = { path = "../steamworks-rs" }\n'
  52. } >> "$STEAMWORKSJS/Cargo.toml"
  53. fi
  54. echo "==> Building steamworks.js (this runs cargo + napi, may take a minute)"
  55. cd "$STEAMWORKSJS"
  56. npm install
  57. npm run "${STEAMWORKSJS_BUILD:-build:debug}"
  58. echo ""
  59. echo "==> Done. Built artifact:"
  60. ls -la "$STEAMWORKSJS/dist/linux64/steamworksjs.linux-x64-gnu.node"
  61. echo ""
  62. echo "Next: wire it into we_manager with:"
  63. echo " cd /path/to/we_manager"
  64. echo " npm pkg set dependencies.steamworks.js=\"file:$STEAMWORKSJS\""
  65. echo " npm install && npm run build"