rustyscreeps / cargo-screeps

Build tool for deploying Rust WASM code to Screeps game servers
MIT License
25 stars 13 forks source link
cargo-subcommand rust screeps wasm

cargo-screeps

Linux Build Status crates.io version badge dependency status

Build tool for deploying Rust WASM repositories to Screeps game servers.

cargo-screeps wraps wasm-pack, adding the ability to trim node.js and web javascript code from the output files, and allows uploading directly to Screeps servers.

The other main project in this organization is screeps-game-api, type-safe bindings to the in-game Screeps API.

These two tools go together well, but do not depend on eachother. cargo-screeps can compile and upload any screeps WASM project buildable with wasm-bindgen's wasm-pack, and screeps-game-api is usable in any project built with wasm-pack.


Build Options

build:

Configured in [build] config section. No required settings.

  1. runs wasm-pack --target nodejs to build the rust source for Screeps: World bots, or wasm-pack --target web to build Screeps: Arena bots
  2. Modifies the generated module's javascript loader file to be compatibile with Screeps; adds a polyfill for TextEncoder/TextDecoder, and replaces the node-compatible module loader function with one that works with Screeps: World when the build_mode is set to world (the default)

deploy:

Runs the deployment mode specified by the --mode setting, or the default_deploy_mode configuration setting if none is specified.

  1. runs build
  2. depending on whether the mode uploads (has authentication credentials) or copies (has a destination), proceeds to deploy the built code

If copying (when destination is defined):

  1. copies compiled .js/.mjs and .wasm/.bin files from the directories specified in include_files (default pkg and javascript) to the specified directory and branch
  2. if pruning is enabled, deletes all other files in <destination directory>/<branch name>/

If uploading (when auth_token or username and password are defined):

  1. reads compiled .js and .wasm files from the directories specified in include_files (default pkg and javascript).
  2. reads screeps.toml for upload options
  3. uploads all read files to server on the specified branch, using filenames as the filenames on the server

upload:

A shortcut for cargo screeps deploy -m upload.

copy:

A shortcut for cargo screeps deploy -m copy.

Configuration Options

No namespace

[build]

This configures general build options.

Any of these options can be overridden for a given mode with its own build section. For instance,

[upload.build]
extra_options = ["--features=alliance_behavior"]

would cause a feature on your crate named alliance_behavior to be built when running the upload mode.

Configuration modes

Configuration modes can either copy the built files to a destination directory, or upload to a destination server using the Screeps API.

A mode should either have a filesystem destination to copy to, or authentication credentials (and optionally, server information) to upload to.

Optionally, it also have a sub-table [mode.build] to override any of the global [build] options.

Copy Options

Options for deploying to a filesystem location.

Upload Options

Options for deploying to a Screeps server.

Updating cargo screeps

To update cargo-screeps, simply repeat the install process with the --force (-f) flag.

After updating, you'll want to do a full cargo clean to remove any old artifacts which were built using the older version of cargo-screeps.

cargo install -f cargo-screeps
cargo clean
cargo screeps build