Skip to content

Commit

Permalink
fix and enable windows build/test in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Sep 18, 2024
2 parents 66e4603 + bed324b commit ad333ae
Show file tree
Hide file tree
Showing 20 changed files with 119 additions and 58 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
28 changes: 10 additions & 18 deletions cmake/helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_RUNTIME_DLLS:${target}> $<TARGET_FILE_DIR:${target}>
COMMAND_EXPAND_LISTS
)
endif()
set(have_runtime_dlls $<BOOL:$<TARGET_RUNTIME_DLLS:${target}>>)
set(command
${CMAKE_COMMAND} -E copy_if_different
$<TARGET_RUNTIME_DLLS:${target}>
$<TARGET_FILE_DIR:${target}>
)
add_custom_command(TARGET ${target} POST_BUILD
COMMAND "$<${have_runtime_dlls}:${command}>"
COMMAND_EXPAND_LISTS
)
endfunction()

#
Expand Down Expand Up @@ -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 $<TARGET_RUNTIME_DLLS:${target}> $<TARGET_FILE_DIR:${target}>
COMMAND_EXPAND_LISTS
)
endif()
endfunction()

#
# get property value avoiding CMake behavior - setting variable to <VAR>-NOTFOUND for undefined property
#
Expand Down
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion examples/simple/universal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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)
set_property(TARGET zc_simple PROPERTY CXX_STANDARD 17)
copy_dlls(zc_simple)
5 changes: 4 additions & 1 deletion examples/simple/zenohc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
set_property(TARGET zc_simple PROPERTY CXX_STANDARD 17)
copy_dlls(zc_simple)
4 changes: 4 additions & 0 deletions examples/simple/zenohpico/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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)
7 changes: 7 additions & 0 deletions examples/zenohc/z_get_shm.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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; });
Expand Down
6 changes: 6 additions & 0 deletions examples/zenohc/z_pub_shm.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ int _main(int argc, char **argv) {
ZShmMut &&buf = std::get<ZShmMut>(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;
}
Expand Down
8 changes: 7 additions & 1 deletion examples/zenohc/z_pub_shm_thr.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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})));
Expand Down
6 changes: 6 additions & 0 deletions examples/zenohc/z_queryable_shm.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ int _main(int argc, char **argv) {
ZShmMut &&buf = std::get<ZShmMut>(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"; };
Expand Down
1 change: 1 addition & 0 deletions include/zenoh/api/bytes.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "shm/buffer/buffer.hxx"
#endif

#include <array>
#include <cstddef>
#include <cstdint>
#include <deque>
Expand Down
9 changes: 5 additions & 4 deletions include/zenoh/api/interop.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ const OwnedType* as_owned_c_ptr(const Owned<OwnedType>& cpp_obj) {
template <
class OwnedType,
class Loaned = typename ::z_owned_to_loaned_type_t<OwnedType>::type, // SFINAE here if no loaned type declared
class LoanAvailable = std::enable_if_t<detail::is_loan_available_v<OwnedType>, Loaned> // SFINAE here if immutable
// loan is not available
class LoanAvailable = std::enable_if_t<zenoh::detail::is_loan_available_v<OwnedType>, Loaned> // SFINAE here if
// immutable loan is
// not available
>
const Loaned* as_loaned_c_ptr(const Owned<OwnedType>& cpp_obj) {
return ::z_loan(*as_owned_c_ptr(cpp_obj));
Expand All @@ -93,8 +94,8 @@ const Loaned* as_loaned_c_ptr(const Owned<OwnedType>& cpp_obj) {
template <class OwnedType,
class Loaned = typename ::z_owned_to_loaned_type_t<OwnedType>::type, // SFINAE here if no loaned type
// declared
class LoanAvailable = std::enable_if_t<detail::is_loan_mut_available_v<OwnedType>,
Loaned> // SFINAE here if immutable loan is not available
class LoanAvailable = std::enable_if_t<zenoh::detail::is_loan_mut_available_v<OwnedType>,
Loaned> // SFINAE here if mutable loan is not available
>
Loaned* as_loaned_c_ptr(Owned<OwnedType>& cpp_obj) {
return ::z_loan_mut(*as_owned_c_ptr(cpp_obj));
Expand Down
4 changes: 2 additions & 2 deletions scripts/build_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ cd "$project_folder"
rm -rf ./build
mkdir ./build
cd ./build
cmake .. "${@:3}" --install-prefix "$absolute_install_location"
make
cmake .. "${@:3}" -DCMAKE_BUILD_TYPE=Release --install-prefix "$absolute_install_location"
cmake --build . --config Release
15 changes: 12 additions & 3 deletions scripts/build_standalone_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

37 changes: 30 additions & 7 deletions scripts/install_from_git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
cmake .. -DCMAKE_BUILD_TYPE=Release -DZENOHCXX_ZENOHPICO=$BUILD_PICO --install-prefix "$absolute_install_location"
cmake --build . --target install --config Release
5 changes: 2 additions & 3 deletions scripts/install_from_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
cmake .. -DCMAKE_BUILD_TYPE=Release -DZENOHCXX_ZENOHPICO=ON --install-prefix "$absolute_install_location"
cmake --build . --target install --config Release
3 changes: 1 addition & 2 deletions scripts/install_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ rm -rf ./build
mkdir ./build
cd ./build
cmake .. "${@:3}" --install-prefix "$absolute_install_location"
make
make install
cmake --build . --target install --config Release
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_FILE:${target}> ${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")
Expand Down
Loading

0 comments on commit ad333ae

Please sign in to comment.