Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

icu4c: add support for cross-compilation #6505

Merged
merged 9 commits into from
Mar 5, 2025
88 changes: 61 additions & 27 deletions packages/i/icu4c/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package("icu4c")
add_urls("https://github.com/unicode-org/icu/releases/download/release-$(version)-src.tgz", {version = function (version)
return (version:gsub("%.", "-")) .. "/icu4c-" .. (version:gsub("%.", "_"))
end})
add_versions("76.1", "dfacb46bfe4747410472ce3e1144bf28a102feeaa4e3875bac9b4c6cf30f4f3e")
add_versions("75.1", "cb968df3e4d2e87e8b11c49a5d01c787bd13b9545280fc6642f826527618caef")
add_versions("73.2", "818a80712ed3caacd9b652305e01afc7fa167e6f2e94996da44b90c2ab604ce1")
add_versions("73.1", "a457431de164b4aa7eca00ed134d00dfbf88a77c6986a10ae7774fc076bb8c45")
Expand Down Expand Up @@ -40,6 +41,12 @@ package("icu4c")
end

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:config("tools") then
package:add("deps", "python 3.x", {kind = "binary"})
Expand All @@ -63,36 +70,48 @@ package("icu4c")
on_install("windows", function (package)
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 sln = path.join("source", "allinone", "allinone.sln")
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 = {
sln,
"/p:Configuration=Release",
"/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()
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
package:arch_set(arch_prev)
os.vcp(package:dep("icu4c"):installdir("bin/*"), "bin" .. host_suffix .. "/")
end

local configs = {
Expand All @@ -106,21 +125,24 @@ package("icu4c")
end
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("bin" .. suffix .. "/*", package:installdir("bin"))
os.vcp("lib" .. suffix .. "/*", package:installdir("lib"))
package:addenv("PATH", "bin")
end)

on_install("macosx", "linux", "mingw@msys", function (package)
on_install("@!windows and !wasm and !iphoneos", function (package)
import("package.tools.autoconf")

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"}
if package:debug() then
table.insert(configs, "--enable-debug")
Expand All @@ -136,7 +158,9 @@ package("icu4c")
if package:is_plat("mingw") then
table.insert(configs, "--with-data-packaging=dll")
end

if package:is_cross() then
table.insert(configs, "--with-cross-build=" .. path.unix(package:dep("icu4c"):installdir()))
end

local envs = {}
local cxxflags = "-std=gnu++17"
Expand All @@ -147,10 +171,20 @@ package("icu4c")
end
-- suppress ar errors when passing --toolchain=clang
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})
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)

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)
Loading