Mercurial
diff gui_ze/gui_ze.bzl @ 156:cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Mon, 12 Jan 2026 15:20:39 -0800 |
| parents | bdcc610eeed8 |
| children | f3084bca7317 |
line wrap: on
line diff
--- a/gui_ze/gui_ze.bzl Mon Jan 12 09:12:31 2026 -0800 +++ b/gui_ze/gui_ze.bzl Mon Jan 12 15:20:39 2026 -0800 @@ -203,6 +203,69 @@ }, ) +def _bun_run_impl(ctx): + actual_exe = ctx.actions.declare_file(ctx.label.name) + + # 1. Get the workspace name (crucial for runfiles paths) + workspace_name = ctx.workspace_name + + # 2. Define the paths relative to the runfiles root + bun_path = ctx.executable._bun.short_path + src_path = ctx.file.src.short_path + + # 3. Create the launcher script + # We use a template to handle the environment and pathing + script_content = """#!/bin/bash +# Find the runfiles directory +if [[ -z "$RUNFILES_DIR" ]]; then + if [[ -d "$0.runfiles" ]]; then + RUNFILES_DIR="$0.runfiles" + fi +fi + +# Navigate to the workspace root inside runfiles +cd "$RUNFILES_DIR/{workspace}" +pwd +# Execute bun with the src file and any extra arguments +exec "./{bun_bin}" run "./{src_file}" "$@" +""".format( + workspace = workspace_name, + bun_bin = bun_path, + src_file = src_path + ) + + ctx.actions.write( + output = actual_exe, + content = script_content, + is_executable = True, + ) + + return [ + DefaultInfo( + executable = actual_exe, + runfiles = ctx.runfiles( + files = [ctx.file.src] + ctx.files.data + ctx.files._bun_files + ).merge(ctx.attr._bun[DefaultInfo].default_runfiles), + ), + ] + +# TODO: Fix the rules so that it can do relative import. +bun_run = rule( + implementation = _bun_run_impl, + executable = True, + attrs = { + "src": attr.label(allow_single_file = True, mandatory = True), + "data": attr.label_list(allow_files = True), + "_bun": attr.label( + default = Label("//third_party/bun:bun"), + executable = True, + cfg = "exec" + ), + "_bun_files": attr.label(default = Label("//third_party/bun:bun_files")), + }, +) + + def _move_files_into_dir_impl(ctx): srcs = ctx.files.srcs outs = []