2
0
Эх сурвалжийг харах

libcurl: Use CMake to compile on Android (#3644)

* libcurl: Use CMake to compile on Android

Fixes Android on Windows

* Update xmake.lua

* Update android.yml

* Update xmake.lua

* Update xmake.lua

* Remove logs

* Update libcurl to 8.7.1 and fix android armv7 compilation
Jérôme Leclercq 1 жил өмнө
parent
commit
d3c13992f5

+ 38 - 0
packages/l/libcurl/patches/8.7.1/android_armv7.patch

@@ -0,0 +1,38 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 656aa7c74..4897369fa 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -1228,7 +1228,6 @@ check_symbol_exists(getifaddrs     "${CURL_INCLUDES};stdlib.h" HAVE_GETIFADDRS)
+ check_symbol_exists(freeaddrinfo   "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
+ check_symbol_exists(pipe           "${CURL_INCLUDES}" HAVE_PIPE)
+ check_symbol_exists(ftruncate      "${CURL_INCLUDES}" HAVE_FTRUNCATE)
+-check_symbol_exists(fseeko         "${CURL_INCLUDES};stdio.h" HAVE_FSEEKO)
+ check_symbol_exists(_fseeki64      "${CURL_INCLUDES};stdio.h" HAVE__FSEEKI64)
+ check_symbol_exists(getpeername    "${CURL_INCLUDES}" HAVE_GETPEERNAME)
+ check_symbol_exists(getsockname    "${CURL_INCLUDES}" HAVE_GETSOCKNAME)
+@@ -1238,10 +1237,6 @@ check_symbol_exists(setlocale      "${CURL_INCLUDES}" HAVE_SETLOCALE)
+ check_symbol_exists(setmode        "${CURL_INCLUDES}" HAVE_SETMODE)
+ check_symbol_exists(setrlimit      "${CURL_INCLUDES}" HAVE_SETRLIMIT)
+ 
+-if(HAVE_FSEEKO)
+-  set(HAVE_DECL_FSEEKO 1)
+-endif()
+-
+ if(NOT MSVC OR (MSVC_VERSION GREATER_EQUAL 1900))
+   # earlier MSVC compilers had faulty snprintf implementations
+   check_symbol_exists(snprintf       "stdio.h" HAVE_SNPRINTF)
+@@ -1304,6 +1299,14 @@ if(HAVE_FILE_OFFSET_BITS)
+ endif()
+ check_type_size("off_t"  SIZEOF_OFF_T)
+ 
++# fseeko may not exist with _FILE_OFFSET_BITS=64 but can exist with _FILE_OFFSET_BITS unset or 32 (e.g. Android ARMv7 with NDK 26b and API level < 24)
++# so we need to test fseeko after testing for _FILE_OFFSEt_BITS
++check_symbol_exists(fseeko         "${CURL_INCLUDES};stdio.h" HAVE_FSEEKO)
++
++if(HAVE_FSEEKO)
++  set(HAVE_DECL_FSEEKO 1)
++endif()
++
+ # include this header to get the type
+ set(CMAKE_REQUIRED_INCLUDES "${CURL_SOURCE_DIR}/include")
+ set(CMAKE_EXTRA_INCLUDE_FILES "curl/system.h")

+ 1 - 2
packages/l/libcurl/versions.lua

@@ -1,4 +1,5 @@
 function add_versions_list()
+    add_versions("8.7.1", "05bbd2b698e9cfbab477c33aa5e99b4975501835a41b7ca6ca71de03d8849e76")
     add_versions("8.5.0", "ce4b6a6655431147624aaf582632a36fe1ade262d5fab385c60f78942dd8d87b")
     add_versions("8.4.0", "e5250581a9c032b1b6ed3cf2f9c114c811fc41881069e9892d115cc73f9e88c6")
     add_versions("8.0.1", "9b6b1e96b748d04b968786b6bdf407aa5c75ab53a3d37c1c8c81cdb736555ccf")
@@ -59,6 +60,4 @@ function add_versions_list()
     add_versions("7.33.0", "0afde4cd949e2658eddc3cda675b19b165eea1af48ac5f3e1ec160792255d1b3")
     add_versions("7.32.0", "8e3db42548e01407cb2f1407660c0f528b89ec7afda6264442fc2b229b95223b")
     add_versions("7.31.0", "a73b118eececff5de25111f35d1d0aafe1e71afdbb83082a8e44d847267e3e08")
-
-    add_patches("7.84.0", path.join(os.scriptdir(), "patches", "7.84.0", "sched.patch"), "e79f56f840cbc6996a153f19d9266bd46fe4154e6b494c8ee0478cb5b87662d3")
 end

+ 1 - 0
packages/l/libcurl/versions.txt

@@ -1,3 +1,4 @@
+8.7.1 05bbd2b698e9cfbab477c33aa5e99b4975501835a41b7ca6ca71de03d8849e76
 8.6.0 b4785f2d8877fa92c0e45d7155cf8cc6750dbda961f4b1a45bcbec990cf2fa9b
 8.5.0 ce4b6a6655431147624aaf582632a36fe1ade262d5fab385c60f78942dd8d87b
 8.4.0 e5250581a9c032b1b6ed3cf2f9c114c811fc41881069e9892d115cc73f9e88c6

+ 41 - 38
packages/l/libcurl/xmake.lua

@@ -15,6 +15,9 @@ package("libcurl")
         add_versions_list()
     end
 
+    add_patches("7.84.0", path.join(os.scriptdir(), "patches", "7.84.0", "sched.patch"), "e79f56f840cbc6996a153f19d9266bd46fe4154e6b494c8ee0478cb5b87662d3")
+    add_patches("8.7.1", path.join(os.scriptdir(), "patches", "8.7.1", "android_armv7.patch"), "b172fd25063fcf4bce987b47a3d95d9d79bcf80f45e7e45dbf4aba72c685fb24")
+
     add_deps("cmake")
 
     if is_plat("macosx", "iphoneos") then
@@ -74,7 +77,7 @@ package("libcurl")
         end
     end)
 
-    on_install("windows", "mingw", "linux", "macosx", "iphoneos", "cross", function (package)
+    on_install("windows", "mingw", "linux", "macosx", "iphoneos", "cross", "android", function (package)
         local version = package:version()
 
         local configs = {"-DBUILD_TESTING=OFF", "-DENABLE_MANUAL=OFF"}
@@ -117,45 +120,45 @@ package("libcurl")
             io.replace("CMakeLists.txt", "list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto)", "list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto dl)", {plain = true})
             io.replace("CMakeLists.txt", "list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})", "list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES} dl)", {plain = true})
         end
-        import("package.tools.cmake").install(package, configs, opt)
-    end)
-
-    on_install("android", function (package)
-        local configs = {"--disable-silent-rules",
-                         "--disable-dependency-tracking",
-                         "--without-hyper",
-                         "--without-libgsasl",
-                         "--without-librtmp",
-                         "--without-quiche",
-                         "--without-ngtcp2",
-                         "--without-nghttp3"}
-
-        local version = package:version()
-        if (package:is_plat("mingw") and version:ge("7.85")) then
-            package:add("syslinks", "Bcrypt")
-        end
-
-        table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
-        table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes"))
-        if package:debug() then
-            table.insert(configs, "--enable-debug")
-        end
-        if package:is_plat("macosx", "iphoneos") then
-            table.insert(configs, (package:version():ge("7.77") and "--with-secure-transport" or "--with-darwinssl"))
-        end
-        for _, name in ipairs({"openssl", "mbedtls", "zlib", "brotli", "zstd", "libssh2", "libidn2", "libpsl", "nghttp2"}) do
-            table.insert(configs, package:config(name) and "--with-" .. name or "--without-" .. name)
-        end
-        table.insert(configs, package:config("cares") and "--enable-ares" or "--disable-ares")
-        table.insert(configs, package:config("openldap") and "--enable-ldap" or "--disable-ldap")
-        if package:is_plat("macosx") then
-            local cares = package:dep("c-ares")
-            if cares and not cares:config("shared") then
-                -- we need fix missing `-lresolv` when checking c-ares
-                io.replace("./configure", "PKGCONFIG --libs-only-l libcares", "PKGCONFIG --libs-only-l --static libcares", {plain = true})
+        local function handledependency(conf, depname, includeconfig, libconfig)
+            if package:config(conf) then
+                local dep = package:dep(depname)
+                if dep and not dep:is_system() then
+                    local fetchinfo = dep:fetch({external = false})
+                    if fetchinfo then
+                        local includedirs = fetchinfo.includedirs or fetchinfo.sysincludedirs
+                        if includedirs and #includedirs > 0 then
+                            table.insert(configs, "-D" .. includeconfig .. "=" .. table.concat(includedirs, ";"):gsub("\\", "/"))
+                        end
+                        if type(libconfig) == "table" then
+                            if fetchinfo.libfiles then
+                                for _, libfile in ipairs(fetchinfo.libfiles) do
+                                    local libname = path.basename(libfile)
+                                    if libname:startswith("lib") then
+                                        libname = libname:sub(4)
+                                    end
+                                    for opt, suffix in pairs(libconfig) do
+                                        if libname:endswith(suffix) then
+                                            table.insert(configs, "-D" .. opt .. "=" .. libfile:gsub("\\", "/"))
+                                        end
+                                    end
+                                end
+                            end
+                        else
+                            if fetchinfo.libfiles then
+                                table.insert(configs, "-D" .. libconfig .. "=" .. table.concat(fetchinfo.libfiles, ";"):gsub("\\", "/"))
+                            end
+                        end
+                    end
+                end
             end
         end
-        import("package.tools.autoconf").install(package, configs)
+        handledependency("brotli", "brotli", "BROTLI_INCLUDE_DIR", {BROTLICOMMON_LIBRARY = "brotlicommon", BROTLIDEC_LIBRARY = "brotlidec"})
+        handledependency("openssl", "openssl", "OPENSSL_INCLUDE_DIR", {OPENSSL_CRYPTO_LIBRARY = "crypto", OPENSSL_SSL_LIBRARY = "ssl"})
+        handledependency("mbedtls", "mbedtls", "MBEDTLS_INCLUDE_DIRS", {MBEDTLS_LIBRARY = "mbedtls", MBEDX509_LIBRARY = "mbedx509", MBEDCRYPTO_LIBRARY = "mbedcrypto"})
+        handledependency("zlib", "zlib", "ZLIB_INCLUDE_DIR", "ZLIB_LIBRARY")
+        handledependency("zstd", "zstd", "Zstd_INCLUDE_DIR", "Zstd_LIBRARY")
+        import("package.tools.cmake").install(package, configs, opt)
     end)
 
     on_test(function (package)