Skip to content

Commit 7e81a0d

Browse files
authored
ci: improve the pre-commit hook and fix nightly rustfmt (#30)
1 parent e55fdac commit 7e81a0d

File tree

13 files changed

+121
-155
lines changed

13 files changed

+121
-155
lines changed

flake.nix

Lines changed: 27 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
];
4343
};
4444

45+
rustfmtNightly = pkgs.rust-bin.nightly.latest.rustfmt;
46+
47+
# Override rustfmt to use nightly
48+
rustfmt-nightly-bin = pkgs.writeShellScriptBin "rustfmt" ''
49+
exec ${rustfmtNightly}/bin/rustfmt "$@"
50+
'';
51+
4552
# Factory to create environment for a specific ROS distro
4653
mkRosEnv =
4754
rosDistro:
@@ -164,7 +171,13 @@
164171
{
165172
default = mkDevShell {
166173
name = "ros-z-dev-${rosDistro}";
167-
packages = commonBuildInputs ++ devTools ++ [ rosEnv.dev ] ++ pre-commit-check.enabledPackages;
174+
packages = [
175+
rustfmt-nightly-bin
176+
]
177+
++ commonBuildInputs
178+
++ devTools
179+
++ [ rosEnv.dev ]
180+
++ pre-commit-check.enabledPackages;
168181
extraShellHook = pre-commit-check.shellHook;
169182
banner = ''
170183
echo "🦀 ros-z development environment (with ROS)"
@@ -179,137 +192,21 @@
179192
};
180193
};
181194

182-
# Cargo metadata
183-
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
184-
185-
# Helper to create packages for a specific ROS distro
186-
mkRosPackages =
187-
rosDistro:
188-
let
189-
rosEnv = mkRosEnv rosDistro;
190-
in
191-
{
192-
"ros-z-${rosDistro}" = mkRustPackage {
193-
pname = "ros-z";
194-
buildAndTestSubdir = "ros-z";
195-
description = "Native Rust ROS 2 implementation using Zenoh - Core";
196-
};
197-
198-
"rcl-z-${rosDistro}" = mkRustPackage {
199-
pname = "rcl-z";
200-
buildAndTestSubdir = "rcl-z";
201-
rosInputs = [ rosEnv.rcl ];
202-
description = "Native Rust ROS 2 implementation using Zenoh - RCL Bindings (${rosDistro})";
203-
};
204-
205-
"ros-z-msgs-${rosDistro}" = mkRustPackage {
206-
pname = "ros-z-msgs";
207-
buildAndTestSubdir = "ros-z-msgs";
208-
rosInputs = [ rosEnv.msgs ];
209-
description = "Native Rust ROS 2 implementation using Zenoh - Message Definitions (${rosDistro})";
210-
};
211-
212-
"ros-z-full-${rosDistro}" = mkRustPackage {
213-
pname = "ros-z";
214-
rosInputs = [ rosEnv.build ];
215-
description = cargoToml.workspace.package.description;
216-
};
217-
};
218-
219-
# Common package attributes factory
220-
mkRustPackage =
221-
{
222-
pname,
223-
buildAndTestSubdir ? null,
224-
rosInputs ? [ ],
225-
description,
226-
}:
227-
pkgs.rustPlatform.buildRustPackage {
228-
inherit pname;
229-
version = cargoToml.workspace.package.version;
230-
src = ./.;
231-
inherit buildAndTestSubdir;
232-
233-
cargoLock = {
234-
lockFile = ./Cargo.lock;
235-
};
236-
237-
nativeBuildInputs = commonBuildInputs;
238-
buildInputs = rosInputs;
239-
240-
inherit (commonEnvVars) LIBCLANG_PATH CLANG_PATH RUSTC_WRAPPER;
241-
242-
meta = with pkgs.lib; {
243-
inherit description;
244-
homepage = cargoToml.workspace.package.homepage;
245-
license = licenses.asl20;
246-
maintainers = [ ];
247-
};
248-
};
249-
250195
# Generate shells for all distros
251196
allDistroShells = builtins.listToAttrs (
252197
builtins.map (distro: {
253198
name = distro;
254199
value = mkRosShells distro;
255200
}) distros
256201
);
257-
# yamllint configuration
258-
yamlFormat = pkgs.formats.yaml { };
259-
yamllintConfigData = {
260-
extends = "default";
261-
rules = {
262-
line-length = {
263-
max = 120;
264-
};
265-
document-start = "disable";
266-
truthy = "disable";
267-
};
268-
};
269-
yamllintConfig = yamlFormat.generate ".yamllint.yaml" yamllintConfigData;
270-
271-
# markdownlint configuration
272-
markdownlintConfig = {
273-
MD013 = false; # Line length
274-
MD033 = {
275-
# Inline HTML
276-
allowed_elements = [
277-
"div"
278-
"h1"
279-
"p"
280-
"strong"
281-
"a"
282-
"sub"
283-
];
284-
};
285-
MD041 = false; # First line in file should be a top-level heading
286-
};
287-
288202
# Pre-commit hooks configuration
289-
pre-commit-check = git-hooks.lib.${system}.run {
290-
src = ./.;
291-
hooks = {
292-
# Rust formatter
293-
rustfmt.enable = true;
294-
295-
# TOML formatter
296-
taplo.enable = true;
297-
298-
# YAML linter with relaxed rules
299-
yamllint = {
300-
enable = true;
301-
settings.configPath = "${yamllintConfig}";
302-
};
303-
304-
# Markdown linter
305-
markdownlint = {
306-
enable = true;
307-
settings.configuration = markdownlintConfig;
308-
};
309-
310-
# Nix formatter
311-
nixfmt-rfc-style.enable = true;
312-
};
203+
pre-commit-check = import ./nix/pre-commit.nix {
204+
inherit
205+
pkgs
206+
git-hooks
207+
system
208+
rustfmtNightly
209+
;
313210
};
314211
in
315212
{
@@ -326,7 +223,12 @@
326223
# Without ROS
327224
noRos = mkDevShell {
328225
name = "ros-z-no-ros";
329-
packages = commonBuildInputs ++ devTools ++ pre-commit-check.enabledPackages;
226+
packages = [
227+
rustfmt-nightly-bin
228+
]
229+
++ commonBuildInputs
230+
++ devTools
231+
++ pre-commit-check.enabledPackages;
330232
extraShellHook = pre-commit-check.shellHook;
331233
banner = ''
332234
echo "🦀 ros-z development environment (without ROS)"

nix/pre-commit.nix

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
pkgs,
3+
git-hooks,
4+
system,
5+
rustfmtNightly,
6+
}:
7+
let
8+
# yamllint configuration
9+
yamlFormat = pkgs.formats.yaml { };
10+
yamllintConfigData = {
11+
extends = "default";
12+
rules = {
13+
line-length = {
14+
max = 120;
15+
};
16+
document-start = "disable";
17+
truthy = "disable";
18+
};
19+
};
20+
yamllintConfig = yamlFormat.generate ".yamllint.yaml" yamllintConfigData;
21+
22+
# markdownlint configuration
23+
markdownlintConfig = {
24+
MD013 = false; # Line length
25+
MD033 = {
26+
# Inline HTML
27+
allowed_elements = [
28+
"div"
29+
"h1"
30+
"p"
31+
"strong"
32+
"a"
33+
"sub"
34+
];
35+
};
36+
MD041 = false; # First line in file should be a top-level heading
37+
};
38+
in
39+
git-hooks.lib.${system}.run {
40+
src = ./..;
41+
tools = {
42+
rustfmt = rustfmtNightly;
43+
};
44+
hooks = {
45+
# Rust formatter (using nightly for unstable features)
46+
rustfmt.enable = true;
47+
48+
# TOML formatter
49+
taplo.enable = true;
50+
51+
# YAML linter with relaxed rules
52+
yamllint = {
53+
enable = true;
54+
settings.configPath = "${yamllintConfig}";
55+
};
56+
57+
# Markdown linter
58+
markdownlint = {
59+
enable = true;
60+
settings.configuration = markdownlintConfig;
61+
};
62+
63+
# Nix formatter
64+
nixfmt-rfc-style.enable = true;
65+
};
66+
}

rcl-z/build.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use std::env;
2-
use std::path::PathBuf;
1+
use std::{env, path::PathBuf};
32

43
const INCLUDE_PACKAGES: &[&str] = &[
54
"rcl",

ros-z-codegen/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ pub mod protobuf_adapter;
33
pub mod roslibrust_adapter;
44
pub mod type_info_generator;
55

6-
use anyhow::Result;
76
use std::path::{Path, PathBuf};
87

8+
use anyhow::Result;
9+
910
pub struct MessageGenerator {
1011
config: GeneratorConfig,
1112
}

ros-z-msgs/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use std::{env, path::PathBuf};
2+
13
use anyhow::Result;
2-
use std::env;
3-
use std::path::PathBuf;
44

55
fn main() -> Result<()> {
66
let out_dir = PathBuf::from(env::var("OUT_DIR")?);

ros-z-msgs/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ pub mod proto {
2525
}
2626

2727
// Re-export commonly used items from ros-z for convenience
28-
pub use ros_z::MessageTypeInfo;
29-
pub use ros_z::entity::{TypeHash, TypeInfo};
28+
pub use ros_z::{
29+
MessageTypeInfo,
30+
entity::{TypeHash, TypeInfo},
31+
};

ros-z-tests/tests/pubsub_interop.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
mod common;
44

5-
use std::process::{Command, Stdio};
6-
use std::sync::{Arc, Mutex};
7-
use std::thread;
8-
use std::time::Duration;
5+
use std::{
6+
process::{Command, Stdio},
7+
sync::{Arc, Mutex},
8+
thread,
9+
time::Duration,
10+
};
911

12+
use common::*;
1013
use ros_z::Builder;
1114
use ros_z_msgs::std_msgs::String as RosString;
1215

13-
use common::*;
14-
1516
#[serial_test::serial]
1617
#[test]
1718
fn test_ros_z_pub_to_ros2_sub() {

ros-z-tests/tests/service_interop.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
mod common;
44

5-
use std::process::Command;
6-
use std::thread;
7-
use std::time::Duration;
5+
use std::{process::Command, thread, time::Duration};
86

7+
use common::*;
98
use ros_z::Builder;
109
use ros_z_msgs::example_interfaces::{AddTwoInts, AddTwoIntsRequest, AddTwoIntsResponse};
1110

12-
use common::*;
13-
1411
#[serial_test::serial]
1512
#[test]
1613
fn test_ros_z_server_ros_z_client() {

ros-z/examples/laser_scan.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1+
use std::{thread, time::Duration};
2+
13
use clap::Parser;
24
use ros_z::{Builder, Result, context::ZContextBuilder};
3-
use ros_z_msgs::builtin_interfaces::Time;
4-
use ros_z_msgs::sensor_msgs::LaserScan;
5-
use ros_z_msgs::std_msgs::Header;
6-
use std::thread;
7-
use std::time::Duration;
5+
use ros_z_msgs::{builtin_interfaces::Time, sensor_msgs::LaserScan, std_msgs::Header};
86

97
#[derive(Debug, Parser)]
108
struct Args {

ros-z/examples/protobuf_demo/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
use std::time::Duration;
2+
13
use ros_z::{
24
Builder, MessageTypeInfo, Result, WithTypeInfo, entity::TypeHash, msg::ProtobufSerdes,
35
};
4-
use std::time::Duration;
5-
66
// Import ROS-generated protobuf messages
77
use ros_z_msgs::proto::geometry_msgs::Vector3 as Vector3Proto;
88

0 commit comments

Comments
 (0)