From df5c424af84e61ab1f304ba5549815478b4c189c Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Fri, 25 Oct 2024 13:53:10 +0200 Subject: [PATCH] add cross-compilation test for linux --- .cargo/config.toml | 1 + .github/workflows/ci.yml | 67 ++++++++++++++++++- CMakeLists.txt | 1 - .../TC-aarch64-unknown-linux-gnu.cmake | 5 ++ .../TC-aarch64-unknown-linux-musl.cmake | 5 ++ .../TC-arm-unknown-linux-gnueabi.cmake | 5 ++ .../TC-armv7-unknown-linux-gnueabihf.cmake | 2 +- ci/toolchains/TC-x86_64-pc-windows-gnu.cmake | 2 +- .../TC-x86_64-unknown-linux-gnu.cmake | 2 +- .../TC-x86_64-unknown-linux-musl.cmake | 5 ++ cmake/cross_build_check.cmake | 34 ---------- 11 files changed, 90 insertions(+), 39 deletions(-) create mode 100644 ci/toolchains/TC-aarch64-unknown-linux-gnu.cmake create mode 100644 ci/toolchains/TC-aarch64-unknown-linux-musl.cmake create mode 100644 ci/toolchains/TC-arm-unknown-linux-gnueabi.cmake create mode 100644 ci/toolchains/TC-x86_64-unknown-linux-musl.cmake delete mode 100644 cmake/cross_build_check.cmake diff --git a/.cargo/config.toml b/.cargo/config.toml index 9897badd9..829125ef6 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,5 +1,6 @@ [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" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 232868cf8..336498474 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -121,7 +121,7 @@ jobs: !target/release/.* !target/release/*.d - cross-compile-mac: + cross-compile-mac-os: name: Cross compile on macOS-latest runs-on: macOS-latest strategy: @@ -163,6 +163,71 @@ jobs: 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 diff --git a/CMakeLists.txt b/CMakeLists.txt index a8ce07dfc..6a125d71e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -315,7 +315,6 @@ 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) diff --git a/ci/toolchains/TC-aarch64-unknown-linux-gnu.cmake b/ci/toolchains/TC-aarch64-unknown-linux-gnu.cmake new file mode 100644 index 000000000..8f1a6b36c --- /dev/null +++ b/ci/toolchains/TC-aarch64-unknown-linux-gnu.cmake @@ -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++) diff --git a/ci/toolchains/TC-aarch64-unknown-linux-musl.cmake b/ci/toolchains/TC-aarch64-unknown-linux-musl.cmake new file mode 100644 index 000000000..0793da1ab --- /dev/null +++ b/ci/toolchains/TC-aarch64-unknown-linux-musl.cmake @@ -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++) diff --git a/ci/toolchains/TC-arm-unknown-linux-gnueabi.cmake b/ci/toolchains/TC-arm-unknown-linux-gnueabi.cmake new file mode 100644 index 000000000..8b340ce22 --- /dev/null +++ b/ci/toolchains/TC-arm-unknown-linux-gnueabi.cmake @@ -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++) diff --git a/ci/toolchains/TC-armv7-unknown-linux-gnueabihf.cmake b/ci/toolchains/TC-armv7-unknown-linux-gnueabihf.cmake index 846a53d6a..83362af52 100644 --- a/ci/toolchains/TC-armv7-unknown-linux-gnueabihf.cmake +++ b/ci/toolchains/TC-armv7-unknown-linux-gnueabihf.cmake @@ -2,4 +2,4 @@ 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++) \ No newline at end of file +set(CMAKE_CXX_COMPILER armv7-linux-gnueabihf-g++) diff --git a/ci/toolchains/TC-x86_64-pc-windows-gnu.cmake b/ci/toolchains/TC-x86_64-pc-windows-gnu.cmake index 2afb5508d..9be83069d 100644 --- a/ci/toolchains/TC-x86_64-pc-windows-gnu.cmake +++ b/ci/toolchains/TC-x86_64-pc-windows-gnu.cmake @@ -2,4 +2,4 @@ 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++) \ No newline at end of file +set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) diff --git a/ci/toolchains/TC-x86_64-unknown-linux-gnu.cmake b/ci/toolchains/TC-x86_64-unknown-linux-gnu.cmake index 523c95d6d..ce56df0f3 100644 --- a/ci/toolchains/TC-x86_64-unknown-linux-gnu.cmake +++ b/ci/toolchains/TC-x86_64-unknown-linux-gnu.cmake @@ -2,4 +2,4 @@ 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++) \ No newline at end of file +set(CMAKE_CXX_COMPILER x86_64-unknown-linux-gnu-g++) diff --git a/ci/toolchains/TC-x86_64-unknown-linux-musl.cmake b/ci/toolchains/TC-x86_64-unknown-linux-musl.cmake new file mode 100644 index 000000000..f4904a4ae --- /dev/null +++ b/ci/toolchains/TC-x86_64-unknown-linux-musl.cmake @@ -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++) diff --git a/cmake/cross_build_check.cmake b/cmake/cross_build_check.cmake deleted file mode 100644 index 49b5a67d1..000000000 --- a/cmake/cross_build_check.cmake +++ /dev/null @@ -1,34 +0,0 @@ -# -# Rust cross-build check for supported processor architectures -# This check works on linux only -# It requires that the following packages are installed for cross compilation: -# -# sudo apt install gcc-arm-linux-gnueabi -# sudo apt install gcc-x86-64-linux-gnu -# sudo apt install gcc-aarch64-linux-gnu -# -# and the following targets in rustup -# -# rustup target add arm-unknown-linux-gnueabi -# rustup target add aarch64-unknown-linux-gnu -# rustup target add x86_64-unknown-linux-gnu -# -# check which targets are already installed with -# -# rustup target list --installed -# -add_custom_target(crosscheck) - -set(targets -aarch64-unknown-linux-gnu -x86_64-unknown-linux-gnu -arm-unknown-linux-gnueabi -) - -foreach(target ${targets}) - add_custom_target(cargo_check_${target} - COMMAND cargo check --target ${target} ${cargo_flags} - COMMENT "cargo check on ${target}" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - add_dependencies(crosscheck cargo_check_${target}) -endforeach()