From 24f15fb7c24996b20f13d0163e8dd17706db18fa Mon Sep 17 00:00:00 2001 From: Saikari Date: Tue, 28 Apr 2026 07:00:58 +0300 Subject: fix: handle Windows cross-compilation prefix and installation path in Meson --- xmake/modules/package/tools/meson.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/xmake/modules/package/tools/meson.lua b/xmake/modules/package/tools/meson.lua index 598370997..5434ec7f6 100644 --- a/xmake/modules/package/tools/meson.lua +++ b/xmake/modules/package/tools/meson.lua @@ -329,9 +329,16 @@ end function _get_configs(package, configs, opt) -- add prefix + -- when cross-compiling on Windows to a Unix-like target (e.g. Android), Meson validates + -- the prefix as a Unix absolute path and rejects Windows paths like C:/... Use prefix=/ + -- and redirect installation via DESTDIR in the install step instead. configs = configs or {} opt._configs_str = string.serialize(configs, {indent = false, strip = true}) - table.insert(configs, "--prefix=" .. path.unix(opt.prefix or package:installdir())) + if is_host("windows") and package:is_cross() and not package:is_plat("windows", "mingw") then + table.insert(configs, "--prefix=/") + else + table.insert(configs, "--prefix=" .. path.unix(opt.prefix or package:installdir())) + end table.insert(configs, "--libdir=lib") -- set build type @@ -614,6 +621,14 @@ function install(package, configs, opt) local builddir = _get_builddir(package, opt) local argv = {"install", "-C", builddir} + -- when prefix=/ was used for cross-builds on Windows, redirect the install to the + -- actual package directory via DESTDIR so files land in the right place. + -- meson's destdir_join strips the leading / from prefix, giving DESTDIR/lib, DESTDIR/include, etc. + if is_host("windows") and package:is_cross() and not package:is_plat("windows", "mingw") then + table.insert(argv, "--destdir") + table.insert(argv, opt.prefix or package:installdir()) + end + -- do install local meson = assert(find_tool("meson"), "meson not found!") os.vrunv(meson.program, argv, {envs = opt.envs or buildenvs(package, opt)}) -- cgit v1.3.1