Integrate with ament.

This commit is contained in:
James Pace 2026-08-14 12:10:32 -04:00
parent 3931b54432
commit 893ab2f951
4 changed files with 77 additions and 1 deletions

13
CMakeLists.txt Normal file
View File

@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 4.2)
project(j7s_diagnostics_py)
find_package(ament_cmake REQUIRED)
add_custom_target(build_info ALL)
add_custom_command(TARGET build_info
POST_BUILD
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build.py --install-path ${CMAKE_INSTALL_PREFIX} --build-dir ${PROJECT_BINARY_DIR} --src-dir ${CMAKE_CURRENT_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
ament_package()

48
build.py Executable file
View File

@ -0,0 +1,48 @@
#!/usr/bin/env python3
#
# Copyright 2026 James Pace
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
#
import argparse
import subprocess
import venv
from pathlib import Path
# The build for this is a little funky.
# Maturin only plays nice with pyproject.toml style configs.
# ROS2 is the opposite.
# So... We setup an venv, pip install into it (which plays nice with pyproject.toml).
# Then we copy the result to the right place for ament/ros2.
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--src-dir", type=str)
parser.add_argument("--build-dir", type=str)
parser.add_argument("--install-path", type=str)
args = parser.parse_args()
build(args.src_dir, args.build_dir, args.install_path)
def build(source_directory, build_directory, install_directory):
# Make a venv in the build_directory.
builder = venv.EnvBuilder(system_site_packages=True, with_pip=True, prompt="")
venv_directory = Path(build_directory) / "venv"
builder.create(venv_directory)
# activate it and call pip install.
command = f". {venv_directory}/bin/activate && pip install {source_directory}"
subprocess.run(command, shell=True)
# copy the result to the install directory.
command = f"cp -r {venv_directory}/lib {install_directory}"
subprocess.run(command, shell=True)
if __name__ == "__main__":
main()

16
package.xml Normal file
View File

@ -0,0 +1,16 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>j7s_diagnostics_py</name>
<version>0.0.1</version>
<description>TODO</description>
<license>MPL 2.0</license>
<author email="jpace121@gmail.com">James Pace</author>
<maintainer email="jpace121@gmail.com">James Pace</maintainer>
<buildtool_depend>ament_cmake</buildtool_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>

View File

@ -3,7 +3,6 @@ use pyo3::prelude::*;
use pyo3::types::{PyDict, PyString}; use pyo3::types::{PyDict, PyString};
use std::collections::BTreeMap; use std::collections::BTreeMap;
/// A Python module implemented in Rust.
#[pymodule] #[pymodule]
mod j7s_diagnostics_py { mod j7s_diagnostics_py {
#[pymodule_export] #[pymodule_export]