|
| 1 | +# CI checks module |
| 2 | +# This module defines all CI checks for ros-z project |
| 3 | +{ |
| 4 | + pkgs, |
| 5 | + self, |
| 6 | + commonBuildInputs, |
| 7 | + mkRosEnv, |
| 8 | + exportEnvVars, |
| 9 | +}: |
| 10 | +let |
| 11 | + # Vendor Cargo dependencies for sandboxed builds |
| 12 | + cargoVendorDir = pkgs.rustPlatform.importCargoLock { |
| 13 | + lockFile = ./Cargo.lock; |
| 14 | + outputHashes = { |
| 15 | + "cdr-encoding-0.10.2" = "sha256-bpo8Fu3Qp5TapzFFAvyRJdSiO50G3YBBTSJNV/cNa4Y="; |
| 16 | + "roslibrust-0.16.0" = "sha256-qi4h1ksC/iLwK1uiUs6LU9CX3RDYVOd6E4SRdUAbqZo="; |
| 17 | + }; |
| 18 | + }; |
| 19 | + |
| 20 | + # Fetch roslibrust git repo for assets directory (with submodules for ros2_common_interfaces) |
| 21 | + roslibrustSrc = pkgs.fetchgit { |
| 22 | + url = "https://github.com/YuanYuYuan/roslibrust"; |
| 23 | + rev = "f08547babb04c3b19a77af9a55a10b8148908e55"; # dev/ros-z branch |
| 24 | + hash = "sha256-qi4h1ksC/iLwK1uiUs6LU9CX3RDYVOd6E4SRdUAbqZo="; |
| 25 | + fetchSubmodules = true; |
| 26 | + }; |
| 27 | +in |
| 28 | +let |
| 29 | + # Create a cargo check that runs in sandbox with vendored dependencies |
| 30 | + mkCargoCheck = |
| 31 | + { |
| 32 | + name, |
| 33 | + packages, |
| 34 | + rosEnv ? null, |
| 35 | + script, |
| 36 | + extraAttrs ? { }, |
| 37 | + }: |
| 38 | + pkgs.stdenv.mkDerivation ( |
| 39 | + { |
| 40 | + name = "check-${name}"; |
| 41 | + src = self; |
| 42 | + nativeBuildInputs = packages ++ [ pkgs.nixfmt-rfc-style ]; # For format checks |
| 43 | + buildInputs = pkgs.lib.optional (rosEnv != null) rosEnv; |
| 44 | + |
| 45 | + # Disable ROS setup hooks that interfere with Cargo builds |
| 46 | + dontUseCmakeConfigure = true; |
| 47 | + dontUseColconBuildSetup = true; |
| 48 | + |
| 49 | + buildPhase = '' |
| 50 | + # Export environment variables |
| 51 | + ${exportEnvVars} |
| 52 | +
|
| 53 | + # Disable sccache in sandbox (no HOME directory) |
| 54 | + unset RUSTC_WRAPPER |
| 55 | +
|
| 56 | + # Setup ROS environment if provided |
| 57 | + ${pkgs.lib.optionalString (rosEnv != null) '' |
| 58 | + export AMENT_PREFIX_PATH="${rosEnv}" |
| 59 | + export CMAKE_PREFIX_PATH="${rosEnv}" |
| 60 | + ''} |
| 61 | +
|
| 62 | + # Setup vendored cargo dependencies |
| 63 | + export CARGO_HOME=$(pwd)/.cargo |
| 64 | + mkdir -p .cargo |
| 65 | + cat > .cargo/config.toml <<EOF |
| 66 | + [source.crates-io] |
| 67 | + replace-with = "vendored-sources" |
| 68 | +
|
| 69 | + [source."https://github.com/YuanYuYuan/cdr-encoding"] |
| 70 | + git = "https://github.com/YuanYuYuan/cdr-encoding" |
| 71 | + branch = "feat/byte-buf" |
| 72 | + replace-with = "vendored-sources" |
| 73 | +
|
| 74 | + [source."https://github.com/YuanYuYuan/roslibrust"] |
| 75 | + git = "https://github.com/YuanYuYuan/roslibrust" |
| 76 | + branch = "dev/ros-z" |
| 77 | + replace-with = "vendored-sources" |
| 78 | +
|
| 79 | + [source.vendored-sources] |
| 80 | + directory = "${cargoVendorDir}" |
| 81 | + EOF |
| 82 | +
|
| 83 | + # Point build.rs to roslibrust assets from fetched git repo |
| 84 | + export ROSLIBRUST_ASSETS_DIR="${roslibrustSrc}/assets" |
| 85 | +
|
| 86 | + # Run checks |
| 87 | + set -euo pipefail |
| 88 | + ${script} |
| 89 | + ''; |
| 90 | + |
| 91 | + installPhase = '' |
| 92 | + touch $out |
| 93 | + ''; |
| 94 | + |
| 95 | + # Disable hardening for ROS compatibility |
| 96 | + hardeningDisable = [ "all" ]; |
| 97 | + } |
| 98 | + // extraAttrs |
| 99 | + ); |
| 100 | +in |
| 101 | +let |
| 102 | + # Formatting check - runs first and other checks depend on this |
| 103 | + formatting = mkCargoCheck { |
| 104 | + name = "formatting"; |
| 105 | + packages = commonBuildInputs; |
| 106 | + script = '' |
| 107 | + echo "=== Nix Formatting ===" |
| 108 | + nixfmt --check flake.nix |
| 109 | +
|
| 110 | + echo "=== Markdown Linting ===" |
| 111 | + markdownlint '**/*.md' |
| 112 | +
|
| 113 | + echo "=== Rust Formatting ===" |
| 114 | + cargo fmt --all -- --check |
| 115 | + ''; |
| 116 | + }; |
| 117 | + |
| 118 | + # ROS-independent checks (linting, build, test) |
| 119 | + no-ros = mkCargoCheck { |
| 120 | + name = "no-ros"; |
| 121 | + packages = commonBuildInputs; |
| 122 | + script = '' |
| 123 | + # This check depends on formatting passing first |
| 124 | + # Reference the formatting check to create a build-time dependency |
| 125 | + echo "Prerequisites: ${formatting}" |
| 126 | +
|
| 127 | + echo "=== Build & Test ===" |
| 128 | + cargo build --workspace --lib --bins --exclude rcl-z --exclude protobuf_demo |
| 129 | + cargo test --workspace --lib --bins --exclude rcl-z --exclude protobuf_demo |
| 130 | +
|
| 131 | + echo "=== Lint ===" |
| 132 | + cargo clippy --workspace --lib --bins --exclude rcl-z -- -D warnings |
| 133 | +
|
| 134 | + echo "=== Message Package Checks ===" |
| 135 | + cargo check -p ros-z-msgs |
| 136 | + cargo check -p ros-z-msgs --features bundled_msgs |
| 137 | + cargo check -p ros-z-msgs --features common_interfaces |
| 138 | +
|
| 139 | + echo "=== Individual Message Packages ===" |
| 140 | + cargo build -p ros-z-msgs --no-default-features --features std_msgs |
| 141 | + cargo build -p ros-z-msgs --no-default-features --features geometry_msgs |
| 142 | + cargo build -p ros-z-msgs --no-default-features --features sensor_msgs |
| 143 | + cargo build -p ros-z-msgs --no-default-features --features nav_msgs |
| 144 | + ''; |
| 145 | + }; |
| 146 | + |
| 147 | + # ROS-dependent checks for Jazzy distribution |
| 148 | + with-ros-jazzy = mkCargoCheck { |
| 149 | + name = "with-ros-jazzy"; |
| 150 | + packages = commonBuildInputs; |
| 151 | + rosEnv = (mkRosEnv "jazzy").build; |
| 152 | + script = '' |
| 153 | + # This check depends on formatting passing first |
| 154 | + # Reference the formatting check to create a build-time dependency |
| 155 | + echo "Prerequisites: ${formatting}" |
| 156 | +
|
| 157 | + echo "=== RCL Bindings ===" |
| 158 | + cargo check -p rcl-z |
| 159 | +
|
| 160 | + echo "=== Message Packages ===" |
| 161 | + cargo check -p ros-z-msgs |
| 162 | + cargo check -p ros-z-msgs --features external_msgs |
| 163 | + cargo check -p ros-z-msgs --features example_interfaces |
| 164 | + cargo check -p ros-z-msgs --features all_msgs |
| 165 | +
|
| 166 | + echo "=== Feature Checks ===" |
| 167 | + cargo check -p ros-z -p ros-z-msgs --features ros-z/protobuf,ros-z-msgs/protobuf |
| 168 | + cargo check -p ros-z --features rcl-z |
| 169 | +
|
| 170 | + echo "=== Build Examples ===" |
| 171 | + cargo build -p ros-z-msgs |
| 172 | + cargo build --examples |
| 173 | + cargo build --example z_srvcli --features external_msgs |
| 174 | + cargo build -p protobuf_demo |
| 175 | + ''; |
| 176 | + }; |
| 177 | +in |
| 178 | +{ |
| 179 | + # Export all checks |
| 180 | + inherit formatting no-ros with-ros-jazzy; |
| 181 | +} |
0 commit comments