Support for Rust 2024
The 2024 edition of Rust was released this February. https://blog.rust-lang.org/2025/02/20/Rust-1.85.0.html
Building a package via colcon with the 2024 edition fails.
Following the ros2_rust tutorial https://github.com/ros2-rust/ros2_rust/blob/main/docs/writing-your-first-rclrs-node.md I get the following error.
(.venv) robert@BAYMAX:~/ros2_ws$ colcon build
Starting >>> republisher_node
{"packages":[{"name":"republisher_node","version":"0.1.0","id":"path+file:///home/robert/ros2_ws/src/republisher_node#0.1.0","license":null,"license_file":null,"description":null,"source":null,"dependencies":[{"name":"rclrs","source":"registry+https://github.com/rust-lang/crates.io-index","req":"*","kind":null,"rename":null,"optional":false,"uses_default_features":true,"features":[],"target":null,"registry":null},{"name":"std_msgs","source":"registry+https://github.com/rust-lang/crates.io-index","req":"*","kind":null,"rename":null,"optional":false,"uses_default_features":true,"features":[],"target":null,"registry":null}],"targets":[{"kind":["bin"],"crate_types":["bin"],"name":"republisher_node","src_path":"/home/robert/ros2_ws/src/republisher_node/src/main.rs","edition":"2024","doc":true,"doctest":false,"test":true}],"features":{},"manifest_path":"/home/robert/ros2_ws/src/republisher_node/Cargo.toml","metadata":null,"publish":null,"authors":[],"categories":[],"keywords":[],"readme":null,"repository":null,"homepage":null,"documentation":null,"edition":"2024","links":null,"default_run":null,"rust_version":null}],"workspace_members":["path+file:///home/robert/ros2_ws/src/republisher_node#0.1.0"],"workspace_default_members":["path+file:///home/robert/ros2_ws/src/republisher_node#0.1.0"],"resolve":null,"target_directory":"/home/robert/ros2_ws/src/republisher_node/target","version":1,"workspace_root":"/home/robert/ros2_ws/src/republisher_node","metadata":null}
Error in cargo-ament-build
Caused by:
0: unknown variant `2024`, expected one of `2015`, `2018`, `2021` for key `package.edition` at line 6 column 1
1: unknown variant `2024`, expected one of `2015`, `2018`, `2021` for key `package.edition` at line 6 column 1
Failed <<< republisher_node [0.33s, exited with code 1]
Actually, it seems like this is an issue with cargo-ament-build
It uses cargo-manifest = "0.2". https://github.com/ros2-rust/cargo-ament-build/blob/7529850228880b2f01f57420b40e5624a256ec7d/Cargo.toml#L17C1-L17C23
However, support for the 2024 edition in the manifest parses was added in version 17. https://github.com/LukeMathWalker/cargo-manifest/blob/master/CHANGELOG.md#v0170-2024-11-28
I wouldn't be surprised if cargo-manifest has put out a new minor version which cargo's semantic versioning thinks is compatible with 0.2, so it's automatically using the newer version.
If that's the case we should be able to fix this by using
cargo-manifest = "=0.2"
Edit or maybe something more up to date like =0.16.1 would be more appropriate.
Can I check how you installed cargo-ament-build? I'm surprised that we're not seeing a problem in the 1.75 MSRV CI.
Maybe there is a misunderstanding,
The issue is that cargo-ament-build is using version 0.2 of cargo-manifest which doesn't have support for parsing edition="2024".
Version 0.17 added support for it. So the fix would be cargo-manifest = "0.17".
And I believe cargo treats any change in the leftmost non-zero number as potentially breaking a build. So even though cargo-ament-build doesn't have a lock file committed, it will not update to the latest version. https://doc.rust-lang.org/cargo/reference/semver.html
In the linked issue I also created a pull request to update it.
You're right, I misunderstood the direction of the problem. I've gotten too accustomed to needing to freeze old versions of crates when builds start to break.
@skrobchik this should be fixed via https://github.com/ros2-rust/cargo-ament-build/pull/22 , right?
Correct
Linked PR https://github.com/ros2-rust/cargo-ament-build/pull/22 was merged, closing this, feel free to reopen if you still have issues with Rust 2024!