Skip to content

Commit 24e7dc4

Browse files
committed
Add build.rs to messages to automatically find the message libraries
1 parent cb87f98 commit 24e7dc4

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

rosidl_generator_rs/cmake/rosidl_generator_rs_generate_interfaces.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ endforeach()
6767

6868
list(APPEND _generated_common_rs_files
6969
"${_output_path}/rust/src/lib.rs"
70+
"${_output_path}/rust/build.rs"
7071
"${_output_path}/rust/Cargo.toml"
7172
)
7273

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use std::path::Path;
2+
3+
fn main() {
4+
let lib_dir = Path::new("../../../lib")
5+
.canonicalize()
6+
.expect("Could not find '../../../lib'");
7+
// This allows building Rust packages that depend on message crates without
8+
// sourcing the install directory first.
9+
println!("cargo:rustc-link-search={}", lib_dir.display());
10+
}

rosidl_generator_rs/rosidl_generator_rs/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ def generate_rs(generator_arguments_file, typesupport_impls):
164164
os.path.join(args['output_dir'], 'rust/Cargo.toml'),
165165
minimum_timestamp=latest_target_timestamp)
166166

167+
expand_template(
168+
os.path.join(template_dir, 'build.rs.em'),
169+
{},
170+
os.path.join(args['output_dir'], 'rust/build.rs'),
171+
minimum_timestamp=latest_target_timestamp)
172+
167173
return 0
168174

169175
def get_rs_name(name):

0 commit comments

Comments
 (0)