summaryrefslogtreecommitdiff
path: root/xmake
diff options
context:
space:
mode:
authorSaikari <[email protected]>2026-01-29 04:19:55 +0300
committerGitHub <[email protected]>2026-01-29 04:19:55 +0300
commit3ab13106137658925e66cd387739276f8cfd9d8e (patch)
tree2b81243f04a35fb355c6df391bcf0d11e1a41849 /xmake
parentc94c14fb23d09af85672f2e7dd1081b4976822c5 (diff)
parent45f856e3ccdec7da98ac7f07251f30d85640d268 (diff)
Merge branch 'xmake-io:dev' into nimlib
Diffstat (limited to 'xmake')
-rw-r--r--xmake/core/base/tty.lua64
-rw-r--r--xmake/toolchains/zig/xmake.lua63
2 files changed, 98 insertions, 29 deletions
diff --git a/xmake/core/base/tty.lua b/xmake/core/base/tty.lua
index dd053b3e6..b3ac35b2b 100644
--- a/xmake/core/base/tty.lua
+++ b/xmake/core/base/tty.lua
@@ -23,6 +23,7 @@ local tty = tty or {}
-- load modules
local io = require("base/io")
+local path = require("base/path")
-- save metatable and builtin functions
tty._term_mode = tty._term_mode or tty.term_mode
@@ -234,6 +235,59 @@ function tty.flush()
return tty
end
+-- find the shell from the parent process (linux)
+function tty._find_shell_from_parent()
+ if os.host() ~= "linux" or not os.isfile("/proc/self/stat") then
+ return
+ end
+
+ local shell
+ local pid = os.getpid()
+ local count = 0
+ while pid ~= 0 and count < 4 do
+ count = count + 1
+ local shell_name = nil
+ local shell_path = nil
+ if os.isfile("/proc/" .. pid .. "/exe") then
+ local link = os.readlink("/proc/" .. pid .. "/exe")
+ if link then
+ shell_path = link
+ end
+ end
+
+ if not shell_path and os.isfile("/proc/" .. pid .. "/comm") then
+ shell_name = io.readfile("/proc/" .. pid .. "/comm")
+ if shell_name then
+ shell_name = shell_name:trim()
+ end
+ end
+ if shell_path then
+ shell_name = path.filename(shell_path)
+ end
+
+ if shell_name then
+ shell_name = shell_name:ltrim("-")
+ for _, name in ipairs({"zsh", "bash", "fish", "nu", "elvish", "pwsh", "sh"}) do
+ if shell_name == name then
+ shell = name
+ break
+ end
+ end
+ if shell then
+ break
+ end
+ end
+
+ local stat = io.readfile("/proc/" .. pid .. "/stat")
+ local ppid = stat and tonumber(stat:match(".*%) %S+ (%d+)"))
+ if not ppid or ppid == 0 then
+ break
+ end
+ pid = ppid
+ end
+ return shell
+end
+
-- get shell name
function tty.shell()
local shell = tty._SHELL
@@ -256,13 +310,18 @@ function tty.shell()
end
end
end
+ -- try to find the shell from the parent process (linux)
+ if not shell then
+ shell = tty._find_shell_from_parent()
+ end
+
if not shell then
shell = os.getenv("XMAKE_SHELL")
end
if not shell then
shell = os.getenv("SHELL")
if shell then
- for _, shellname in ipairs({"zsh", "bash", "sh"}) do
+ for _, shellname in ipairs({"zsh", "bash", "fish", "nu", "elvish", "pwsh", "sh"}) do
if shell:find(shellname) then
shell = shellname
break
@@ -323,6 +382,8 @@ function tty.term()
term = "xterm"
elseif TERM == "cygwin" then
term = "cygwin"
+ elseif TERM:find("alacritty", 1, true) then
+ term = "alacritty"
end
end
end
@@ -560,4 +621,3 @@ end
-- return module
return tty
-
diff --git a/xmake/toolchains/zig/xmake.lua b/xmake/toolchains/zig/xmake.lua
index e9d099782..72e4b943f 100644
--- a/xmake/toolchains/zig/xmake.lua
+++ b/xmake/toolchains/zig/xmake.lua
@@ -78,6 +78,7 @@ toolchain("zig")
on_load(function (toolchain)
import("core.base.semver")
+ import("private.core.base.is_cross")
-- set toolset
-- we patch target to `zig cc` to fix has_flags. see https://github.com/xmake-io/xmake/issues/955#issuecomment-766929692
@@ -106,36 +107,42 @@ toolchain("zig")
toolchain:set("toolset", "zcld", zig)
toolchain:set("toolset", "zcsh", zig)
- -- init arch
- if toolchain:is_arch("arm64", "arm64-v8a") then
- arch = "aarch64"
- elseif toolchain:is_arch("arm", "armv7") then
- arch = "arm"
- elseif toolchain:is_arch("i386", "x86") then
- if zig_version and semver.compare(zig_version, "0.11") >= 0 then
- arch = "x86"
+ -- get target from cross only for cross-compilation
+ -- @see https://github.com/xmake-io/xmake/issues/7180
+ local target
+ if not target and is_cross(toolchain:plat(), toolchain:arch()) then
+ target = toolchain:cross()
+ end
+
+ -- get target from arch
+ if not target then
+ local arch
+ if toolchain:is_arch("arm64", "arm64-v8a") then
+ arch = "aarch64"
+ elseif toolchain:is_arch("arm", "armv7") then
+ arch = "arm"
+ elseif toolchain:is_arch("i386", "x86") then
+ if zig_version and semver.compare(zig_version, "0.11") >= 0 then
+ arch = "x86"
+ else
+ arch = "i386"
+ end
+ elseif toolchain:is_arch("riscv64") then
+ arch = "riscv64"
+ elseif toolchain:is_arch("loong64") then
+ arch = "loongarch64"
+ elseif toolchain:is_arch("mips.*") then
+ arch = toolchain:arch()
+ elseif toolchain:is_arch("ppc64") then
+ arch = "powerpc64"
+ elseif toolchain:is_arch("ppc") then
+ arch = "powerpc"
+ elseif toolchain:is_arch("s390x") then
+ arch = "s390x"
else
- arch = "i386"
+ arch = "x86_64"
end
- elseif toolchain:is_arch("riscv64") then
- arch = "riscv64"
- elseif toolchain:is_arch("loong64") then
- arch = "loongarch64"
- elseif toolchain:is_arch("mips.*") then
- arch = toolchain:arch()
- elseif toolchain:is_arch("ppc64") then
- arch = "powerpc64"
- elseif toolchain:is_arch("ppc") then
- arch = "powerpc"
- elseif toolchain:is_arch("s390x") then
- arch = "s390x"
- else
- arch = "x86_64"
- end
- -- init target
- local target = toolchain:cross()
- if target == nil then
if toolchain:is_plat("cross") then
-- xmake f -p cross --toolchain=zig --cross=mips64el-linux-gnuabi64
elseif toolchain:is_plat("macosx") then
@@ -155,6 +162,8 @@ toolchain("zig")
target = arch .. "-windows-gnu"
end
end
+
+ -- set target flags
if target then
toolchain:add("asflags", "-target", target)
toolchain:add("cxflags", "-target", target)