Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cross-compile tests to ci and fix library names #790

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
[target.x86_64-unknown-linux-musl]
rustflags = "-Ctarget-feature=-crt-static"
linker = "x86_64-linux-musl-gcc"

[target.aarch64-unknown-linux-musl]
rustflags = "-Ctarget-feature=-crt-static"
linker = "aarch64-linux-musl-gcc"

[target.arm-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"

[target.arm-unknown-linux-gnueabi]
linker = "arm-linux-gnueabi-gcc"

[target.armv7-unknown-linux-gnueabihf]
linker = "armv7-linux-gnueabihf-gcc"

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"

[target.x86_64-unknown-linux-gnu]
linker = "x86_64-linux-gnu-gcc"

[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"
108 changes: 108 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,114 @@ jobs:
!target/release/.*
!target/release/*.d

cross-compile-mac-os:
name: Cross compile on macOS-latest
runs-on: macOS-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
brew tap messense/macos-cross-toolchains
brew install armv7-unknown-linux-gnueabihf
brew install mingw-w64
brew install x86_64-unknown-linux-gnu

- name: Install rust toolchains
run: |
rustup target add armv7-unknown-linux-gnueabihf
rustup target add x86_64-pc-windows-gnu
rustup target add x86_64-unknown-linux-gnu

- name: Cross compile for armv7-unknown-linux-gnueabihf
run: |
rm -rf ./build
mkdir -p ./build && cd ./build
cmake -DCMAKE_TOOLCHAIN_FILE="../ci/toolchains/TC-armv7-unknown-linux-gnueabihf.cmake" -DZENOHC_BUILD_WITH_SHARED_MEMORY=ON -DZENOHC_BUILD_WITH_UNSTABLE_API=ON ..
cmake --build . --target examples

- name: Cross compile for x86_64-unknown-linux-gnu
run: |
rm -rf ./build
mkdir -p ./build && cd ./build
cmake -DCMAKE_TOOLCHAIN_FILE="../ci/toolchains/TC-x86_64-unknown-linux-gnu.cmake" -DZENOHC_BUILD_WITH_SHARED_MEMORY=ON -DZENOHC_BUILD_WITH_UNSTABLE_API=ON ..
cmake --build . --target examples

- name: Cross compile for x86_64-pc-windows-gnu
run: |
rm -rf ./build
mkdir -p ./build && cd ./build
cmake -DCMAKE_TOOLCHAIN_FILE="../ci/toolchains/TC-x86_64-pc-windows-gnu.cmake" -DZENOHC_BUILD_WITH_SHARED_MEMORY=ON -DZENOHC_BUILD_WITH_UNSTABLE_API=ON ..
cmake --build . --target examples

cross-compile-ubuntu:
name: Cross compile on ubuntu-latest
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get install -y musl-tools
sudo apt-get install -y gcc-arm-linux-gnueabi
sudo apt-get install -y g++-arm-linux-gnueabi
sudo apt-get install -y mingw-w64
sudo apt-get install -y gcc-aarch64-linux-gnu
sudo apt-get install -y g++-aarch64-linux-gnu
wget https://musl.cc/aarch64-linux-musl-cross.tgz
tar xvfz aarch64-linux-musl-cross.tgz
echo "$(readlink -f aarch64-linux-musl-cross)/bin" >> "$GITHUB_PATH"
wget https://musl.cc/x86_64-linux-musl-cross.tgz
tar xvfz x86_64-linux-musl-cross.tgz
echo "$(readlink -f x86_64-linux-musl-cross)/bin" >> "$GITHUB_PATH"

- name: Install rust toolchains
run: |
rustup target add arm-unknown-linux-gnueabi
rustup target add x86_64-pc-windows-gnu
rustup target add aarch64-unknown-linux-gnu
rustup target add aarch64-unknown-linux-musl
rustup target add x86_64-unknown-linux-musl

- name: Cross compile for arm-unknown-linux-gnueabi
run: |
rm -rf ./build
mkdir -p ./build && cd ./build
cmake -DCMAKE_TOOLCHAIN_FILE="../ci/toolchains/TC-arm-unknown-linux-gnueabi.cmake" -DZENOHC_BUILD_WITH_SHARED_MEMORY=ON -DZENOHC_BUILD_WITH_UNSTABLE_API=ON ..
cmake --build . --target examples

- name: Cross compile for aarch64-unknown-linux-gnu
run: |
rm -rf ./build
mkdir -p ./build && cd ./build
cmake -DCMAKE_TOOLCHAIN_FILE="../ci/toolchains/TC-aarch64-unknown-linux-gnu.cmake" -DZENOHC_BUILD_WITH_SHARED_MEMORY=ON -DZENOHC_BUILD_WITH_UNSTABLE_API=ON ..
cmake --build . --target examples

- name: Cross compile for aarch64-unknown-linux-musl
run: |
rm -rf ./build
mkdir -p ./build && cd ./build
cmake -DCMAKE_TOOLCHAIN_FILE="../ci/toolchains/TC-aarch64-unknown-linux-musl.cmake" -DZENOHC_BUILD_WITH_SHARED_MEMORY=ON -DZENOHC_BUILD_WITH_UNSTABLE_API=ON ..
cmake --build . --target examples

- name: Cross compile for x86_64-unknown-linux-musl
run: |
rm -rf ./build
mkdir -p ./build && cd ./build
cmake -DCMAKE_TOOLCHAIN_FILE="../ci/toolchains/TC-x86_64-unknown-linux-musl.cmake" -DZENOHC_BUILD_WITH_SHARED_MEMORY=ON -DZENOHC_BUILD_WITH_UNSTABLE_API=ON ..
cmake --build . --target examples

- name: Cross compile for x86_64-pc-windows-gnu
run: |
rm -rf ./build
mkdir -p ./build && cd ./build
cmake -DCMAKE_TOOLCHAIN_FILE="../ci/toolchains/TC-x86_64-pc-windows-gnu.cmake" -DZENOHC_BUILD_WITH_SHARED_MEMORY=ON -DZENOHC_BUILD_WITH_UNSTABLE_API=ON ..
cmake --build . --target examples

# NOTE: In GitHub repository settings, the "Require status checks to pass
# before merging" branch protection rule ensures that commits are only merged
# from branches where specific status checks have passed. These checks are
Expand Down
80 changes: 50 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,35 @@ endmacro()
# dylib[r|d] - dymamic library (.so, .dll, .dylib)
# staticlib[r|d] - static library (.a, .lib)
# implib[r|d] - import library for windows dynamic library (DLL) - .lib
# dylibs[r|d] - list of files required for use dynamic libraty
# staticlibs[r|d] - list of files required for use static libraty
set_lib(dylibsr dylibr ${CMAKE_SHARED_LIBRARY_PREFIX}zenohc${CMAKE_SHARED_LIBRARY_SUFFIX})
set_lib(dylibsd dylibd ${CMAKE_SHARED_LIBRARY_PREFIX}zenohcd${CMAKE_SHARED_LIBRARY_SUFFIX})
set_lib(staticlibsr staticlibr ${CMAKE_STATIC_LIBRARY_PREFIX}zenohc${CMAKE_STATIC_LIBRARY_SUFFIX})
set_lib(staticlibsd staticlibd ${CMAKE_STATIC_LIBRARY_PREFIX}zenohcd${CMAKE_STATIC_LIBRARY_SUFFIX})
# dylibs[r|d] - list of files required for use dynamic library
# staticlibs[r|d] - list of files required for use static library
# get rust output library names from https://github.com/corrosion-rs/corrosion/blob/1c6974c2473765449e7c4649f9f96f1b751420c3/cmake/Corrosion.cmake#L331
if(WIN32)
set_lib(dylibsr implibr ${CMAKE_IMPORT_LIBRARY_PREFIX}zenohc${CMAKE_SHARED_LIBRARY_SUFFIX}${CMAKE_IMPORT_LIBRARY_SUFFIX})
set_lib(dylibsd implibd ${CMAKE_IMPORT_LIBRARY_PREFIX}zenohcd${CMAKE_SHARED_LIBRARY_SUFFIX}${CMAKE_IMPORT_LIBRARY_SUFFIX})
set_lib(dylibsr dylibr zenohc.dll)
set_lib(dylibsd dylibd zenohcd.dll)
if(MSVC)
set_lib(staticlibsr staticlibr zenohc.lib)
set_lib(staticlibsd staticlibd zenohcd.lib)
set_lib(dylibsr implibr zenohc.dll.lib)
set_lib(dylibsd implibd zenohcd.dll.lib)
else() #gnu/mingw/msys ?
set_lib(staticlibsr staticlibr libzenohc.a)
set_lib(staticlibsd staticlibd libzenohcd.a)
set_lib(dylibsr implibr libzenohc.dll.a)
set_lib(dylibsd implibd libzenohcd.dll.a)
endif()
elseif(APPLE)
set_lib(dylibsr dylibr libzenohc.dylib)
set_lib(dylibsd dylibd libzenohcd.dylib)
set_lib(staticlibsr staticlibr libzenohc.a)
set_lib(staticlibsd staticlibd libzenohcd.a)
else() #UNIX
set_lib(dylibsr dylibr libzenohc.so)
set_lib(dylibsd dylibd libzenohcd.so)
set_lib(staticlibsr staticlibr libzenohc.a)
set_lib(staticlibsd staticlibd libzenohcd.a)
endif()

list(APPEND libsr ${dylibsr})
list(APPEND libsr ${staticlibsr})
list(APPEND libsd ${dylibsd})
Expand Down Expand Up @@ -262,39 +281,40 @@ endfunction()
# *IMPORTANT* any options in this section should be repeated in install/PackageConfig.cmake.in
# to achieve correct behavior of find_package(zenohc)
#
add_library(zenohc_shared SHARED IMPORTED GLOBAL)
add_library(zenohc::shared ALIAS zenohc_shared)
add_dependencies(zenohc_shared cargo)
target_compile_definitions(zenohc_shared INTERFACE ZENOHC_DYN_LIB)
# Workaroud for https://github.com/rust-lang/cargo/issues/5045
# mentioned in https://github.com/eclipse-zenoh/zenoh-c/issues/138
# If it's fixed, do not forget to correct PackageConfig.cmake.in also
set_target_properties(zenohc_shared PROPERTIES IMPORTED_NO_SONAME TRUE)
set_target_imported_locations(zenohc_shared ${dylibr} ${dylibd})
add_library(zenohc_static STATIC IMPORTED GLOBAL)
add_library(zenohc::static ALIAS zenohc_static)
add_dependencies(zenohc_static cargo)
get_required_static_libs(NATIVE_STATIC_LIBS)
target_link_libraries(zenohc_static INTERFACE ${NATIVE_STATIC_LIBS})
set_target_imported_locations(zenohc_static ${staticlibr} ${staticlibd})
target_include_directories(zenohc_static INTERFACE ${cargo_generated_include_dir})
set_target_properties(zenohc_static PROPERTIES IMPORTED_GLOBAL TRUE)

if(DEFINED implibr)
set_target_imported_implib(zenohc_shared ${implibr} ${implibd})
endif()
target_include_directories(zenohc_shared INTERFACE ${cargo_generated_include_dir})
set_target_properties(zenohc_shared PROPERTIES IMPORTED_GLOBAL TRUE)
if (BUILD_SHARED_LIBS)
add_library(zenohc_shared SHARED IMPORTED GLOBAL)
add_library(zenohc::lib ALIAS zenohc_shared)
add_dependencies(zenohc_shared cargo)
target_compile_definitions(zenohc_shared INTERFACE ZENOHC_DYN_LIB)
# Workaroud for https://github.com/rust-lang/cargo/issues/5045
# mentioned in https://github.com/eclipse-zenoh/zenoh-c/issues/138
# If it's fixed, do not forget to correct PackageConfig.cmake.in also
set_target_properties(zenohc_shared PROPERTIES IMPORTED_NO_SONAME TRUE)
set_target_imported_locations(zenohc_shared ${dylibr} ${dylibd})
if(DEFINED implibr)
set_target_imported_implib(zenohc_shared ${implibr} ${implibd})
endif()
target_include_directories(zenohc_shared INTERFACE ${cargo_generated_include_dir})
set_target_properties(zenohc_shared PROPERTIES IMPORTED_GLOBAL TRUE)
else()
add_library(zenohc_static STATIC IMPORTED GLOBAL)
add_library(zenohc::lib ALIAS zenohc_static)
add_library(zenohc::static ALIAS zenohc_static)
add_dependencies(zenohc_static cargo)
get_required_static_libs(NATIVE_STATIC_LIBS)
target_link_libraries(zenohc_static INTERFACE ${NATIVE_STATIC_LIBS})
set_target_imported_locations(zenohc_static ${staticlibr} ${staticlibd})
target_include_directories(zenohc_static INTERFACE ${cargo_generated_include_dir})
set_target_properties(zenohc_static PROPERTIES IMPORTED_GLOBAL TRUE)
endif()


#
# Components included only if project is the root project
#
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
include(cmake/cross_build_check.cmake)
add_subdirectory(install)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${cargo_binary_dir}/tests)
add_subdirectory(tests)
Expand Down
5 changes: 5 additions & 0 deletions ci/toolchains/TC-aarch64-unknown-linux-gnu.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(ZENOHC_CUSTOM_TARGET aarch64-unknown-linux-gnu)
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
5 changes: 5 additions & 0 deletions ci/toolchains/TC-aarch64-unknown-linux-musl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(ZENOHC_CUSTOM_TARGET aarch64-unknown-linux-musl)
set(CMAKE_C_COMPILER aarch64-linux-musl-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-musl-g++)
5 changes: 5 additions & 0 deletions ci/toolchains/TC-arm-unknown-linux-gnueabi.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(ZENOHC_CUSTOM_TARGET arm-unknown-linux-gnueabi)
set(CMAKE_C_COMPILER arm-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER arm-linux-gnueabi-g++)
5 changes: 5 additions & 0 deletions ci/toolchains/TC-armv7-unknown-linux-gnueabihf.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv7)
set(ZENOHC_CUSTOM_TARGET armv7-unknown-linux-gnueabihf)
set(CMAKE_C_COMPILER armv7-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER armv7-linux-gnueabihf-g++)
5 changes: 5 additions & 0 deletions ci/toolchains/TC-x86_64-pc-windows-gnu.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(ZENOHC_CUSTOM_TARGET x86_64-pc-windows-gnu)
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
5 changes: 5 additions & 0 deletions ci/toolchains/TC-x86_64-unknown-linux-gnu.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(ZENOHC_CUSTOM_TARGET x86_64-unknown-linux-gnu)
set(CMAKE_C_COMPILER x86_64-unknown-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER x86_64-unknown-linux-gnu-g++)
5 changes: 5 additions & 0 deletions ci/toolchains/TC-x86_64-unknown-linux-musl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(ZENOHC_CUSTOM_TARGET x86_64-unknown-linux-musl)
set(CMAKE_C_COMPILER x86_64-linux-musl-gcc)
set(CMAKE_CXX_COMPILER x86_64-linux-musl-g++)
34 changes: 0 additions & 34 deletions cmake/cross_build_check.cmake

This file was deleted.

5 changes: 0 additions & 5 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ foreach(file ${files})
endif()
endif()

# FIXME: remove once zenoh time primitives are available and examples updated
if(NOT(UNIX) AND(${target} STREQUAL "z_ping" OR ${target} STREQUAL "z_pong" OR ${target} STREQUAL "z_sub_thr"))
continue()
endif()

add_executable(${target} EXCLUDE_FROM_ALL ${file})
add_dependencies(examples ${target})

Expand Down
Loading