summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-04-11 00:53:07 +0800
committerruki <[email protected]>2024-04-11 00:53:07 +0800
commitdec2cf143065520452917393ecf28d7479f026c4 (patch)
treec4684bcaca8e454558c2d4d9e9459286edb12e06
parent6bf4a28541f4a785db59fdd7bc62c3b2ede4017f (diff)
improve to fetch package for cross-compilation #4935
-rw-r--r--xmake/core/package/package.lua5
-rw-r--r--xmake/core/sandbox/modules/import/private/core/base/is_cross.lua23
-rw-r--r--xmake/modules/package/manager/find_package.lua27
3 files changed, 33 insertions, 22 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 292f774c5..5d80c5e38 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -1729,8 +1729,9 @@ end
function _instance:_fetch_library(opt)
opt = opt or {}
local fetchinfo
+ local is_cross = self:is_cross()
local on_fetch = self:script("fetch")
- if on_fetch then
+ if on_fetch and not is_cross() then
fetchinfo = on_fetch(self, {force = opt.force,
system = opt.system,
external = opt.external,
@@ -1947,7 +1948,7 @@ function _instance:fetch(opt)
end
end
- -- fetch it from the system and external package sources (disabled for cross-compilation)
+ -- fetch it from the system and external package sources
if not fetchinfo and system ~= false then
fetchinfo = self:_fetch_library({system = true, require_version = require_ver, external = external, force = opt.force})
if fetchinfo then
diff --git a/xmake/core/sandbox/modules/import/private/core/base/is_cross.lua b/xmake/core/sandbox/modules/import/private/core/base/is_cross.lua
new file mode 100644
index 000000000..08ed715c9
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/private/core/base/is_cross.lua
@@ -0,0 +1,23 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file is_cross.lua
+--
+
+return require("base/private/is_cross")
+
+
diff --git a/xmake/modules/package/manager/find_package.lua b/xmake/modules/package/manager/find_package.lua
index 82f029c34..022e92511 100644
--- a/xmake/modules/package/manager/find_package.lua
+++ b/xmake/modules/package/manager/find_package.lua
@@ -23,6 +23,7 @@ import("core.base.semver")
import("core.base.option")
import("core.project.config")
import("lib.detect.find_tool")
+import("private.core.base.is_cross")
-- Is the current version matched?
function _is_match_version(current_version, require_version)
@@ -53,37 +54,23 @@ function _find_package_with_builtin_rule(package_name, opt)
-- find system package if be not disabled
if opt.system ~= false then
-
- -- find it from homebrew
- if not is_host("windows") then
+ local plat = opt.plat
+ local arch = opt.arch
+ local find_from_host = not is_cross(plat, arch)
+ if find_from_host and not is_host("windows") then
table.insert(managers, "brew")
end
-
- -- find it from vcpkg (support multi-platforms/architectures)
+ -- vcpkg/conan support multi-platforms/architectures
table.insert(managers, "vcpkg")
-
- -- find it from conan (support multi-platforms/architectures)
table.insert(managers, "conan")
-
- -- only support the current sub-host platform and sub-architecture, e.g. linux, macosx, or msys (subsystem)
- local plat = opt.plat
- local arch = opt.arch
- if plat == os.subhost() and arch == os.subarch() then
-
- -- find it from pkg-config
+ if find_from_host then
table.insert(managers, "pkgconfig")
-
- -- find it from pacman
if is_subhost("linux", "msys") and plat ~= "windows" and find_tool("pacman") then
table.insert(managers, "pacman")
end
-
- -- find it from portage
if is_subhost("linux", "msys") and plat ~= "windows" and find_tool("emerge") then
table.insert(managers, "portage")
end
-
- -- find it from system
table.insert(managers, "system")
end
end