dora-rs / dora

DORA (Dataflow-Oriented Robotic Application) is middleware designed to streamline and simplify the creation of AI-based robotic applications. It offers low latency, composable, and distributed dataflow capabilities. Applications are modeled as directed graphs, also referred to as pipelines.
https://dora-rs.ai
Apache License 2.0
1.36k stars 69 forks source link

How to use CMake to build c++-ros2-dataflow #446

Closed bobd988 closed 2 months ago

bobd988 commented 3 months ago

We are trying to start dora integration with examples/c++-ros2-dataflow There are some C++ existing system built with cmake while dora c++-ros2-dataflow is built with cargo. Can this c++-ros2-dataflow example provide a cmake example so that dora modules can be easily integrated to cmake system?

There is a similar one in examples/cmake-dataflow which may be used as a base , however when running the below from a Ubuntu 20.04 with Cmake 3.28

cd build && cmake .. make install

I got error: failed to run custom build command for dora-node-api-cxx v0.3.2 (/home/demo/Public/github_dora/dora/examples/cmake-dataflow/build/dora/src/Dora/apis/c++/node)

It will be great if this cmake example cmake build issue can be resolved. And then apply to c++-ros2-dataflow exmaple ? Please provide instructions how to build and run , for example the current command to run is

cargo run --example cxx-ros2-dataflow --features ros2-examples

After applied to cmake, do we still run with this or different command ?

phil-opp commented 3 months ago

I'm not familiar with cmake, so I'm not sure if I can help you with the details, but I try to take a look.

Maybe @XxChang can help?

XxChang commented 3 months ago

Please run it with cmake -DDORA_ROOT_DIR=<path-to-dora>, see run.rs for more details.

LoL. My negligence.

The case of out-of-tree compile fails because the target_dir() in build.rs was changed in last version. But it is ok with cargo run --example cmake-dataflow.

To fix these bugs, please modify DoraTargets.cmake replace

        BUILD_COMMAND
            cargo build
            --package dora-node-api-c
            --target-dir ${CMAKE_CURRENT_BINARY_DIR}
            &&
            cargo build
            --package dora-operator-api-c
            --target-dir ${CMAKE_CURRENT_BINARY_DIR}
            &&
            cargo build
            --package dora-node-api-cxx
            --target-dir ${CMAKE_CURRENT_BINARY_DIR}
            &&
            cargo build
            --package dora-operator-api-cxx
            --target-dir ${CMAKE_CURRENT_BINARY_DIR}

with

        BUILD_COMMAND
            cargo build
            --package dora-node-api-c
            --target-dir ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target
            &&
            cargo build
            --package dora-operator-api-c
            --target-dir ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target
            &&
            cargo build
            --package dora-node-api-cxx
            --target-dir ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target
            &&
            cargo build
            --package dora-operator-api-cxx
            --target-dir ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target

replace

    add_custom_command(OUTPUT ${node_bridge} ${dora_cxx_include_dir} ${operator_bridge}
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        DEPENDS Dora

with

    add_custom_command(OUTPUT ${node_bridge} ${dora_cxx_include_dir} ${operator_bridge}
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target
        DEPENDS Dora

and set(dora_link_dirs ${CMAKE_CURRENT_BINARY_DIR}/debug) -> set(dora_link_dirs ${CMAKE_CURRENT_BINARY_DIR}/dora/src/Dora/target/debug)

how to build with a existing cmake project? May be you can learn more from this repo

phil-opp commented 3 months ago

Thanks a lot!

To fix these bugs, please modify DoraTargets.cmake replace

So we should perform these changes in the repo?

XxChang commented 3 months ago

There is no problem with cargo run --example cmake-dataflow, so it is ok with test scripts.

but when people want to do it on a separate project, it will fail. So please perform these changes. Thanks.

bobd988 commented 3 months ago

@XxChang with current latest code from main , to add above changes in DoraTargets.cmake, When I run cmake -DDORA_ROOT_DIR=/home/demo/Public/github_dora/dora, i got

"/home/demo/Public/github_dora/dora" does not appear to contain CMakeLists.txt ,

then I change to run cmake -DDORA_ROOT_DIR=/home/demo/Public/github_dora/dora/examples/cmake-dataflow , i got

execute_process failed command indexes:

1: "Child return code: 101"

Call Stack (most recent call first): _deps/corrosion-src/cmake/CorrosionGenerator.cmake:217 (_cargo_metadata) _deps/corrosion-src/cmake/Corrosion.cmake:1051 (_generator_add_cargo_targets) DoraTargets.cmake:19 (corrosion_import_crate) CMakeLists.txt:7 (include)

It may also caused by my Ubuntu environment. Let me verify this with another ubuntu 20.04

XxChang commented 3 months ago

You should run cmake -DDORA_ROOT_DIR=<path-to-dora> under the cmake-dataflow directory

or

cd <path-to-cmake-dataflow-directory>
mkdir build
cd build
cmake -DDORA_ROOT_DIR=<path-to-dora> ..
make

or just

cd <path-to-cmake-dataflow-directory>
mkdir build
cd build
cmake ..
make

The former will build the dora with the existing dora project. The later will fetch a new one from github.

phil-opp commented 3 months ago

@XxChang

but when people want to do it on a separate project, it will fail. So please perform these changes. Thanks.

I opened a PR at #453

bobd988 commented 3 months ago

I got different error when running cargo run --example cmake-dataflowunder ubuntu22.04. Latest dora code from main

Finished dev [unoptimized + debuginfo] target(s) in 11.70s Running target/debug/examples/cmake-dataflow -- Rust Toolchain: 1.76-x86_64-unknown-linux-gnu -- Rust Target: x86_64-unknown-linux-gnu -- Found Rust: /home/demo/.rustup/toolchains/1.76-x86_64-unknown-linux-gnu/bin/rustc (found version "1.76.0") -- Using Corrosion as a subdirectory -- Rust Toolchain: 1.76-x86_64-unknown-linux-gnu -- Rust Target: x86_64-unknown-linux-gnu -- Found Rust: /home/demo/.rustup/toolchains/1.76-x86_64-unknown-linux-gnu/bin/rustc (found suitable version "1.76.0", minimum required is "1.72") -- Configuring done (0.4s) -- Generating done (0.0s) -- Build files have been written to: /home/demo/Public/dora/examples/cmake-dataflow/build [ 0%] Built target cargo-prebuild_dora-node-api-c Finished dev [unoptimized + debuginfo] target(s) in 0.15s Copying byproducts libdora_node_api_c.a to /home/demo/Public/dora/examples/cmake-dataflow/build [ 0%] Built target _cargo-build_dora-node-api-c [ 0%] Built target cargo-build_dora-node-api-c [ 0%] Built target cargo-prebuild_dora-operator-api-c Finished dev [unoptimized + debuginfo] target(s) in 0.13s Copying byproducts libdora_operator_api_c.a to /home/demo/Public/dora/examples/cmake-dataflow/build [ 0%] Built target _cargo-build_dora-operator-api-c [ 0%] Built target cargo-build_dora-operator-api-c [ 0%] Built target cargo-prebuild_dora-node-api-cxx Finished dev [unoptimized + debuginfo] target(s) in 0.11s Copying byproducts libdora_node_api_cxx.a to /home/demo/Public/dora/examples/cmake-dataflow/build [ 0%] Built target _cargo-build_dora-node-api-cxx [ 0%] Built target cargo-build_dora-node-api-cxx [ 0%] Built target cargo-prebuild_dora-operator-api-cxx Finished dev [unoptimized + debuginfo] target(s) in 0.08s Copying byproducts libdora_operator_api_cxx.a to /home/demo/Public/dora/examples/cmake-dataflow/build [ 0%] Built target _cargo-build_dora-operator-api-cxx [ 0%] Built target cargo-build_dora-operator-api-cxx [ 8%] Built target Dora_c [ 25%] Built target node_c_api [ 33%] Generating node_bridge.cc, include/cxx, operator_bridge.cc cp: cannot stat 'target/cxxbridge/dora-node-api-cxx/src/lib.rs.cc': No such file or directory gmake[2]: [CMakeFiles/Dora_cxx.dir/build.make:75: node_bridge.cc] Error 1 gmake[1]: [CMakeFiles/Makefile2:630: CMakeFiles/Dora_cxx.dir/all] Error 2 gmake: *** [Makefile:136: all] Error 2 Error: failed to build a cmake-generated project binary tree

XxChang commented 3 months ago

see PR https://github.com/dora-rs/dora/pull/453

XxChang commented 3 months ago

I got different error when running cargo run --example cmake-dataflowunder ubuntu22.04. Latest dora code from main

Finished dev [unoptimized + debuginfo] target(s) in 11.70s Running target/debug/examples/cmake-dataflow -- Rust Toolchain: 1.76-x86_64-unknown-linux-gnu -- Rust Target: x86_64-unknown-linux-gnu -- Found Rust: /home/demo/.rustup/toolchains/1.76-x86_64-unknown-linux-gnu/bin/rustc (found version "1.76.0") -- Using Corrosion as a subdirectory -- Rust Toolchain: 1.76-x86_64-unknown-linux-gnu -- Rust Target: x86_64-unknown-linux-gnu -- Found Rust: /home/demo/.rustup/toolchains/1.76-x86_64-unknown-linux-gnu/bin/rustc (found suitable version "1.76.0", minimum required is "1.72") -- Configuring done (0.4s) -- Generating done (0.0s) -- Build files have been written to: /home/demo/Public/dora/examples/cmake-dataflow/build [ 0%] Built target cargo-prebuild_dora-node-api-c Finished dev [unoptimized + debuginfo] target(s) in 0.15s Copying byproducts libdora_node_api_c.a to /home/demo/Public/dora/examples/cmake-dataflow/build [ 0%] Built target _cargo-build_dora-node-api-c [ 0%] Built target cargo-build_dora-node-api-c [ 0%] Built target cargo-prebuild_dora-operator-api-c Finished dev [unoptimized + debuginfo] target(s) in 0.13s Copying byproducts libdora_operator_api_c.a to /home/demo/Public/dora/examples/cmake-dataflow/build [ 0%] Built target _cargo-build_dora-operator-api-c [ 0%] Built target cargo-build_dora-operator-api-c [ 0%] Built target cargo-prebuild_dora-node-api-cxx Finished dev [unoptimized + debuginfo] target(s) in 0.11s Copying byproducts libdora_node_api_cxx.a to /home/demo/Public/dora/examples/cmake-dataflow/build [ 0%] Built target _cargo-build_dora-node-api-cxx [ 0%] Built target cargo-build_dora-node-api-cxx [ 0%] Built target cargo-prebuild_dora-operator-api-cxx Finished dev [unoptimized + debuginfo] target(s) in 0.08s Copying byproducts libdora_operator_api_cxx.a to /home/demo/Public/dora/examples/cmake-dataflow/build [ 0%] Built target _cargo-build_dora-operator-api-cxx [ 0%] Built target cargo-build_dora-operator-api-cxx [ 8%] Built target Dora_c [ 25%] Built target node_c_api [ 33%] Generating node_bridge.cc, include/cxx, operator_bridge.cc cp: cannot stat 'target/cxxbridge/dora-node-api-cxx/src/lib.rs.cc': No such file or directory gmake[2]: [CMakeFiles/Dora_cxx.dir/build.make:75: node_bridge.cc] Error 1 gmake[1]: [CMakeFiles/Makefile2:630: CMakeFiles/Dora_cxx.dir/all] Error 2 gmake: *** [Makefile:136: all] Error 2 Error: failed to build a cmake-generated project binary tree

fix it on https://github.com/dora-rs/dora/pull/460