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

icu4c: add support for cross-compilation (#6505)

* icu4c: add support for cross-compilation

* Improve build host tool on windows

* icu4c: update to 76.1

* icu4c: exclude unsupported iOS target

* icu4c: fix macOS build issue due to unexpected behavior of `echo -n`

* Set cxx env for cross-compilation

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

---------

Co-authored-by: star9029 <[email protected]>
Doekin 6 сар өмнө
parent
commit
bb54400b27

+ 61 - 27
packages/i/icu4c/xmake.lua

@@ -5,6 +5,7 @@ package("icu4c")
     add_urls("https://github.com/unicode-org/icu/releases/download/release-$(version)-src.tgz", {version = function (version)
     add_urls("https://github.com/unicode-org/icu/releases/download/release-$(version)-src.tgz", {version = function (version)
             return (version:gsub("%.", "-")) .. "/icu4c-" .. (version:gsub("%.", "_"))
             return (version:gsub("%.", "-")) .. "/icu4c-" .. (version:gsub("%.", "_"))
         end})
         end})
+    add_versions("76.1", "dfacb46bfe4747410472ce3e1144bf28a102feeaa4e3875bac9b4c6cf30f4f3e")
     add_versions("75.1", "cb968df3e4d2e87e8b11c49a5d01c787bd13b9545280fc6642f826527618caef")
     add_versions("75.1", "cb968df3e4d2e87e8b11c49a5d01c787bd13b9545280fc6642f826527618caef")
     add_versions("73.2", "818a80712ed3caacd9b652305e01afc7fa167e6f2e94996da44b90c2ab604ce1")
     add_versions("73.2", "818a80712ed3caacd9b652305e01afc7fa167e6f2e94996da44b90c2ab604ce1")
     add_versions("73.1", "a457431de164b4aa7eca00ed134d00dfbf88a77c6986a10ae7774fc076bb8c45")
     add_versions("73.1", "a457431de164b4aa7eca00ed134d00dfbf88a77c6986a10ae7774fc076bb8c45")
@@ -40,6 +41,12 @@ package("icu4c")
     end
     end
 
 
     on_load(function (package)
     on_load(function (package)
+        if package:is_cross() then
+            package:add("deps", "icu4c~host", {kind = "binary", private = true})
+        else
+            package:addenv("PATH", "bin")
+        end
+
         if package:is_plat("windows") then
         if package:is_plat("windows") then
             if package:config("tools") then
             if package:config("tools") then
                 package:add("deps", "python 3.x", {kind = "binary"})
                 package:add("deps", "python 3.x", {kind = "binary"})
@@ -63,36 +70,48 @@ package("icu4c")
     on_install("windows", function (package)
     on_install("windows", function (package)
         import("package.tools.msbuild")
         import("package.tools.msbuild")
 
 
+        if package:has_runtime("MT", "MTd") then
+            local files = {
+                "source/common/common.vcxproj",
+                "source/i18n/i18n.vcxproj",
+                "source/extra/uconv/uconv.vcxproj",
+                "source/io/io.vcxproj",
+                "source/stubdata/stubdata.vcxproj",
+            }
+            for _, vcxproj in ipairs(files) do
+                io.replace(vcxproj, "MultiThreadedDLL", "MultiThreaded", {plain = true})
+                io.replace(vcxproj, "MultiThreadedDebugDLL", "MultiThreadedDebug", {plain = true})
+            end
+        end
+
         local projectfiles = os.files("source/**.vcxproj")
         local projectfiles = os.files("source/**.vcxproj")
         local sln = path.join("source", "allinone", "allinone.sln")
         local sln = path.join("source", "allinone", "allinone.sln")
         table.join2(projectfiles, sln, os.files("source/**.props"))
         table.join2(projectfiles, sln, os.files("source/**.props"))
 
 
-        if package:is_cross() then
-            -- icu build requires native tools
+        local suffix = package:is_arch("arm.*") and "ARM" or ""
+        if package:is_arch64() then
+            suffix = suffix .. "64"
+        end
+
+        if package:is_binary() then
             local configs = {
             local configs = {
                 sln,
                 sln,
                 "/p:Configuration=Release",
                 "/p:Configuration=Release",
                 "/target:pkgdata,genrb"
                 "/target:pkgdata,genrb"
             }
             }
 
 
+            msbuild.build(package, configs, {upgrade = projectfiles})
+            os.vcp("bin" .. suffix .. "/*", package:installdir("bin"))
+            return
+        elseif package:is_cross() then
             local arch_prev = package:arch()
             local arch_prev = package:arch()
             package:arch_set(os.arch())
             package:arch_set(os.arch())
-            msbuild.build(package, configs, {upgrade = projectfiles})
-            package:arch_set(arch_prev)
-        end
-
-        if package:has_runtime("MT", "MTd") then
-            local files = {
-                "source/common/common.vcxproj",
-                "source/i18n/i18n.vcxproj",
-                "source/extra/uconv/uconv.vcxproj",
-                "source/io/io.vcxproj",
-                "source/stubdata/stubdata.vcxproj",
-            }
-            for _, vcxproj in ipairs(files) do
-                io.replace(vcxproj, "MultiThreadedDLL", "MultiThreaded", {plain = true})
-                io.replace(vcxproj, "MultiThreadedDebugDLL", "MultiThreadedDebug", {plain = true})
+            local host_suffix = package:is_arch("arm.*") and "ARM" or ""
+            if package:is_arch64() then
+                host_suffix = host_suffix .. "64"
             end
             end
+            package:arch_set(arch_prev)
+            os.vcp(package:dep("icu4c"):installdir("bin/*"), "bin" .. host_suffix .. "/")
         end
         end
 
 
         local configs = {
         local configs = {
@@ -106,21 +125,24 @@ package("icu4c")
         end
         end
         msbuild.build(package, configs, {upgrade = projectfiles})
         msbuild.build(package, configs, {upgrade = projectfiles})
 
 
-        local suffix = package:is_arch("arm.*") and "ARM" or ""
-        if package:is_arch(".*64") then
-            suffix = suffix .. "64"
-        end
-
         os.vcp("include", package:installdir())
         os.vcp("include", package:installdir())
         os.vcp("bin" .. suffix .. "/*", package:installdir("bin"))
         os.vcp("bin" .. suffix .. "/*", package:installdir("bin"))
         os.vcp("lib" .. suffix .. "/*", package:installdir("lib"))
         os.vcp("lib" .. suffix .. "/*", package:installdir("lib"))
-        package:addenv("PATH", "bin")
     end)
     end)
 
 
-    on_install("macosx", "linux", "mingw@msys", function (package)
+    on_install("@!windows and !wasm and !iphoneos", function (package)
         import("package.tools.autoconf")
         import("package.tools.autoconf")
 
 
         os.cd("source")
         os.cd("source")
+        if is_host("macosx") then
+            -- On Mac OS X, the echo command does not support the -n option
+            -- @see https://unicode-org.atlassian.net/browse/ICU-22418
+            local mkfiles = {"Makefile.in"}
+            table.join2(mkfiles, os.files("config/mh-*"))
+            for _, mkfile in ipairs(mkfiles) do
+                io.replace(mkfile, "@echo%s+-n%s+\"", "@printf \"") -- replace @echo -n with @printf
+            end
+        end
         local configs = {"--disable-samples", "--disable-tests"}
         local configs = {"--disable-samples", "--disable-tests"}
         if package:debug() then
         if package:debug() then
             table.insert(configs, "--enable-debug")
             table.insert(configs, "--enable-debug")
@@ -136,7 +158,9 @@ package("icu4c")
         if package:is_plat("mingw") then
         if package:is_plat("mingw") then
             table.insert(configs, "--with-data-packaging=dll")
             table.insert(configs, "--with-data-packaging=dll")
         end
         end
-
+        if package:is_cross() then
+            table.insert(configs, "--with-cross-build=" .. path.unix(package:dep("icu4c"):installdir()))
+        end
 
 
         local envs = {}
         local envs = {}
         local cxxflags = "-std=gnu++17"
         local cxxflags = "-std=gnu++17"
@@ -147,10 +171,20 @@ package("icu4c")
         end
         end
         -- suppress ar errors when passing --toolchain=clang
         -- suppress ar errors when passing --toolchain=clang
         envs.ARFLAGS = nil
         envs.ARFLAGS = nil
+        if package:is_cross() and not envs.CXX then
+            envs.CXX = path.unix(package:build_getenv("cxx"))
+        end
         autoconf.install(package, configs, {envs = envs})
         autoconf.install(package, configs, {envs = envs})
-        package:addenv("PATH", "bin")
+
+        if not package:is_cross() then
+            os.trycp("config/icucross.mk", package:installdir("config"))
+            os.trycp("config/icucross.inc", package:installdir("config"))
+            os.trycp("bin/icupkg*", package:installdir("bin"))
+        end
     end)
     end)
 
 
     on_test(function (package)
     on_test(function (package)
-        assert(package:has_cfuncs("ucnv_convert", {includes = "unicode/ucnv.h"}))
+        if package:is_library() then
+            assert(package:has_cfuncs("ucnv_convert", {includes = "unicode/ucnv.h"}))
+        end
     end)
     end)