Skip to content

Commit

Permalink
Merge pull request #4739 from xmake-io/cross
Browse files Browse the repository at this point in the history
Add is_cross
  • Loading branch information
waruqi authored Feb 15, 2024
2 parents 197ec37 + da52cf4 commit 0abc694
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 21 deletions.
49 changes: 49 additions & 0 deletions xmake/core/base/private/is_cross.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--!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
--

-- load modules
local os = require("base/os")

-- is cross-compilation?
function is_cross(plat, arch)
if os.host() == "windows" then
local host_arch = os.arch()
if plat == "windows" then
-- maybe cross-compilation for arm64 on x86/x64
if (host_arch == "x86" or host_arch == "x64") and arch == "arm64" then
return true
-- maybe cross-compilation for x86/64 on arm64
elseif host_arch == "arm64" and arch ~= "arm64" then
return true
end
return false
elseif plat == "mingw" then
return false
end
end
if plat ~= os.host() and plat ~= os.subhost() then
return true
end
if arch ~= os.arch() and arch ~= os.subarch() then
return true
end
end

return is_cross
23 changes: 2 additions & 21 deletions xmake/core/package/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ local hashset = require("base/hashset")
local scopeinfo = require("base/scopeinfo")
local interpreter = require("base/interpreter")
local select_script = require("base/private/select_script")
local is_cross = require("base/private/is_cross")
local memcache = require("cache/memcache")
local toolchain = require("tool/toolchain")
local compiler = require("tool/compiler")
Expand Down Expand Up @@ -684,27 +685,7 @@ end

-- is cross-compilation?
function _instance:is_cross()
if os.host() == "windows" then
local host_arch = os.arch()
if self:is_plat("windows") then
-- maybe cross-compilation for arm64 on x86/x64
if (host_arch == "x86" or host_arch == "x64") and self:is_arch("arm64") then
return true
-- maybe cross-compilation for x86/64 on arm64
elseif host_arch == "arm64" and not self:is_arch("arm64") then
return true
end
return false
elseif self:is_plat("mingw") then
return false
end
end
if not self:is_plat(os.host()) and not self:is_plat(os.subhost()) then
return true
end
if not self:is_arch(os.arch()) and not self:is_arch(os.subarch()) then
return true
end
return is_cross(self:plat(), self:arch())
end

-- get the filelock of the whole package directory
Expand Down
6 changes: 6 additions & 0 deletions xmake/core/project/target.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ local hashset = require("base/hashset")
local deprecated = require("base/deprecated")
local select_script = require("base/private/select_script")
local instance_deps = require("base/private/instance_deps")
local is_cross = require("base/private/is_cross")
local memcache = require("cache/memcache")
local rule = require("project/rule")
local option = require("project/option")
Expand Down Expand Up @@ -1248,6 +1249,11 @@ function _instance:is_rebuilt()
return self:data("rebuilt")
end

-- is cross-compilation?
function _instance:is_cross()
return is_cross(self:plat(), self:arch())
end

-- get the enabled option
function _instance:opt(name, opt)
return self:opts(opt)[name]
Expand Down
23 changes: 23 additions & 0 deletions xmake/core/sandbox/modules/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 module
return require("base/private/is_cross")

0 comments on commit 0abc694

Please sign in to comment.