Note: This is an unofficial integration of the SpatialOS C API with Rust. Improbable does not officially support Rust as a worker language.
To develop in this repository you'll need:
- Rust v1.39
- A SpatialOS account
Clone this repository.
$ cargo install --path ./cargo-spatial --force
SPATIAL_LIB_DIRenvironment variable to the location of the SpatialOS dependencies.
$ export SPATIAL_LIB_DIR=$(pwd)/dependencies
Download the C API dependencies.
$ cargo spatial download sdk --sdk-version 14.0.0
$ 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:
- Navigate to the example project:
$ cd project-example
- Generate Rust code from the project's SpatialOS schema.
$ cargo spatial codegen
- 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
$ 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/test.sb.json
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
clangas a dependency. See bindgen's documentation for more info.
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.