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

add BUILD_ONLY_PYTHON_INTERFACE option #658

Draft
wants to merge 5 commits into
base: devel
Choose a base branch
from

Conversation

nim65s
Copy link
Contributor

@nim65s nim65s commented Feb 13, 2025

Here is an example for jrl-umi3218/jrl-cmakemodules#745

I'm testing this with that script
#!/usr/bin/env bash

set -euxo pipefail

BLD=/tmp/coal/build
PFX=/tmp/coal/prefix
PYTHONPATH=""
export PYTHONPATH

rm -rf /tmp/coal

SUB=base
CMAKE_PREFIX_PATH=$PFX/$SUB
export CMAKE_PREFIX_PATH

cmake -B $BLD/$SUB -DCMAKE_INSTALL_PREFIX=$PFX/$SUB \
    -DBUILD_PYTHON_INTERFACE=OFF \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -Wno-dev
cmake --build $BLD/$SUB
cmake --build $BLD/$SUB -t test
cmake --build $BLD/$SUB -t install

SUB=py312

cmake -B $BLD/$SUB -DCMAKE_INSTALL_PREFIX=$PFX/$SUB \
    -DBUILD_PYTHON_INTERFACE=ON \
    -DBUILD_ONLY_PYTHON_INTERFACE=ON \
    -DPYTHON_EXECUTABLE="$(which python3.12)" \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -Wno-dev
cmake --build $BLD/$SUB
cmake --build $BLD/$SUB -t test
cmake --build $BLD/$SUB -t install

SUB=py313

cmake -B $BLD/$SUB -DCMAKE_INSTALL_PREFIX=$PFX/$SUB \
    -DBUILD_PYTHON_INTERFACE=ON \
    -DBUILD_ONLY_PYTHON_INTERFACE=ON \
    -DPYTHON_EXECUTABLE="$(which python3.13)" \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -Wno-dev
cmake --build $BLD/$SUB
cmake --build $BLD/$SUB -t test
cmake --build $BLD/$SUB -t install

SUB=all
CMAKE_PREFIX_PATH=
export CMAKE_PREFIX_PATH

cmake -B $BLD/$SUB -DCMAKE_INSTALL_PREFIX=$PFX/$SUB \
    -DBUILD_PYTHON_INTERFACE=ON \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -Wno-dev
cmake --build $BLD/$SUB
cmake --build $BLD/$SUB -t test
cmake --build $BLD/$SUB -t install

SUB=merged
CMAKE_PREFIX_PATH=$PFX/$SUB
export CMAKE_PREFIX_PATH

cmake -B $BLD/$SUB -DCMAKE_INSTALL_PREFIX=$PFX/merged \
    -DBUILD_PYTHON_INTERFACE=OFF \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -Wno-dev
cmake --build $BLD/$SUB
cmake --build $BLD/$SUB -t test
cmake --build $BLD/$SUB -t install

SUB=merged/py312

cmake -B $BLD/$SUB -DCMAKE_INSTALL_PREFIX=$PFX/merged \
    -DBUILD_PYTHON_INTERFACE=ON \
    -DBUILD_ONLY_PYTHON_INTERFACE=ON \
    -DPYTHON_EXECUTABLE="$(which python3.12)" \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -Wno-dev
cmake --build $BLD/$SUB
cmake --build $BLD/$SUB -t test
cmake --build $BLD/$SUB -t install

SUB=merged/py313

cmake -B $BLD/$SUB -DCMAKE_INSTALL_PREFIX=$PFX/merged \
    -DBUILD_PYTHON_INTERFACE=ON \
    -DBUILD_ONLY_PYTHON_INTERFACE=ON \
    -DPYTHON_EXECUTABLE="$(which python3.13)" \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -Wno-dev
cmake --build $BLD/$SUB
cmake --build $BLD/$SUB -t test
cmake --build $BLD/$SUB -t install

NB: the nix commit is not meant to stay in the final version of this PR.

Copy link
Contributor

@jorisv jorisv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will review it as soon as I can

@jorisv
Copy link
Contributor

jorisv commented Feb 18, 2025

@nim65s I think your change are good. I will try to create local conda-package to check if it's working well.

The only issue I see is in most of our project, the root CMakeLists will search for all dependencies. If we don't want some dependencies in the Python build, we will have to add guards around add_dependencies to avoid searching for them in the Python only build.

I was thinking to an alternative approach: turning the python/CMakeLists.txt file into a standalone project. So user that only want the python binding can go on this sub directory, run cmake and build it.
What do you think of this approach ?

@nim65s
Copy link
Contributor Author

nim65s commented Feb 18, 2025

@nim65s I think your change are good. I will try to create local conda-package to check if it's working well.

Yes, I'm planninng to do test packaging on robotpkg / cmeel / nix before marking this as ready.

The only issue I see is in most of our project, the root CMakeLists will search for all dependencies. If we don't want some dependencies in the Python build, we will have to add guards around add_dependencies to avoid searching for them in the Python only build.

do you have an example in mind ? For eg. boost, we'll got this transitively with the c++ package anyways. For eg. eigen, well, I don't really see the issue.

I was thinking to an alternative approach: turning the python/CMakeLists.txt file into a standalone project. So user that only want the python binding can go on this sub directory, run cmake and build it. What do you think of this approach ?

I like the idea, this should probably be tried too. It sounds like it will require heavy changes in the cmake, the docs and the tests though.

@jorisv
Copy link
Contributor

jorisv commented Feb 19, 2025

You right for the dependencies, it should be a non issue. The only issue is the guard added to avoid building the main project.

I have tried to create a separate sub project in this PR : #660
I'm just worried with JRL CMake and subproject using JRL CMake can conflict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants