Skip to content

Commit 7d805d5

Browse files
committed
Correct linker-wrapper script under Msys2 and Cygwin. Fixes #58
1 parent aff8cdb commit 7d805d5

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1+
@echo off
2+
if defined SHELL (
3+
where /q cygpath
4+
if ERRORLEVEL 1 (
5+
goto WINSHELL
6+
)
7+
setlocal enabledelayedexpansion
8+
for /f %%i in ('cygpath -w %SHELL%') do (
9+
if exist "%%i" (
10+
"%%i" -c 'exec "$(cygpath -u "%~dp0linker-wrapper.sh")" "%*"'
11+
exit !errorlevel!
12+
)
13+
exit 1
14+
)
15+
endlocal
16+
)
17+
:WINSHELL
18+
@echo on
119
"%RUST_ANDROID_GRADLE_PYTHON_COMMAND%" "%RUST_ANDROID_GRADLE_LINKER_WRAPPER_PY%" %*

plugin/src/main/resources/com/nishtahir/linker-wrapper.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,25 @@
55
import subprocess
66
import sys
77

8-
args = [os.environ['RUST_ANDROID_GRADLE_CC'], os.environ['RUST_ANDROID_GRADLE_CC_LINK_ARG']] + sys.argv[1:]
8+
rustcc = os.environ['RUST_ANDROID_GRADLE_CC']
9+
10+
# Cygwin and Msys2 python need convert executable file path to unix path
11+
if sys.platform == 'msys' or sys.platform == 'cygwin':
12+
import ctypes
13+
14+
cygdll = 'cygwin1.dll' if sys.platform == 'cygwin' else 'msys-2.0.dll'
15+
cygwin = ctypes.cdll.LoadLibrary(cygdll)
16+
17+
def win2posix(path):
18+
CCP_WIN_W_TO_POSIX = 3
19+
size = cygwin.cygwin_conv_path(CCP_WIN_W_TO_POSIX, path, 0, 0)
20+
retval = ctypes.create_string_buffer(size)
21+
cygwin.cygwin_conv_path(CCP_WIN_W_TO_POSIX, path, retval, size)
22+
return retval.value.decode()
23+
24+
rustcc = win2posix(rustcc)
25+
26+
args = [rustcc, os.environ['RUST_ANDROID_GRADLE_CC_LINK_ARG']] + sys.argv[1:]
927

1028
# This only appears when the subprocess call fails, but it's helpful then.
1129
printable_cmd = ' '.join(pipes.quote(arg) for arg in args)

0 commit comments

Comments
 (0)