feat: add phase 3 bun_binary bootstrap and tests

This commit is contained in:
Eric
2026-03-04 03:10:35 +00:00
parent b08c8db371
commit f9bd15e3e4
7 changed files with 106 additions and 2 deletions

View File

@@ -1,2 +1,49 @@
def bun_binary(**_kwargs):
fail("bun_binary is not implemented yet")
"""Rule for running JS/TS scripts with Bun."""
def _bun_binary_impl(ctx):
toolchain = ctx.toolchains["//bun:toolchain_type"]
bun_bin = toolchain.bun.bun_bin
entry_point = ctx.file.entry_point
launcher = ctx.actions.declare_file(ctx.label.name)
ctx.actions.write(
output = launcher,
is_executable = True,
content = """#!/usr/bin/env bash
set -euo pipefail
exec \"{}\" run \"{}\" \"$@\"
""".format(bun_bin.path, entry_point.path),
)
transitive_files = []
if ctx.attr.node_modules:
transitive_files.append(ctx.attr.node_modules[DefaultInfo].files)
runfiles = ctx.runfiles(
files = [bun_bin, entry_point] + ctx.files.data,
transitive_files = depset(transitive = transitive_files),
)
return [
DefaultInfo(
executable = launcher,
runfiles = runfiles,
),
]
bun_binary = rule(
implementation = _bun_binary_impl,
attrs = {
"entry_point": attr.label(
mandatory = True,
allow_single_file = [".js", ".ts", ".jsx", ".tsx", ".mjs", ".cjs"],
),
"node_modules": attr.label(),
"data": attr.label_list(allow_files = True),
},
executable = True,
toolchains = ["//bun:toolchain_type"],
)