Skip to content

Commit 55a90f0

Browse files
committed
Fix strip/ranlib detection for Android cross builds
Always default strip/ranlib to the host tools, then derive Android-specific llvm-strip/llvm-ranlib based on the detected NDK toolchain location. Moves detection after potential ndk_bin/AR adjustments, falling back to llvm-strip/llvm-ranlib next to the final AR when present, and ensures non-Android SDKs keep the host "strip"/"ranlib". This improves reliability of selecting the correct strip/ranlib for cross compiles with varying NDK layouts.
1 parent 57f0114 commit 55a90f0

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

src/forge/build.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -265,16 +265,8 @@ def compile_env(self, **kwargs) -> dict[str, str]:
265265
ar = sysconfig_data["AR"]
266266
cc = sysconfig_data["CC"]
267267
cxx = sysconfig_data["CXX"]
268-
strip = (
269-
str(Path(ar).parent.joinpath("llvm-strip"))
270-
if ar and self.cross_venv.sdk == "android"
271-
else "strip"
272-
)
273-
ranlib = (
274-
str(Path(ar).parent.joinpath("llvm-ranlib"))
275-
if ar and self.cross_venv.sdk == "android"
276-
else "ranlib"
277-
)
268+
strip = "strip"
269+
ranlib = "ranlib"
278270
cflags = self.cross_venv.sysconfig_data["CFLAGS"]
279271
cppflags = self.cross_venv.sysconfig_data["CPPFLAGS"]
280272
ndk_sysroot = None
@@ -315,9 +307,26 @@ def compile_env(self, **kwargs) -> dict[str, str]:
315307
cxx = str(ndk_bin / Path(cxx).name)
316308
if not Path(ar).is_file():
317309
ar = str(ndk_bin / Path(ar).name)
310+
if not Path(strip).is_file():
311+
strip = str(ndk_bin / "llvm-strip")
312+
if not Path(ranlib).is_file():
313+
ranlib = str(ndk_bin / "llvm-ranlib")
314+
315+
# Derive strip/ranlib from the final AR location when available.
316+
if ar:
317+
ar_parent = Path(ar).parent
318+
derived_strip = ar_parent / "llvm-strip"
319+
derived_ranlib = ar_parent / "llvm-ranlib"
320+
if derived_strip.is_file():
321+
strip = str(derived_strip)
322+
if derived_ranlib.is_file():
323+
ranlib = str(derived_ranlib)
318324
ndk_sysroot = Path(cc).parent.parent / "sysroot"
319325
if (ndk_sysroot / "usr" / "include").is_dir():
320326
cflags += f" -I{ndk_sysroot}/usr/include"
327+
if self.cross_venv.sdk != "android":
328+
strip = "strip"
329+
ranlib = "ranlib"
321330

322331
ldflags = self.cross_venv.sysconfig_data["LDFLAGS"]
323332

0 commit comments

Comments
 (0)