From 655655ed1920eb03dc673c2b84b17de7e6a1be78 Mon Sep 17 00:00:00 2001 From: Samson <16504129+sagudev@users.noreply.github.com> Date: Wed, 6 Dec 2023 16:34:19 +0100 Subject: [PATCH] Fix ld64 detect (#436) --- .../etc/patches/0029-fix-ld64-detection.patch | 42 +++++++++++++++++++ .../build/moz.configure/toolchain.configure | 12 +++--- 2 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 mozjs-sys/etc/patches/0029-fix-ld64-detection.patch diff --git a/mozjs-sys/etc/patches/0029-fix-ld64-detection.patch b/mozjs-sys/etc/patches/0029-fix-ld64-detection.patch new file mode 100644 index 00000000000..6da0fcb9a68 --- /dev/null +++ b/mozjs-sys/etc/patches/0029-fix-ld64-detection.patch @@ -0,0 +1,42 @@ +diff --git a/build/moz.configure/toolchain.configure b/build/moz.configure/toolchain.configure +index 3f91d7153..abe78a50c 100755 +--- a/build/moz.configure/toolchain.configure ++++ b/build/moz.configure/toolchain.configure +@@ -1752,10 +1752,9 @@ def select_linker_tmpl(host_or_target): + die("Unsupported linker " + linker) + + # Check the kind of linker +- version_check = ["-Wl,--version"] + cmd_base = c_compiler.wrapper + [c_compiler.compiler] + c_compiler.flags + +- def try_linker(linker): ++ def try_linker(linker, version_check="-Wl,--version"): + # Generate the compiler flag + if linker == "ld64": + linker_flag = ["-fuse-ld=ld"] +@@ -1763,7 +1762,7 @@ def select_linker_tmpl(host_or_target): + linker_flag = ["-fuse-ld=" + linker] + else: + linker_flag = [] +- cmd = cmd_base + linker_flag + version_check ++ cmd = cmd_base + linker_flag + [version_check] + if toolchain_flags: + cmd += toolchain_flags + +@@ -1779,11 +1778,14 @@ def select_linker_tmpl(host_or_target): + # ensure consistent output. + env["LC_ALL"] = "C" + retcode, stdout, stderr = get_cmd_output(*cmd, env=env) +- if retcode == 1 and "Logging ld64 options" in stderr: ++ if retcode == 1 and ("Logging ld64 options" in stderr or "PROGRAM:ld PROJECT:dyld" in stderr): + kind = "ld64" + + elif retcode != 0: +- return None ++ if version_check == "-Wl,--version": ++ return try_linker(linker, "-Wl,-v") ++ else: ++ return None + + elif "mold" in stdout: + kind = "mold" diff --git a/mozjs-sys/mozjs/build/moz.configure/toolchain.configure b/mozjs-sys/mozjs/build/moz.configure/toolchain.configure index 3f91d715379..abe78a50ce7 100755 --- a/mozjs-sys/mozjs/build/moz.configure/toolchain.configure +++ b/mozjs-sys/mozjs/build/moz.configure/toolchain.configure @@ -1752,10 +1752,9 @@ def select_linker_tmpl(host_or_target): die("Unsupported linker " + linker) # Check the kind of linker - version_check = ["-Wl,--version"] cmd_base = c_compiler.wrapper + [c_compiler.compiler] + c_compiler.flags - def try_linker(linker): + def try_linker(linker, version_check="-Wl,--version"): # Generate the compiler flag if linker == "ld64": linker_flag = ["-fuse-ld=ld"] @@ -1763,7 +1762,7 @@ def select_linker_tmpl(host_or_target): linker_flag = ["-fuse-ld=" + linker] else: linker_flag = [] - cmd = cmd_base + linker_flag + version_check + cmd = cmd_base + linker_flag + [version_check] if toolchain_flags: cmd += toolchain_flags @@ -1779,11 +1778,14 @@ def select_linker_tmpl(host_or_target): # ensure consistent output. env["LC_ALL"] = "C" retcode, stdout, stderr = get_cmd_output(*cmd, env=env) - if retcode == 1 and "Logging ld64 options" in stderr: + if retcode == 1 and ("Logging ld64 options" in stderr or "PROGRAM:ld PROJECT:dyld" in stderr): kind = "ld64" elif retcode != 0: - return None + if version_check == "-Wl,--version": + return try_linker(linker, "-Wl,-v") + else: + return None elif "mold" in stdout: kind = "mold"