Browse Source

leveldb: fix build under clang-cl. (#6118)

RedbeanW 8 months ago
parent
commit
89519365b0

+ 25 - 0
packages/l/leveldb/patches/disable-crt-secure-warnings.patch

@@ -0,0 +1,25 @@
+From 76e16e35a47a76e3eab00e55867abd203be8ffbf Mon Sep 17 00:00:00 2001
+From: Redbeanw44602 <[email protected]>
+Date: Thu, 2 Jan 2025 22:25:44 +0800
+Subject: [PATCH] disable crt secure warnings.
+
+---
+ util/env_windows.cc | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/util/env_windows.cc b/util/env_windows.cc
+index 1c74b02..76eb58a 100644
+--- a/util/env_windows.cc
++++ b/util/env_windows.cc
+@@ -4,6 +4,8 @@
+ 
+ // Prevent Windows headers from defining min/max macros and instead
+ // use STL.
++#define _CRT_SECURE_NO_WARNINGS
++
+ #ifndef NOMINMAX
+ #define NOMINMAX
+ #endif  // ifndef NOMINMAX
+-- 
+2.47.1
+

+ 27 - 0
packages/l/leveldb/patches/fix-build-under-clang-msabi.patch

@@ -0,0 +1,27 @@
+From 0f049b61b6f611ed6d3b8c44b4f1232290936aa3 Mon Sep 17 00:00:00 2001
+From: Redbeanw44602 <[email protected]>
+Date: Thu, 2 Jan 2025 22:03:20 +0800
+Subject: [PATCH] fix build under clang/msabi.
+
+---
+ db/c.cc | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git a/db/c.cc b/db/c.cc
+index 8bdde38..8c6418a 100644
+--- a/db/c.cc
++++ b/db/c.cc
+@@ -19,6 +19,10 @@
+ #include "leveldb/status.h"
+ #include "leveldb/write_batch.h"
+ 
++#if defined(_MSC_VER)
++#define strdup _strdup
++#endif
++
+ using leveldb::Cache;
+ using leveldb::Comparator;
+ using leveldb::CompressionType;
+-- 
+2.47.1
+

+ 4 - 1
packages/l/leveldb/xmake.lua

@@ -9,6 +9,9 @@ package("leveldb")
     add_versions("1.22", "55423cac9e3306f4a9502c738a001e4a339d1a38ffbee7572d4a07d5d63949b2")
     add_versions("1.23", "9a37f8a6174f09bd622bc723b55881dc541cd50747cbd08831c2a82d620f6d76")
 
+    add_patches("*", path.join(os.scriptdir(), "patches", "fix-build-under-clang-msabi.patch"), "e90d3ac992e6b00aed529da53c37bca9a0fe77cd223ca0857848ccd66239f24a")
+    add_patches("*", path.join(os.scriptdir(), "patches", "disable-crt-secure-warnings.patch"), "fbc769c1e0472aeeb2b6e8fddf21c84980142f0ab3896d0369e974bca982a2f9")
+
     add_deps("cmake")
     add_deps("snappy")
     if is_plat("linux") then
@@ -30,5 +33,5 @@ package("leveldb")
                 options.create_if_missing = true;
                 leveldb::Status status = leveldb::DB::Open(options, "./test", &db);
             }
-        ]]}, {configs = {languages = "c++11"}, includes = "leveldb/db.h"}))
+        ]]}, {configs = {languages = package:is_plat("windows") and "c++14" or "c++11"}, includes = "leveldb/db.h"}))
     end)