Skip to content

Commit 1bf6b67

Browse files
committed
Allowed build under msys2 or cygwin
1 parent 8fe507b commit 1bf6b67

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

core/src/main/rust/linker-wrapper.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
from __future__ import absolute_import, print_function, unicode_literals
22

3+
import codecs
34
import os
45
import pipes
56
import shutil
67
import subprocess
78
import sys
9+
import tempfile
10+
11+
rustcc = os.environ['RUST_ANDROID_GRADLE_CC']
12+
13+
if sys.platform == 'msys' or sys.platform == 'cygwin':
14+
rustcc = subprocess.check_output(['/usr/bin/cygpath', '-u', rustcc]).decode('ascii').strip()
15+
16+
args = [rustcc, os.environ['RUST_ANDROID_GRADLE_CC_LINK_ARG']] + sys.argv[1:]
17+
18+
linkargfileName = ''
19+
if (sys.platform == 'msys' or sys.platform == 'cygwin') and len(''.join(args)) > 8191:
20+
# response file should be use UTF-16 with BOM
21+
linkargfile = tempfile.NamedTemporaryFile(delete=False)
22+
linkargfile.write(codecs.BOM_UTF16_LE)
23+
linkargfile.write('\n'.join(sys.argv[1:]).encode('utf-16-le'))
24+
linkargfile.close()
25+
linkargfileName = linkargfile.name
26+
linkargfileNameW = subprocess.check_output(['/usr/bin/cygpath', '-w', linkargfileName]).decode('ascii').strip()
27+
args = [rustcc, os.environ['RUST_ANDROID_GRADLE_CC_LINK_ARG'], '@' + linkargfileNameW]
828

9-
args = [os.environ['RUST_ANDROID_GRADLE_CC'], os.environ['RUST_ANDROID_GRADLE_CC_LINK_ARG']] + sys.argv[1:]
1029

1130
# This only appears when the subprocess call fails, but it's helpful then.
1231
printable_cmd = ' '.join(pipes.quote(arg) for arg in args)
@@ -20,4 +39,6 @@
2039
with open(linkargs[0][1:]) as f:
2140
sys_argv = f.read().splitlines()
2241
shutil.copyfile(sys_argv[sys_argv.index('-o') + 1], os.environ['RUST_ANDROID_GRADLE_TARGET'])
42+
if linkargfileName != '':
43+
os.unlink(linkargfileName)
2344
sys.exit(code)

0 commit comments

Comments
 (0)