Skip to content

Commit 5d827ac

Browse files
committed
Fix bioconda wrapper types and R conda package load failure
- Pass SWIGWORDSIZE64 to the Python and Java SWIG runs on Linux for ALL SWIG versions, not only >= 4.4. Bioconda pins swig <4.3 and its conda-forge swig 4.2.1 build resolves int64_t to 'long long' through Sim.i's stdint.i include, reproducing the original vector<long long> vs vector<long> compile failure. With the flag the typedef says 'long', which is correct on Linux whether a given SWIG build resolves the typedef or keeps int64_t literal. R keeps the >= 4.4 gate (TTTRLIB_SWIG_INT64_FLAG_R): SWIG 4.2's R backend breaks literal 'long long' returns under the define, and the R module never includes stdint.i in the first place. - Build tttrlibStatic without LTO. R CMD INSTALL links the static archive outside our CMake build; with slim LTO bitcode members the consumer drops vague-linkage symbols and the R package failed to load with undefined 'typeinfo for TTTRRange'. Same class of fix as the bundled libtiff archive.
1 parent 1e698d6 commit 5d827ac

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,13 @@ IF(BUILD_LIBRARY)
316316
# cmake needs unique target name, thus place shared in front of project
317317
ADD_LIBRARY(${PROJECT_NAME}Shared SHARED ${SRC_files})
318318
ADD_LIBRARY(${PROJECT_NAME}Static STATIC ${SRC_files})
319+
IF(NOT MSVC)
320+
# The static archive is consumed outside this build (e.g. R CMD INSTALL
321+
# links it into the R package). If it holds slim LTO bitcode, an ar/linker
322+
# without the LTO plugin drops vague-linkage symbols (typeinfo/vtables,
323+
# e.g. _ZTI9TTTRRange) and the consumer fails at load. Archive real code.
324+
TARGET_COMPILE_OPTIONS(${PROJECT_NAME}Static PRIVATE -fno-lto)
325+
ENDIF()
319326

320327
# Link libraries (Boost removed - using C++17 standard library)
321328

ext/CMakeLists.txt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,23 @@ MESSAGE(STATUS "SWIG_VERSION: ${SWIG_VERSION}")
1515
INCLUDE(${SWIG_USE_FILE})
1616
INCLUDE_DIRECTORIES(.)
1717

18-
# glibc on LP64 Linux defines int64_t as 'long', but SWIG >= 4.4 eagerly
19-
# resolves the stdint.i typedefs and picks 'long long' unless SWIGWORDSIZE64
20-
# is defined. Without this flag the generated wrappers mix
18+
# glibc on LP64 Linux defines int64_t as 'long', but SWIG's stdint.i (pulled
19+
# in by Sim.i) typedefs it to 'long long' unless SWIGWORDSIZE64 is defined,
20+
# and depending on the SWIG build the generated Python wrappers then mix
2121
# std::vector<long long> with the library's std::vector<long> and do not
22-
# compile on Linux. Only define it for SWIG >= 4.4: older SWIG keeps int64_t
23-
# literal in generated code (so the flag is unnecessary), and SWIG 4.2's R
24-
# backend mishandles 'long long' returns under SWIGWORDSIZE64 (the C side
25-
# returns a native vector while the R proxy expects an external pointer).
26-
IF(UNIX AND NOT APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT SWIG_VERSION VERSION_LESS "4.4")
22+
# compile (seen with conda-forge swig 4.2.1 and 4.4.1). With the flag the
23+
# typedef says 'long', which is correct on Linux whether SWIG resolves it or
24+
# keeps int64_t literal, so pass it unconditionally for the Python and Java
25+
# modules. The R module is the exception: it never includes stdint.i, and
26+
# SWIG 4.2's R backend mishandles 'long long' returns under SWIGWORDSIZE64
27+
# (the C side returns a native vector while the R proxy expects an external
28+
# pointer), so R only gets the flag for SWIG >= 4.4 where it is verified fine.
29+
IF(UNIX AND NOT APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 8)
2730
SET(TTTRLIB_SWIG_INT64_FLAG "-DSWIGWORDSIZE64")
2831
LIST(APPEND CMAKE_SWIG_FLAGS ${TTTRLIB_SWIG_INT64_FLAG})
32+
IF(NOT SWIG_VERSION VERSION_LESS "4.4")
33+
SET(TTTRLIB_SWIG_INT64_FLAG_R "-DSWIGWORDSIZE64")
34+
ENDIF()
2935
ENDIF()
3036

3137
IF(BUILD_PYTHON_INTERFACE)
@@ -212,7 +218,7 @@ IF(BUILD_R_INTERFACE)
212218
SWIG_MODULE_NAME tttrlib)
213219

214220
# r/tttrlib.i re-includes the shared fragments that live in ext/python.
215-
SET(CMAKE_SWIG_FLAGS -I${CMAKE_CURRENT_SOURCE_DIR}/python ${TTTRLIB_SWIG_INT64_FLAG})
221+
SET(CMAKE_SWIG_FLAGS -I${CMAKE_CURRENT_SOURCE_DIR}/python ${TTTRLIB_SWIG_INT64_FLAG_R})
216222

217223
# Rerun SWIG when any shared fragment, the R module, or the R array library changes.
218224
file(GLOB R_SWIG_DEPS

0 commit comments

Comments
 (0)