Commit 6272fc75 authored by SquallATF's avatar SquallATF Committed by Max Lv

Allowed build under msys2 or cygwin

parent eb32cb43
...@@ -6,7 +6,46 @@ import shutil ...@@ -6,7 +6,46 @@ import shutil
import subprocess import subprocess
import sys import sys
args = [os.environ['RUST_ANDROID_GRADLE_CC'], os.environ['RUST_ANDROID_GRADLE_CC_LINK_ARG']] + sys.argv[1:] rustcc = os.environ['RUST_ANDROID_GRADLE_CC']
if sys.platform == 'msys' or sys.platform == 'cygwin':
import ctypes
cygdll = 'cygwin1.dll' if sys.platform == 'cygwin' else 'msys-2.0.dll'
cygwin = ctypes.cdll.LoadLibrary(cygdll)
def win2posix(path):
CCP_WIN_W_TO_POSIX = 3
size = cygwin.cygwin_conv_path(CCP_WIN_W_TO_POSIX, path, 0, 0)
retval = ctypes.create_string_buffer(size)
cygwin.cygwin_conv_path(CCP_WIN_W_TO_POSIX, path, retval, size)
return retval.value.decode()
rustcc = win2posix(rustcc)
args = [rustcc, os.environ['RUST_ANDROID_GRADLE_CC_LINK_ARG']] + sys.argv[1:]
linkargfileName = ''
if (sys.platform == 'msys' or sys.platform == 'cygwin') and len(''.join(args)) > 8191:
import codecs
import tempfile
def posix2win(path):
CCP_POSIX_TO_WIN_W = 1
size = cygwin.cygwin_conv_path(CCP_POSIX_TO_WIN_W, str(path).encode(), 0, 0)
retval = ctypes.create_unicode_buffer(size)
cygwin.cygwin_conv_path(CCP_POSIX_TO_WIN_W, str(path).encode(), retval, size)
return retval.value
# response file should be use UTF-16 with BOM
linkargfile = tempfile.NamedTemporaryFile(delete=False)
linkargfile.write(codecs.BOM_UTF16_LE)
linkargfile.write('\n'.join(sys.argv[1:]).encode('utf-16-le'))
linkargfile.close()
linkargfileName = linkargfile.name
linkargfileNameW = posix2win(linkargfileName)
args = [rustcc, os.environ['RUST_ANDROID_GRADLE_CC_LINK_ARG'], '@' + linkargfileNameW]
# This only appears when the subprocess call fails, but it's helpful then. # This only appears when the subprocess call fails, but it's helpful then.
printable_cmd = ' '.join(pipes.quote(arg) for arg in args) printable_cmd = ' '.join(pipes.quote(arg) for arg in args)
...@@ -21,4 +60,6 @@ if code == 0: ...@@ -21,4 +60,6 @@ if code == 0:
with open(linkargs[0][1:]) as f: with open(linkargs[0][1:]) as f:
sys_argv = f.read().splitlines() sys_argv = f.read().splitlines()
shutil.copyfile(sys_argv[sys_argv.index('-o') + 1], os.environ['RUST_ANDROID_GRADLE_TARGET']) shutil.copyfile(sys_argv[sys_argv.index('-o') + 1], os.environ['RUST_ANDROID_GRADLE_TARGET'])
if linkargfileName != '':
os.unlink(linkargfileName)
sys.exit(code) sys.exit(code)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment