You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Dora C++ Dataflow Example
  2. This example shows how to create dora operators and custom nodes with C++.
  3. 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.
  4. ## Compile and Run
  5. To try it out, you can use the [`run.rs`](./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`.
  6. For a manual build, follow these steps:
  7. - Create a `build` folder in this directory (i.e., next to the `node.c` file)
  8. - Build the `cxx-dataflow-example-node-rust-api` and `cxx-dataflow-example-operator-rust-api` crates:
  9. ```
  10. cargo build -p cxx-dataflow-example-node-rust-api --release
  11. cargo build -p cxx-dataflow-example-operator-rust-api --release
  12. ```
  13. - Compile the `dora-node-api-c` crate into a static library.
  14. - Run `cargo build -p dora-node-api-c --release`
  15. - The resulting staticlib is then available under `../../target/release/libdora-node-api-c.a`.
  16. - Compile the `node-c-api/main.cc` (e.g. using `clang++`) and link the staticlib
  17. - For example, use the following command:
  18. ```
  19. clang++ node-c-api/main.cc <FLAGS> -std=c++14 -ldora_node_api_c -L ../../target/release --output build/node_c_api
  20. ```
  21. - The `<FLAGS>` depend on the operating system and the libraries that the C node uses. The following flags are required for each OS:
  22. - Linux: `-lm -lrt -ldl -pthread`
  23. - macOS: `-framework CoreServices -framework Security -l System -l resolv -l pthread -l c -l m`
  24. - Windows:
  25. ```
  26. -ladvapi32 -luserenv -lkernel32 -lws2_32 -lbcrypt -lncrypt -lschannel -lntdll -liphlpapi
  27. -lcfgmgr32 -lcredui -lcrypt32 -lcryptnet -lfwpuclnt -lgdi32 -lmsimg32 -lmswsock -lole32
  28. -lopengl32 -lsecur32 -lshell32 -lsynchronization -luser32 -lwinspool
  29. -Wl,-nodefaultlib:libcmt -D_DLL -lmsvcrt
  30. ```
  31. Also: On Windows, the output file should have an `.exe` extension: `--output build/c_node.exe`
  32. - Compile the `operator-c-api/operator.cc` file into a shared library.
  33. - For example, use the following commands:
  34. ```
  35. clang++ -c operator-c-api/operator.cc -std=c++14 -o build/operator_c_api.o -fPIC
  36. clang++ -shared build/operator_c_api.o -o build/liboperator_c_api.so
  37. ```
  38. Omit the `-fPIC` argument on Windows. Replace the `liboperator_c_api.so` name with the shared library standard library prefix/extensions used on your OS, e.g. `.dll` on Windows.
  39. **Build the dora coordinator and runtime:**
  40. - Build the `dora-coordinator` executable using `cargo build -p dora-coordinator --release`
  41. - Build the `dora-runtime` executable using `cargo build -p dora-runtime --release`
  42. **Run the dataflow:**
  43. - Start the `dora-coordinator`, passing the paths to the dataflow file and the `dora-runtime` as arguments:
  44. ```
  45. ../../target/release/dora-daemon --run-dataflow dataflow.yml ../../target/release/dora-runtime
  46. ```