Skip to content

Add build.rs to messages to automatically find the message libraries #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ endforeach()

list(APPEND _generated_common_rs_files
"${_output_path}/rust/src/lib.rs"
"${_output_path}/rust/build.rs"
"${_output_path}/rust/Cargo.toml"
)

Expand Down
10 changes: 10 additions & 0 deletions rosidl_generator_rs/resource/build.rs.em
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use std::path::Path;

fn main() {
let lib_dir = Path::new("../../../lib")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this expecting a specific directory structure? What would happen with a merge install? i.e. everything installed into the install directory, no separate packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, the relative path is still the same. I tested it.

.canonicalize()
.expect("Could not find '../../../lib'");
// This allows building Rust packages that depend on message crates without
// sourcing the install directory first.
println!("cargo:rustc-link-search={}", lib_dir.display());
}
6 changes: 6 additions & 0 deletions rosidl_generator_rs/rosidl_generator_rs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ def generate_rs(generator_arguments_file, typesupport_impls):
os.path.join(args['output_dir'], 'rust/Cargo.toml'),
minimum_timestamp=latest_target_timestamp)

expand_template(
os.path.join(template_dir, 'build.rs.em'),
{},
os.path.join(args['output_dir'], 'rust/build.rs'),
minimum_timestamp=latest_target_timestamp)

return 0

def get_rs_name(name):
Expand Down