diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml new file mode 100644 index 00000000..83e444ad --- /dev/null +++ b/.github/workflows/wheels.yml @@ -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/cibuildwheel@v2.19.2 + + - 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/cibuildwheel@v2.19.2 + + - uses: actions/upload-artifact@v4 + with: + path: ./wheelhouse/*.whl diff --git a/.gitignore b/.gitignore index d858b73c..a67de63b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ __pycache__ # ignore vscode folder .vscode + +# py-build-cmake cache folder +.py-build-cmake_cache diff --git a/README.md b/README.md index 4cf06f71..3e41cc42 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/fastdds_python/CMakeLists.txt b/fastdds_python/CMakeLists.txt index 3eedf30c..ccadb180 100644 --- a/fastdds_python/CMakeLists.txt +++ b/fastdds_python/CMakeLists.txt @@ -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) diff --git a/fastdds_python/src/swig/CMakeLists.txt b/fastdds_python/src/swig/CMakeLists.txt index c30d7820..8830010e 100644 --- a/fastdds_python/src/swig/CMakeLists.txt +++ b/fastdds_python/src/swig/CMakeLists.txt @@ -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 diff --git a/fastdds_python/src/swig/fastdds.i b/fastdds_python/src/swig/fastdds.i index 9e5275f2..c4f0a515 100644 --- a/fastdds_python/src/swig/fastdds.i +++ b/fastdds_python/src/swig/fastdds.i @@ -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); } diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..9187f9a0 --- /dev/null +++ b/pyproject.toml @@ -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" = "pieter.p.dev@outlook.com" }] +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" diff --git a/scripts/Makefile.win32 b/scripts/Makefile.win32 new file mode 100644 index 00000000..fbfcf2db --- /dev/null +++ b/scripts/Makefile.win32 @@ -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 diff --git a/scripts/build_deps.bat b/scripts/build_deps.bat new file mode 100755 index 00000000..ca4ea38e --- /dev/null +++ b/scripts/build_deps.bat @@ -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 diff --git a/scripts/build_deps.sh b/scripts/build_deps.sh new file mode 100755 index 00000000..78c6315a --- /dev/null +++ b/scripts/build_deps.sh @@ -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