diff --git a/repositories/ros2_rust.BUILD.bazel b/repositories/ros2_rust.BUILD.bazel index 7b976e99..bce3159c 100644 --- a/repositories/ros2_rust.BUILD.bazel +++ b/repositories/ros2_rust.BUILD.bazel @@ -12,8 +12,12 @@ load("@rules_rust//rust:defs.bzl", "rust_library") rust_library( name = "rosidl_runtime_rs", srcs = glob(["rosidl_runtime_rs/src/**/*.rs"]), + crate_features = ["serde"], edition = "2021", visibility = ["//visibility:public"], + deps = [ + "@rules_ros2_crate_index//:serde", + ], ) cc_library( diff --git a/repositories/rust/Cargo.Bazel.lock b/repositories/rust/Cargo.Bazel.lock index 301bec42..e172a13e 100644 --- a/repositories/rust/Cargo.Bazel.lock +++ b/repositories/rust/Cargo.Bazel.lock @@ -1,5 +1,5 @@ { - "checksum": "ceb872808bc19dea7e2bf3a800912471a769fb8aee7fbea69782a3c2d397541b", + "checksum": "b775f30e6fbf62d0a7d15de9feaf871608d6ca3f5c1520a3464f5af0e21a0aef", "crates": { "autocfg 1.3.0": { "name": "autocfg", @@ -74,6 +74,14 @@ "id": "serde 1.0.201", "target": "serde" }, + { + "id": "serde-big-array 0.5.1", + "target": "serde_big_array" + }, + { + "id": "serde_json 1.0.128", + "target": "serde_json" + }, { "id": "signal-hook 0.3.17", "target": "signal_hook" @@ -640,6 +648,45 @@ ], "license_file": "LICENSE-APACHE" }, + "itoa 1.0.11": { + "name": "itoa", + "version": "1.0.11", + "package_url": "https://github.com/dtolnay/itoa", + "repository": { + "Http": { + "url": "https://static.crates.io/crates/itoa/1.0.11/download", + "sha256": "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + } + }, + "targets": [ + { + "Library": { + "crate_name": "itoa", + "crate_root": "src/lib.rs", + "srcs": { + "allow_empty": true, + "include": [ + "**/*.rs" + ] + } + } + } + ], + "library_target_name": "itoa", + "common_attrs": { + "compile_data_glob": [ + "**" + ], + "edition": "2018", + "version": "1.0.11" + }, + "license": "MIT OR Apache-2.0", + "license_ids": [ + "Apache-2.0", + "MIT" + ], + "license_file": "LICENSE-APACHE" + }, "libc 0.2.155": { "name": "libc", "version": "0.2.155", @@ -968,6 +1015,45 @@ ], "license_file": "LICENSE-APACHE" }, + "ryu 1.0.18": { + "name": "ryu", + "version": "1.0.18", + "package_url": "https://github.com/dtolnay/ryu", + "repository": { + "Http": { + "url": "https://static.crates.io/crates/ryu/1.0.18/download", + "sha256": "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + } + }, + "targets": [ + { + "Library": { + "crate_name": "ryu", + "crate_root": "src/lib.rs", + "srcs": { + "allow_empty": true, + "include": [ + "**/*.rs" + ] + } + } + } + ], + "library_target_name": "ryu", + "common_attrs": { + "compile_data_glob": [ + "**" + ], + "edition": "2018", + "version": "1.0.18" + }, + "license": "Apache-2.0 OR BSL-1.0", + "license_ids": [ + "Apache-2.0", + "BSL-1.0" + ], + "license_file": "LICENSE-APACHE" + }, "serde 1.0.201": { "name": "serde", "version": "1.0.201", @@ -1051,6 +1137,54 @@ ], "license_file": "LICENSE-APACHE" }, + "serde-big-array 0.5.1": { + "name": "serde-big-array", + "version": "0.5.1", + "package_url": "https://github.com/est31/serde-big-array", + "repository": { + "Http": { + "url": "https://static.crates.io/crates/serde-big-array/0.5.1/download", + "sha256": "11fc7cc2c76d73e0f27ee52abbd64eec84d46f370c88371120433196934e4b7f" + } + }, + "targets": [ + { + "Library": { + "crate_name": "serde_big_array", + "crate_root": "src/lib.rs", + "srcs": { + "allow_empty": true, + "include": [ + "**/*.rs" + ] + } + } + } + ], + "library_target_name": "serde_big_array", + "common_attrs": { + "compile_data_glob": [ + "**" + ], + "deps": { + "common": [ + { + "id": "serde 1.0.201", + "target": "serde" + } + ], + "selects": {} + }, + "edition": "2021", + "version": "0.5.1" + }, + "license": "MIT OR Apache-2.0", + "license_ids": [ + "Apache-2.0", + "MIT" + ], + "license_file": "LICENSE-APACHE" + }, "serde_derive 1.0.201": { "name": "serde_derive", "version": "1.0.201", @@ -1113,6 +1247,94 @@ ], "license_file": "LICENSE-APACHE" }, + "serde_json 1.0.128": { + "name": "serde_json", + "version": "1.0.128", + "package_url": "https://github.com/serde-rs/json", + "repository": { + "Http": { + "url": "https://static.crates.io/crates/serde_json/1.0.128/download", + "sha256": "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" + } + }, + "targets": [ + { + "Library": { + "crate_name": "serde_json", + "crate_root": "src/lib.rs", + "srcs": { + "allow_empty": true, + "include": [ + "**/*.rs" + ] + } + } + }, + { + "BuildScript": { + "crate_name": "build_script_build", + "crate_root": "build.rs", + "srcs": { + "allow_empty": true, + "include": [ + "**/*.rs" + ] + } + } + } + ], + "library_target_name": "serde_json", + "common_attrs": { + "compile_data_glob": [ + "**" + ], + "crate_features": { + "common": [ + "default", + "std" + ], + "selects": {} + }, + "deps": { + "common": [ + { + "id": "itoa 1.0.11", + "target": "itoa" + }, + { + "id": "memchr 2.7.2", + "target": "memchr" + }, + { + "id": "ryu 1.0.18", + "target": "ryu" + }, + { + "id": "serde 1.0.201", + "target": "serde" + }, + { + "id": "serde_json 1.0.128", + "target": "build_script_build" + } + ], + "selects": {} + }, + "edition": "2021", + "version": "1.0.128" + }, + "build_script_attrs": { + "data_glob": [ + "**" + ] + }, + "license": "MIT OR Apache-2.0", + "license_ids": [ + "Apache-2.0", + "MIT" + ], + "license_file": "LICENSE-APACHE" + }, "signal-hook 0.3.17": { "name": "signal-hook", "version": "0.3.17", @@ -1542,6 +1764,8 @@ "direct_deps": [ "futures 0.3.30", "serde 1.0.201", + "serde-big-array 0.5.1", + "serde_json 1.0.128", "signal-hook 0.3.17" ], "direct_dev_deps": [] diff --git a/repositories/rust/Cargo.lock b/repositories/rust/Cargo.lock index f393bc62..00a37c41 100644 --- a/repositories/rust/Cargo.lock +++ b/repositories/rust/Cargo.lock @@ -14,6 +14,8 @@ version = "0.0.1" dependencies = [ "futures", "serde", + "serde-big-array", + "serde_json", "signal-hook", ] @@ -106,6 +108,12 @@ dependencies = [ "slab", ] +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + [[package]] name = "libc" version = "0.2.155" @@ -148,6 +156,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + [[package]] name = "serde" version = "1.0.201" @@ -157,6 +171,15 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-big-array" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11fc7cc2c76d73e0f27ee52abbd64eec84d46f370c88371120433196934e4b7f" +dependencies = [ + "serde", +] + [[package]] name = "serde_derive" version = "1.0.201" @@ -168,6 +191,18 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + [[package]] name = "signal-hook" version = "0.3.17" diff --git a/repositories/rust_setup_stage_3.bzl b/repositories/rust_setup_stage_3.bzl index bcb3d15c..f2707ca0 100644 --- a/repositories/rust_setup_stage_3.bzl +++ b/repositories/rust_setup_stage_3.bzl @@ -13,6 +13,13 @@ def rust_setup_stage_3(**kwargs): features = ["derive"], version = "1", ), + "serde-big-array": crate.spec( + version = "0.5", + ), + # Not used by rclrs, used for testing. + "serde_json": crate.spec( + version = "1", + ), # Not used by rclrs, but handy to have. "signal-hook": crate.spec( version = "0.3", diff --git a/ros2/rust_interfaces.bzl b/ros2/rust_interfaces.bzl index 31060825..5277a296 100644 --- a/ros2/rust_interfaces.bzl +++ b/ros2/rust_interfaces.bzl @@ -91,9 +91,12 @@ def _compile_rust_code(ctx, label, crate_name, srcs, deps): ) rustc_rmeta_output = generate_output_diagnostics(ctx, rust_metadata) + attr = ctx.rule.attr + struct(crate_features = [ + "serde", + ]) providers = rustc_compile_action( ctx = ctx, - attr = ctx.rule.attr, + attr = attr, toolchain = toolchain, output_hash = output_hash, crate_info_dict = dict( @@ -199,6 +202,7 @@ rust_generator_aspect = aspect( default = [ "@ros2_rust//:rosidl_runtime_rs", "@rules_ros2_crate_index//:serde", + "@rules_ros2_crate_index//:serde-big-array", ], ), "_cc_toolchain": attr.label( diff --git a/ros2/test/rust/BUILD.bazel b/ros2/test/rust/BUILD.bazel index 3c10d616..9dac7885 100644 --- a/ros2/test/rust/BUILD.bazel +++ b/ros2/test/rust/BUILD.bazel @@ -11,7 +11,10 @@ rust_test( name = "rust_idl_no_deps_tests", srcs = ["rust_idl_no_deps_tests.rs"], edition = "2021", - deps = [":rust_builtin_interfaces"], + deps = [ + ":rust_builtin_interfaces", + "@rules_ros2_crate_index//:serde_json", + ], ) rust_ros2_interface_library( diff --git a/ros2/test/rust/rust_idl_no_deps_tests.rs b/ros2/test/rust/rust_idl_no_deps_tests.rs index 07f2ed4d..4225c674 100644 --- a/ros2/test/rust/rust_idl_no_deps_tests.rs +++ b/ros2/test/rust/rust_idl_no_deps_tests.rs @@ -6,4 +6,10 @@ mod test { fn test_time_default() { let _msg = builtin_interfaces::msg::Time::default(); } + + #[test] + fn test_serialization() { + let msg = builtin_interfaces::msg::Time::default(); + let _json = serde_json::to_string(&msg).unwrap(); + } }