Skip to content

Commit e3a2593

Browse files
committed
Get linker to remove debug symbols
Before we used strip which removed everything. Removing only debug symbols will allow backtraces to work. See pypa/cibuildwheel#331 for lots of discussion
1 parent 87be7da commit e3a2593

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

tools/vend.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -526,15 +526,6 @@ def do_build(what: set[str], verbose: bool, fail_fast: bool = False):
526526
shutil.rmtree(output_dir, ignore_errors=True)
527527
compiler.mkpath(str(output_dir))
528528

529-
def strip_and_copy(src: str, dest: str):
530-
# windows doesn't have strip
531-
if compiler.compiler_type != "msvc":
532-
# macos strip messes up code signing and doesn't save any space
533-
if sys.platform != "darwin":
534-
# we don't care if this fails
535-
subprocess.run(["strip", src], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
536-
shutil.copy2(src, dest)
537-
538529
print("Checking if compiler works")
539530
compile_check_name = get_compile_check(build_dir)
540531
try:
@@ -551,6 +542,14 @@ def strip_and_copy(src: str, dest: str):
551542
print(f" Failed to compile hello world because {exc}")
552543
return
553544

545+
# we want the linker to strip debug rather than trying to do so at
546+
# copy time which caused various problems
547+
if ci.name in ("gcc", "clang"):
548+
if sys.platform == "darwin":
549+
link_extra_preargs = ["-Wl,-S"]
550+
else:
551+
link_extra_preargs = ["-Wl,--strip-debug"]
552+
554553
# figure out if compile and link pre args work, and remove them if not
555554
new_objs = objs
556555
if compile_extra_preargs:
@@ -645,7 +644,7 @@ def strip_and_copy(src: str, dest: str):
645644
new_name = str(pathlib.Path(sqlite_lib_filename).with_suffix(".dylib"))
646645
os.rename(sqlite_lib_filename, new_name)
647646
sqlite_lib_filename = new_name
648-
strip_and_copy(sqlite_lib_filename, str(output_dir))
647+
shutil.copy2(sqlite_lib_filename, str(output_dir))
649648

650649
except Exception as exc:
651650
print(f"Compiling SQLite failed {exc_type(exc)} - giving up")
@@ -826,7 +825,7 @@ def strip_and_copy(src: str, dest: str):
826825
except FileNotFoundError:
827826
pass
828827

829-
strip_and_copy(str(build_dir / out_name), str(output_dir / out_name))
828+
shutil.copy2(str(build_dir / out_name), str(output_dir / out_name))
830829

831830
logging.info("")
832831

0 commit comments

Comments
 (0)