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

Patch cargo toolchain for noble #136

Merged
merged 11 commits into from
Apr 2, 2024
3 changes: 2 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
docker_image: ['ros:iron-ros-base', 'ros:rolling-ros-base']
container:
Expand All @@ -21,7 +22,7 @@ jobs:
run: |
apt update && apt install -y curl
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
uses: dtolnay/rust-toolchain@1.75.0
- uses: actions/checkout@v2
- name: rosdep
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/style.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
docker_image: ['ros:iron-ros-base', 'ros:rolling-ros-base']
container:
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/tmp_build_noble.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: build_noble
on:
pull_request:
push:
branches: [ rolling ]
workflow_dispatch:
defaults:
run:
shell: bash
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
docker_image: ['ubuntu:noble-20240225']
container:
image: ${{ matrix.docker_image }}
timeout-minutes: 30
steps:
- name: Setup rolling
run: |
apt update && apt install curl -y
curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null
apt update && apt install ros-dev-tools -y
apt install ros-rolling-ros-base -y
- uses: actions/checkout@v2
- name: rosdep
run: |
rosdep init
rosdep update
rosdep install --from-paths . --rosdistro rolling -yir
- name: build
run: |
source /opt/ros/rolling/setup.bash
colcon build
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ For information about the Design please visit [design](docs/design.md) page.

## Setup

Install latest rustc.
> Note: The version of rustc that can be installed via apt is outdated.
Install latest rustc via `rustup` if building on Ubuntu Jammy.
Skip this step if building on Ubuntu Noble as `cargo` and `rustc` will be
Copy link
Member

@ruffsl ruffsl Mar 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool! When/how did that happen with rosdep? Or does Noble ship debs for rust build tools?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The debs are available in Jammy too but the versions are very dated so we install them via rustup to compile zenoh. Noble ships with cargo/rustc 1.75.0 which works out of the box for our use case.

installed via `rosdep`.
```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup install 1.75.0
```

Build `rmw_zenoh_cpp`
Expand Down
16 changes: 16 additions & 0 deletions zenoh_c_vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,29 @@ find_package(ament_cmake_vendor_package REQUIRED)
# when expanded.
set(ZENOHC_CARGO_FLAGS "--no-default-features$<SEMICOLON>--features=zenoh/transport_tcp zenoh/shared-memory")

# Always force rustc 1.75.0.
# This this is default version of rustc available via apt in Ubuntu Noble.
Yadunund marked this conversation as resolved.
Show resolved Hide resolved
# We explictly use the +1.75.0 toolchain when building on Ubuntu Jammy.
set(ZENOHC_CARGO_CHANNEL "1.75.0")

# Apply the patch the zenoh-c CMakeLists.txt only if building an ROS 2 version
Yadunund marked this conversation as resolved.
Show resolved Hide resolved
# newer than Iron. The patch removes the ability to set ZENOHC_CARGO_CHANNEL
# via cmake args
set(pathces "")
Yadunund marked this conversation as resolved.
Show resolved Hide resolved
string(SUBSTRING "$ENV{ROS_DISTRO}" 0 1 first_char)
if("${first_char}" STRGREATER "i")
set(patches "patches")
endif()

# Set VCS_VERSION to include changes from https://github.com/eclipse-zenoh/zenoh/pull/802
# which was synced to zenoh-c in https://github.com/eclipse-zenoh/zenoh-c/pull/272.
ament_vendor(zenoh_c_vendor
VCS_URL https://github.com/eclipse-zenoh/zenoh-c.git
VCS_VERSION 10176b911096cb92b8ee46bc491b78079ee26c20
CMAKE_ARGS
"-DZENOHC_CARGO_FLAGS=${ZENOHC_CARGO_FLAGS}"
"-DZENOHC_CARGO_CHANNEL=${ZENOHC_CARGO_CHANNEL}"
PATCHES patches
)

# set(INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-prefix/install")
Expand Down
3 changes: 2 additions & 1 deletion zenoh_c_vendor/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>ament_cmake_vendor_package</buildtool_depend>

<!-- <build_depend>cargo</build_depend> -->
<!-- TODO(Yadunund) switch condition such that it checks if $ROS_DISTRO[0] > 'i' -->
<build_depend condition="$ROS_DISTRO == rolling">cargo</build_depend>
<build_depend>clang</build_depend>

<export>
Expand Down
56 changes: 56 additions & 0 deletions zenoh_c_vendor/patches/cargo_toolchain.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 00aa5ca..eacd7d6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,7 +27,6 @@ declare_cache_var_true_if_vscode(ZENOHC_BUILD_IN_SOURCE_TREE "Do build inside so
declare_cache_var(ZENOHC_BUILD_WITH_LOGGER_AUTOINIT TRUE BOOL "Enable logger-autoinit zenoh-c feature")
declare_cache_var(ZENOHC_BUILD_WITH_SHARED_MEMORY TRUE BOOL "Enable shared-memory zenoh-c feature")
declare_cache_var(ZENOHC_CUSTOM_TARGET "" STRING "Rust target for cross compilation, 'aarch64-unknown-linux-gnu' for example")
-declare_cache_var(ZENOHC_CARGO_CHANNEL "stable" STRING "Cargo channel selected: stable or nightly")
declare_cache_var(ZENOHC_CARGO_FLAGS "" STRING "Additional cargo flags")
declare_cache_var(ZENOHC_LIB_STATIC FALSE BOOL "Alias zenohc::lib target to zenohc::static if TRUE, to zenohc::shared if FALSE")

@@ -47,9 +46,9 @@ status_print(project_version)
#
# There are 3 possible variants of placement generated Cargo.toml files:
# 1. Build in source tree (in IDE usually), using single config generator (Ninja, Makefiles)
-#
+#
# In this case Cargo.toml is placed at the root of source tree to make it visible for rust-analyzer. When release or debug
-# configuration is selected, Cargo.toml is updated accordingly
+# configuration is selected, Cargo.toml is updated accordingly
#
# 2. Build in source tree (in IDE usually), using multi config generator (Visual Studio, Ninja Multi-Config)
#
@@ -112,7 +111,7 @@ function(configure_cargo_toml cargo_toml_dir CARGO_PROJECT_VERSION CARGO_LIB_NAM
${CMAKE_CURRENT_SOURCE_DIR}/Cargo.lock
${CMAKE_CURRENT_SOURCE_DIR}/rust-toolchain.toml
DESTINATION ${cargo_toml_dir})
- endif()
+ endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Cargo.toml.in" "${cargo_toml_dir}/Cargo.toml" @ONLY)
endfunction()

@@ -173,9 +172,9 @@ set_genexpr_condition(libs DEBUG $<CONFIG:Debug> "${libsd}" "${libsr}")
#

# Combine "--release" and "--manifest-path" options under DEBUG condition to avoid passing empty parameter to cargo command line in `add_custom_command`, causing build failure
-# This empty item ($<IF:$<CONFIG:Debug>;,--release>) can't be filtered out by `list(FILTER ...)` because it becomes empty only on
+# This empty item ($<IF:$<CONFIG:Debug>;,--release>) can't be filtered out by `list(FILTER ...)` because it becomes empty only on
# build stage when generator expressions are evaluated.
-set_genexpr_condition(cargo_flags DEBUG $<CONFIG:Debug>
+set_genexpr_condition(cargo_flags DEBUG $<CONFIG:Debug>
"--manifest-path=${cargo_toml_dir_debug}/Cargo.toml"
"--release;--manifest-path=${cargo_toml_dir_release}/Cargo.toml")
set(cargo_flags ${cargo_flags} ${ZENOHC_CARGO_FLAGS})
@@ -198,8 +197,8 @@ file(GLOB_RECURSE rust_sources "Cargo.toml.in" "src/*.rs" "build.rs" "splitguide
add_custom_command(
OUTPUT ${libs}
COMMAND ${CMAKE_COMMAND} -E echo \"RUSTFLAGS = $$RUSTFLAGS\"
- COMMAND ${CMAKE_COMMAND} -E echo \"cargo +${ZENOHC_CARGO_CHANNEL} build ${cargo_flags}\"
- COMMAND cargo +${ZENOHC_CARGO_CHANNEL} build ${cargo_flags}
+ COMMAND ${CMAKE_COMMAND} -E echo \"cargo build ${cargo_flags}\"
+ COMMAND cargo build ${cargo_flags}
VERBATIM
COMMAND_EXPAND_LISTS
DEPENDS "${rust_sources}"
Loading