Skip to content

Commit 25b7f28

Browse files
committed
deps,test: fixed failures
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
1 parent 94f320b commit 25b7f28

2 files changed

Lines changed: 111 additions & 1 deletion

File tree

deps/libffi/libffi.gyp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
'variables': {
2020
'libffi_arch_sources': [
2121
'src/x86/ffiw64.c',
22-
'src/x86/win64_intel.S',
2322
],
2423
'libffi_defines': [
2524
'LIBFFI_HIDE_BASIC_TYPES',
@@ -146,6 +145,45 @@
146145
],
147146
},
148147
],
148+
'conditions': [
149+
['OS == "win" and target_arch == "x64"', {
150+
'actions': [
151+
{
152+
'action_name': 'preprocess_win64_intel_asm',
153+
'process_outputs_as_sources': 1,
154+
'inputs': [
155+
'preprocess_asm.py',
156+
'include/ffi_cfi.h',
157+
'src/x86/asmnames.h',
158+
'src/x86/win64_intel.S',
159+
'<(INTERMEDIATE_DIR)/ffi.h',
160+
'<(INTERMEDIATE_DIR)/fficonfig.h',
161+
],
162+
'outputs': [
163+
'<(INTERMEDIATE_DIR)/win64_intel.asm',
164+
],
165+
'action': [
166+
'<(python)',
167+
'preprocess_asm.py',
168+
'--input',
169+
'src/x86/win64_intel.S',
170+
'--output',
171+
'<@(_outputs)',
172+
'--include-dir',
173+
'include',
174+
'--include-dir',
175+
'src/x86',
176+
'--include-dir',
177+
'<(INTERMEDIATE_DIR)',
178+
'--define',
179+
'FFI_BUILDING',
180+
'--define',
181+
'LIBFFI_HIDE_BASIC_TYPES',
182+
],
183+
},
184+
],
185+
}],
186+
],
149187
'direct_dependent_settings': {
150188
'include_dirs': [
151189
'include',

deps/libffi/preprocess_asm.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import os
5+
from pathlib import Path
6+
import shlex
7+
import shutil
8+
import subprocess
9+
import sys
10+
11+
12+
def split_command(value):
13+
if not value:
14+
return None
15+
value = value.strip()
16+
if not value:
17+
return None
18+
return shlex.split(value, posix=(os.name != 'nt'))
19+
20+
21+
def find_compiler():
22+
for var in ('CC', 'CXX'):
23+
command = split_command(os.environ.get(var))
24+
if command and shutil.which(command[0]):
25+
return command
26+
27+
for name in ('cl.exe', 'cl', 'clang-cl.exe', 'clang-cl', 'cc', 'clang', 'gcc'):
28+
path = shutil.which(name)
29+
if path:
30+
return [path]
31+
32+
raise RuntimeError('Unable to locate a compiler for preprocessing assembly')
33+
34+
35+
def preprocess(args):
36+
compiler = find_compiler()
37+
output = Path(args.output)
38+
output.parent.mkdir(parents=True, exist_ok=True)
39+
40+
if os.name == 'nt' and Path(compiler[0]).name.lower() in ('cl.exe', 'cl', 'clang-cl.exe', 'clang-cl'):
41+
command = compiler + ['/nologo', '/EP', '/TC']
42+
command += [f'/I{include_dir}' for include_dir in args.include_dir]
43+
command += [f'/D{define}' for define in args.define]
44+
command += [args.input]
45+
else:
46+
command = compiler + ['-E', '-P', '-x', 'c']
47+
command += [f'-I{include_dir}' for include_dir in args.include_dir]
48+
command += [f'-D{define}' for define in args.define]
49+
command += [args.input]
50+
51+
result = subprocess.run(command, capture_output=True, text=True)
52+
if result.returncode != 0:
53+
sys.stderr.write(result.stderr)
54+
raise RuntimeError(f'Preprocessing failed: {" ".join(command)}')
55+
56+
output.write_text(result.stdout, encoding='utf-8')
57+
58+
59+
def main(argv=None):
60+
parser = argparse.ArgumentParser(description='Preprocess libffi assembly source')
61+
parser.add_argument('--input', required=True)
62+
parser.add_argument('--output', required=True)
63+
parser.add_argument('--include-dir', action='append', default=[])
64+
parser.add_argument('--define', action='append', default=[])
65+
args = parser.parse_args(argv)
66+
67+
preprocess(args)
68+
return 0
69+
70+
71+
if __name__ == '__main__':
72+
raise SystemExit(main())

0 commit comments

Comments
 (0)