Mercurial
diff gui_ze/gui_ze.bzl @ 185:dfdd66825396
Merged in keep alive changes and mrjunejune changes.
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Fri, 23 Jan 2026 22:22:30 -0800 |
| parents | 8c74204fd362 |
| children | 8cf4ec5e2191 |
line wrap: on
line diff
--- a/gui_ze/gui_ze.bzl Fri Jan 23 21:09:49 2026 -0800 +++ b/gui_ze/gui_ze.bzl Fri Jan 23 22:22:30 2026 -0800 @@ -1,68 +1,3 @@ -def _wasm_binary_impl(ctx): - """ - Compile C source to WASM using clang --target=wasm32. - No libc - suitable for standalone WASM modules. - - Requires LLVM with wasm32 support (e.g., Homebrew LLVM on macOS). - """ - src = ctx.file.src - out = ctx.actions.declare_file(ctx.label.name + ".wasm") - - # Shell script to find clang with wasm support and set PATH for wasm-ld - setup_cmd = """ - export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH" - if [ -x /opt/homebrew/opt/llvm/bin/clang ]; then - CLANG=/opt/homebrew/opt/llvm/bin/clang - elif [ -x /usr/local/opt/llvm/bin/clang ]; then - CLANG=/usr/local/opt/llvm/bin/clang - else - CLANG=clang - fi - """ - - # Build clang command - cmd_parts = [ - setup_cmd, - "$CLANG", - "--target=wasm32-unknown-unknown", - "-O2", - "-Wl,--no-entry", - "-Wl,--export-dynamic", - ] - - # Add exported functions - for fn in ctx.attr.exports: - cmd_parts.append("-Wl,--export=" + fn) - - cmd_parts.append("-o") - cmd_parts.append(out.path) - cmd_parts.append(src.path) - - ctx.actions.run_shell( - inputs = [src], - outputs = [out], - command = " ".join(cmd_parts), - progress_message = "Compiling {} to WASM".format(src.basename), - execution_requirements = {"no-sandbox": "1"}, - ) - - return [DefaultInfo(files = depset([out]))] - -wasm_binary = rule( - implementation = _wasm_binary_impl, - attrs = { - "src": attr.label( - allow_single_file = [".c"], - mandatory = True, - doc = "The C source file to compile", - ), - "exports": attr.string_list( - default = [], - doc = "List of function names to export (without leading underscore)", - ), - }, -) - def _foo_impl(ctx): out = ctx.actions.declare_file(ctx.label.name) ctx.actions.write(