Skip to content

Commit 565dbfe

Browse files
committed
Add wheel repair test
Signed-off-by: Cristian Le <git@lecris.dev>
1 parent ebc4192 commit 565dbfe

File tree

17 files changed

+285
-0
lines changed

17 files changed

+285
-0
lines changed

tests/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import dataclasses
55
import importlib.util
66
import os
7+
import platform
78
import shutil
89
import subprocess
910
import sys
@@ -56,6 +57,11 @@ def pep518_wheelhouse(tmp_path_factory: pytest.TempPathFactory) -> Path:
5657
"virtualenv",
5758
"wheel",
5859
]
60+
if platform.system() == "Linux":
61+
packages.append("auditwheel")
62+
packages.append("patchelf")
63+
if platform.system() == "Darwin":
64+
packages.append("delocate")
5965

6066
if importlib.util.find_spec("cmake") is not None:
6167
packages.append("cmake")
@@ -346,6 +352,15 @@ def package_pep639_pure(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Pack
346352
return package
347353

348354

355+
@pytest.fixture
356+
def repair_wheel(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> PackageInfo:
357+
package = PackageInfo(
358+
"repair_wheel",
359+
)
360+
process_package(package, tmp_path, monkeypatch)
361+
return package
362+
363+
349364
def which_mock(name: str) -> str | None:
350365
if name in {"ninja", "ninja-build", "cmake3", "samu", "gmake", "make"}:
351366
return None
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
cmake_minimum_required(VERSION 3.15...3.26)
2+
3+
project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX)
4+
5+
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
6+
7+
include(GNUInstallDirs)
8+
include(CMakePackageConfigHelpers)
9+
10+
find_package(Base CONFIG REQUIRED)
11+
find_package(Python COMPONENTS Interpreter Development.Module)
12+
13+
add_executable(main src/main.cpp)
14+
add_library(other SHARED src/other.cpp)
15+
python_add_library(_module MODULE src/module.cpp WITH_SOABI)
16+
17+
target_link_libraries(other PRIVATE base::base)
18+
target_link_libraries(main PRIVATE other)
19+
target_link_libraries(_module PRIVATE base::base)
20+
21+
install(TARGETS main other)
22+
install(TARGETS _module DESTINATION ".")
23+
24+
if(DO_MANUAL_REPAIR)
25+
if(APPLE)
26+
set(origin_token "@loader_path")
27+
else()
28+
set(origin_token "$ORIGIN")
29+
endif()
30+
set_property(
31+
TARGET main PROPERTY INSTALL_RPATH
32+
"${origin_token}/../${CMAKE_INSTALL_LIBDIR}")
33+
set_property(
34+
TARGET other
35+
PROPERTY INSTALL_RPATH
36+
"${origin_token}/../../base_project/${CMAKE_INSTALL_LIBDIR}")
37+
set_property(
38+
TARGET _module
39+
PROPERTY INSTALL_RPATH
40+
"${origin_token}/../base_project/${CMAKE_INSTALL_LIBDIR}")
41+
if(WIN32)
42+
install(TARGETS other RUNTIME DESTINATION ${SKBUILD_SCRIPTS_DIR})
43+
file(
44+
WRITE ${CMAKE_CURRENT_BINARY_DIR}/__init__.py
45+
"
46+
import os
47+
import sysconfig
48+
from pathlib import Path
49+
50+
base_project_bindir = Path(__file__).parent / \"../base_project/${CMAKE_INSTALL_BINDIR}\"
51+
project_bindir = Path(__file__).parent / \"${CMAKE_INSTALL_BINDIR}\"
52+
os.add_dll_directory(str(base_project_bindir))
53+
os.add_dll_directory(str(project_bindir))
54+
")
55+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/__init__.py DESTINATION ".")
56+
endif()
57+
endif()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@PACKAGE_INIT@
2+
3+
include(${CMAKE_CURRENT_LIST_DIR}/BaseTargets.cmake)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
cmake_minimum_required(VERSION 3.15...3.26)
2+
3+
project(Base LANGUAGES CXX)
4+
5+
include(GNUInstallDirs)
6+
include(CMakePackageConfigHelpers)
7+
8+
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
9+
10+
add_library(base SHARED)
11+
12+
target_sources(base PRIVATE base.cpp)
13+
set_property(
14+
TARGET base
15+
APPEND
16+
PROPERTY PUBLIC_HEADER base.h)
17+
target_include_directories(
18+
base PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
19+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
20+
21+
install(TARGETS base EXPORT BaseTargets)
22+
install(
23+
EXPORT BaseTargets
24+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/base
25+
NAMESPACE base::)
26+
configure_package_config_file(
27+
BaseConfig.cmake.in BaseConfig.cmake
28+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Base)
29+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/BaseConfig.cmake
30+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/base)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <iostream>
2+
3+
#include "base.h"
4+
5+
void base::hello() {
6+
std::cout << "Hello, World!" << std::endl;
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
namespace base {
4+
void hello();
5+
}

tests/packages/repair_wheel/extern/base_project/__init__.py

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[build-system]
2+
requires = ["scikit-build-core"]
3+
build-backend = "scikit_build_core.build"
4+
5+
[project]
6+
name = "base_project"
7+
version = "0.1.0"
8+
9+
[project.entry-points."cmake.root"]
10+
Base = "base_project"
11+
12+
[tool.scikit-build]
13+
wheel.install-dir = "base_project"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[build-system]
2+
requires = ["scikit-build-core"]
3+
build-backend = "scikit_build_core.build"
4+
5+
[project]
6+
name = "repair_wheel"
7+
version = "0.1.0"
8+
dependencies = ["base_project"]
9+
10+
[tool.scikit-build]
11+
build.requires = ["base_project @ {root:uri}/extern"]
12+
wheel.install-dir = "repair_wheel"
13+
wheel.repair = true
14+
experimental = true
15+
16+
[project.scripts]
17+
main = "repair_wheel.__main__:run"
18+
19+
[[tool.scikit-build.overrides]]
20+
if.env.MANUAL = true
21+
wheel.repair = false
22+
cmake.define.DO_MANUAL_REPAIR = true

tests/packages/repair_wheel/python/repair_wheel/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)