Skip to content

Commit

Permalink
zig cc: fix wrapper in Git Bash
Browse files Browse the repository at this point in the history
  • Loading branch information
Doekin committed Dec 28, 2024
1 parent 4f408eb commit 9e409d9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ function sandbox_lib_detect_find_program._check(program, opt)
elseif os.subhost() == "msys" and os.isfile(program) and os.filesize(program) < 256 then
-- only a sh script on msys2? e.g. c:/msys64/usr/bin/7z
-- we need to use sh to wrap it, otherwise os.exec cannot run it
program = "sh " .. program
local program_lower = program:lower()
if not program_lower:endswith(".exe") and not program_lower:endswith(".cmd") and not program_lower:endswith(".bat") then
program = "sh " .. program
end
findname = program
end
if sandbox_lib_detect_find_program._do_check(findname, opt) then
Expand Down
6 changes: 5 additions & 1 deletion xmake/modules/package/tools/autoconf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ end
function _translate_windows_bin_path(bin_path)
if bin_path then
local argv = os.argv(bin_path)
argv[1] = path.unix(argv[1]) .. ".exe"
argv[1] = path.unix(argv[1])
local path_lower = argv[1]:lower()
if not path_lower:endswith(".exe") and not path_lower:endswith(".cmd") and not path_lower:endswith(".bat") then
argv[1] = argv[1] .. ".exe"
end
return os.args(argv)
end
end
Expand Down
7 changes: 6 additions & 1 deletion xmake/modules/package/tools/make.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ import("private.utils.toolchain", {alias = "toolchain_utils"})
-- translate bin path
function _translate_bin_path(bin_path)
if is_host("windows") and bin_path then
return bin_path:gsub("\\", "/") .. ".exe"
bin_path = bin_path:gsub("\\", "/")
local bin_path_lower = bin_path:lower()
if not bin_path_lower:endswith(".exe") and not bin_path_lower:endswith(".cmd") and not bin_path_lower:endswith(".bat") then
bin_path = bin_path .. ".exe"
end
return bin_path
end
return bin_path
end
Expand Down
2 changes: 1 addition & 1 deletion xmake/toolchains/zig/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ toolchain("zig")
local wrapper_path = path.join(os.tmpdir(), "zigcc", tool) .. script_suffix
if not os.isfile(wrapper_path) then
if is_host("windows") then
io.writefile(wrapper_path, ("@echo off\n\"%s\" %s %%*"):format(zig, tool))
io.writefile(wrapper_path, ("@echo off || true\n" .. [["%s" %s %%* || exec "%s" %s "$@"]]):format(zig, tool, zig, tool))
else
io.writefile(wrapper_path, ("#!/bin/bash\nexec \"%s\" %s \"$@\""):format(zig, tool))
os.runv("chmod", {"+x", wrapper_path})
Expand Down

0 comments on commit 9e409d9

Please sign in to comment.