| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #!/usr/bin/env bash
- # Idempotent build script for the steamworks.js vote and favorites patch. Safe to re-run: every step
- # checks whether it already happened before doing anything.
- #
- # Usage: ./build.sh [path-to-projects-dir]
- # Defaults to ~/projects/private if no argument is given (matches this project's usual layout).
- # STEAMWORKSJS_BUILD=build makes a release build instead of the default debug one.
- set -euo pipefail
- PROJECTS_DIR="${1:-$HOME/projects/private}"
- PATCHES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
- STEAMWORKS_RS="$PROJECTS_DIR/steamworks-rs"
- STEAMWORKSJS="$PROJECTS_DIR/steamworksjs"
- PINNED_REV="fbb79635b06b4feea8261e5ca3e8ea3ef42facf9"
- echo "==> Rust toolchain"
- if ! command -v cargo >/dev/null 2>&1; then
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
- fi
- # shellcheck disable=SC1091
- [ -f "$HOME/.cargo/env" ] && source "$HOME/.cargo/env"
- cargo --version
- echo "==> Cloning steamworks-rs (skipped if already present)"
- if [ ! -d "$STEAMWORKS_RS" ]; then
- git clone https://github.com/Noxime/steamworks-rs "$STEAMWORKS_RS"
- fi
- git -C "$STEAMWORKS_RS" checkout --quiet "$PINNED_REV"
- echo "==> Cloning steamworks.js (skipped if already present)"
- if [ ! -d "$STEAMWORKSJS" ]; then
- git clone https://github.com/ceifa/steamworks.js "$STEAMWORKSJS"
- fi
- # A clone patched before favorites were added has only the vote half, so anything short of the
- # full patch is reset to upstream first and patched again.
- apply_patch() {
- local repo="$1" file="$2" marker="$3" patch="$4"
- if grep -q "$marker" "$repo/$file"; then
- echo " already applied"
- return
- fi
- git -C "$repo" checkout -- "$file"
- git -C "$repo" apply "$patch"
- }
- echo "==> Applying steamworks-rs patch (skipped if already applied)"
- apply_patch "$STEAMWORKS_RS" src/ugc.rs add_item_to_favorites "$PATCHES_DIR/steamworks-rs-ugc.patch"
- echo "==> Applying steamworks.js patch (skipped if already applied)"
- apply_patch "$STEAMWORKSJS" src/api/workshop.rs add_favorite "$PATCHES_DIR/steamworks-js-workshop.patch"
- echo "==> Pointing steamworks.js's Cargo.toml at the local patched steamworks-rs (skipped if already done)"
- if grep -qF 'Noxime/steamworks-rs' "$STEAMWORKSJS/Cargo.toml" && grep -q '\[patch\.' "$STEAMWORKSJS/Cargo.toml"; then
- echo " already present"
- else
- {
- printf '\n[patch."https://github.com/Noxime/steamworks-rs/"]\n'
- printf 'steamworks = { path = "../steamworks-rs" }\n'
- } >> "$STEAMWORKSJS/Cargo.toml"
- fi
- echo "==> Building steamworks.js (this runs cargo + napi, may take a minute)"
- cd "$STEAMWORKSJS"
- npm install
- npm run "${STEAMWORKSJS_BUILD:-build:debug}"
- echo ""
- echo "==> Done. Built artifact:"
- ls -la "$STEAMWORKSJS/dist/linux64/steamworksjs.linux-x64-gnu.node"
- echo ""
- echo "Next: wire it into we_manager with:"
- echo " cd /path/to/we_manager"
- echo " npm pkg set dependencies.steamworks.js=\"file:$STEAMWORKSJS\""
- echo " npm install && npm run build"
|