feat: proper windows support

This commit is contained in:
eric
2026-03-15 11:04:44 +01:00
parent 4f8e27cd74
commit 626a6640f8
70 changed files with 3410 additions and 1689 deletions

View File

@@ -1,5 +1,5 @@
load("//bun:defs.bzl", "bun_binary")
load("@rules_shell//shell:sh_test.bzl", "sh_test")
load("//bun:defs.bzl", "bun_binary")
bun_binary(
name = "hello_js_bin",
@@ -8,8 +8,12 @@ bun_binary(
sh_test(
name = "bun_binary_js_test",
size = "small",
srcs = ["run_binary.sh"],
args = ["$(location :hello_js_bin)", "hello-js"],
args = [
"$(location :hello_js_bin)",
"hello-js",
],
data = [":hello_js_bin"],
)
@@ -20,19 +24,24 @@ bun_binary(
sh_test(
name = "bun_binary_ts_test",
size = "small",
srcs = ["run_binary.sh"],
args = ["$(location :hello_ts_bin)", "hello-ts"],
args = [
"$(location :hello_ts_bin)",
"hello-ts",
],
data = [":hello_ts_bin"],
)
bun_binary(
name = "hello_js_with_data_bin",
entry_point = "hello.js",
data = ["payload.txt"],
entry_point = "hello.js",
)
sh_test(
name = "bun_binary_data_test",
size = "small",
srcs = ["verify_data_shape.sh"],
args = [
"$(location //internal:bun_binary.bzl)",
@@ -46,13 +55,14 @@ sh_test(
bun_binary(
name = "env_cwd_bin",
entry_point = "env.ts",
data = [".env"],
entry_point = "env.ts",
working_dir = "entry_point",
)
sh_test(
name = "bun_binary_env_cwd_test",
size = "small",
srcs = ["run_env_binary.sh"],
args = ["$(location :env_cwd_bin)"],
data = [":env_cwd_bin"],
@@ -60,13 +70,14 @@ sh_test(
bun_binary(
name = "env_parent_cwd_bin",
entry_point = "env_parent/src/main.ts",
data = ["env_parent/.env"],
entry_point = "env_parent/src/main.ts",
working_dir = "entry_point",
)
sh_test(
name = "bun_binary_env_parent_cwd_test",
size = "small",
srcs = ["run_parent_env_binary.sh"],
args = ["$(location :env_parent_cwd_bin)"],
data = [":env_parent_cwd_bin"],
@@ -74,14 +85,18 @@ sh_test(
bun_binary(
name = "runtime_flag_bin",
args = [
"one",
"two",
],
entry_point = "flag_probe.ts",
args = ["one", "two"],
preload = ["preload.ts"],
env_files = ["runtime.env"],
preload = ["preload.ts"],
)
sh_test(
name = "bun_binary_runtime_flags_test",
size = "small",
srcs = ["run_flag_binary.sh"],
args = ["$(location :runtime_flag_bin)"],
data = [":runtime_flag_bin"],
@@ -89,6 +104,7 @@ sh_test(
sh_test(
name = "bun_binary_runtime_flags_shape_test",
size = "small",
srcs = ["verify_runtime_flags_shape.sh"],
args = ["$(location :runtime_flag_bin)"],
data = [":runtime_flag_bin"],
@@ -96,24 +112,52 @@ sh_test(
bun_binary(
name = "configured_launcher_bin",
entry_point = "hello.ts",
node_modules = "@script_test_vite_node_modules//:node_modules",
smol = True,
conditions = [
"browser",
"development",
],
entry_point = "hello.ts",
inherit_host_path = True,
install_mode = "force",
node_modules = "@script_test_vite_node_modules//:node_modules",
run_flags = [
"--hot",
"--console-depth",
"4",
],
smol = True,
visibility = ["//tests/ci_test:__pkg__"],
)
sh_test(
name = "bun_binary_configured_launcher_shape_test",
size = "small",
srcs = ["verify_configured_launcher_shape.sh"],
args = ["$(location :configured_launcher_bin)"],
data = [":configured_launcher_bin"],
)
bun_binary(
name = "path_default_bin",
entry_point = "path_probe.ts",
)
bun_binary(
name = "path_inherit_bin",
entry_point = "path_probe.ts",
inherit_host_path = True,
)
sh_test(
name = "bun_binary_host_path_test",
size = "small",
srcs = ["run_path_binary.sh"],
args = [
"$(location :path_default_bin)",
"$(location :path_inherit_bin)",
],
data = [
":path_default_bin",
":path_inherit_bin",
],
)

View File

@@ -0,0 +1,5 @@
const pathValue = process.env.PATH ?? "";
console.log(JSON.stringify({
hasHostSentinel: pathValue.includes("rules_bun_host_path_sentinel"),
}));

View File

@@ -3,7 +3,23 @@ set -euo pipefail
binary="$1"
expected="$2"
output="$(${binary})"
run_launcher() {
local launcher="$1"
shift
if [[ ${launcher} == *.cmd ]]; then
local command
printf -v command '"%s"' "${launcher}"
for arg in "$@"; do
printf -v command '%s "%s"' "${command}" "${arg}"
done
cmd.exe /c "${command}" | tr -d '\r'
return 0
fi
"${launcher}" "$@"
}
output="$(run_launcher "${binary}")"
if [[ ${output} != "${expected}" ]]; then
echo "Unexpected output from ${binary}: ${output}" >&2

View File

@@ -2,7 +2,23 @@
set -euo pipefail
binary="$1"
output="$(${binary})"
run_launcher() {
local launcher="$1"
shift
if [[ ${launcher} == *.cmd ]]; then
local command
printf -v command '"%s"' "${launcher}"
for arg in "$@"; do
printf -v command '%s "%s"' "${command}" "${arg}"
done
cmd.exe /c "${command}" | tr -d '\r'
return 0
fi
"${launcher}" "$@"
}
output="$(run_launcher "${binary}")"
if [[ ${output} != "from-dotenv" ]]; then
echo "Expected .env value from entry-point directory, got: ${output}" >&2

View File

@@ -2,7 +2,23 @@
set -euo pipefail
binary="$1"
output="$(${binary})"
run_launcher() {
local launcher="$1"
shift
if [[ ${launcher} == *.cmd ]]; then
local command
printf -v command '"%s"' "${launcher}"
for arg in "$@"; do
printf -v command '%s "%s"' "${command}" "${arg}"
done
cmd.exe /c "${command}" | tr -d '\r'
return 0
fi
"${launcher}" "$@"
}
output="$(run_launcher "${binary}")"
expected='{"preloaded":"yes","env":"from-env-file","argv":["one","two"]}'

View File

@@ -2,7 +2,23 @@
set -euo pipefail
binary="$1"
output="$(${binary})"
run_launcher() {
local launcher="$1"
shift
if [[ ${launcher} == *.cmd ]]; then
local command
printf -v command '"%s"' "${launcher}"
for arg in "$@"; do
printf -v command '%s "%s"' "${command}" "${arg}"
done
cmd.exe /c "${command}" | tr -d '\r'
return 0
fi
"${launcher}" "$@"
}
output="$(run_launcher "${binary}")"
if [[ ${output} != "from-parent-dotenv" ]]; then
echo "Expected .env value from parent directory, got: ${output}" >&2

View File

@@ -0,0 +1,33 @@
#!/usr/bin/env bash
set -euo pipefail
default_binary="$1"
inherit_binary="$2"
run_launcher() {
local launcher="$1"
shift
if [[ ${launcher} == *.cmd ]]; then
local command
printf -v command '"%s"' "${launcher}"
for arg in "$@"; do
printf -v command '%s "%s"' "${command}" "${arg}"
done
env PATH="rules_bun_host_path_sentinel:${PATH:-}" cmd.exe /c "${command}" | tr -d '\r'
return 0
fi
env PATH="rules_bun_host_path_sentinel:${PATH:-}" "${launcher}" "$@"
}
default_output="$(run_launcher "${default_binary}")"
inherit_output="$(run_launcher "${inherit_binary}")"
if [[ ${default_output} != '{"hasHostSentinel":false}' ]]; then
echo "Expected default launcher to hide host PATH, got: ${default_output}" >&2
exit 1
fi
if [[ ${inherit_output} != '{"hasHostSentinel":true}' ]]; then
echo "Expected inherit_host_path launcher to preserve host PATH, got: ${inherit_output}" >&2
exit 1
fi

View File

@@ -1,16 +1,23 @@
#!/usr/bin/env bash
set -euo pipefail
binary="$1"
launcher="$1"
grep -Fq -- 'install_metadata="${runfiles_dir}/_main/' "${binary}"
grep -Fq -- 'node_modules/.rules_bun/install.json' "${binary}"
grep -Fq -- "--smol" "${binary}"
grep -Fq -- "--conditions" "${binary}"
grep -Fq -- "'browser'" "${binary}"
grep -Fq -- "'development'" "${binary}"
grep -Fq -- "--install" "${binary}"
grep -Fq -- "'force'" "${binary}"
grep -Fq -- "'--hot'" "${binary}"
grep -Fq -- "'--console-depth'" "${binary}"
grep -Fq -- "'4'" "${binary}"
python3 - "${launcher}" <<'PY'
import json
import pathlib
import sys
path = pathlib.Path(sys.argv[1])
if path.suffix.lower() == ".cmd":
path = pathlib.Path(str(path)[:-4])
spec = json.loads(pathlib.Path(f"{path}.launcher.json").read_text())
argv = spec["argv"]
assert spec["install_metadata_short_path"].endswith("node_modules/.rules_bun/install.json"), spec
assert spec["inherit_host_path"] is True, spec
assert spec["node_modules_roots"], spec
assert all(not root.startswith("../") for root in spec["node_modules_roots"]), spec
for value in ["--smol", "--conditions", "browser", "development", "--install", "force", "--hot", "--console-depth", "4"]:
assert value in argv, (value, spec)
PY

View File

@@ -1,8 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail
binary="$1"
launcher="$1"
grep -Fq -- '--no-install' "${binary}"
grep -Fq -- '--preload' "${binary}"
grep -Fq -- '--env-file' "${binary}"
python3 - "${launcher}" <<'PY'
import json
import pathlib
import sys
path = pathlib.Path(sys.argv[1])
if path.suffix.lower() == ".cmd":
path = pathlib.Path(str(path)[:-4])
spec = json.loads(pathlib.Path(f"{path}.launcher.json").read_text())
assert "--no-install" in spec["argv"], spec
assert spec["inherit_host_path"] is False, spec
assert spec["preload_short_paths"] and spec["preload_short_paths"][0].endswith("tests/binary_test/preload.ts"), spec
assert spec["env_file_short_paths"] and spec["env_file_short_paths"][0].endswith("tests/binary_test/runtime.env"), spec
PY