File
Blob: build/wasm_tools_parse.bzl
| 1 | load("@bazel_skylib//lib:paths.bzl", "paths") |
| 2 | |
| 3 | def _impl(ctx): |
| 4 | in_file = ctx.file.src |
| 5 | out_file = ctx.actions.declare_file(paths.replace_extension(in_file.basename, ".wasm")) |
| 6 | ctx.actions.run_shell( |
| 7 | tools = [ctx.executable._wasm_tools], |
| 8 | inputs = [in_file], |
| 9 | outputs = [out_file], |
| 10 | arguments = [ |
| 11 | ctx.executable._wasm_tools.path, |
| 12 | in_file.path, |
| 13 | out_file.path, |
| 14 | ], |
| 15 | progress_message = "Running wasm-tools parse on %s" % in_file.short_path, |
| 16 | command = "$1 parse $2 -o $3", |
| 17 | ) |
| 18 | |
| 19 | return [DefaultInfo(files = depset([out_file]))] |
| 20 | |
| 21 | wasm_tools_parse = rule( |
| 22 | implementation = _impl, |
| 23 | attrs = { |
| 24 | "src": attr.label(mandatory = True, allow_single_file = True), |
| 25 | "_wasm_tools": attr.label( |
| 26 | executable = True, |
| 27 | allow_files = True, |
| 28 | cfg = "exec", |
| 29 | default = Label("//tools:wasm-tools"), |
| 30 | ), |
| 31 | }, |
| 32 | ) |