From 70b70772e54f816d11754591eca26bf191396aad Mon Sep 17 00:00:00 2001 From: starlitxiling <1754165401@qq.com> Date: Tue, 29 Apr 2025 17:21:49 +0800 Subject: [PATCH] add document to use install_dora --- .github/workflows/libdora-release.yml | 4 ++-- examples/c++-dataflow/README.md | 15 +++++++++++++++ install_libdora.sh | 18 ++++++++++-------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/.github/workflows/libdora-release.yml b/.github/workflows/libdora-release.yml index 36caf04e..c1f5507d 100644 --- a/.github/workflows/libdora-release.yml +++ b/.github/workflows/libdora-release.yml @@ -111,11 +111,11 @@ jobs: echo "Copying library files..." case "$RUNNER_OS" in "Linux" | "macOS") - cp target/${{ matrix.target }}/release/*.a dist/lib/ || echo "No libdora_node_api_c.a found" + cp target/${{ matrix.target }}/debug/*.a dist/lib/ || echo "No libdora_node_api_c.a found" cp target/${{ matrix.target }}/debug/libdora_node_api_cxx.a dist/lib || echo "No libdora_node_api_cxx.a found" ;; "Windows") - cp target/${{ matrix.target }}/release/*.lib dist/lib/ || echo "No dora_node_api_c found" + cp target/${{ matrix.target }}/debug/*.lib dist/lib/ || echo "No dora_node_api_c found" cp target/${{ matrix.target }}/debug/libdora_node_api_cxx.a dist/lib || echo "No libdora_node_api_cxx.a found" ;; esac diff --git a/examples/c++-dataflow/README.md b/examples/c++-dataflow/README.md index 100ac99e..f5eb9578 100644 --- a/examples/c++-dataflow/README.md +++ b/examples/c++-dataflow/README.md @@ -4,6 +4,21 @@ 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. +## Install Dora cpp library +You can use the following script to install the latest dora cpp api. +```bash +curl --proto '=https' --tlsv1.2 -LsSf https://github.com/dora-rs/dora/blob/main/install_libdora.sh | sudo -E bash +``` +If you want to install other versions, you can download them from https://github.com/dora-rs/dora/tags. +If you have it installed, you can compile your Dora node with the C API like this: +~~~bash +clang++ -std=c++11 -I/usr/local/include/dora -o main main.cc -L/usr/local/lib -ldora_node_api_c +~~~ +If you're writing a Dora node in C++ and need to use the `dora_node_api_cxx` binding (generated using Rust's `cxx` crate), use the following: +```bash +clang++ -std=c++17 -I/usr/local/include/dora main.cc -ldora_node_api_cxx -o main +``` + ## Compile and Run 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`. diff --git a/install_libdora.sh b/install_libdora.sh index 74444da0..53a5a97b 100755 --- a/install_libdora.sh +++ b/install_libdora.sh @@ -55,7 +55,7 @@ if ! command -v curl >/dev/null 2>&1; then fi if ! command -v jq >/dev/null 2>&1; then - echo "Error: 'jq' not found!" >&2 + echo "Error: 'jq' not found! Please install it (e.g. 'brew install jq' or 'apt install jq')" >&2 exit 1 fi @@ -64,7 +64,7 @@ PLATFORM="$(detect_platform)" echo " => PLATFORM: $PLATFORM" echo "==> Fetching latest Dora release info from GitHub..." -LATEST_JSON=$(curl -s https://api.github.com/repos/starlitxiling/dora-rerun/releases/latest) +LATEST_JSON=$(curl -s https://api.github.com/repos/dora-rs/dora/releases/latest) if [ -z "$LATEST_JSON" ]; then echo "Error: failed to fetch release info from GitHub!" @@ -122,15 +122,17 @@ echo "==> Extracting $CHOSEN_ASSET_NAME ..." tar -zxvf "$CHOSEN_ASSET_NAME" FILE_TO_FIX="include/operator.h" -OLD_PATH="../operator-rust-api/operator.h" -NEW_PATH="operator.h" -if [ -f "$FILE_TO_FIX" ] && grep -q "$OLD_PATH" "$FILE_TO_FIX"; then - echo "==> Fixing include path in $FILE_TO_FIX ..." +if [ -f "$FILE_TO_FIX" ]; then + echo "==> Fixing include paths in $FILE_TO_FIX ..." if sed --version 2>/dev/null | grep -q "GNU"; then - sed -i "s|$OLD_PATH|$NEW_PATH|g" "$FILE_TO_FIX" + sed -i 's|../operator-rust-api/operator.h|operator.h|g' "$FILE_TO_FIX" + sed -i 's|#include "../../../apis/c/operator/operator_api.h"|#include "operator_api.h"|' "$FILE_TO_FIX" + sed -i 's|#include "../build/dora-operator-api.h"|#include "dora-operator-api.h"|' "$FILE_TO_FIX" else - sed -i "" "s|$OLD_PATH|$NEW_PATH|g" "$FILE_TO_FIX" + sed -i '' 's|../operator-rust-api/operator.h|operator.h|g' "$FILE_TO_FIX" + sed -i '' 's|#include "../../../apis/c/operator/operator_api.h"|#include "operator_api.h"|' "$FILE_TO_FIX" + sed -i '' 's|#include "../build/dora-operator-api.h"|#include "dora-operator-api.h"|' "$FILE_TO_FIX" fi fi