Support cross-language LTO on OSX (with upstream clang/lld)
[ldk-c-bindings] / deterministic-build-wrappers / clang-lto-link-osx
diff --git a/deterministic-build-wrappers/clang-lto-link-osx b/deterministic-build-wrappers/clang-lto-link-osx
new file mode 100755 (executable)
index 0000000..ae566d1
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh
+# We want to use rustc's -C linker-plugin-lto, but it passes several arguments
+# that are not understood by OSX clang/ld64.lld. Specifically, it passes
+# -plugin-opt* arguments to set optimization levels, which are not supported.
+# Thus, we intercept the call here, strip the unsupported arguments, and pass
+# -flto and -O3.
+args=("$@")
+for ((i=0; i<"${#args[@]}"; ++i)); do
+    case ${args[i]} in
+        -Wl,-plugin-opt*)
+                       args[i]=""
+                       ;;
+    esac
+done
+$LDK_CLANG_PATH -flto -O3 -Wl,-O3 "${args[@]}"