From d842877c7c2f458ba26a900ea83e5557f4af7a2d Mon Sep 17 00:00:00 2001
From: Yaroslav Dynnikov <yaroslav.dynnikov@gmail.com>
Date: Tue, 31 Jan 2023 18:39:21 +0300
Subject: [PATCH] build: fix libcrypto naming conflict

---
 build.rs | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/build.rs b/build.rs
index d4f73633bc..8469e584d7 100644
--- a/build.rs
+++ b/build.rs
@@ -193,13 +193,22 @@ fn build_tarantool(build_root: &Path) {
     rustc::link_search(format!("{b}/{tarantool_prefix}/build/ares/dest/lib"));
     rustc::link_lib_static("cares");
 
+    // `openssl-prefix/lib/libcrypto.a` conflicts with
+    // `src/lib/crypto/libcrypto.a` by name when passed as `-lcrypto` link
+    // argument. So we rename one of the libraries, which seems to solve the
+    // problem.
+    let openssl_dir = build_dir.join("openssl-prefix/lib");
+    let old_lib = openssl_dir.join("libcrypto.a");
+    let new_lib = openssl_dir.join("libcrypto-ssl.a");
+
+    if old_lib.exists() {
+        std::fs::remove_file(&new_lib).ok();
+        std::fs::rename(old_lib, new_lib).unwrap();
+    }
+
     rustc::link_search(format!("{b}/openssl-prefix/lib"));
     rustc::link_lib_static("ssl");
-
-    // This one must be linked as a positional argument, because -lcrypto
-    // conflicts with `src/lib/crypto/libcrypto.a`
-    // duplicate symbols which is not allowed (by default) when linking with via
-    rustc::link_arg(format!("{b}/openssl-prefix/lib/libcrypto.a"));
+    rustc::link_lib_static("crypto-ssl");
 
     rustc::link_search(format!("{b}/ncurses-prefix/lib"));
     rustc::link_lib_static("tinfo");
-- 
GitLab