Skip to content

Commit

Permalink
Adds maliput-sys package and basic bindings. (#6)
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 e23804f commit 94bc5d3
Show file tree
Hide file tree
Showing 10 changed files with 521 additions and 3 deletions.
180 changes: 180 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ resolver = "2"

members = [
"maliput-sdk",
"maliput-sys",
]
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
# maliput-rs

Providing a Rust API for maliput.
Provides a Rust API for maliput.

## Packages

TODO
* [`maliput-sdk`](./maliput-sdk/): Brings binaries of maliput ecosystem to cargo workspace.
* [`maliput-sys`](./maliput-sys/): Provides ffi Rust bindings for the [`maliput`](https://github.com/maliput/maliput) API.
* [`maliput-rs`]: Provides a rustacean API for maliput on top of `maliput-sys`. (Not implemented yet.)

## Prerequisites

* OS: Ubuntu 20.04
* Bazel

## Installation

TODO

```
cargo build
```


## Usage

TODO

## Examples

### maliput-sys
- Load `maliput::api::RoadNetwork` and perform some basic queries
```
cargo run --examples 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._
14 changes: 14 additions & 0 deletions maliput-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "maliput-sys"
version = "0.1.0"
edition = "2021"
authors = ["Franco Cipollone <[email protected]>"]
description = "FFI Rust bindings for maliput"
build = "build.rs"

[dependencies]
cxx = "1.0.78"
maliput-sdk = { path = "../maliput-sdk" }

[build-dependencies]
cxx-build = "1.0.78"
61 changes: 61 additions & 0 deletions maliput-sys/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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 std::env;
use std::error::Error;
use std::path::PathBuf;

fn main() -> Result<(), Box<dyn Error>> {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=src/lib.rs");
println!("cargo:rerun-if-changed=src/create_road_network_wrapper.h");

let maliput_bin_path = PathBuf::from(env::var("DEP_MALIPUT_SDK_MALIPUT_BIN_PATH").expect("DEP_MALIPUT_SDK_MALIPUT_BIN_PATH not set"));

println!("cargo:rustc-link-search=native={}", maliput_bin_path.display());

// Link to all the libraries in the bazel-bin folder.
// The order of these is important! Otherwise, we get undefined reference errors.
println!("cargo:rustc-link-lib=drake");
println!("cargo:rustc-link-lib=geometry_base");
println!("cargo:rustc-link-lib=plugin");
println!("cargo:rustc-link-lib=common");
println!("cargo:rustc-link-lib=utility");
println!("cargo:rustc-link-lib=math");
println!("cargo:rustc-link-lib=base");
println!("cargo:rustc-link-lib=api");

cxx_build::bridges(["src/api.rs", "src/plugin.rs"])
.flag_if_supported("-std=c++17")
.include("src")
.compile("maliput-sys");

Ok(())
}
53 changes: 53 additions & 0 deletions maliput-sys/examples/create_rn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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_sys::plugin::ffi::CreateRoadNetwork;

fn main() {
println!("\nExecuting create_rn.rs example: ");

let road_network_loader_id = "maliput_malidrive".to_string();
let properties = vec![
"road_geometry_id:my_rg_from_rust".to_string(),
"opendrive_file:/opt/ros/foxy/share/maliput_malidrive/resources/odr/TShapeRoad.xodr".to_string(),
];

let road_network = CreateRoadNetwork(&road_network_loader_id, &properties);
let road_geometry = road_network.road_geometry();

// Excercise the RoadGeometry bindings.
unsafe {
// This is unsafe because we are dereferencing a raw pointer.
println!("linear_tolerance: {}", (*road_geometry).linear_tolerance());
println!("angular_tolerance: {}", (*road_geometry).angular_tolerance());
println!("num_junctions: {}", (*road_geometry).num_junctions());
println!("num_branch_points: {}", (*road_geometry).num_branch_points());
}
}
Loading

0 comments on commit 94bc5d3

Please sign in to comment.