Skip to content

Latest commit

 

History

History
57 lines (46 loc) · 1.98 KB

README.md

File metadata and controls

57 lines (46 loc) · 1.98 KB

C++ --> WASM particles

Setup

Our C++ code is built by Bazel. You will need to install Bazel, and use it to build and run the wasm code/tests (everything under src/wasm/).

  1. Installing Bazel: Follow project install instructions.

Build

See here for a working example.

  • Add a BUILD file in the relevant directory
  • Generate a C++ header file from your particle spec using the arcs_cc_schema build rule:
    arcs_cc_schema(
        # Name of the BUILD rule (tell Bazel to build this schema using this name).
        name = "example_schema",
        # Input source.
        src = "example.arcs",
        # Optional output filename.
        out = "example.h",
    )
    
  • Write your C++ particle(s)
    • Include the Arcs C++ header: #include "src/wasm/cpp/arcs.h".
    • Include your generated schema header(s): #include "particles/Native/Wasm/example.h".
    • Particles inherit from arcs::Particle and use arcs::Singleton and arcs::Collection
  • Add a wasm_cc_binary build rule for your C++ particle(s) to your BUILD file:
    cc_wasm_binary(
        # Name of the BUILD rule (tell Bazel to build this particle using this name).
        name = "example_particle",
        # Input C++ particle source files to compile.
        srcs = ["example.cc"],
        # Input C++ header files (example.h was generated by the example_schema rule above).
        hdrs = ["example.h"],
        # Other C++ dependencies this binary depends on (just the Arcs library).
        deps = ["//src/wasm/cpp:arcs"],
    )
    
  • Build your particle using Bazel: ./tools/bazelisk build //particles/Native/Wasm:example_particle.

Execute

Test

./tools/bazelisk test //src/wasm/tests:wasm-api-test