Skip to content

Commit 159d04b

Browse files
committed
Improve build procedure and document steps in README.
This change fixes minor issues with the build system and the CI, and better document build steps and wheel construction in the README.
1 parent 05a04e8 commit 159d04b

4 files changed

Lines changed: 94 additions & 19 deletions

File tree

CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,10 @@ if(BUILD_TESTING)
346346
pybind11::pybind11
347347
GTest::gmock
348348
)
349-
gtest_discover_tests(test_qipython)
349+
gtest_discover_tests(
350+
test_qipython
351+
DISCOVERY_MODE PRE_TEST
352+
)
350353

351354
add_executable(test_qipython_local_interpreter)
352355
target_sources(
@@ -363,7 +366,10 @@ if(BUILD_TESTING)
363366
cxx_standard
364367
GTest::gmock
365368
)
366-
gtest_discover_tests(test_qipython_local_interpreter)
369+
gtest_discover_tests(
370+
test_qipython_local_interpreter
371+
DISCOVERY_MODE PRE_TEST
372+
)
367373
endif()
368374

369375
if(NOT Python_Interpreter_FOUND)

README.rst

Lines changed: 81 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,30 @@ __ LibQi_repo_
1010
Building
1111
========
1212

13-
The libqi-python project requires a compiler that supports C++17 to build.
13+
To build the project, you need:
1414

15-
It is built with CMake >= 3.23.
15+
- a compiler that supports C++17.
16+
17+
- on Ubuntu: `apt-get install build-essential`.
18+
19+
- CMake with at least version 3.23.
20+
21+
- on PyPI (**recommended**): `pip install "cmake>=3.23"`.
22+
- on Ubuntu: `apt-get install cmake`.
23+
24+
- Python with at least version 3.7 and its development libraries.
25+
26+
- On Ubuntu: `apt-get install libpython3-dev`.
27+
28+
- a Python `virtualenv`.
29+
30+
- On Ubuntu:
31+
32+
.. code-block:: console
33+
34+
apt-get install python3-venv
35+
python3 -m venv ~/my-venv # Use the path of your convenience.
36+
source ~/my-venv/bin/activate
1637
1738
.. note::
1839
The CMake project offers several configuration options and exports a set
@@ -21,13 +42,13 @@ It is built with CMake >= 3.23.
2142

2243
.. note::
2344
The procedures described below assume that you have downloaded the project
24-
sources and that your current working directory is the project sources root
25-
directory.
45+
sources, that your current working directory is the project sources root
46+
directory and that you are working inside your virtualenv.
2647

2748
Conan
2849
^^^^^
2950

30-
Additionally, libqi-python is available as a Conan 2 project, which means you
51+
Additionally, `libqi-python` is available as a Conan 2 project, which means you
3152
can use Conan to fetch dependencies.
3253

3354
You can install and/or upgrade Conan 2 and create a default profile in the
@@ -46,11 +67,35 @@ Install dependencies from Conan and build with CMake
4667
The procedure to build the project using Conan to fetch dependencies is the
4768
following.
4869

49-
You must first install the project dependencies in Conan.
70+
Most dependencies are available on Conan Center repository and should not
71+
require any additional steps to make them available. However, you might need to
72+
first get and export the `libqi` recipe into your local Conan cache.
5073

5174
.. code-block:: console
5275
53-
conan install . --build=missing -s build_type=Debug
76+
# GitHub is available, but you can also use internal GitLab.
77+
QI_REPOSITORY="https://github.com/aldebaran/libqi.git"
78+
QI_VERSION="4.0.1" # Checkout the version your project need.
79+
QI_PATH="$HOME/libqi" # Or whatever path you want.
80+
git clone \
81+
--depth=1 `# Only fetch one commit.` \
82+
--branch "qi-framework-v${QI_VERSION}" \
83+
"${QI_REPOSITORY}" \
84+
"${QI_PATH}"
85+
conan export "${QI_PATH}" \
86+
--version "${QI_VERSION}" # Technically not required but some
87+
# versions of libqi require it
88+
# because of a bug.
89+
90+
You can then install the `libqi-python` dependencies in Conan.
91+
92+
.. code-block:: console
93+
94+
conan install . \
95+
--build=missing `# Build dependencies binaries that are missing in Conan.` \
96+
-s build_type=Debug `# Build in debug mode.` \
97+
-c tools.build:skip_test=true `# Skip tests building for dependencies.` \
98+
-c '&:tools.build:skip_test=false' # Do not skip tests for the project.
5499
55100
This will generate a build directory containing a configuration with a
56101
toolchain file that allows CMake to find dependencies inside the Conan cache.
@@ -73,20 +118,24 @@ To start building, you need to configure with CMake and then build:
73118
cmake --preset conan-linux-x86_64-gcc-debug
74119
cmake --build --preset conan-linux-x86_64-gcc-debug
75120
76-
You can then invoke tests using CTest_:
121+
Tests can now be invoked using CTest_, but they require a runtime environment
122+
from Conan so that all dependencies are found:
77123

78124
.. code-block:: console
79125
126+
source build/linux-x86_64-gcc-debug/generators/conanrun.sh
80127
ctest --preset conan-linux-x86_64-gcc-debug --output-on-failure
128+
source build/linux-x86_64-gcc-debug/generators/deactivate_conanrun.sh
81129
82130
Finally, you can install the project in the directory of your choice.
83131

84132
The project defines a single install component, the ``Module`` component.
85133

86134
.. code-block:: console
87135
88-
# "cmake --install" does not support preset sadly.
89-
cmake --install build/linux-x86_64-gcc-debug
136+
# `cmake --install` does not support presets sadly.
137+
cmake \
138+
--install build/linux-x86_64-gcc-debug \
90139
--component Module --prefix ~/my-libqi-python-install
91140
92141
Wheel (PEP 517)
@@ -101,34 +150,50 @@ dependencies, such as a toolchain generated by Conan:
101150

102151
.. code-block:: console
103152
104-
conan install . --build=missing
153+
conan install . \
154+
--build=missing `# Build dependencies binaries that are missing in Conan.` \
155+
-c tools.build:skip_test=true # Skip any test.
105156
106157
You now can use the ``build`` Python module to build the wheel using PEP 517.
107158

108159
.. code-block:: console
109160
110-
export CMAKE_TOOLCHAIN_FILE=$PWD/build/linux-x86_64-gcc-release/generators/conan_toolchain.cmake
111-
python -m build
161+
pip install -U build
162+
python -m build \
163+
--config-setting cmake.define.CMAKE_TOOLCHAIN_FILE=$PWD/build/linux-x86_64-gcc-release/generators/conan_toolchain.cmake
112164
113165
When built that way, the native libraries present in the wheel are most likely incomplete.
114166
You will need to use ``auditwheel`` or ``delocate`` to fix it.
115167

168+
.. note::
169+
`auditwheel` requires the `patchelf` utility program on Linux. You may need
170+
to install it (on Ubuntu: `apt-get install patchelf`).
171+
116172
.. code-block:: console
117173
118-
auditwheel repair --plat manylinux_2_31_x86_64 dist/qi-*.whl
174+
pip install -U auditwheel # or `delocate` on MacOS.
175+
auditwheel repair \
176+
--strip `# Strip debugging symbols to get a lighter archive.` \
177+
`# The desired platform, which may differ depending on your build host.` \
178+
`# With Ubuntu 20.04, we can target manylinux_2_31. Newer versions of` \
179+
`# Ubuntu will have to target newer versions of manylinux.` \
180+
`# If you don't need a manylinux archive, you can also target the` \
181+
`# 'linux_x86_64' platform.` \
182+
--plat manylinux_2_31_x86_64 \
183+
`# Path to the wheel archive.` \
184+
dist/qi-*.whl
119185
# The wheel will be by default placed in a `./wheelhouse/` directory.
120186
121187
Crosscompiling
122188
--------------
123189

124190
The project supports cross-compiling as explained in the `CMake manual about
125191
toolchains`__. You may simply set the ``CMAKE_TOOLCHAIN_FILE`` variable to the
126-
path of the CMake file in your toolchain.
192+
path of the CMake file of your toolchain.
127193

128194
__ CMake_toolchains_
129195

130196
.. _LibQi_repo: https://github.com/aldebaran/libqi
131197
.. _scikit-build: https://scikit-build.readthedocs.io/en/latest/
132-
.. _setuptools: https://setuptools.readthedocs.io/en/latest/setuptools.html
133198
.. _CMake_toolchains: https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html
134199
.. _CTest: https://cmake.org/cmake/help/latest/manual/ctest.1.html

ci/cibuildwheel_linux_before_all.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ yum install -y perl-IPC-Cmd perl-Digest-SHA
1212
conan config install "$PACKAGE/ci/conan"
1313

1414
# Clone and export libqi to Conan cache.
15-
QI_VERSION=$(sed -nE '/^\s*requires\s*=/,/^\s*]/{ s/\s*"qi\/([^"]+)"/\1/p }' "$PACKAGE/conanfile.py")
15+
QI_VERSION=$(sed -nE '/^\s*requires\s*=/,/^\s*]/{ s/\s*"qi\/([^"]+)".*/\1/p }' "$PACKAGE/conanfile.py")
1616

1717
GIT_SSL_NO_VERIFY=true \
1818
git clone --depth=1 \

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ repository = "https://github.com/aldebaran/libqi-python"
5252
# Rely only on CMake install, not on Python packages detection.
5353
wheel.packages = []
5454

55+
[tool.scikit-build.cmake.define]
56+
# Disable building tests by default when building a wheel.
57+
BUILD_TESTING = "OFF"
58+
5559
[tool.cibuildwheel]
5660
build = "cp*manylinux*x86_64"
5761
build-frontend = "build"

0 commit comments

Comments
 (0)