Skip to content

Commit fe1b200

Browse files
committed
darwin/macos: don't explicit-codesign bundled C extensions (keep linker-signed)
strip_framework() already strips every .so/.dylib, and on arm64 they keep the *linker-signed* adhoc signature install_name_tool/strip apply (CodeDirectory flags 0x20002). codesign_framework() was then re-signing the .so with `codesign -s -`, replacing that with an *explicit* adhoc signature (flags 0x2). An explicit adhoc signature is treated as final: a downstream Xcode app build refuses to strip it ("not stripping binary because it is signed", once per extension) and won't re-sign it. A linker-signed signature is replaceable, so the app build strips + re-signs the extension cleanly — exactly like a pip wheel's .so. Sign only the framework binary and the bundled OpenSSL dylibs; leave the lib-dynload .so stripped + linker-signed. They're extracted into the stdlib resource tree, so they aren't covered by the framework's own seal anyway. Result for any consuming app (SPM or CocoaPods): no per-extension strip warnings and a smaller app, since Xcode can finally strip + re-sign them.
1 parent 69fd887 commit fe1b200

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

darwin/build_macos.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,19 @@ def make_relocatable(framework: Path, short: str) -> None:
483483
def codesign_framework(framework: Path, short: str) -> None:
484484
args = ["codesign", "-s", "-", "--preserve-metadata=identifier,entitlements,flags,runtime", "-f"]
485485
run(args + [framework / "Versions" / short / "Python"])
486-
for pattern in ("*.dylib", "*.so"):
487-
for binary in framework.rglob(pattern):
488-
if binary.is_file():
489-
run(args + [binary])
486+
# Sign the framework binary and the bundled OpenSSL dylibs, but NOT the
487+
# C-extension .so. strip_framework() already left them stripped and
488+
# *linker-signed* (the replaceable adhoc signature install_name_tool/strip
489+
# apply on arm64). Re-signing with `codesign -s -` would replace that with an
490+
# *explicit* adhoc signature (CodeDirectory flags 0x2 instead of 0x20002),
491+
# which a downstream Xcode app build refuses to strip ("not stripping binary
492+
# because it is signed", once per extension) and won't re-sign. A
493+
# linker-signed extension is instead re-signed into the consuming app
494+
# cleanly, exactly like a pip wheel's .so. The .so are extracted to the
495+
# stdlib resource tree, so they aren't covered by the framework's own seal.
496+
for binary in framework.rglob("*.dylib"):
497+
if binary.is_file():
498+
run(args + [binary])
490499
run(args + [framework])
491500

492501

0 commit comments

Comments
 (0)