Build a worker

Code in a C++ worker will normally make use of the worker APIs defined in <improbable/worker.h> and the C++ generated code, which is based on the user-specified schema.

Supported compilers and runtimes

See Requirements.

Compiling and linking

In order to build a C++ worker, you'll need to download both the cpp_headers package and one or more Worker SDK for C library packages to link against.

The header file package cpp_headers contains the following structure:

  • <worker_package>/include/improbable- This folder contains a number of header files:
    • detail - A folder containing implementation details. These should not be included directly and are subject to change at any time.
    • worker.h - The worker API, including connecting to SpatialOS and interacting with snapshots.
    • view.h - The view, an optional data structure that maintains the known state of entities in the worker's view of the simulation.
    • collections.h - Some collection types like worker::List, worker::Map, worker::Option and more.
    • c_worker.h - The C worker API. Included automatically by worker.h and should not be included directly.
    • c_schema.h - The C schema API. Included automatically by worker.h and should not be included directly.

Library packages to link against are described in more detail in the Worker SDK for C documentation.

Building for a cloud deployment

After building a project, a certain directory structure is expected when uploading an assembly.

We don't provide generated build scripts, for C++ workers, so the steps of the Build task for your worker (within spatialos.<worker_type>.worker.json) should:

  • Create a zip file containing the worker binary with a name matching the value for the artifact_name specified in the managed worker configuration, under managed then linux.

  • Place the zip file in build/assembly/worker/, so it is picked up when uploading an assembly during spatial cloud upload <assembly name>.

SpatialOS runs managed workers as part of a cloud deployment in a Linux environment similar to Ubuntu 16.04 LTS. Therefore, you need to build a binary that can be executed in this environment.

If you are developing on Windows or macOS, we suggest installing Ubuntu 16.04 LTS inside a virtual machine using VirtualBox, and using our Linux support to build managed workers.

Alternatively, on Windows 10, you can install Ubuntu using the Windows Subsystem for Linux instead of a virtual machine. This is not required for local deployments during development: just for cloud deployments.

Updated about a year ago

Build a worker

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.