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:
Install cargo-spatial
.
$ cargo install --path ./cargo-spatial --force
Set the SPATIAL_LIB_DIR
environment 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.8.0 --with-test-schema
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.
To run the example project, you will need to:
Navigate to the example project:
$ cd project-example
$ cargo spatial codegen
$ 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.
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
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
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 hasclang
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.