dart-sdk/third_party/binaryen/generate_needed_files.py
Martin Kustermann 0fdeaee8f6 [dart2wasm] Add building binaryen as part of our GN build
We use binaryen from googlesource mirror with commits that have already
been rolled into g3.

Since binaryen doesn't come with GN files (it uses cmake), we add
our own in third_party/binaryen/BUILD.gn.

TEST=ci

Change-Id: Iee5c37c9d391ee41dc57250d7a33177cbe9ed2aa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/270640
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2022-11-18 10:58:54 +00:00

55 lines
1.8 KiB
Python

#!/usr/bin/env python3
# Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
import os
import re
import subprocess
import sys
def main(args):
# Build Wasm WasmIntrinsics.cpp.
wasm_intrinsics_wat = args[0]
wasm_intrinsics_cpp_in = args[1]
wasm_intrinsics_cpp_out = args[2]
with open(wasm_intrinsics_wat, 'rb') as fd:
wat = fd.read()
wat_hex = ','.join([hex(byte) for byte in wat])
with open(wasm_intrinsics_cpp_in) as fd:
template = fd.read()
template = template.replace('@WASM_INTRINSICS_SIZE@', '%s' % len(wat))
template = template.replace('@WASM_INTRINSICS_EMBED@', wat_hex)
with open(wasm_intrinsics_cpp_out, 'w') as fd:
fd.write(template)
# Build config.h
cmake_in = args[3]
config_h_in = args[4]
config_out = args[5]
with open(cmake_in) as fd:
cmake = fd.read()
with open(config_h_in) as fd:
template = fd.read()
match = re.search(
r'project\(binaryen LANGUAGES C CXX VERSION (?P<version>[0-9]+)\)',
cmake)
version = match['version']
git_args = ['git', 'describe', '--tags', '--match', 'version_*']
try:
output = subprocess.check_output(git_args,
cwd=os.path.dirname(cmake_in),
text=True)
version = '%s (%s)' % (version, output.strip())
except:
pass
template = template.replace('#cmakedefine', '#define')
template = template.replace('${PROJECT_VERSION}', version)
with open(config_out, 'w') as fd:
fd.write(template)
if __name__ == '__main__':
main(sys.argv[1:])