diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07f76a97..e0d073ae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,9 +26,9 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macOS-latest] - shm: [false, true] - unstable: [false, true] + os: [ubuntu-latest, macOS-latest, windows-latest] + shm: [FALSE, TRUE] + unstable: [FALSE, TRUE] steps: - name: Clone this repository @@ -37,14 +37,14 @@ jobs: - name: install zenoh-cpp shell: bash run: | - ./scripts/install_from_git.sh ~/local + ./scripts/install_from_git.sh ~/local ${{ matrix.unstable }} ${{ matrix.shm }} - name: make examples shell: bash run: | cd build cmake .. -DCMAKE_INSTALL_PREFIX=~/local -DZENOHC_BUILD_WITH_SHARED_MEMORY=${{ matrix.shm }} -DZENOHC_BUILD_WITH_UNSTABLE_API=${{ matrix.unstable }} - cmake --build . --target examples + cmake --build . --target examples --config Release - name: make stand-alone examples shell: bash @@ -55,13 +55,13 @@ jobs: shell: bash run: | cd build - cmake --build . --target tests + cmake --build . --target tests --config Release - name: run tests shell: bash run: | cd build - ctest --output-on-failure + ctest -C Release --output-on-failure - name: Upload artifact uses: actions/upload-artifact@v4 diff --git a/cmake/helpers.cmake b/cmake/helpers.cmake index 04aa39cb..fd25c7e3 100644 --- a/cmake/helpers.cmake +++ b/cmake/helpers.cmake @@ -94,12 +94,16 @@ endfunction() # Copy necessary dlls to target runtime directory # function(copy_dlls target) - if(WIN32) - add_custom_command(TARGET ${target} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ - COMMAND_EXPAND_LISTS - ) - endif() + set(have_runtime_dlls $>) + set(command + ${CMAKE_COMMAND} -E copy_if_different + $ + $ + ) + add_custom_command(TARGET ${target} POST_BUILD + COMMAND "$<${have_runtime_dlls}:${command}>" + COMMAND_EXPAND_LISTS + ) endfunction() # @@ -158,18 +162,6 @@ function(get_required_static_libs variable) message(STATUS "${variable} = ${native_static_libs}") endfunction() -# -# Copy necessary dlls to target runtime directory -# -function(copy_dlls target) - if(WIN32) - add_custom_command(TARGET ${target} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ - COMMAND_EXPAND_LISTS - ) - endif() -endfunction() - # # get property value avoiding CMake behavior - setting variable to -NOTFOUND for undefined property # diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 55a1ff63..8bfcad8f 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -22,6 +22,7 @@ function(add_example file mode lib) target_link_libraries(${target} PUBLIC ${lib}) set_property(TARGET ${target} PROPERTY LANGUAGE CXX) set_property(TARGET ${target} PROPERTY CXX_STANDARD 17) + copy_dlls(${target}) endfunction() function(add_examples glob mode lib) diff --git a/examples/simple/universal/CMakeLists.txt b/examples/simple/universal/CMakeLists.txt index 38fd4244..a1b38678 100644 --- a/examples/simple/universal/CMakeLists.txt +++ b/examples/simple/universal/CMakeLists.txt @@ -1,6 +1,9 @@ cmake_minimum_required(VERSION 3.16) project(zenohcxx_examples LANGUAGES C CXX) +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake" ${CMAKE_MODULE_PATH}) +include(helpers) + if(CMAKE_BUILD_TYPE STREQUAL "") set(CMAKE_BUILD_TYPE Release) endif() @@ -13,8 +16,10 @@ add_executable(zp_simple z_simple.cxx) target_link_libraries(zp_simple PRIVATE zenohcxx::zenohpico) set_property(TARGET zp_simple PROPERTY LANGUAGE CXX) set_property(TARGET zp_simple PROPERTY CXX_STANDARD 17) +copy_dlls(zp_simple) add_executable(zc_simple z_simple.cxx) target_link_libraries(zc_simple PRIVATE zenohcxx::zenohc) set_property(TARGET zc_simple PROPERTY LANGUAGE CXX) -set_property(TARGET zc_simple PROPERTY CXX_STANDARD 17) \ No newline at end of file +set_property(TARGET zc_simple PROPERTY CXX_STANDARD 17) +copy_dlls(zc_simple) \ No newline at end of file diff --git a/examples/simple/zenohc/CMakeLists.txt b/examples/simple/zenohc/CMakeLists.txt index 8a63d0f8..0a608bce 100644 --- a/examples/simple/zenohc/CMakeLists.txt +++ b/examples/simple/zenohc/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 3.16) project(zenohcxx_examples LANGUAGES C CXX) +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake" ${CMAKE_MODULE_PATH}) +include(helpers) if(CMAKE_BUILD_TYPE STREQUAL "") set(CMAKE_BUILD_TYPE Release) @@ -11,4 +13,5 @@ find_package(zenohcxx REQUIRED) add_executable(zc_simple zc_simple.cxx) target_link_libraries(zc_simple PRIVATE zenohcxx::zenohc) set_property(TARGET zc_simple PROPERTY LANGUAGE CXX) -set_property(TARGET zc_simple PROPERTY CXX_STANDARD 17) \ No newline at end of file +set_property(TARGET zc_simple PROPERTY CXX_STANDARD 17) +copy_dlls(zc_simple) \ No newline at end of file diff --git a/examples/simple/zenohpico/CMakeLists.txt b/examples/simple/zenohpico/CMakeLists.txt index 79627845..1d3c41ad 100644 --- a/examples/simple/zenohpico/CMakeLists.txt +++ b/examples/simple/zenohpico/CMakeLists.txt @@ -1,6 +1,9 @@ cmake_minimum_required(VERSION 3.16) project(zenohcxx_examples LANGUAGES C CXX) +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake" ${CMAKE_MODULE_PATH}) +include(helpers) + if(CMAKE_BUILD_TYPE STREQUAL "") set(CMAKE_BUILD_TYPE Release) endif() @@ -12,3 +15,4 @@ add_executable(zp_simple zp_simple.cxx) target_link_libraries(zp_simple PRIVATE zenohcxx::zenohpico) set_property(TARGET zp_simple PROPERTY LANGUAGE CXX) set_property(TARGET zp_simple PROPERTY CXX_STANDARD 17) +copy_dlls(zp_simple) diff --git a/examples/zenohc/z_get_shm.cxx b/examples/zenohc/z_get_shm.cxx index d68c3b83..4fcb1055 100644 --- a/examples/zenohc/z_get_shm.cxx +++ b/examples/zenohc/z_get_shm.cxx @@ -83,8 +83,15 @@ int _main(int argc, char **argv) { memcpy(buf.data(), value, len); std::cout << "Sending Query '" << expr << "'...\n"; +#if __cpp_designated_initializers >= 201707L session.get(keyexpr, "", on_reply, on_done, {.target = Z_QUERY_TARGET_ALL, .payload = Bytes::serialize(std::move(buf))}); +#else + Session::GetOptions options; + options.target = Z_QUERY_TARGET_ALL; + options.payload = Bytes::serialize(std::move(buf)); + session.get(keyexpr, "", on_reply, on_done, std::move(options)); +#endif std::unique_lock lock(m); done_signal.wait(lock, [&done] { return done; }); diff --git a/examples/zenohc/z_pub_shm.cxx b/examples/zenohc/z_pub_shm.cxx index ed3d9efc..dea79919 100644 --- a/examples/zenohc/z_pub_shm.cxx +++ b/examples/zenohc/z_pub_shm.cxx @@ -80,7 +80,13 @@ int _main(int argc, char **argv) { ZShmMut &&buf = std::get(std::move(alloc_result)); memcpy(buf.data(), s.data(), len); +#if __cpp_designated_initializers >= 201707L pub.put(Bytes::serialize(std::move(buf)), {.encoding = Encoding("text/plain")}); +#else + Publisher::PutOptions options; + options.encoding = Encoding("text/plain"); + pub.put(Bytes::serialize(std::move(buf)), std::move(options)); +#endif } return 0; } diff --git a/examples/zenohc/z_pub_shm_thr.cxx b/examples/zenohc/z_pub_shm_thr.cxx index 2874c279..81e9efeb 100644 --- a/examples/zenohc/z_pub_shm_thr.cxx +++ b/examples/zenohc/z_pub_shm_thr.cxx @@ -51,8 +51,14 @@ int _main(int argc, char **argv) { auto session = Session::open(std::move(config)); std::cout << "Declaring Publisher on " << keyexpr << "...\n"; - auto pub = session.declare_publisher(KeyExpr(keyexpr), {.congestion_control = Z_CONGESTION_CONTROL_BLOCK}); +#if __cpp_designated_initializers >= 201707L + auto pub = session.declare_publisher(KeyExpr(keyexpr), {.congestion_control = Z_CONGESTION_CONTROL_BLOCK}); +#else + Session::PublisherOptions options; + options.congestion_control = Z_CONGESTION_CONTROL_BLOCK; + auto pub = session.declare_publisher(keyexpr, std::move(options)); +#endif std::cout << "Preparing SHM Provider...\n"; constexpr auto buffers_count = 4; PosixShmProvider provider(MemoryLayout(buffers_count * len, AllocAlignment({2}))); diff --git a/examples/zenohc/z_queryable_shm.cxx b/examples/zenohc/z_queryable_shm.cxx index 6a955445..8a0d59f6 100644 --- a/examples/zenohc/z_queryable_shm.cxx +++ b/examples/zenohc/z_queryable_shm.cxx @@ -88,7 +88,13 @@ int _main(int argc, char **argv) { ZShmMut &&buf = std::get(std::move(alloc_result)); memcpy(buf.data(), value, len); +#if __cpp_designated_initializers >= 201707L query.reply(KeyExpr(expr), Bytes::serialize(std::move(buf)), {.encoding = Encoding("text/plain")}); +#else + Query::ReplyOptions options; + options.encoding = Encoding("text/plain"); + query.reply(KeyExpr(expr), Bytes::serialize(std::move(buf)), std::move(options)); +#endif }; auto on_drop_queryable = []() { std::cout << "Destroying queryable\n"; }; diff --git a/include/zenoh/api/bytes.hxx b/include/zenoh/api/bytes.hxx index d03710b6..b84681a9 100644 --- a/include/zenoh/api/bytes.hxx +++ b/include/zenoh/api/bytes.hxx @@ -22,6 +22,7 @@ #include "shm/buffer/buffer.hxx" #endif +#include #include #include #include diff --git a/include/zenoh/api/interop.hxx b/include/zenoh/api/interop.hxx index e6671f76..6f3319ee 100644 --- a/include/zenoh/api/interop.hxx +++ b/include/zenoh/api/interop.hxx @@ -82,8 +82,9 @@ const OwnedType* as_owned_c_ptr(const Owned& cpp_obj) { template < class OwnedType, class Loaned = typename ::z_owned_to_loaned_type_t::type, // SFINAE here if no loaned type declared - class LoanAvailable = std::enable_if_t, Loaned> // SFINAE here if immutable - // loan is not available + class LoanAvailable = std::enable_if_t, Loaned> // SFINAE here if + // immutable loan is + // not available > const Loaned* as_loaned_c_ptr(const Owned& cpp_obj) { return ::z_loan(*as_owned_c_ptr(cpp_obj)); @@ -93,8 +94,8 @@ const Loaned* as_loaned_c_ptr(const Owned& cpp_obj) { template ::type, // SFINAE here if no loaned type // declared - class LoanAvailable = std::enable_if_t, - Loaned> // SFINAE here if immutable loan is not available + class LoanAvailable = std::enable_if_t, + Loaned> // SFINAE here if mutable loan is not available > Loaned* as_loaned_c_ptr(Owned& cpp_obj) { return ::z_loan_mut(*as_owned_c_ptr(cpp_obj)); diff --git a/scripts/build_local.sh b/scripts/build_local.sh index 957e967e..13383012 100755 --- a/scripts/build_local.sh +++ b/scripts/build_local.sh @@ -16,5 +16,5 @@ cd "$project_folder" rm -rf ./build mkdir ./build cd ./build -cmake .. "${@:3}" --install-prefix "$absolute_install_location" -make \ No newline at end of file +cmake .. "${@:3}" -DCMAKE_BUILD_TYPE=Release --install-prefix "$absolute_install_location" +cmake --build . --config Release \ No newline at end of file diff --git a/scripts/build_standalone_examples.sh b/scripts/build_standalone_examples.sh index 8c149a6a..2b84e5d6 100755 --- a/scripts/build_standalone_examples.sh +++ b/scripts/build_standalone_examples.sh @@ -3,12 +3,21 @@ set -e SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) if [ "$#" -eq 0 ]; then - echo "Usage: build_standalone_examples INSTALL_PATH" + echo "Usage: build_standalone_examples INSTALL_PATH [BUILD_PICO]" exit fi +BUILD_PICO="ON" +if [ "$#" -ge 2 ]; then + BUILD_PICO=$2 +fi absolute_install_location=$(cd $1; pwd) -bash $SCRIPT_DIR/build_local.sh $SCRIPT_DIR/../examples/simple/universal $absolute_install_location bash $SCRIPT_DIR/build_local.sh $SCRIPT_DIR/../examples/simple/zenohc $absolute_install_location -bash $SCRIPT_DIR/build_local.sh $SCRIPT_DIR/../examples/simple/zenohpico $absolute_install_location \ No newline at end of file + +if [ "$BUILD_PICO" == "ON" ]; then + #build examples requiring zenoh-pico + bash $SCRIPT_DIR/build_local.sh $SCRIPT_DIR/../examples/simple/universal $absolute_install_location + bash $SCRIPT_DIR/build_local.sh $SCRIPT_DIR/../examples/simple/zenohpico $absolute_install_location +fi + diff --git a/scripts/install_from_git.sh b/scripts/install_from_git.sh index c1e1d0fb..ab695516 100755 --- a/scripts/install_from_git.sh +++ b/scripts/install_from_git.sh @@ -3,23 +3,46 @@ set -e SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) if [ "$#" -eq 0 ]; then - echo "Usage: install_from_git INSTALL_PATH" + echo "Usage: install_from_git INSTALL_PATH [BUILD_WITH_UNSTABLE_API] [BUILD_WITH_SHARED_MEMORY] [BUILD_PICO]" exit fi +USE_UNSTABLE="TRUE" +USE_SHARED_MEMORY="TRUE" +USE_UNSTABLE_PICO="0" +BUILD_PICO="ON" + +if [ "$#" -ge 2 ]; then + USE_UNSTABLE=$2 +fi + +if [ "$#" -ge 3 ]; then + USE_SHARED_MEMORY=$3 +fi + +if ("$USE_UNSTABLE" == "TRUE"); then + USE_UNSTABLE_PICO="1" +fi + +if [ "$#" -ge 4 ]; then + BUILD_PICO=$4 +fi + + git submodule init git submodule update mkdir -p $1 absolute_install_location=$(cd $1; pwd) #build zenoh-c -bash $SCRIPT_DIR/install_local.sh $SCRIPT_DIR/../zenoh-c $absolute_install_location -DZENOHC_BUILD_WITH_UNSTABLE_API=TRUE -DZENOHC_BUILD_WITH_SHARED_MEMORY=TRUE -#build zenoh-pico -bash $SCRIPT_DIR/install_local.sh $SCRIPT_DIR/../zenoh-pico $absolute_install_location -DZ_FEATURE_UNSTABLE_API=1 +bash $SCRIPT_DIR/install_local.sh $SCRIPT_DIR/../zenoh-c $absolute_install_location -DZENOHC_BUILD_WITH_UNSTABLE_API=$USE_UNSTABLE -DZENOHC_BUILD_WITH_SHARED_MEMORY=$USE_SHARED_MEMORY +if [ "$BUILD_PICO" == "ON" ]; then + #build zenoh-pico + bash $SCRIPT_DIR/install_local.sh $SCRIPT_DIR/../zenoh-pico $absolute_install_location -DZ_FEATURE_UNSTABLE_API=$USE_UNSTABLE_PICO +fi rm -rf ./build mkdir ./build cd ./build -cmake .. -DZENOHCXX_ZENOHPICO=ON --install-prefix "$absolute_install_location" -make -make install \ No newline at end of file +cmake .. -DCMAKE_BUILD_TYPE=Release -DZENOHCXX_ZENOHPICO=$BUILD_PICO --install-prefix "$absolute_install_location" +cmake --build . --target install --config Release \ No newline at end of file diff --git a/scripts/install_from_local.sh b/scripts/install_from_local.sh index bf40cad2..0542cba3 100755 --- a/scripts/install_from_local.sh +++ b/scripts/install_from_local.sh @@ -17,6 +17,5 @@ bash $SCRIPT_DIR/install_local.sh $SCRIPT_DIR/../../zenoh-pico $absolute_install rm -rf ./build mkdir ./build cd ./build -cmake .. -DZENOHCXX_ZENOHPICO=ON --install-prefix "$absolute_install_location" -make -make install \ No newline at end of file +cmake .. -DCMAKE_BUILD_TYPE=Release -DZENOHCXX_ZENOHPICO=ON --install-prefix "$absolute_install_location" +cmake --build . --target install --config Release \ No newline at end of file diff --git a/scripts/install_local.sh b/scripts/install_local.sh index 5a782def..b74d6384 100755 --- a/scripts/install_local.sh +++ b/scripts/install_local.sh @@ -17,5 +17,4 @@ rm -rf ./build mkdir ./build cd ./build cmake .. "${@:3}" --install-prefix "$absolute_install_location" -make -make install \ No newline at end of file +cmake --build . --target install --config Release \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bda25495..311180e4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -32,10 +32,11 @@ function(add_test_instance file mode lib option) set_property(TARGET ${target} PROPERTY LANGUAGE CXX) set_property(TARGET ${target} PROPERTY CXX_STANDARD 17) if (option STREQUAL "Router") - add_test(NAME "test_${target}" COMMAND bash ${CMAKE_CURRENT_BINARY_DIR}/run_with_router.sh ${target} ${zenoh_router_branch}) + add_test(NAME "test_${target}" COMMAND bash ${CMAKE_CURRENT_BINARY_DIR}/run_with_router.sh $ ${zenoh_router_branch}) else() add_test(NAME "test_${target}" COMMAND ${target}) endif() + copy_dlls(${target}) endfunction() file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/universal/*.cxx") diff --git a/tests/run_with_router.sh b/tests/run_with_router.sh index 4fa0a4ba..1309a118 100644 --- a/tests/run_with_router.sh +++ b/tests/run_with_router.sh @@ -17,11 +17,9 @@ TESTBIN="$1" TESTDIR=$(dirname "$0") ZENOH_BRANCH="$2" -if [ "$OSTYPE" = "msys" ]; then - TESTBIN="$TESTDIR/Debug/$TESTBIN.exe" -else - TESTBIN="./$TESTBIN" -fi +# get vinary name without extension +TEST_NAME_WE=$(basename -- "$TESTBIN") +TEST_NAME_WE="${TEST_NAME_WE%.*}" cd "$TESTDIR"|| exit @@ -46,7 +44,7 @@ for LOCATOR in $(echo "$LOCATORS" | xargs); do sleep 1 echo "> Running zenohd ... $LOCATOR" - RUST_LOG=debug ./zenohd --plugin-search-dir "$TESTDIR/zenoh-git/target/debug" -l "$LOCATOR" > zenohd."$1".log 2>&1 & + RUST_LOG=debug ./zenohd --plugin-search-dir "$TESTDIR/zenoh-git/target/debug" -l "$LOCATOR" > zenohd."$TEST_NAME_WE".log 2>&1 & ZPID=$! sleep 5 @@ -61,7 +59,7 @@ for LOCATOR in $(echo "$LOCATORS" | xargs); do sleep 1 echo "> Logs of zenohd ..." - cat zenohd."$1".log + cat zenohd."$TEST_NAME_WE".log [ "$RETCODE" -lt 0 ] && exit "$RETCODE" done diff --git a/zenoh-c b/zenoh-c index 7eb05090..610a4b90 160000 --- a/zenoh-c +++ b/zenoh-c @@ -1 +1 @@ -Subproject commit 7eb0509051e271977e9cbf600c82ec0989f06855 +Subproject commit 610a4b9057a703ecba5f098e084bdc40e4e786f3 diff --git a/zenoh-pico b/zenoh-pico index dbaf8cd0..c9deea09 160000 --- a/zenoh-pico +++ b/zenoh-pico @@ -1 +1 @@ -Subproject commit dbaf8cd06f9274fae5396d56e14fa31df9ae8221 +Subproject commit c9deea09d1f126008e6c3558433049caa260d102