summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-02-15 18:09:26 +0800
committerGitHub <[email protected]>2024-02-15 18:09:26 +0800
commit0abc694eb2fd8efeb0150482e10c9d903c26de67 (patch)
treeb0730b84bb88e0613719fe1d0d02340a47fbbd14
parent197ec373651d6672f7a11e9a07a01fb7dacdb8fa (diff)
parentda52cf4aa1bbc67b0812c4d4e902e79143391dee (diff)
Merge pull request #4739 from xmake-io/cross
Add is_cross
-rw-r--r--xmake/core/base/private/is_cross.lua49
-rw-r--r--xmake/core/package/package.lua23
-rw-r--r--xmake/core/project/target.lua6
-rw-r--r--xmake/core/sandbox/modules/is_cross.lua23
4 files changed, 80 insertions, 21 deletions
diff --git a/xmake/core/base/private/is_cross.lua b/xmake/core/base/private/is_cross.lua
new file mode 100644
index 000000000..7c02aa18c
--- /dev/null
+++ b/xmake/core/base/private/is_cross.lua
@@ -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
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index a3985a5e9..eef05d80e 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -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")
@@ -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
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 39d43bec9..e6fb98a7b 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -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")
@@ -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]
diff --git a/xmake/core/sandbox/modules/is_cross.lua b/xmake/core/sandbox/modules/is_cross.lua
new file mode 100644
index 000000000..09b4e0ed4
--- /dev/null
+++ b/xmake/core/sandbox/modules/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 module
+return require("base/private/is_cross")
+