Skip to content

Commit

Permalink
improve to fetch package for cross-compilation #4935
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Apr 10, 2024
1 parent 6bf4a28 commit dec2cf1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
5 changes: 3 additions & 2 deletions xmake/core/package/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions xmake/core/sandbox/modules/import/private/core/base/is_cross.lua
Original file line number Diff line number Diff line change
@@ -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")


27 changes: 7 additions & 20 deletions xmake/modules/package/manager/find_package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dec2cf1

Please sign in to comment.