comparison gui_ze/gui_ze.bzl @ 154:bdcc610eeed8

[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
author June Park <parkjune1995@gmail.com>
date Mon, 12 Jan 2026 09:11:58 -0800
parents 7eb79fd91c7e
children cd35e600ae34
comparison
equal deleted inserted replaced
153:790930d9bb90 154:bdcc610eeed8
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",
28 "-nostdlib",
29 "-O2",
30 "-Wl,--no-entry",
31 "-Wl,--export-dynamic",
32 ]
33
34 # Add exported functions
35 for fn in ctx.attr.exports:
36 cmd_parts.append("-Wl,--export=" + fn)
37
38 cmd_parts.append("-o")
39 cmd_parts.append(out.path)
40 cmd_parts.append(src.path)
41
42 ctx.actions.run_shell(
43 inputs = [src],
44 outputs = [out],
45 command = " ".join(cmd_parts),
46 progress_message = "Compiling {} to WASM".format(src.basename),
47 execution_requirements = {"no-sandbox": "1"},
48 )
49
50 return [DefaultInfo(files = depset([out]))]
51
52 wasm_binary = rule(
53 implementation = _wasm_binary_impl,
54 attrs = {
55 "src": attr.label(
56 allow_single_file = [".c"],
57 mandatory = True,
58 doc = "The C source file to compile",
59 ),
60 "exports": attr.string_list(
61 default = [],
62 doc = "List of function names to export (without leading underscore)",
63 ),
64 },
65 )
66
1 def _foo_impl(ctx): 67 def _foo_impl(ctx):
2 out = ctx.actions.declare_file(ctx.label.name) 68 out = ctx.actions.declare_file(ctx.label.name)
3 ctx.actions.write( 69 ctx.actions.write(
4 output = out, 70 output = out,
5 content = "Hello!\n", 71 content = "Hello!\n",