This example shows how to create dora operators and custom nodes with C++.
Dora does not provide a C++ API yet, but we can create adapters for either the C or Rust API. The operator-rust-api and node-rust-api folders implement an example operator and node based on dora's Rust API, using the cxx crate for bridging. The operator-c-api and node-c-api show how to create operators and nodes based on dora's C API. Both approaches work, so you can choose the API that fits your application better.
To try it out, you can use the run.rs binary. It performs all required build steps and then starts the dataflow. Use the following command to run it: cargo run --example cxx-dataflow.
For a manual build, follow these steps:
- Create a
buildfolder in this directory - Build the
cxx-dataflow-example-node-rust-apiandcxx-dataflow-example-operator-rust-apicrates:cargo build -p cxx-dataflow-example-node-rust-api --release cargo build -p cxx-dataflow-example-operator-rust-api --release - Compile the
dora-node-api-ccrate into a static library.- Run
cargo build -p dora-node-api-c --release - The resulting staticlib is then available under
../../target/release/libdora-node-api-c.a.
- Run
- Compile the
node-c-api/main.cc(e.g. usingclang++) and link the staticlib- For example, use the following command:
clang++ node-c-api/main.cc <FLAGS> -std=c++14 -ldora_node_api_c -L ../../target/release --output build/node_c_api - The
<FLAGS>depend on the operating system and the libraries that the C node uses. The following flags are required for each OS:- Linux:
-lm -lrt -ldl -pthread - macOS:
-framework CoreServices -framework Security -l System -l resolv -l pthread -l c -l m - Windows:
Also: On Windows, the output file should have an
-ladvapi32 -luserenv -lkernel32 -lws2_32 -lbcrypt -lncrypt -lschannel -lntdll -liphlpapi -lcfgmgr32 -lcredui -lcrypt32 -lcryptnet -lfwpuclnt -lgdi32 -lmsimg32 -lmswsock -lole32 -loleaut32 -lopengl32 -lsecur32 -lshell32 -lsynchronization -luser32 -lwinspool -Wl,-nodefaultlib:libcmt -D_DLL -lmsvcrt.exeextension:--output build/c_node.exe
- Linux:
- For example, use the following command:
- Compile the
operator-c-api/operator.ccfile into a shared library.- For example, use the following commands:
Omit the
clang++ -c operator-c-api/operator.cc -std=c++14 -o build/operator_c_api.o -fPIC clang++ -shared build/operator_c_api.o -o build/liboperator_c_api.so-fPICargument on Windows. Replace theliboperator_c_api.soname with the shared library standard library prefix/extensions used on your OS, e.g..dllon Windows.
- For example, use the following commands:
Build the dora CLI:
- Build the
doraexecutable usingcargo build -p dora-cli --release- This is the only dora binary you need: it embeds the coordinator and the
daemon, and hosts shared-library operators like the one above through its
dora runtimesubcommand, which the daemon spawns for you.
- This is the only dora binary you need: it embeds the coordinator and the
daemon, and hosts shared-library operators like the one above through its
Run the dataflow:
-
Run the dataflow with the CLI built above:
../../target/release/dora run dataflow.yml