Skip to content

Commit c6e9476

Browse files
committed
Fixed some problems in macos and windows when building wheel.
1 parent a2077dc commit c6e9476

4 files changed

Lines changed: 41 additions & 14 deletions

File tree

.github/workflows/python-app.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,12 +565,12 @@ jobs:
565565
fi
566566
if [ -n "$LLVM_OMP_BIN" ]; then
567567
echo "Bundling OpenMP from $LLVM_OMP_BIN"
568-
delvewheel repair --add-path "$LLVM_OMP_BIN" -w {dest_dir} {wheel} || true
568+
delvewheel repair --add-path "$LLVM_OMP_BIN" -w "{dest_dir}" "{wheel}" || true
569569
else
570570
echo "WARNING: MSVC LLVM OpenMP not found; running delvewheel without --add-path"
571-
delvewheel repair -w {dest_dir} {wheel} || true
571+
delvewheel repair -w "{dest_dir}" "{wheel}" || true
572572
fi
573-
python "{project}/maintenance_scripts/repair_windows_wheel.py" {dest_dir} {wheel}
573+
python "{project}/maintenance_scripts/repair_windows_wheel.py" "{dest_dir}" "{wheel}"
574574
575575
# 注意:CIBW_BEFORE_BUILD(通用)在所有平台都提供了平台专用版本时
576576
# 永远不会执行(平台专用变体会覆盖通用变体),已移除死代码。

maintenance_scripts/build_macos_ci_libomp.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ _libomp_deploy_ok() {
4747
}
4848

4949
_libomp_symbol_ok() {
50-
# LLVM-built libomp exports kmpc symbols with nm -g; avoid brittle exact names.
51-
nm -g "$LIBOMP" 2>/dev/null | grep -q 'kmpc_dispatch_deinit'
50+
# LLVM-built libomp may not export dispatch_deinit, but always exports kmpc/omp APIs.
51+
nm -g "$LIBOMP" 2>/dev/null | grep -Eq '__kmpc_|omp_get_max_threads'
5252
}
5353

5454
if [[ -f "$LIBOMP" ]] && _libomp_arch_ok && _libomp_deploy_ok && _libomp_symbol_ok; then
@@ -115,7 +115,7 @@ if ! _libomp_arch_ok || ! _libomp_deploy_ok || ! _libomp_symbol_ok; then
115115
_libomp_symbol_ok || echo " - missing OpenMP runtime symbols" >&2
116116
file "$LIBOMP" >&2 || true
117117
otool -l "$LIBOMP" | awk '/LC_BUILD_VERSION|LC_VERSION_MIN_MACOSX|minos|version/' >&2 || true
118-
nm -g "$LIBOMP" 2>/dev/null | grep kmpc | head -5 >&2 || true
118+
nm -g "$LIBOMP" 2>/dev/null | grep -E '__kmpc_|omp_get_max_threads' | head -5 >&2 || true
119119
exit 1
120120
fi
121121

maintenance_scripts/repair_windows_wheel.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ def main() -> int:
1515
)
1616
return 2
1717

18-
dest = Path(sys.argv[1])
19-
wheel = Path(sys.argv[2])
18+
dest = Path(sys.argv[1]).resolve()
19+
wheel = Path(sys.argv[2]).resolve()
2020
dest.mkdir(parents=True, exist_ok=True)
2121

22+
if not wheel.is_file():
23+
print(f"Source wheel not found: {wheel}", file=sys.stderr)
24+
return 1
25+
2226
wheels = sorted(dest.glob("*.whl"))
2327
if not wheels:
2428
print("delvewheel did not emit a wheel; copying built wheel as-is")
@@ -29,7 +33,11 @@ def main() -> int:
2933
wheels = [target]
3034

3135
if not wheels:
32-
print(f"Failed to place repaired wheel in {dest}", file=sys.stderr)
36+
print(
37+
f"Failed to place repaired wheel in {dest} "
38+
f"(source={wheel}, dest_exists={dest.is_dir()})",
39+
file=sys.stderr,
40+
)
3341
return 1
3442

3543
print(f"Repaired wheel: {wheels[0]}")

setup.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,26 +217,45 @@ def _find_libomp_prefix():
217217
if (
218218
os.path.isfile(os.path.join(inc, 'omp.h'))
219219
and os.path.isfile(libomp)
220-
and _libomp_has_symbol(libomp, '___kmpc_dispatch_deinit')
220+
and _libomp_prefix_is_usable(prefix, libomp)
221221
):
222222
return inc, lib
223223
return None, None
224224

225225

226-
def _libomp_has_symbol(libomp_path, symbol):
226+
def _libomp_exports_runtime_symbols(libomp_path):
227+
"""Return True when libomp.dylib exposes usable OpenMP/kmpc entry points."""
227228
if sys.platform != 'darwin':
228229
return True
229230
try:
230231
result = subprocess.run(
231-
['nm', '-gU', libomp_path],
232+
['nm', '-g', libomp_path],
232233
stdout=subprocess.PIPE,
233234
stderr=subprocess.DEVNULL,
234235
text=True,
235236
check=False,
236237
)
237-
return symbol in result.stdout
238238
except Exception:
239239
return False
240+
if result.returncode != 0:
241+
return False
242+
text = result.stdout
243+
markers = (
244+
'___kmpc_dispatch_deinit',
245+
'___kmpc_barrier',
246+
'_omp_get_max_threads',
247+
'omp_get_max_threads',
248+
'__kmpc_',
249+
)
250+
return any(marker in text for marker in markers)
251+
252+
253+
def _libomp_prefix_is_usable(prefix, libomp_path):
254+
"""Validate libomp prefix; trust CI-built runtimes from SEQUENZO_LIBOMP_PREFIX."""
255+
ci_prefix = os.environ.get('SEQUENZO_LIBOMP_PREFIX', '').strip()
256+
if ci_prefix and os.path.abspath(prefix) == os.path.abspath(ci_prefix):
257+
return True
258+
return _libomp_exports_runtime_symbols(libomp_path)
240259

241260
def install_libomp_on_apple_silicon():
242261
"""..."""
@@ -493,7 +512,7 @@ def _find_libomp_runtime_library():
493512
unique_candidates.append(candidate)
494513

495514
for candidate in unique_candidates:
496-
if candidate.exists() and _lib_exports_symbol(candidate, "___kmpc_dispatch_deinit"):
515+
if candidate.exists() and _libomp_exports_runtime_symbols(str(candidate)):
497516
return str(candidate)
498517

499518
return None

0 commit comments

Comments
 (0)