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

First attempt at building a wheel. See issue #176 #179

Draft
wants to merge 11 commits into
base: 1.4.2
Choose a base branch
from
Draft
145 changes: 145 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
name: Build

on: [push, pull_request]

jobs:
build-fastdds-ubuntu:
name: Build fast DDS library for ubuntu
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Cache build
id: cache-build
uses: actions/cache@v4
with:
path: install
key: fastdds-ubuntu-${{ hashFiles('scripts/build_deps.sh') }}

- name: Build fast DDS library
if: steps.cache-build.outputs.cache-hit != 'true'
run: |
sudo apt install -y libasio-dev libtinyxml2-dev libssl-dev
scripts/build_deps.sh

- uses: actions/upload-artifact@v4
with:
name: fastdds-ubuntu
path: ./install

build-fastdds-linux:
name: Build fast DDS library for manylinux2014
runs-on: ubuntu-latest
container: quay.io/pypa/manylinux2014_x86_64

steps:
- uses: actions/checkout@v4

- name: Cache build
id: cache-build
uses: actions/cache@v4
with:
path: install
key: fastdds-linux-${{ hashFiles('scripts/build_deps.sh') }}

- name: Build fast DDS library
if: steps.cache-build.outputs.cache-hit != 'true'
run: |
yum install -y tinyxml2-devel asio-devel
scripts/build_deps.sh

- uses: actions/upload-artifact@v4
with:
name: fastdds-linux
path: ./install

build-fastdds-windows:
name: Build fast DDS library for windows
runs-on: windows-latest

steps:
- uses: actions/checkout@v4
- uses: ilammy/msvc-dev-cmd@v1

- name: Cache build
id: cache-build
uses: actions/cache@v4
with:
path: install
key: fastdds-windows-${{ hashFiles('scripts/Makefile.win32') }}

- name: Build fast DDS library
if: steps.cache-build.outputs.cache-hit != 'true'
run: nmake /F scripts\Makefile.win32

- uses: actions/upload-artifact@v4
with:
name: fastdds-windows
path: ./install

build-ubuntu-wheels:
name: Build wheels for ubuntu
runs-on: ubuntu-latest
needs: build-fastdds-ubuntu

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5

- name: Download Library Build
uses: actions/download-artifact@v4
with:
name: fastdds-ubuntu

- name: Install build python package
run: pip install build

- name: Build wheels
run: python -m build .

- uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/*.whl

build-linux-wheels:
name: Build wheels for linux
runs-on: ubuntu-latest
needs: build-fastdds-linux

steps:
- uses: actions/checkout@v4

- name: Download Library Build
uses: actions/download-artifact@v4
with:
name: fastdds-linux

- name: Build wheels
env:
CIBW_BEFORE_BUILD_LINUX: "scripts/build_deps.sh"
uses: pypa/[email protected]

- uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/*.whl

build-windows-wheels:
name: Build wheels for windows
runs-on: windows-latest
needs: build-fastdds-windows

steps:
- uses: actions/checkout@v4

- name: Download windows fastdds Build
uses: actions/download-artifact@v4
with:
name: fastdds-windows

- name: Build wheels
uses: pypa/[email protected]

- uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/*.whl
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ __pycache__

# ignore vscode folder
.vscode

# py-build-cmake cache folder
.py-build-cmake_cache
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ colcon build

Please, refer to [colcon documentation](https://colcon.readthedocs.io/en/released/reference/verb/build.html) for more information, such as building only one of the packages.

### Building a python wheel

First build fast DDS as per usual. Setup CMAKE_PREFIX_PATH to point to this installation.

Then build the python wheel using the [build frontend](https://build.pypa.io/en/stable/) and the [py-cmake-build](https://tttapa.github.io/py-build-cmake/) backend:

```bash
export CMAKE_PREFIX_PATH=~/fastdds/install
pip install build
python -m build .

```

## Python example

Fast DDS documentation includes a first publisher-subscriber application using Python.
Expand Down
2 changes: 1 addition & 1 deletion fastdds_python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
set(CMAKE_SWIG_FLAGS "")

find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED)

find_package(fastcdr REQUIRED)
find_package(fastrtps 2.12 REQUIRED)
Expand Down
1 change: 1 addition & 0 deletions fastdds_python/src/swig/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ endif()
if(MSVC OR MSVC_IDE)
target_compile_options(${PROJECT_NAME} PRIVATE /bigobj)
endif()
target_compile_options(${PROJECT_NAME} PRIVATE -DPy_LIMITED_API=0x03090000)

target_link_libraries(${PROJECT_NAME}
Python3::Module
Expand Down
4 changes: 2 additions & 2 deletions fastdds_python/src/swig/fastdds.i
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
std::string err_msg("In method '$symname': ");

PyObject* exc_str = PyObject_GetAttrString(exc, "__name__");
err_msg += PyUnicode_AsUTF8(exc_str);
err_msg += "Oi";// PyUnicode_AsUTF8(exc_str);
Py_XDECREF(exc_str);

if (val != NULL)
{
PyObject* val_str = PyObject_Str(val);
err_msg += ": ";
err_msg += PyUnicode_AsUTF8(val_str);
err_msg += "Oi"; // PyUnicode_AsUTF8(val_str);
Py_XDECREF(val_str);
}

Expand Down
45 changes: 45 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[project]
name = "fastdds"
readme = "README.md"
version = "2.0.0"
requires-python = ">=3.8"
license = { "file" = "LICENSE" }
authors = [{ "name" = "Pieter P", "email" = "[email protected]" }]
keywords = ["dds"]
classifiers = [
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft :: Windows",
"Operating System :: MacOS",
]
urls = { "Documentation" = "https://fast-dds.docs.eprosima.com" }
dependencies = []

[build-system]
# Use a pre release, see this issue: https://github.com/tttapa/py-build-cmake/issues/22
# This allows usage of generated = "package" below.
requires = ["py-build-cmake==0.2.0a14", "setuptools"]
build-backend = "py_build_cmake.build"

[tool.py-build-cmake.module]
generated = "package"

[tool.py-build-cmake.sdist]
include = ["fastdds_python"]

[tool.py-build-cmake.cmake]
minimum_version = "3.22"
source_path = "fastdds_python"
build_type = "Release"

[tool.cibuildwheel]
# use podman instead of docker
container-engine = "podman"
build = ["cp39-manylinux_x86_64", "cp39-win_amd64"]
build-frontend = "build"
29 changes: 29 additions & 0 deletions scripts/Makefile.win32
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

all: fastdds

foonathan:
@echo Foo nathan
git clone --branch v0.7-3 https://github.com/foonathan/memory.git
mkdir memory\build
pushd memory\build
cmake .. -DCMAKE_BUILD_TYPE=Release -DFOONATHAN_MEMORY_BUILD_EXAMPLES=OFF -DFOONATHAN_MEMORY_BUILD_TESTS=OFF -G Ninja
ninja install
popd

fastcdr:
@echo Fast CDR
git clone --branch 2.2.3 https://github.com/eProsima/Fast-CDR.git
mkdir Fast-CDR\build
pushd Fast-CDR\build
cmake .. -DCMAKE_BUILD_TYPE=Release -G Ninja
ninja install
popd

fastdds: fastcdr foonathan
@echo Fast RTPS
git clone --branch v2.14.3 https://github.com/eProsima/Fast-DDS.git
mkdir Fast-DDS\build
pushd Fast-DDS\build
cmake .. -DCMAKE_BUILD_TYPE=Release -G Ninja
ninja install
popd
24 changes: 24 additions & 0 deletions scripts/build_deps.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

@REM Foo nathan
git clone --branch v0.7-3 https://github.com/foonathan/memory.git
mkdir memory\build
pushd memory\build
cmake .. -DCMAKE_BUILD_TYPE=Release -DFOONATHAN_MEMORY_BUILD_EXAMPLES=OFF -DFOONATHAN_MEMORY_BUILD_TESTS=OFF -G Ninja
ninja install
popd

@REM Fast CDR
git clone --branch 2.2.3 https://github.com/eProsima/Fast-CDR.git
mkdir Fast-CDR\build
pushd Fast-CDR\build
cmake .. -DCMAKE_BUILD_TYPE=Release -G Ninja
ninja install
popd

@REM Fast RTPS
git clone --branch v2.14.3 https://github.com/eProsima/Fast-DDS.git
mkdir Fast-DDS\build
pushd Fast-DDS\build
cmake .. -DCMAKE_BUILD_TYPE=Release -G Ninja
ninja install
popd
34 changes: 34 additions & 0 deletions scripts/build_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Script to install required software in manylinux2014 container

set -eu

# Install tinyxml2 and asio
# yum install -y tinyxml2-devel asio-devel
INSTALL_FOLDER=`pwd`/install
echo "Installing to ${INSTALL_FOLDER}"

# Foo nathan
git clone --branch v0.7-3 https://github.com/foonathan/memory.git
mkdir memory/build
pushd memory/build
cmake .. --install-prefix ${INSTALL_FOLDER} -DCMAKE_BUILD_TYPE=Release -DFOONATHAN_MEMORY_BUILD_EXAMPLES=OFF -DFOONATHAN_MEMORY_BUILD_TESTS=OFF
make install
popd

# Fast CDR:
git clone --branch 2.2.3 https://github.com/eProsima/Fast-CDR.git
mkdir Fast-CDR/build
pushd Fast-CDR/build
cmake .. --install-prefix ${INSTALL_FOLDER} -DCMAKE_BUILD_TYPE=Release
make install
popd

# Fast RTPS:
git clone --branch v2.14.3 https://github.com/eProsima/Fast-DDS.git
mkdir Fast-DDS/build
pushd Fast-DDS/build
cmake .. --install-prefix ${INSTALL_FOLDER} -DCMAKE_BUILD_TYPE=Release
make install
popd