Skip to content

Commit 46b17c0

Browse files
authored
fix(build): hide C++ symbols to prevent conflicts with numpy/sklearn (#248)
1 parent 45604c2 commit 46b17c0

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

.github/workflows/build.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ jobs:
101101
exit 0
102102
fi
103103
104-
# Set up PR refs and fetch base branch to ensure we have the commits
104+
# Set up PR refs - fetch BOTH base and head to ensure commits are available
105105
BASE_SHA="${{ github.event.pull_request.base.sha }}"
106106
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
107107
git fetch origin "${{ github.event.pull_request.base.ref }}" --quiet || true
108+
git fetch origin "pull/${{ github.event.pull_request.number }}/head:pr-head" --quiet || true
108109
109110
# Check all commits in the PR for [build]
110111
COMMIT_MSGS=$(git log --format=%B "${BASE_SHA}..${HEAD_SHA}" 2>/dev/null || echo "")
@@ -116,6 +117,10 @@ jobs:
116117
117118
# Check which files changed in the PR
118119
CHANGED_FILES=$(git diff --name-only "${BASE_SHA}" "${HEAD_SHA}" 2>/dev/null || echo "")
120+
121+
# Debug: show what we found
122+
echo "Changed files in PR:"
123+
echo "$CHANGED_FILES"
119124
else
120125
# For pushes, check if the head commit message contains [build]
121126
if [[ "${{ contains(github.event.head_commit.message, '[build]') }}" == "true" ]]; then
@@ -147,7 +152,7 @@ jobs:
147152
fi
148153
fi
149154
150-
RESULT=1
155+
RESULT=0
151156
echo "$CHANGED_FILES" | grep -q -E '^(src/hyperscan/|README.md|CMakeLists.txt|pyproject.toml|MANIFEST.in|cmake/)' || RESULT=$?
152157
153158
if [[ "$RESULT" -eq 0 ]]; then

CMakeLists.txt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,14 @@ endif()
513513
if(WIN32)
514514
target_compile_options(${HS_EXT_NAME} PRIVATE ${HS_CMAKE_COMMON_FLAGS})
515515
else()
516-
target_compile_options(${HS_EXT_NAME} PRIVATE -fPIC -D_GLIBCXX_USE_CXX11_ABI=1)
516+
# Hide all symbols by default to prevent conflicts with other C++ extensions
517+
# (e.g., numpy, scipy, sklearn) that may use the same C++ runtime symbols
518+
target_compile_options(${HS_EXT_NAME} PRIVATE
519+
-fPIC
520+
-D_GLIBCXX_USE_CXX11_ABI=1
521+
-fvisibility=hidden
522+
-fvisibility-inlines-hidden
523+
)
517524
target_link_options(${HS_EXT_NAME} PRIVATE -O0)
518525
endif()
519526

@@ -523,6 +530,7 @@ if("$ENV{AUDITWHEEL_PLAT}" MATCHES "musllinux")
523530
target_link_options(${HS_EXT_NAME} PRIVATE
524531
-Wl,-s
525532
-Wl,--gc-sections
533+
-Wl,--exclude-libs,ALL
526534
-static-libgcc
527535
-Wl,--whole-archive
528536
-l:libstdc++.a
@@ -541,12 +549,16 @@ elseif(NOT WIN32)
541549
-Wl,--no-as-needed
542550
-Wl,--copy-dt-needed-entries
543551
-Wl,--no-allow-shlib-undefined
552+
-Wl,--exclude-libs,ALL
544553
)
545554
target_link_libraries(${HS_EXT_NAME} PRIVATE ${HS_LIBS})
546555
target_link_libraries(${HS_EXT_NAME} PRIVATE -Wl,--push-state -Wl,-Bstatic -lstdc++ -Wl,--pop-state)
547556
else()
548-
# Other Linux platforms
549-
target_link_options(${HS_EXT_NAME} PRIVATE -Wl,--no-as-needed)
557+
# Other Linux platforms (local dev, CI without auditwheel)
558+
target_link_options(${HS_EXT_NAME} PRIVATE
559+
-Wl,--no-as-needed
560+
-Wl,--exclude-libs,ALL
561+
)
550562
target_link_libraries(${HS_EXT_NAME} PRIVATE ${HS_LIBS})
551563
target_link_libraries(${HS_EXT_NAME} PRIVATE stdc++)
552564
endif()

0 commit comments

Comments
 (0)