Skip to content
Rust integration of the SpatialOS C API bindings
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows Upgrade to Rust 1.39 + use new futures (#134) Dec 29, 2019
.idea Add Intellij Configs (#142) Jan 3, 2020
cargo-spatial `cargo-spatial` error handling consolidation (#143) Jan 13, 2020
project-example Refactor vtable module (#141) Jan 3, 2020
spatialos-sdk-code-generator Refactor vtable module (#141) Jan 3, 2020
spatialos-sdk-sys Update dependencies (#110) Oct 4, 2019
spatialos-sdk-tools Update bindgen requirement from 0.51.1 to 0.52.0 (#133) Nov 24, 2019
spatialos-sdk Assorted tidy up (#147) Jan 13, 2020
.editorconfig add editor config Oct 29, 2018
.gitattributes Spatial CLI in CI round 2 (#48) Jan 15, 2019
Cargo.toml Finish Snapshot API (#80) Mar 21, 2019
LICENSE-APACHE Add Dual License (#59) Feb 3, 2019
LICENSE-MIT Add Dual License (#59) Feb 3, 2019

SpatialOS SDK for Rust

An integration of the SpatialOS C API and the Rust programming language.

Note: This is an unofficial integration of the SpatialOS C API with Rust. Improbable does not officially support Rust as a worker language.

Quick start


To develop in this repository you'll need:

  1. Rust v1.39
  2. A SpatialOS account


  1. Clone this repository.

  2. Install cargo-spatial.

    $ cargo install --path ./cargo-spatial --force
  3. Set the SPATIAL_LIB_DIR environment variable to the location of the SpatialOS dependencies.

    $ export SPATIAL_LIB_DIR=$(pwd)/dependencies
  4. Download the C API dependencies.

    $ cargo spatial download sdk --sdk-version 14.0.0
  5. Build the spatialos-sdk crate.

    $ cd spatialos-sdk && cargo build

At this point, the spatialos-sdk crate has been built and linked successfully and can be used in user code.

Running the Example Project

To run the example project, you will need to:

  1. Navigate to the example project:
$ cd project-example
  1. Generate Rust code from the project's SpatialOS schema.
$ cargo spatial codegen
  1. Launch a local deployment:
$ cargo spatial local launch

Its ready to go when you see a message like the following in your console.

Access the Inspector at http://localhost:21000/inspector

Navigate to http://localhost:21000/inspector in your browser to view your deployment. You should see 4 workers already connected, these were started by the SpatialOS Runtime.

If you want to manually launch another instance of the worker, run the following command from the project-example directory:

$ cargo run -- --worker-id RustWorker999 --worker-type RustWorker receptionist

This will allow you to see the log output of the worker as it runs.

Running the test-suite

There are some integration tests that live in the test-suite crate. These utilize and test generated code. To run these tests:

$ cd test-suite && cargo spatial codegen && cargo test

Testing the code generator

To regenerate the schema bundle, run the following:

$ ./dependencies/schema-compiler/schema_compiler --schema_path=project-example/schema --schema_path=dependencies/std-lib project-example/schema/example.schema --bundle_json_out=spatialos-sdk-code-generator/data/

To run the code generator tests, run the following:

$ cargo test -p spatialos-sdk-code-generator

To display Rusts auto-generated debug representation of the schema bundle, run the following:

$ cargo test -p spatialos-sdk-code-generator -- --nocapture

Updating Rust bindings

To update the Rust bindings found in spatialos-sdk-sys run the following command from the root of the repository:

$ cargo run --bin generate_bindings -- -i ./dependencies/headers/include/improbable/ -o ./spatialos-sdk-sys/src/

Note: this depends on bindgen which has clang as a dependency. See bindgen's documentation for more info.


Licensed under either of Apache License, Version 2.0 or MIT at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

You can’t perform that action at this time.