Commit f1f573b5 by Nicolas Capens Committed by Nicolas Capens

Add Windows support to LLVM config generation script

Windows doesn't support 'make', but CMake can build the generated files using 'cmake --build'. Also set host=x64 to ensure the 64-bit toolchain gets used, to avoid LLVM linking issues. Also define __i386__ and __x86_64__ macros. Bug b/115344057 Change-Id: Idc3f78560b50e67b81a2e7a2490e0e5f23e6cc9d Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/27809Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent cc3c98df
...@@ -54,6 +54,14 @@ LLVM_TRIPLES = { ...@@ -54,6 +54,14 @@ LLVM_TRIPLES = {
'darwin': [ 'darwin': [
('__x86_64__', 'x86_64-apple-darwin'), ('__x86_64__', 'x86_64-apple-darwin'),
], ],
'windows': [
('__x86_64__', 'x86_64-pc-win32'),
('__i386__', 'i686-pc-win32'),
('__arm__', 'armv7-pc-win32'),
('__aarch64__', 'aarch64-pc-win32'),
('__mips__', 'mipsel-pc-win32'),
('__mips64', 'mips64el-pc-win32'),
],
} }
LLVM_OPTIONS = [ LLVM_OPTIONS = [
...@@ -71,19 +79,23 @@ LLVM_OPTIONS = [ ...@@ -71,19 +79,23 @@ LLVM_OPTIONS = [
def _parse_args(): def _parse_args():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('name', help='destination name', parser.add_argument('name', help='destination name',
choices=['android', 'linux', 'darwin']) choices=['android', 'linux', 'darwin', 'windows'])
parser.add_argument('-j', '--jobs', help='parallel compilation', type=int) parser.add_argument('-j', '--jobs', help='parallel compilation', type=int)
return parser.parse_args() return parser.parse_args()
def build_llvm(num_jobs): def build_llvm(name, num_jobs):
"""Build LLVM and get all generated files.""" """Build LLVM and get all generated files."""
if num_jobs is None: if num_jobs is None:
num_jobs = multiprocessing.cpu_count() num_jobs = multiprocessing.cpu_count()
"""On Windows we need to have CMake generate build files for the 64-bit
Visual Studio host toolchain."""
host = '-Thost=x64' if name is 'windows' else ''
os.makedirs(LLVM_OBJS, exist_ok=True) os.makedirs(LLVM_OBJS, exist_ok=True)
run(['cmake', LLVM_DIR] + LLVM_OPTIONS, cwd=LLVM_OBJS) run(['cmake', host, LLVM_DIR] + LLVM_OPTIONS, cwd=LLVM_OBJS)
run(['make', '-j' + str(num_jobs)], cwd=LLVM_OBJS) run(['cmake', '--build', '.', '-j', str(num_jobs)], cwd=LLVM_OBJS)
def list_files(src_base, src, dst_base, suffixes): def list_files(src_base, src, dst_base, suffixes):
...@@ -155,6 +167,18 @@ def copy_platform_file(platform, src, dst): ...@@ -155,6 +167,18 @@ def copy_platform_file(platform, src, dst):
os.makedirs(os.path.dirname(dst), exist_ok=True) os.makedirs(os.path.dirname(dst), exist_ok=True)
with open(dst, 'w') as dst_file: with open(dst, 'w') as dst_file:
for line in src_file: for line in src_file:
if line == '#define LLVM_CONFIG_H\n':
print(line, file=dst_file, end='')
print('', file=dst_file)
print('#if !defined(__i386__) && defined(_M_IX86)', file=dst_file)
print('#define __i386__ 1', file=dst_file)
print('#endif', file=dst_file)
print('', file=dst_file)
print('#if !defined(__x86_64__) && (defined(_M_AMD64) || defined (_M_X64))', file=dst_file)
print('#define __x86_64__ 1', file=dst_file)
print('#endif', file=dst_file)
print('', file=dst_file)
match = llvm_target_pattern.match(line) match = llvm_target_pattern.match(line)
if match: if match:
arch = match.group(1) arch = match.group(1)
...@@ -215,7 +239,7 @@ def copy_platform_generated_files(platform, dst_base): ...@@ -215,7 +239,7 @@ def copy_platform_generated_files(platform, dst_base):
def main(): def main():
args = _parse_args() args = _parse_args()
build_llvm(args.jobs) build_llvm(args.name, args.jobs)
copy_common_generated_files(os.path.join(LLVM_CONFIGS, 'common')) copy_common_generated_files(os.path.join(LLVM_CONFIGS, 'common'))
copy_platform_generated_files( copy_platform_generated_files(
args.name, os.path.join(LLVM_CONFIGS, args.name)) args.name, os.path.join(LLVM_CONFIGS, args.name))
......
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