Skip to content

Commit 6d89803

Browse files
authored
[build] Lean install: ship single stripped libclangCppInterOp (#50)
Drops wheel sizes by about half. Previously the entire install tree of CppInterOp was staged that included duplicate shared libs due to versioning. This is fixed by adding a stripped shared-lib option in CppInterOp, leveraged in this patch.
1 parent 133da28 commit 6d89803

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

CMakeLists.txt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include(GNUInstallDirs)
1212
# Perhaps this should permanently be OFF and users can build their own CppInterOp if they want to run the tests?
1313
option(CPPJIT_ENABLE_CPPINTEROP_TESTS "enable CppInterOp tests" OFF)
1414
set(CPPINTEROP_GIT_REPOSITORY "https://github.com/compiler-research/CppInterOp.git" CACHE STRING "")
15-
set(CPPINTEROP_GIT_TAG "8d624c621a4b95e36ff73ac708c85a768287478f" CACHE STRING "")
15+
set(CPPINTEROP_GIT_TAG "9802d61921ad5688ae42e4e628d754fc1192244d" CACHE STRING "")
1616
set(CPPINTEROP_SOURCE_DIR "" CACHE PATH
1717
"Override default CppInterOp built by ExternalProject_Add, with a path to local CppInterOp source")
1818

@@ -101,7 +101,10 @@ if(_python_platlib)
101101
else()
102102
set(CPPINTEROP_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
103103
endif()
104-
set(CPPINTEROP_INSTALL_DIR "${CPPINTEROP_INSTALL_PREFIX}/cppjit/interop")
104+
105+
# CppInterOp installs here; cppjit's own rules ship a subset, so the wheel
106+
# owns every installed file.
107+
set(CPPINTEROP_STAGE_DIR "${CMAKE_BINARY_DIR}/cppinterop-stage")
105108

106109
# Include cmake for CppInterOp config and build using ExternalProject.
107110
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/AddCppInterOp.cmake)
@@ -134,7 +137,7 @@ target_include_directories(cppjit PRIVATE
134137
${CMAKE_CURRENT_SOURCE_DIR}/src
135138
${CMAKE_CURRENT_SOURCE_DIR}/src/cpyrt
136139
${CMAKE_CURRENT_SOURCE_DIR}/src/interop
137-
${CPPINTEROP_INSTALL_DIR}/include
140+
${CPPINTEROP_STAGE_DIR}/include
138141
${Python_INCLUDE_DIRS}
139142
)
140143

@@ -164,17 +167,12 @@ install(TARGETS cppjit
164167
LIBRARY DESTINATION cppjit
165168
)
166169

167-
# install CppInterOp libraries and headers
168-
install(CODE "
169-
file(GLOB _interop_libs \"${CPPINTEROP_INSTALL_DIR}/lib/libclangCppInterOp*\")
170-
foreach(_lib \${_interop_libs})
171-
file(INSTALL \${_lib} DESTINATION \${CMAKE_INSTALL_PREFIX}/cppjit/interop/lib)
172-
endforeach()
173-
")
174-
175-
install(CODE "
176-
file(INSTALL \"${CPPINTEROP_INSTALL_DIR}/include/\" DESTINATION \${CMAKE_INSTALL_PREFIX}/cppjit/interop/include)
177-
")
170+
install(DIRECTORY "${CPPINTEROP_STAGE_DIR}/lib/"
171+
DESTINATION cppjit/interop/lib
172+
)
173+
install(DIRECTORY "${CPPINTEROP_STAGE_DIR}/include/"
174+
DESTINATION cppjit/interop/include
175+
)
178176

179177
# ship the builtin headers of the build clang, laid out as a headers-only
180178
# resource dir: only include/ ships

cmake/AddCppInterOp.cmake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ function(cppjit_add_cppinterop)
2222
-DLLVM_DIR=${LLVM_DIR}
2323
-DCPPINTEROP_ENABLE_TESTING=${CPPJIT_ENABLE_CPPINTEROP_TESTS}
2424
-DBUILD_SHARED_LIBS=ON
25-
-DCMAKE_INSTALL_PREFIX=${CPPINTEROP_INSTALL_DIR}
25+
# The wheel ships a single unversioned library file.
26+
-DCPPINTEROP_SHARED_LIBRARY_VERSIONING=OFF
27+
-DCMAKE_INSTALL_PREFIX=${CPPINTEROP_STAGE_DIR}
2628
-DCMAKE_INSTALL_LIBDIR=lib
2729
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
2830
-DCMAKE_CXX_STANDARD=17
@@ -85,12 +87,16 @@ function(cppjit_add_cppinterop)
8587
set(_log_args "")
8688
endif()
8789

90+
# Install only the library and headers, not CppInterOp's full install tree.
8891
ExternalProject_Add(CppInterOp
8992
${_source_args}
9093
PREFIX "${CMAKE_BINARY_DIR}/CppInterOp"
9194
CMAKE_ARGS ${_args}
95+
# -stripped keeps .dynsym, so the dlsym-based dispatch still resolves.
96+
INSTALL_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR>
97+
--target install-clangCppInterOp-stripped install-cppinterop-headers
9298
BUILD_BYPRODUCTS
93-
"${CPPINTEROP_INSTALL_DIR}/lib/libclangCppInterOp${CMAKE_SHARED_LIBRARY_SUFFIX}"
99+
"${CPPINTEROP_STAGE_DIR}/lib/libclangCppInterOp${CMAKE_SHARED_LIBRARY_SUFFIX}"
94100
${_log_args}
95101
)
96102

0 commit comments

Comments
 (0)