Skip to content

Commit 006c1d3

Browse files
Danipizarichiware
andauthored
Added cmake-arg 'USE_PYTHON_STABLE_ABI' (#250)
* Refs #23483. First approach Signed-off-by: Ricardo González <ricardo@richiware.dev> * [#23483] Added cmake-arg 'USE_PYTHON_STABLE_ABI' Signed-off-by: danipiza <dpizarrogallego@gmail.com> * [#23483] Added cmake-arg in the tests Signed-off-by: danipiza <dpizarrogallego@gmail.com> * [#23483] Added STABLE_ABI configuration to python_examples + modified calculator.i Signed-off-by: danipiza <dpizarrogallego@gmail.com> * [#23483] Added 'Development.SABIModule' to all tests Signed-off-by: danipiza <dpizarrogallego@gmail.com> * Refs #23483. Improve Signed-off-by: Ricardo González <ricardo@richiware.dev> * Refs #23483. Remove from generated code Signed-off-by: Ricardo González <ricardo@richiware.dev> * Testing cmake 3.24 Signed-off-by: Ricardo González <ricardo@richiware.dev> * Refs #23483. Increase cmake_minimum_required Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev> --------- Signed-off-by: Ricardo González <ricardo@richiware.dev> Signed-off-by: danipiza <dpizarrogallego@gmail.com> Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev> Co-authored-by: Ricardo González <ricardo@richiware.dev>
1 parent e143c3b commit 006c1d3

File tree

9 files changed

+34
-10
lines changed

9 files changed

+34
-10
lines changed

.github/workflows/reusable-ubuntu-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
- name: Get minimum supported version of CMake
8989
uses: eProsima/eProsima-CI/external/get-cmake@v0
9090
with:
91-
cmakeVersion: '3.22.6'
91+
cmakeVersion: '3.24.4'
9292

9393
- name: Install apt dependencies
9494
uses: eProsima/eProsima-CI/ubuntu/install_apt_packages@v0
@@ -188,7 +188,7 @@ jobs:
188188
- name: Get minimum supported version of CMake
189189
uses: eProsima/eProsima-CI/external/get-cmake@v0
190190
with:
191-
cmakeVersion: '3.22.6'
191+
cmakeVersion: '3.24.4'
192192

193193
- name: Install apt packages
194194
uses: eProsima/eProsima-CI/ubuntu/install_apt_packages@v0

.github/workflows/reusable-windows-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
- name: Get minimum supported version of CMake
9292
uses: eProsima/eProsima-CI/external/get-cmake@v0
9393
with:
94-
cmakeVersion: '3.22.6'
94+
cmakeVersion: '3.24.4'
9595

9696
- name: Install OpenSSL
9797
uses: eProsima/eprosima-CI/windows/install_openssl@v0
@@ -210,7 +210,7 @@ jobs:
210210
- name: Get minimum supported version of CMake
211211
uses: eProsima/eProsima-CI/external/get-cmake@v0
212212
with:
213-
cmakeVersion: '3.22.6'
213+
cmakeVersion: '3.24.4'
214214

215215
- name: Install OpenSSL
216216
uses: eProsima/eprosima-CI/windows/install_openssl@v0

fastdds_python/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
cmake_minimum_required(VERSION 3.22)
15+
cmake_minimum_required(VERSION 3.24)
1616

1717
# SWIG: use standard target name.
1818
if(POLICY CMP0078)
@@ -53,7 +53,13 @@ endif()
5353
include(${SWIG_USE_FILE})
5454
set(CMAKE_SWIG_FLAGS "")
5555

56-
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
56+
option(USE_PYTHON_STABLE_ABI "Generate Fast DDS python against Python Stable ABI" OFF)
57+
58+
if(USE_PYTHON_STABLE_ABI)
59+
find_package(Python3 COMPONENTS Interpreter Development.SABIModule REQUIRED)
60+
else()
61+
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
62+
endif()
5763

5864
find_package(fastcdr REQUIRED)
5965
find_package(fastdds 3 REQUIRED)

fastdds_python/colcon.pkg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"name": "fastdds_python",
33
"type": "cmake",
4-
"build-dependencies": ["fastdds"]
4+
"dependencies": ["fastdds"]
55
}

fastdds_python/src/swig/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,19 @@ endif()
5959

6060
if(MSVC OR MSVC_IDE)
6161
target_compile_options(${PROJECT_NAME} PRIVATE /bigobj)
62+
63+
if(USE_PYTHON_STABLE_ABI)
64+
target_compile_definitions(${PROJECT_NAME}
65+
PRIVATE
66+
NOMINMAX
67+
Py_LIMITED_API=0x03040000
68+
)
69+
endif()
70+
6271
endif()
6372

6473
target_link_libraries(${PROJECT_NAME}
65-
Python3::Module
74+
$<IF:$<BOOL:${USE_PYTHON_STABLE_ABI}>, Python3::SABIModule, Python3::Module>
6675
fastcdr
6776
fastdds
6877
)

fastdds_python/src/swig/fastdds.i

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@
2424
std::string err_msg("In method '$symname': ");
2525

2626
PyObject* exc_str = PyObject_GetAttrString(exc, "__name__");
27-
err_msg += PyUnicode_AsUTF8(exc_str);
27+
PyObject* unicode = PyUnicode_AsUTF8String (exc_str);
28+
err_msg += PyBytes_AsString(unicode);
29+
Py_XDECREF(unicode);
2830
Py_XDECREF(exc_str);
2931

3032
if (val != NULL)
3133
{
3234
PyObject* val_str = PyObject_Str(val);
35+
PyObject* unicode2 = PyUnicode_AsUTF8String (val_str);
3336
err_msg += ": ";
34-
err_msg += PyUnicode_AsUTF8(val_str);
37+
err_msg += PyBytes_AsString(unicode);
38+
Py_XDECREF(unicode2);
3539
Py_XDECREF(val_str);
3640
}
3741

fastdds_python/test/types/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ include(${SWIG_USE_FILE})
7979
set(CMAKE_SWIG_FLAGS "")
8080

8181
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
82+
8283
set(PYTHON_INCLUDE_PATH ${Python3_INCLUDE_DIRS})
8384
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
8485
set(PYTHON_LIBRARIES ${Python3_LIBRARIES})
@@ -191,6 +192,7 @@ include(${SWIG_USE_FILE})
191192
set(CMAKE_SWIG_FLAGS "")
192193

193194
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
195+
194196
set(PYTHON_INCLUDE_PATH ${Python3_INCLUDE_DIRS})
195197
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
196198
set(PYTHON_LIBRARIES ${Python3_LIBRARIES})
@@ -304,6 +306,7 @@ include(${SWIG_USE_FILE})
304306
set(CMAKE_SWIG_FLAGS "")
305307

306308
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
309+
307310
set(PYTHON_INCLUDE_PATH ${Python3_INCLUDE_DIRS})
308311
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
309312
set(PYTHON_LIBRARIES ${Python3_LIBRARIES})

fastdds_python_examples/HelloWorldExample/generated_code/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ include(${SWIG_USE_FILE})
7979
set(CMAKE_SWIG_FLAGS "")
8080

8181
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
82+
8283
set(PYTHON_INCLUDE_PATH ${Python3_INCLUDE_DIRS})
8384
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
8485
set(PYTHON_LIBRARIES ${Python3_LIBRARIES})

fastdds_python_examples/RPCExample/generated_code/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ include(${SWIG_USE_FILE})
7474
set(CMAKE_SWIG_FLAGS "")
7575

7676
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
77+
7778
set(PYTHON_INCLUDE_PATH ${Python3_INCLUDE_DIRS})
7879
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
7980
set(PYTHON_LIBRARIES ${Python3_LIBRARIES})

0 commit comments

Comments
 (0)