Skip to content

Commit

Permalink
Brings maliput_malidrive to maliput-sdk (#7)
Browse files Browse the repository at this point in the history
Signed-off-by: Franco Cipollone <[email protected]>
  • Loading branch information
francocipollone authored Jan 9, 2024
1 parent 94bc5d3 commit 896f157
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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._
1 change: 1 addition & 0 deletions maliput-sdk/.bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
maliput_malidrive
4 changes: 4 additions & 0 deletions maliput-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ links = "maliput-sdk"
[dependencies]

[build-dependencies]

[[bin]]
name = "maliput_malidrive_plugin_path"
path = "src/maliput_malidrive_plugin_path.rs"
2 changes: 1 addition & 1 deletion maliput-sdk/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Welcome to Maliput Malidrive!
Maliput SDK!
"""

module(
Expand Down
2 changes: 1 addition & 1 deletion maliput-sdk/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion maliput-sdk/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,20 @@ fn main() -> Result<(), Box<dyn Error>> {
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";
Expand All @@ -77,13 +90,27 @@ fn main() -> Result<(), Box<dyn Error>> {
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(())

Expand Down
1 change: 1 addition & 0 deletions maliput-sdk/maliput_malidrive
Submodule maliput_malidrive added at 098d2d
1 change: 1 addition & 0 deletions maliput-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))),
]
}
39 changes: 39 additions & 0 deletions maliput-sdk/src/maliput_malidrive_plugin_path.rs
Original file line number Diff line number Diff line change
@@ -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());
}
6 changes: 6 additions & 0 deletions maliput-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,11 @@ fn main() -> Result<(), Box<dyn Error>> {
.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(())
}

0 comments on commit 896f157

Please sign in to comment.