Skip to content
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

Build system refactor #64

Merged
merged 15 commits into from
Nov 22, 2021
Merged
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,7 @@ Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk

# Ignore generated .cargo/config.toml files
**/.cargo/config.toml

# End of https://www.toptal.com/developers/gitignore/api/cmake,rust,python,cpp,c
7 changes: 5 additions & 2 deletions ament_cmake_export_crates/package.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?xml version="1.0"?>
<package format="2">
<?xml-model
href="http://download.ros.org/schema/package_format3.xsd"
schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>ament_cmake_export_crates</name>
<version>0.0.3</version>
<description>The ability to export Rust crates to downstream packages in the ament buildsystem in CMake.</description>
<author email="esteve@apache.org">Esteve Fernandez</author>
<maintainer email="esteve@apache.org">Esteve Fernandez</maintainer>
<license>Apache License 2.0</license>
<author email="esteve@apache.org">Esteve Fernandez</author>

<buildtool_depend>ament_cmake_core</buildtool_depend>

Expand Down
35 changes: 15 additions & 20 deletions rclrs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,25 @@ project(rclrs NONE)

find_package(ament_cmake REQUIRED)
find_package(ament_cmake_export_crates REQUIRED)
find_package(rclrs_common REQUIRED)
find_package(rclrs_crate_config_generator REQUIRED)
find_package(rclrs_msg_utilities REQUIRED)

set(_crates_dependencies "")
set(_found_dependencies "")
foreach(_crate_dependency ${rclrs_common_CRATES})
if(NOT _crate_dependency IN_LIST _found_dependencies)
list(APPEND _found_dependencies ${_crate_dependency})
set(_crates_dependencies "${_crates_dependencies}\n[dependencies.rclrs_common]\npath = '${_crate_dependency}'\n")
endif()
endforeach()
ament_export_crates(${CMAKE_SOURCE_DIR})

file(COPY "${CMAKE_SOURCE_DIR}/Cargo.toml" DESTINATION "${CMAKE_BINARY_DIR}/")
file(APPEND "${CMAKE_BINARY_DIR}/Cargo.toml" "${_crates_dependencies}")
set(ROS_CRATES rclrs_msg_utilities)
rclrs_gen_crate_config(${ROS_CRATES})

install(
FILES ${CMAKE_BINARY_DIR}/Cargo.toml build.rs src/rcl_wrapper.h
DESTINATION share/${PROJECT_NAME}/rust/
# Build library
add_custom_target(
build_crate ALL
COMMAND cargo build $<$<NOT:$<CONFIG:Debug>>:--release>
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)

install(
DIRECTORY src/
DESTINATION share/${PROJECT_NAME}/rust/src
install(FILES
${CMAKE_SOURCE_DIR}/target/$<$<NOT:$<CONFIG:Debug>>:release>$<$<CONFIG:Debug>:debug>/librclrs.rlib
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
DESTINATION lib/${PROJECT_NAME}
)

ament_export_crates("share/${PROJECT_NAME}/rust")

ament_package()
ament_package()
7 changes: 7 additions & 0 deletions rclrs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ version = "0.1.0"
authors = ["Esteve Fernandez <esteve@apache.org>"]
edition = "2018"

[lib]
path = "src/lib.rs"

[dependencies]
libc = "0.2.43"
lock_api = "0.4.5"
Expand All @@ -12,6 +15,10 @@ cty = "0.2"
core-error = "0.0.0"
parking_lot = {version = "0.11.2", optional = true}
spin = "0.9.2"
downcast = "0.10.0"

[dependencies.rclrs_msg_utilities]
version = "*"

[build-dependencies]
bindgen = "0.59.1"
Expand Down
10 changes: 10 additions & 0 deletions rclrs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ fn main() {
.use_core()
.ctypes_prefix("cty")
.derive_copy(false)
.allowlist_recursively(true)
.allowlist_type("rcl_.*")
.allowlist_type("rmw_.*")
.allowlist_type("rcutils_.*")
.allowlist_function("rcl_.*")
.allowlist_function("rmw_.*")
.allowlist_function("rcutils_.*")
.allowlist_var("rcl_.*")
.allowlist_var("rcl_.*")
.allowlist_var("rcutils_.*")
.size_t_is_usize(true)
.default_enum_style(bindgen::EnumVariation::Rust {
non_exhaustive: false,
Expand Down
11 changes: 7 additions & 4 deletions rclrs/package.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<?xml version="1.0"?>
<package format="2">
<?xml-model
href="http://download.ros.org/schema/package_format3.xsd"
schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>rclrs</name>
<version>0.0.3</version>
<description>Package containing the Rust client.</description>
<author email="esteve@apache.org">Esteve Fernandez</author>
<maintainer email="esteve@apache.org">Esteve Fernandez</maintainer>
<license>Apache License 2.0</license>
<author email="esteve@apache.org">Esteve Fernandez</author>

<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>ament_cmake_export_crates</buildtool_depend>
<buildtool_depend>rclrs_crate_config_generator</buildtool_depend>

<build_depend>builtin_interfaces</build_depend>
<build_depend>rclrs_msg_utilities</build_depend>
<build_depend>rcl</build_depend>
<build_depend>rcl_interfaces</build_depend>
<build_depend>rclrs_common</build_depend>

<export>
<build_type>ament_cmake</build_type>
Expand Down
3 changes: 1 addition & 2 deletions rclrs/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::error::ToResult;
use crate::error::{RclReturnCode, ToResult};
use crate::rcl_bindings::*;
use crate::Node;
use alloc::sync::Arc;
use alloc::vec::Vec;
use cstr_core::{c_char, CString};
use rclrs_common::error::RclReturnCode;

#[cfg(not(feature = "std"))]
use spin::{Mutex, MutexGuard};
Expand Down
Loading