Coverage for ci/build-rust.py: 23%
13 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-20 16:25 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-20 16:25 +0000
1# This is a script to generate the `wasmtime/bindgen/generated` directory. That
2# directory itself exposes the Python-based functionality for generating
3# bindings itself, so a bit of a bootstrapping process happens here.
4#
5# Bindings generation itself is written in Rust since that's where all of the
6# `*.wit` tooling is located. That's compiled to a `bindgen.wasm` file and then
7# assembled into a `component.wasm` using the `bindgen.wit` world.
8#
9# From this compiled component we sort of need to run it on itself. To avoid
10# that odd bootstrapping problem we work around that by running the bindgen
11# on the native platform, on the component, to generate bindings. That
12# is then loaded here and re-executed, through wasm, to ensure that everything
13# remains the same.
15import subprocess
18def main():
19 print('======================= Building bindgen.wasm =====================')
21 subprocess.run(
22 ['cargo', 'build', '--release', '--target=wasm32-wasip1', '-p=bindgen'],
23 cwd='rust'
24 ).check_returncode()
26 core = 'rust/target/wasm32-wasip1/release/bindgen.wasm'
27 wasi = 'ci/wasi_snapshot_preview1.reactor.wasm'
28 component = 'rust/target/component.wasm'
30 print('======================= Building component.wasm ===================')
32 subprocess.run(
33 ['wasm-tools', 'component', 'new', core, '--adapt', f'wasi_snapshot_preview1={wasi}', '-o', component],
34 ).check_returncode()
36 print('======================= Bootstrapping with native platform ========')
38 subprocess.run(
39 ['cargo', 'run', '-p=bindgen', '--features=cli', 'target/component.wasm', '../wasmtime/bindgen/generated'],
40 cwd='rust'
41 ).check_returncode()
44if __name__ == '__main__':
45 main()