diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..c3e11a38d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,58 @@ +################################################################################ +# Repo + +.git/* +.dockerignore +.gitignore +**Dockerfile +**.Dockerfile + +################################################################################ +# Rust + +# Generated by Cargo +# will have compiled files and executables +/target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +################################################################################ +# C++ + +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..d8c6b0b61 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,97 @@ +# This dockerfile can be configured via --build-arg +# Build context must be the /ros2_rust root folder for COPY. +# Example build command: +# export OVERLAY_MIXINS="debug ccache coverage" +# export RUN_TESTS="true" +# docker build -t nav2:latest \ +# --build-arg OVERLAY_MIXINS \ +# --build-arg RUN_TESTS +# --pull ./ + +ARG FROM_IMAGE=ros:foxy +ARG OVERLAY_WS=/opt/overlay_ws + +# multi-stage for caching +FROM $FROM_IMAGE AS cacher + +# clone overlay source +ARG OVERLAY_WS +WORKDIR $OVERLAY_WS/src +COPY ./ros2_rust.repos ../ +RUN vcs import ./ < ../ros2_rust.repos && \ + find ./ -name ".git" | xargs rm -rf +COPY ./ ./ros2-rust/ros2_rust + +# copy manifests for caching +WORKDIR /opt +RUN mkdir -p /tmp/opt && \ + find ./ -name "package.xml" | \ + xargs cp --parents -t /tmp/opt && \ + find ./ -name "COLCON_IGNORE" | \ + xargs cp --parents -t /tmp/opt || true + +# multi-stage for building +FROM $FROM_IMAGE AS builder +ARG DEBIAN_FRONTEND=noninteractive + +# install CI dependencies +RUN apt-get update && apt-get install -q -y \ + ccache \ + clang \ + lcov \ + libclang-dev \ + llvm-dev \ + wget \ + && rm -rf /var/lib/apt/lists/* + +# install rust dependencies +ENV RUSTUP_HOME=/usr/local/rustup \ + CARGO_HOME=/usr/local/cargo \ + PATH=/usr/local/cargo/bin:$PATH \ + RUST_VERSION=1.47.0 +RUN set -eux; \ + wget -O rustup-init "https://sh.rustup.rs"; \ + chmod +x rustup-init; \ + ./rustup-init -y \ + --no-modify-path \ + --default-toolchain $RUST_VERSION; \ + rm rustup-init; \ + chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \ + rustup --version; \ + cargo --version; \ + rustc --version; + +# install overlay dependencies +ARG OVERLAY_WS +WORKDIR $OVERLAY_WS +COPY --from=cacher /tmp/$OVERLAY_WS ./ +RUN . /opt/ros/$ROS_DISTRO/setup.sh && \ + apt-get update && rosdep install -q -y \ + --from-paths src \ + --ignore-src \ + && rm -rf /var/lib/apt/lists/* + +# build overlay source +COPY --from=cacher $OVERLAY_WS ./ +ARG OVERLAY_MIXINS="release ccache" +RUN . /opt/ros/$ROS_DISTRO/setup.sh && \ + colcon build \ + --symlink-install \ + --mixin $OVERLAY_MIXINS \ + || ([ -z "$FAIL_ON_BUILD_FAILURE" ] || exit 1) + +# source overlay from entrypoint +ENV OVERLAY_WS $OVERLAY_WS +RUN sed --in-place \ + 's|^source .*|source "$OVERLAY_WS/install/setup.bash"|' \ + /ros_entrypoint.sh + +# test overlay build +ARG RUN_TESTS +ARG FAIL_ON_TEST_FAILURE=True +RUN if [ -n "$RUN_TESTS" ]; then \ + . install/setup.sh && \ + colcon test && \ + colcon test-result \ + || ([ -z "$FAIL_ON_TEST_FAILURE" ] || exit 1) \ + fi diff --git a/README.md b/README.md index 039d2dc2b..3826179cb 100644 --- a/README.md +++ b/README.md @@ -42,18 +42,31 @@ Lots of things! Sounds great, how can I try this out? ------------------------------------- -The following steps were last tested on Ubuntu 18.04. They show how to build the examples: +You can build and run the example using the included Dockerfile: +``` +git clone https://github.com/ros2-rust/ros2_rust.git +docker build --tag ros2:rust . +docker run -it --rm ros2:rust +ros2 run rclrs_examples rclrs_publisher & +ros2 run rclrs_examples rclrs_subscriber + +``` + +Or do so manually as summarized in the steps below: + +> The following steps were last tested on Ubuntu 20.04. ``` # first, install vcstool from PyPI or apt: # sudo apt install ros-foxy-desktop python3-vcstool libclang-dev clang # pip install vcstool -mkdir -p ~/ros2_rust_ws/src -cd ~/ros2_rust_ws -wget https://raw.githubusercontent.com/ros2-rust/ros2_rust/master/ros2_rust.repos -vcs import src < ros2_rust.repos +mkdir -p ~/ros2_rust_ws/src/ros2-rust +cd ~/ros2_rust_ws/src/ros2-rust +git clone https://github.com/ros2-rust/ros2_rust.git +cd ../../ +vcs import src < src/ros2-rust/ros2_rust/ros2_rust.repos source /opt/ros/foxy/setup.sh colcon build ``` diff --git a/ros2_rust.repos b/ros2_rust.repos index 18b65fb40..61b6ae041 100644 --- a/ros2_rust.repos +++ b/ros2_rust.repos @@ -2,16 +2,16 @@ repositories: ros2/common_interfaces: type: git url: https://github.com/ros2/common_interfaces.git - version: crystal + version: foxy ros2/rcl_interfaces: type: git url: https://github.com/ros2/rcl_interfaces.git - version: crystal + version: foxy ros2/rosidl_defaults: type: git url: https://github.com/ros2/rosidl_defaults.git - version: crystal - ros2_rust/ros2_rust: - type: git - url: https://github.com/ros2-rust/ros2_rust.git - version: master + version: foxy + # ros2-rust/ros2_rust: + # type: git + # url: https://github.com/ros2-rust/ros2_rust.git + # version: master