comparison gui_ze/gui_ze.bzl @ 184:8c74204fd362

[MD to HTML] Updated so it can be used through readme to html
author MrJuneJune <me@mrjunejune.com>
date Fri, 23 Jan 2026 22:20:35 -0800
parents f3084bca7317
children 8cf4ec5e2191
comparison
equal deleted inserted replaced
183:a8976a008a9d 184:8c74204fd362
1 def _wasm_binary_impl(ctx):
2 """
3 Compile C source to WASM using clang --target=wasm32.
4 No libc - suitable for standalone WASM modules.
5
6 Requires LLVM with wasm32 support (e.g., Homebrew LLVM on macOS).
7 """
8 src = ctx.file.src
9 out = ctx.actions.declare_file(ctx.label.name + ".wasm")
10
11 # Shell script to find clang with wasm support and set PATH for wasm-ld
12 setup_cmd = """
13 export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"
14 if [ -x /opt/homebrew/opt/llvm/bin/clang ]; then
15 CLANG=/opt/homebrew/opt/llvm/bin/clang
16 elif [ -x /usr/local/opt/llvm/bin/clang ]; then
17 CLANG=/usr/local/opt/llvm/bin/clang
18 else
19 CLANG=clang
20 fi
21 """
22
23 # Build clang command
24 cmd_parts = [
25 setup_cmd,
26 "$CLANG",
27 "--target=wasm32-unknown-unknown",
28 "-O2",
29 "-Wl,--no-entry",
30 "-Wl,--export-dynamic",
31 ]
32
33 # Add exported functions
34 for fn in ctx.attr.exports:
35 cmd_parts.append("-Wl,--export=" + fn)
36
37 cmd_parts.append("-o")
38 cmd_parts.append(out.path)
39 cmd_parts.append(src.path)
40
41 ctx.actions.run_shell(
42 inputs = [src],
43 outputs = [out],
44 command = " ".join(cmd_parts),
45 progress_message = "Compiling {} to WASM".format(src.basename),
46 execution_requirements = {"no-sandbox": "1"},
47 )
48
49 return [DefaultInfo(files = depset([out]))]
50
51 wasm_binary = rule(
52 implementation = _wasm_binary_impl,
53 attrs = {
54 "src": attr.label(
55 allow_single_file = [".c"],
56 mandatory = True,
57 doc = "The C source file to compile",
58 ),
59 "exports": attr.string_list(
60 default = [],
61 doc = "List of function names to export (without leading underscore)",
62 ),
63 },
64 )
65
66 def _foo_impl(ctx): 1 def _foo_impl(ctx):
67 out = ctx.actions.declare_file(ctx.label.name) 2 out = ctx.actions.declare_file(ctx.label.name)
68 ctx.actions.write( 3 ctx.actions.write(
69 output = out, 4 output = out,
70 content = "Hello!\n", 5 content = "Hello!\n",