feat: add phase 3 bun_binary bootstrap and tests
This commit is contained in:
committed by
copilot-swe-agent[bot]
parent
19a0c7ae50
commit
0c4e0aea4e
@@ -16,3 +16,9 @@ Phase 2 bootstrap is in place:
|
|||||||
- Repository-rule based `bun_install` (`/internal/bun_install.bzl`)
|
- Repository-rule based `bun_install` (`/internal/bun_install.bzl`)
|
||||||
- Public export via `bun/defs.bzl`
|
- Public export via `bun/defs.bzl`
|
||||||
- Focused install behavior tests (`//tests/install_test:all`)
|
- Focused install behavior tests (`//tests/install_test:all`)
|
||||||
|
|
||||||
|
Phase 3 bootstrap is in place:
|
||||||
|
|
||||||
|
- Executable `bun_binary` rule (`/internal/bun_binary.bzl`)
|
||||||
|
- Public export via `bun/defs.bzl`
|
||||||
|
- Focused JS/TS runnable tests (`//tests/binary_test:all`)
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
|
load("//internal:bun_binary.bzl", "bun_binary")
|
||||||
load("//internal:bun_install.bzl", "bun_install")
|
load("//internal:bun_install.bzl", "bun_install")
|
||||||
load(":repositories.bzl", "bun_register_toolchains", "bun_repositories")
|
load(":repositories.bzl", "bun_register_toolchains", "bun_repositories")
|
||||||
load(":toolchain.bzl", "BunToolchainInfo", "bun_toolchain")
|
load(":toolchain.bzl", "BunToolchainInfo", "bun_toolchain")
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"BunToolchainInfo",
|
"BunToolchainInfo",
|
||||||
|
"bun_binary",
|
||||||
"bun_install",
|
"bun_install",
|
||||||
"bun_register_toolchains",
|
"bun_register_toolchains",
|
||||||
"bun_repositories",
|
"bun_repositories",
|
||||||
|
|||||||
@@ -1,2 +1,49 @@
|
|||||||
def bun_binary(**_kwargs):
|
"""Rule for running JS/TS scripts with Bun."""
|
||||||
fail("bun_binary is not implemented yet")
|
|
||||||
|
|
||||||
|
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"],
|
||||||
|
)
|
||||||
|
|||||||
35
tests/binary_test/BUILD.bazel
Normal file
35
tests/binary_test/BUILD.bazel
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
load("//bun:defs.bzl", "bun_binary")
|
||||||
|
|
||||||
|
bun_binary(
|
||||||
|
name = "hello_js_bin",
|
||||||
|
entry_point = "hello.js",
|
||||||
|
data = ["hello.js"],
|
||||||
|
)
|
||||||
|
|
||||||
|
sh_test(
|
||||||
|
name = "bun_binary_js_test",
|
||||||
|
srcs = ["run_binary.sh"],
|
||||||
|
args = ["$(location :hello_js_bin)", "hello-js"],
|
||||||
|
data = [":hello_js_bin"],
|
||||||
|
target_compatible_with = [
|
||||||
|
"@platforms//cpu:x86_64",
|
||||||
|
"@platforms//os:linux",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
bun_binary(
|
||||||
|
name = "hello_ts_bin",
|
||||||
|
entry_point = "hello.ts",
|
||||||
|
data = ["hello.ts"],
|
||||||
|
)
|
||||||
|
|
||||||
|
sh_test(
|
||||||
|
name = "bun_binary_ts_test",
|
||||||
|
srcs = ["run_binary.sh"],
|
||||||
|
args = ["$(location :hello_ts_bin)", "hello-ts"],
|
||||||
|
data = [":hello_ts_bin"],
|
||||||
|
target_compatible_with = [
|
||||||
|
"@platforms//cpu:x86_64",
|
||||||
|
"@platforms//os:linux",
|
||||||
|
],
|
||||||
|
)
|
||||||
1
tests/binary_test/hello.js
Normal file
1
tests/binary_test/hello.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
console.log("hello-js");
|
||||||
2
tests/binary_test/hello.ts
Normal file
2
tests/binary_test/hello.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
const message: string = "hello-ts";
|
||||||
|
console.log(message);
|
||||||
11
tests/binary_test/run_binary.sh
Executable file
11
tests/binary_test/run_binary.sh
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
binary="$1"
|
||||||
|
expected="$2"
|
||||||
|
output="$(${binary})"
|
||||||
|
|
||||||
|
if [[ "${output}" != "${expected}" ]]; then
|
||||||
|
echo "Unexpected output from ${binary}: ${output}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user