From abe43a02c59cc9bd9b296b24de7b30b01aa1f856 Mon Sep 17 00:00:00 2001
From: q66 <daniel@octaforge.org>
Date: Sun, 3 May 2020 17:55:50 +0200
Subject: [PATCH 04/10] Prefer libgcc_eh over libunwind on musl

Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
---
 library/unwind/build.rs   | 13 ++-----------
 library/unwind/src/lib.rs |  2 +-
 2 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/library/unwind/build.rs b/library/unwind/build.rs
index 24bcd40c3a8e..3196435865df 100644
--- a/library/unwind/build.rs
+++ b/library/unwind/build.rs
@@ -5,7 +5,7 @@ fn main() {
     let target = env::var("TARGET").expect("TARGET was not set");
 
     if cfg!(feature = "llvm-libunwind")
-        && ((target.contains("linux") && !target.contains("musl")) || target.contains("fuchsia"))
+        && (target.contains("linux") || target.contains("fuchsia"))
     {
         // Build the unwinding from libunwind C/C++ source code.
         llvm_libunwind::compile();
@@ -14,7 +14,7 @@ fn main() {
     } else if target.contains("linux") {
         // linking for Linux is handled in lib.rs
         if target.contains("musl") {
-            llvm_libunwind::compile();
+            println!("cargo:rustc-link-lib=gcc_s");
         }
     } else if target.contains("freebsd") {
         println!("cargo:rustc-link-lib=gcc_s");
@@ -143,15 +143,6 @@ mod llvm_libunwind {
             cfg.file(root.join("src").join(src));
         }
 
-        if target_env == "musl" {
-            // use the same C compiler command to compile C++ code so we do not need to setup the
-            // C++ compiler env variables on the builders
-            cfg.cpp(false);
-            // linking for musl is handled in lib.rs
-            cfg.cargo_metadata(false);
-            println!("cargo:rustc-link-search=native={}", env::var("OUT_DIR").unwrap());
-        }
-
         cfg.compile("unwind");
     }
 }
diff --git a/library/unwind/src/lib.rs b/library/unwind/src/lib.rs
index dbdefa471a9e..cb83404cbd8b 100644
--- a/library/unwind/src/lib.rs
+++ b/library/unwind/src/lib.rs
@@ -38,7 +38,7 @@ cfg_if::cfg_if! {
 }
 
 #[cfg(target_env = "musl")]
-#[link(name = "unwind", kind = "static", cfg(target_feature = "crt-static"))]
+#[link(name = "gcc_eh", cfg(target_feature = "crt-static"))]
 #[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))]
 extern "C" {}
 
-- 
2.30.0

