Skip to content

Commit

Permalink
fix: build wheels on manylinux
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Nov 22, 2023
1 parent 74edade commit 8a714c0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ if (LANELET2_ENABLE_TESTING)
enable_testing()
endif ()

add_subdirectory(lanelet2_maps)
add_subdirectory(lanelet2_core)
add_subdirectory(lanelet2_io)
add_subdirectory(lanelet2_projection)
add_subdirectory(lanelet2_traffic_rules)
add_subdirectory(lanelet2_routing)
add_subdirectory(lanelet2_validation)
#add_subdirectory(lanelet2_examples)
add_subdirectory(lanelet2_python)
add_subdirectory(lanelet2_maps)
add_subdirectory(lanelet2_matching)
add_subdirectory(lanelet2_python)
#add_subdirectory(lanelet2_examples)
1 change: 0 additions & 1 deletion lanelet2_matching/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCE_FILES_SRC})
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(${PROJECT_NAME} PUBLIC lanelet2_core lanelet2_io lanelet2_projection lanelet2_traffic_rules)


#############
## Install ##
#############
Expand Down
28 changes: 17 additions & 11 deletions lanelet2_python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@ project(lanelet2_python)
find_package(Boost REQUIRED COMPONENTS python)
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module REQUIRED)

########################
##########################
## Build python modules ##
########################
##########################
set(PROJECT_PYTHON_TARGETS)
file(GLOB PROJECT_PYTHON_SOURCE_FILES_SRC "${CMAKE_CURRENT_SOURCE_DIR}/python_api/*.cpp")
foreach (PROJECT_PYTHON_SOURCE_FILE ${PROJECT_PYTHON_SOURCE_FILES_SRC})
get_filename_component(PYTHON_MODULE_NAME ${PROJECT_PYTHON_SOURCE_FILE} NAME_WE)
python_add_library(${PYTHON_MODULE_NAME} MODULE ${PROJECT_PYTHON_SOURCE_FILE} WITH_SOABI)
list(APPEND PROJECT_PYTHON_TARGETS ${PYTHON_MODULE_NAME})

target_compile_definitions(${PYTHON_MODULE_NAME} PRIVATE -DPYTHON_API_MODULE_NAME=${PYTHON_MODULE_NAME})
target_include_directories(${PYTHON_MODULE_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_include_directories(${PYTHON_MODULE_NAME} PRIVATE ${Python3_INCLUDE_DIRS})
target_link_libraries(${PYTHON_MODULE_NAME} PUBLIC Boost::python lanelet2_core lanelet2_io lanelet2_projection lanelet2_traffic_rules lanelet2_routing lanelet2_matching)
list(APPEND PROJECT_PYTHON_TARGETS ${PYTHON_MODULE_NAME})

if (DEFINED SKBUILD AND NOT WIN32)
set_target_properties(${PYTHON_MODULE_NAME} PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH_USE_LINK_PATH TRUE
INSTALL_RPATH "${SKBUILD_NULL_DIR}")
endif ()
endforeach ()

#############
Expand All @@ -29,15 +37,13 @@ endforeach ()
if (DEFINED SKBUILD)
install(TARGETS ${PROJECT_PYTHON_TARGETS} DESTINATION "lanelet2")
if (WIN32)
# Bundles shared library dependencies on Windows
# Bundle shared library dependencies on Windows
get_filename_component(PYTHON_LIBRARIES_NAME ${Python_LIBRARIES} NAME_WE)
foreach (PROJECT_PYTHON_TARGET ${PROJECT_PYTHON_TARGETS})
install(FILES "$<TARGET_RUNTIME_DLLS:${PROJECT_PYTHON_TARGET}>" DESTINATION "lanelet2/bin")
install(FILES $<FILTER:$<TARGET_RUNTIME_DLLS:${PROJECT_PYTHON_TARGET}>,EXCLUDE,${PYTHON_LIBRARIES_NAME}.dll> DESTINATION "lanelet2/bin")
endforeach ()
else ()
# Save shared library dependencies to RPATH on Unix
install(TARGETS lanelet2_core lanelet2_io lanelet2_projection lanelet2_traffic_rules lanelet2_routing lanelet2_matching DESTINATION ${SKBUILD_NULL_DIR})
endif ()
endif ()

#############
## Testing ##
#############
# Add test targets for cpp and python tests
# TODO:
10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ input = "lanelet2_python/src/lanelet2/__init__.py"

[[tool.scikit-build.overrides]]
if.platform-system = "win32"
cmake.args = ["--preset conan-default"]
cmake.args = ["--preset conan-default"] # override for multi-configuration generator (i.e. MSVC) on Windows

[tool.cibuildwheel]
skip = ["*-win32", "*-musllinux_x86_64", "*_i686"]
Expand All @@ -66,9 +66,16 @@ before-build = [

[tool.cibuildwheel.linux]
before-build = [
# here, we restore libpython*.a - otherwise conan will fail when adding boost::python
# see https://github.com/pypa/manylinux/blob/main/docker/build_scripts/finalize-python.sh
"pushd /opt/_internal",
"tar -xJf static-libs-for-embedding-only.tar.xz",
"popd",
"python -m pip install --upgrade pip",
"pip install -r requirements.txt",
"conan profile detect --force",
# we force the build of everything from source - prebuilt b2 does not work in manylinux
# also set the generator to use ninja because scikit-build-core will default to ninja
"conan install . --output-folder=build --build=* -c tools.cmake.cmaketoolchain:generator=Ninja"
]

Expand All @@ -77,5 +84,6 @@ before-build = [
"python -m pip install --upgrade pip",
"pip install -r requirements.txt",
"conan profile detect --force",
# set the generator to use ninja because scikit-build-core will default to ninja
"conan install . --output-folder=build --build=missing -c tools.cmake.cmaketoolchain:generator=Ninja"
]

0 comments on commit 8a714c0

Please sign in to comment.