From 896f157298d5fab8130f95d3c4bf456f942bbfc9 Mon Sep 17 00:00:00 2001 From: Franco Cipollone <53065142+francocipollone@users.noreply.github.com> Date: Tue, 9 Jan 2024 17:56:16 -0300 Subject: [PATCH] Brings maliput_malidrive to maliput-sdk (#7) Signed-off-by: Franco Cipollone --- .gitmodules | 4 ++ README.md | 19 +++++++-- maliput-sdk/.bazelignore | 1 + maliput-sdk/Cargo.toml | 4 ++ maliput-sdk/MODULE.bazel | 2 +- maliput-sdk/MODULE.bazel.lock | 2 +- maliput-sdk/build.rs | 29 +++++++++++++- maliput-sdk/maliput_malidrive | 1 + maliput-sdk/src/lib.rs | 1 + .../src/maliput_malidrive_plugin_path.rs | 39 +++++++++++++++++++ maliput-sys/build.rs | 6 +++ 11 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 .gitmodules create mode 100644 maliput-sdk/.bazelignore create mode 160000 maliput-sdk/maliput_malidrive create mode 100644 maliput-sdk/src/maliput_malidrive_plugin_path.rs diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..885d68b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "maliput-sdk/maliput_malidrive"] + path = maliput-sdk/maliput_malidrive + url = https://github.com/francocipollone/maliput_malidrive.git + branch = francocipollone/rust_bazel_plugin_lib diff --git a/README.md b/README.md index d5e0fe2..13d4e95 100644 --- a/README.md +++ b/README.md @@ -25,12 +25,25 @@ cargo build TODO +## Executables + +### maliput-sdk + + - Print libraries being vendored + ```sh + cargo run --bin maliput-sdk + ``` + + - Get location of maliput_malidrive's plugin library: + ```sh + cargo run --bin maliput_malidrive_plugin_path + ``` + ## Examples ### maliput-sys + - Load `maliput::api::RoadNetwork` and perform some basic queries ``` - cargo run --examples create_rn + cargo run --example create_rn ``` - - _Note: RoadNetworks are loaded via [maliput plugin architecture](https://maliput.readthedocs.io/en/latest/html/deps/maliput/html/maliput_plugin_architecture.html), therefore a valid `MALIPUT_PLUGIN_PATH` env var must be set. It will be handleded automatically in the future when maliput_malidrive's binaries are also brought._ diff --git a/maliput-sdk/.bazelignore b/maliput-sdk/.bazelignore new file mode 100644 index 0000000..59699fa --- /dev/null +++ b/maliput-sdk/.bazelignore @@ -0,0 +1 @@ +maliput_malidrive diff --git a/maliput-sdk/Cargo.toml b/maliput-sdk/Cargo.toml index da038d4..6b94cca 100644 --- a/maliput-sdk/Cargo.toml +++ b/maliput-sdk/Cargo.toml @@ -15,3 +15,7 @@ links = "maliput-sdk" [dependencies] [build-dependencies] + +[[bin]] +name = "maliput_malidrive_plugin_path" +path = "src/maliput_malidrive_plugin_path.rs" diff --git a/maliput-sdk/MODULE.bazel b/maliput-sdk/MODULE.bazel index b955393..35ff3be 100644 --- a/maliput-sdk/MODULE.bazel +++ b/maliput-sdk/MODULE.bazel @@ -1,5 +1,5 @@ """ -Welcome to Maliput Malidrive! +Maliput SDK! """ module( diff --git a/maliput-sdk/MODULE.bazel.lock b/maliput-sdk/MODULE.bazel.lock index 47b309e..653cef6 100644 --- a/maliput-sdk/MODULE.bazel.lock +++ b/maliput-sdk/MODULE.bazel.lock @@ -1,6 +1,6 @@ { "lockFileVersion": 3, - "moduleFileHash": "f48451fa55e47b3e940ada4ff68686cb649e685ad59f03cc130dac117f00445b", + "moduleFileHash": "52ecdcb07d692508dc330491ce2a8741a771ecd906bd994126d2180815c99246", "flags": { "cmdRegistries": [ "https://raw.githubusercontent.com/bazelbuild/bazel-central-registry/main/" diff --git a/maliput-sdk/build.rs b/maliput-sdk/build.rs index 7eedadf..76646bd 100644 --- a/maliput-sdk/build.rs +++ b/maliput-sdk/build.rs @@ -55,7 +55,20 @@ fn main() -> Result<(), Box> { let bazel_bin_dir = bazel_output_base_dir.join("bazel-bin"); - // ************* Maliput Files ************* // + // TODO(francocipollone): Remove this custom build once maliput_malidrive is within BCR. + env::set_current_dir("maliput_malidrive") + .unwrap_or_else(|_| panic!("Unable to change directory to {}", "maliput_malidrive")); + let build_malidrive = std::process::Command::new("bazel") + .arg("build") + .arg("//...") + .status() + .expect("Failed to generate build script"); + if build_malidrive.code() != Some(0) { + panic!("Failed to generate build script"); + } + let maliput_malidrive_bin_path = PathBuf::from(env::current_dir().unwrap()).join("bazel-bin"); + + // ************* maliput header files ************* // // TODO(francocipollone): Get version from MODULE.bazel configuration. let maliput_version = "1.2.0"; @@ -77,13 +90,27 @@ fn main() -> Result<(), Box> { println!("cargo:CXXBRIDGE_DIR{}={}", i, path.display()); } + // ************* maliput_malidrive header files ************* // + // TODO(francocipollone): For consistency we should also add include paths for maliput_malidrive. + + // ************* crate output env vars ************* // + // Environment variable to pass down to this crate: println!("cargo:rustc-env=MALIPUT_BIN_PATH={}", maliput_bin_path.display()); + println!("cargo:rustc-env=MALIPUT_MALIDRIVE_BIN_PATH={}", maliput_malidrive_bin_path.display()); // Environment variable to pass down to dependent crates: // See: https://doc.rust-lang.org/cargo/reference/build-scripts.html#the-links-manifest-key println!("cargo:root={}", out_dir.display()); //> Accessed as MALIPUT_SDK_ROOT println!("cargo:maliput_bin_path={}", maliput_bin_path.display()); //> Accessed as MALIPUT_SDK_MALIPUT_BIN_PATH + println!("cargo:maliput_malidrive_bin_path={}", maliput_malidrive_bin_path.display()); //> Accessed as MALIPUT_SDK_MALIPUT_MALIDRIVE_BIN_PATH + println!("cargo:maliput_malidrive_plugin_path={}", + maliput_malidrive_bin_path + .join("maliput_plugins") + .join("libmaliput_malidrive_road_network.so.runfiles") + .join("_main") + .join("maliput_plugins") + .display()); //> Accessed as MALIPUT_SDK_MALIPUT_MALIDRIVE_PLUGIN_PATH Ok(()) diff --git a/maliput-sdk/maliput_malidrive b/maliput-sdk/maliput_malidrive new file mode 160000 index 0000000..098d2dd --- /dev/null +++ b/maliput-sdk/maliput_malidrive @@ -0,0 +1 @@ +Subproject commit 098d2dd01854e19dc4fe57833d749509dc4e1a40 diff --git a/maliput-sdk/src/lib.rs b/maliput-sdk/src/lib.rs index 3f89218..07257bd 100644 --- a/maliput-sdk/src/lib.rs +++ b/maliput-sdk/src/lib.rs @@ -34,5 +34,6 @@ use std::path::PathBuf; pub fn sdk_libraries() -> Vec<(String, PathBuf)> { vec![ ("maliput".to_string(), PathBuf::from(env!("MALIPUT_BIN_PATH"))), + ("maliput_malidrive".to_string(), PathBuf::from(env!("MALIPUT_MALIDRIVE_BIN_PATH"))), ] } diff --git a/maliput-sdk/src/maliput_malidrive_plugin_path.rs b/maliput-sdk/src/maliput_malidrive_plugin_path.rs new file mode 100644 index 0000000..0c831dd --- /dev/null +++ b/maliput-sdk/src/maliput_malidrive_plugin_path.rs @@ -0,0 +1,39 @@ +// BSD 3-Clause License +// +// Copyright (c) 2024, Woven by Toyota. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +use maliput_sdk::sdk_libraries; + +pub fn main () { + // Get maliput_malidrive + let libs = sdk_libraries(); + let maliput_malidrive = libs.get(1).unwrap(); + let maliput_malidrive_plugin_path = maliput_malidrive.1.join("maliput_plugins").join("libmaliput_malidrive_road_network.so.runfiles").join("_main").join("maliput_plugins"); + println!("{}", maliput_malidrive_plugin_path.display()); +} diff --git a/maliput-sys/build.rs b/maliput-sys/build.rs index 09b87bf..f228589 100644 --- a/maliput-sys/build.rs +++ b/maliput-sys/build.rs @@ -57,5 +57,11 @@ fn main() -> Result<(), Box> { .include("src") .compile("maliput-sys"); + + let maliput_malidrive_plugin_path = PathBuf::from(env::var("DEP_MALIPUT_SDK_MALIPUT_MALIDRIVE_PLUGIN_PATH").expect("DEP_MALIPUT_SDK_MALIPUT_MALIDRIVE_PLUGIN_PATH not set")); + + // Environment variables are available from within binaries and tests in the crate. + println!("cargo:rustc-env=MALIPUT_PLUGIN_PATH={}", maliput_malidrive_plugin_path.display()); + Ok(()) }