Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 82b7aa5

Browse files
committed
Add Gitlab CI to build wheels.
This patch adds Gitlab CI to the project to build wheels for Linux for each supported version of Python. This build can be manually triggered for any commit, but is automatic when a "qi-python-vXXX" tag is pushed. Furthermore, when a tag is pushed on GitLab, wheels are published in the package registry and a release is created.
1 parent 6a492e2 commit 82b7aa5

File tree

6 files changed

+168
-47
lines changed

6 files changed

+168
-47
lines changed

.gitlab-ci.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
stages:
2+
- build
3+
- publish
4+
- release
5+
6+
.if-tag: &if-tag
7+
if: "$CI_COMMIT_TAG =~ /^qi-python-v/"
8+
9+
build-wheel:
10+
stage: build
11+
rules:
12+
# Allow manually building on a Git commit on any branch.
13+
- if: $CI_COMMIT_BRANCH
14+
when: manual
15+
# Always build on a Git tag.
16+
- <<: *if-tag
17+
tags:
18+
- docker
19+
image: python:3.8
20+
variables:
21+
LIBQI_REPOSITORY_URL: "https://gitlab-ci-token:$CI_JOB_TOKEN@$CI_SERVER_HOST/qi/libqi"
22+
script:
23+
- curl -sSL https://get.docker.com/ | sh
24+
- pip install cibuildwheel==2.14.1
25+
- cibuildwheel --output-dir wheelhouse
26+
artifacts:
27+
paths:
28+
- wheelhouse/
29+
30+
publish-wheel:
31+
stage: publish
32+
image: python:latest
33+
rules:
34+
- <<: *if-tag
35+
needs:
36+
- build-wheel
37+
script:
38+
- pip install build twine
39+
- python -m build
40+
- TWINE_PASSWORD="${CI_JOB_TOKEN}"
41+
TWINE_USERNAME=gitlab-ci-token
42+
python -m twine upload
43+
--repository-url "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi"
44+
wheelhouse/*
45+
46+
create-release:
47+
stage: release
48+
rules:
49+
- <<: *if-tag
50+
script:
51+
- echo "Releasing $CI_COMMIT_TAG."
52+
release:
53+
tag_name: $CI_COMMIT_TAG
54+
name: 'lib$CI_COMMIT_TITLE'
55+
description: '$CI_COMMIT_TAG_MESSAGE'

CMakeLists.txt

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,14 @@ endif()
6666
##############################################################################
6767
# Find Python
6868
##############################################################################
69-
# First search for Python with Interpreter+Devel components, to allow the module
70-
# to look for the interpreter that goes with the Python development library.
71-
# Then if it could not find both, try looking for the development component
72-
# only, but this time force the module to find it or fail (REQUIRED).
73-
# Some of our toolchains (when crosscompiling for instance) have the Python
74-
# library but not an interpreter that can run on the host.
75-
find_package(Python COMPONENTS Development Interpreter)
76-
if(NOT Python_FOUND)
77-
find_package(Python REQUIRED COMPONENTS Development)
78-
endif()
69+
find_package(
70+
Python REQUIRED
71+
COMPONENTS
72+
Development.Module
73+
OPTIONAL_COMPONENTS
74+
Interpreter
75+
Development.Embed
76+
)
7977

8078
##############################################################################
8179
# Find Boost
@@ -323,47 +321,49 @@ if(BUILD_TESTING)
323321
qi::qi
324322
)
325323

326-
add_executable(test_qipython)
327-
target_sources(
328-
test_qipython
329-
PRIVATE
330-
tests/common.hpp
331-
tests/test_qipython.cpp
332-
tests/test_guard.cpp
333-
tests/test_types.cpp
334-
tests/test_signal.cpp
335-
tests/test_property.cpp
336-
tests/test_object.cpp
337-
tests/test_module.cpp
338-
)
339-
target_link_libraries(
340-
test_qipython
324+
if(Python_Development.Embed_FOUND)
325+
add_executable(test_qipython)
326+
target_sources(
327+
test_qipython
328+
PRIVATE
329+
tests/common.hpp
330+
tests/test_qipython.cpp
331+
tests/test_guard.cpp
332+
tests/test_types.cpp
333+
tests/test_signal.cpp
334+
tests/test_property.cpp
335+
tests/test_object.cpp
336+
tests/test_module.cpp
337+
)
338+
target_link_libraries(
339+
test_qipython
340+
PRIVATE
341+
qi_python_objects
342+
cxx_standard
343+
Python::Python
344+
Boost::headers
345+
pybind11::pybind11
346+
GTest::gmock
347+
)
348+
gtest_discover_tests(test_qipython)
349+
350+
add_executable(test_qipython_local_interpreter)
351+
target_sources(
352+
test_qipython_local_interpreter
353+
PRIVATE
354+
tests/test_qipython_local_interpreter.cpp
355+
)
356+
target_link_libraries(
357+
test_qipython_local_interpreter
341358
PRIVATE
342-
qi_python_objects
343-
cxx_standard
344359
Python::Python
345-
Boost::headers
346360
pybind11::pybind11
361+
qi_python_objects
362+
cxx_standard
347363
GTest::gmock
348-
)
349-
gtest_discover_tests(test_qipython)
350-
351-
add_executable(test_qipython_local_interpreter)
352-
target_sources(
353-
test_qipython_local_interpreter
354-
PRIVATE
355-
tests/test_qipython_local_interpreter.cpp
356-
)
357-
target_link_libraries(
358-
test_qipython_local_interpreter
359-
PRIVATE
360-
Python::Python
361-
pybind11::pybind11
362-
qi_python_objects
363-
cxx_standard
364-
GTest::gmock
365-
)
366-
gtest_discover_tests(test_qipython_local_interpreter)
364+
)
365+
gtest_discover_tests(test_qipython_local_interpreter)
366+
endif()
367367

368368
if(NOT Python_Interpreter_FOUND)
369369
message(WARNING "tests: a compatible Python Interpreter was NOT found, Python tests are DISABLED.")

ci/cibuildwheel_before_all.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/sh
2+
set -x -e
3+
4+
PACKAGE=$1
5+
6+
pip install 'conan>=2' 'cmake>=3.23' ninja
7+
8+
# Perl dependencies required to build OpenSSL.
9+
yum install -y perl-IPC-Cmd perl-Digest-SHA
10+
11+
# Install Conan configuration.
12+
conan config install "$PACKAGE/ci/conan"
13+
14+
# Clone and export libqi to Conan cache.
15+
# Possible improvement:
16+
# Avoid duplicating the version number here with the version
17+
# defined in conanfile.py.
18+
GIT_SSL_NO_VERIFY=true \
19+
git clone --depth=1 \
20+
--branch qi-framework-v4.0.1 \
21+
"$LIBQI_REPOSITORY_URL" \
22+
/work/libqi
23+
conan export /work/libqi --version=4.0.1
24+
25+
# Install dependencies of libqi-python from Conan, including libqi.
26+
# Only use the build_type as a variable for the build folder name, so
27+
# that the generated CMake preset is named "conan-release".
28+
#
29+
# Build everything from sources, so that we do not reuse precompiled binaries.
30+
# This is because the GLIBC from the manylinux images are often older than the
31+
# ones that were used to build the precompiled binaries, which means the binaries
32+
# cannot by executed.
33+
conan install "$PACKAGE" \
34+
--build="*" \
35+
-c tools.build:skip_test=true \
36+
-c tools.cmake.cmaketoolchain:generator=Ninja \
37+
-c tools.cmake.cmake_layout:build_folder_vars=[\"settings.build_type\"]

ci/conan/global.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
core:default_profile=default
2+
core:default_build_profile=default

ci/conan/profiles/default

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[settings]
2+
arch=x86_64
3+
build_type=Release
4+
compiler=gcc
5+
compiler.cppstd=gnu17
6+
compiler.libcxx=libstdc++
7+
compiler.version=10
8+
os=Linux

pyproject.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,22 @@ maintainers = [
4747

4848
[project.urls]
4949
repository = "https://github.com/aldebaran/libqi-python"
50+
51+
[tool.scikit-build]
52+
# Rely only on CMake install, not on Python packages detection.
53+
wheel.packages = []
54+
55+
[tool.cibuildwheel]
56+
build = "cp*manylinux*x86_64"
57+
build-frontend = "build"
58+
59+
environment-pass = ["LIBQI_REPOSITORY_URL"]
60+
61+
[tool.cibuildwheel.linux]
62+
# Build using the manylinux2014 image
63+
manylinux-x86_64-image = "manylinux2014"
64+
65+
before-all = ["ci/cibuildwheel_before_all.sh {package}"]
66+
67+
[tool.cibuildwheel.linux.config-settings]
68+
"cmake.args" = ["--preset=conan-release"]

0 commit comments

Comments
 (0)