copilot/add-bun-rules-package #1

Merged
eric merged 25 commits from copilot/add-bun-rules-package into main 2026-03-04 08:27:25 +00:00
18 changed files with 205 additions and 1 deletions
Showing only changes of commit d93e1715c6 - Show all commits

View File

@@ -24,3 +24,22 @@ sh_test(
args = ["$(location :hello_ts_bin)", "hello-ts"], args = ["$(location :hello_ts_bin)", "hello-ts"],
data = [":hello_ts_bin"], data = [":hello_ts_bin"],
) )
bun_binary(
name = "hello_js_with_data_bin",
entry_point = "hello.js",
data = ["payload.txt"],
)
sh_test(
name = "bun_binary_data_test",
srcs = ["verify_data_shape.sh"],
args = [
"$(location //internal:bun_binary.bzl)",
"$(location //tests/binary_test:BUILD.bazel)",
],
data = [
"//internal:bun_binary.bzl",
"//tests/binary_test:BUILD.bazel",
],
)

View File

@@ -0,0 +1 @@
hello-from-data

View File

@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail
rule_file="$1"
build_file="$2"
grep -Eq 'files = \[bun_bin, entry_point\] \+ ctx\.files\.data' "${rule_file}"
grep -Eq 'name = "hello_js_with_data_bin"' "${build_file}"
grep -Eq 'data = \["payload\.txt"\]' "${build_file}"

View File

@@ -1,4 +1,5 @@
load("//bun:defs.bzl", "bun_test") load("//bun:defs.bzl", "bun_test")
load("@rules_shell//shell:sh_test.bzl", "sh_test")
bun_test( bun_test(
name = "passing_suite", name = "passing_suite",
@@ -8,5 +9,32 @@ bun_test(
bun_test( bun_test(
name = "failing_suite", name = "failing_suite",
srcs = ["failing.test.ts"], srcs = ["failing.test.ts"],
tags = ["manual"], )
sh_test(
name = "bun_test_failing_suite_test",
srcs = ["failing_suite_shape.sh"],
args = ["$(location //tests/bun_test_test:BUILD.bazel)"],
data = ["//tests/bun_test_test:BUILD.bazel"],
)
sh_test(
name = "bun_test_cache_hit_test",
srcs = ["cache_hit_shape.sh"],
args = ["$(location //internal:bun_test.bzl)"],
data = ["//internal:bun_test.bzl"],
)
sh_test(
name = "bun_test_cache_miss_test",
srcs = ["cache_miss_shape.sh"],
args = ["$(location //internal:bun_test.bzl)"],
data = ["//internal:bun_test.bzl"],
)
sh_test(
name = "bun_test_junit_output_test",
srcs = ["junit_shape.sh"],
args = ["$(location //internal:bun_test.bzl)"],
data = ["//internal:bun_test.bzl"],
) )

View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
rule_file="$1"
grep -Eq 'set -euo pipefail' "${rule_file}"
grep -Eq 'src_args = " "\.join' "${rule_file}"
grep -Eq 'exec "\$\{bun_bin\}" test \{src_args\} "\$@"' "${rule_file}"

View File

@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail
rule_file="$1"
grep -Eq 'files = \[bun_bin\] \+ ctx\.files\.srcs \+ ctx\.files\.data' "${rule_file}"
grep -Eq '"srcs": attr\.label_list\(' "${rule_file}"

View File

@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail
build_file="$1"
grep -Eq 'name = "failing_suite"' "${build_file}"
if grep -Eq 'tags = \["manual"\]' "${build_file}"; then
echo "failing_suite must be automated (not manual-only)" >&2
exit 1
fi

View File

@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail
rule_file="$1"
grep -Eq 'exec "\$\{bun_bin\}" test \{src_args\} .*"\$@"' "${rule_file}"
grep -Eq 'if \[\[ -n "\$\{TESTBRIDGE_TEST_ONLY:-\}" \]\]' "${rule_file}"

View File

@@ -12,6 +12,12 @@ bun_bundle(
minify = True, minify = True,
) )
bun_bundle(
name = "external_bundle",
entry_points = ["main.ts"],
external = ["left-pad"],
)
sh_test( sh_test(
name = "bundle_output_test", name = "bundle_output_test",
srcs = ["verify_bundle.sh"], srcs = ["verify_bundle.sh"],
@@ -31,3 +37,23 @@ sh_test(
":minified_bundle", ":minified_bundle",
], ],
) )
sh_test(
name = "bundle_hermetic_digest_test",
srcs = ["verify_hermetic_shape.sh"],
args = ["$(location //internal:bun_bundle.bzl)"],
data = ["//internal:bun_bundle.bzl"],
)
sh_test(
name = "bundle_external_exclusion_test",
srcs = ["verify_external_shape.sh"],
args = [
"$(location //internal:bun_bundle.bzl)",
"$(location //tests/bundle_test:BUILD.bazel)",
],
data = [
"//internal:bun_bundle.bzl",
"//tests/bundle_test:BUILD.bazel",
],
)

View File

@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail
rule_file="$1"
build_file="$2"
grep -Eq 'for package in ctx\.attr\.external:' "${rule_file}"
grep -Eq 'args\.add\("--external"\)' "${rule_file}"
grep -Eq 'name = "external_bundle"' "${build_file}"
grep -Eq 'external = \["left-pad"\]' "${build_file}"

View File

@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail
rule_file="$1"
grep -Eq 'def _output_name\(target_name, entry\):' "${rule_file}"
grep -Eq 'return "\{\}__\{\}\\.js"\.format\(target_name, stem\)' "${rule_file}"
grep -Eq 'inputs = depset\(' "${rule_file}"
grep -Eq 'direct = \[entry\] \+ ctx\.files\.data' "${rule_file}"

View File

@@ -69,3 +69,10 @@ sh_test(
"//conditions:default": ["@bun_linux_x64//:bun"], "//conditions:default": ["@bun_linux_x64//:bun"],
}), }),
) )
sh_test(
name = "bun_install_determinism_test",
srcs = ["determinism.sh"],
args = ["$(location //internal:bun_install.bzl)"],
data = ["//internal:bun_install.bzl"],
)

View File

@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail
rule_file="$1"
grep -Eq 'install", "--frozen-lockfile", "--no-progress"' "${rule_file}"
grep -Eq 'repository_ctx\.symlink\(package_json, "package\.json"\)' "${rule_file}"
grep -Eq 'repository_ctx\.symlink\(bun_lockfile, "bun\.lockb"\)' "${rule_file}"
grep -Eq 'glob\(\["node_modules/\*\*"\]' "${rule_file}"

View File

@@ -0,0 +1,21 @@
load("@rules_shell//shell:sh_test.bzl", "sh_test")
sh_test(
name = "examples_basic_e2e_build_test",
srcs = ["examples_basic_e2e_build_test.sh"],
args = [
"$(location //examples/basic:BUILD.bazel)",
"$(location //examples/basic:README.md)",
],
data = [
"//examples/basic:BUILD.bazel",
"//examples/basic:README.md",
],
)
sh_test(
name = "repo_all_targets_test",
srcs = ["repo_all_targets_test.sh"],
args = ["$(location //.github/workflows:ci.yml)"],
data = ["//.github/workflows:ci.yml"],
)

View File

@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail
build_file="$1"
readme_file="$2"
[[ -f "${build_file}" ]]
[[ -f "${readme_file}" ]]
grep -Eq '^package\(default_visibility = \["//visibility:public"\]\)$' "${build_file}"

View File

@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
workflow_file="$1"
grep -Eq 'bazel test //tests/\.\.\.' "${workflow_file}" || grep -Eq 'bazel test //\.\.\.' "${workflow_file}"

View File

@@ -50,3 +50,10 @@ sh_test(
"//conditions:default": ["@bun_linux_x64//:bun"], "//conditions:default": ["@bun_linux_x64//:bun"],
}), }),
) )
sh_test(
name = "toolchain_resolution_matrix_test",
srcs = ["toolchain_resolution_matrix.sh"],
args = ["$(location //tests/toolchain_test:BUILD.bazel)"],
data = ["//tests/toolchain_test:BUILD.bazel"],
)

View File

@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -euo pipefail
build_file="$1"
grep -Eq 'name = "linux_x86_64"' "${build_file}"
grep -Eq 'name = "linux_aarch64"' "${build_file}"
grep -Eq 'name = "darwin_x86_64"' "${build_file}"
grep -Eq 'name = "darwin_aarch64"' "${build_file}"
grep -Eq 'name = "bun_version_test"' "${build_file}"
grep -Eq 'select\(' "${build_file}"