Compare commits
12 Commits
copilot/ad
...
v0.0.5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6dedca6f5 | ||
|
|
372a62fa9c | ||
|
|
fd5b5ea8c0 | ||
|
|
0115bb3d27 | ||
|
|
8dbddb635d | ||
|
|
485ccdac7c | ||
|
|
5cb20b96c7 | ||
|
|
f31c88adab | ||
|
|
76a3f2f442 | ||
|
|
4d1be5ada2 | ||
|
|
cf18ebeb79 | ||
|
|
9b2420c9b9 |
6
.github/workflows/copilot-setup-steps.yml
vendored
6
.github/workflows/copilot-setup-steps.yml
vendored
@@ -35,5 +35,11 @@ jobs:
|
||||
extra_nix_config: |
|
||||
experimental-features = nix-command flakes
|
||||
|
||||
- name: Restore and save Nix store cache
|
||||
uses: nix-community/cache-nix-action@v7
|
||||
with:
|
||||
primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/flake.lock') }}
|
||||
restore-prefixes-first-match: nix-${{ runner.os }}-
|
||||
|
||||
- name: Install flake dependencies
|
||||
run: nix develop --accept-flake-config -c true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module(
|
||||
name = "rules_bun",
|
||||
version = "0.1.0",
|
||||
version = "0.0.5",
|
||||
)
|
||||
|
||||
bazel_dep(name = "platforms", version = "1.0.0")
|
||||
|
||||
116
README.md
116
README.md
@@ -2,52 +2,102 @@
|
||||
|
||||
Bazel rules for bun.
|
||||
|
||||
## Current status
|
||||
## Use
|
||||
|
||||
Phase 1 bootstrap is in place:
|
||||
These steps show how to consume a tagged release of `rules_bun` in a separate Bazel workspace.
|
||||
|
||||
- Bun toolchain rule and provider (`/bun/toolchain.bzl`)
|
||||
- Platform-specific Bun repository downloads (`/bun/repositories.bzl`)
|
||||
- Toolchain declarations and registration targets (`/bun/BUILD.bazel`)
|
||||
- Smoke test for `bun --version` (`//tests/toolchain_test:bun_version_test`)
|
||||
### 1) Add the module dependency
|
||||
|
||||
Phase 2 bootstrap is in place:
|
||||
In your project's `MODULE.bazel`, add:
|
||||
|
||||
- Repository-rule based `bun_install` (`/internal/bun_install.bzl`)
|
||||
- Public export via `bun/defs.bzl`
|
||||
- Focused install behavior tests (`//tests/install_test:all`)
|
||||
```starlark
|
||||
bazel_dep(name = "rules_bun", version = "0.0.5")
|
||||
|
||||
Phase 3 bootstrap is in place:
|
||||
archive_override(
|
||||
module_name = "rules_bun",
|
||||
urls = ["https://github.com/Eriyc/rules_bun/archiv0.0.5.tar.gz"],
|
||||
strip_prefix = "rules_bun-v0.0.5",
|
||||
)
|
||||
```
|
||||
|
||||
- Executable `bun_binary` rule (`/internal/bun_binary.bzl`)
|
||||
- Public export via `bun/defs.bzl`
|
||||
- Focused JS/TS runnable tests (`//tests/binary_test:all`)
|
||||
For channel/pre-release tags (for example `v0.0.5-rc.1`), use the matching folder prefix:
|
||||
|
||||
Phase 4 bootstrap is in place:
|
||||
```starlark
|
||||
bazel_dep(name = "rules_bun", version = "0.0.5-rc.1")
|
||||
|
||||
- Test rule `bun_test` (`/internal/bun_test.bzl`)
|
||||
- Public export via `bun/defs.bzl`
|
||||
- Focused passing/failing test targets (`//tests/bun_test_test:all`)
|
||||
archive_override(
|
||||
module_name = "rules_bun",
|
||||
urls = ["https://github.com/Eriyc/rules_bun/archiv0.0.5-rc.1.tar.gz"],
|
||||
strip_prefix = "rules_bun-v0.0.5-rc.1",
|
||||
)
|
||||
```
|
||||
|
||||
Phase 5 bootstrap is in place:
|
||||
Note: keep the `v` prefix in the Git tag URL and `strip_prefix`; for `bazel_dep(..., version = ...)`, use the module version string without the leading `v`.
|
||||
|
||||
- Bundle rule `bun_bundle` (`/internal/bun_bundle.bzl`)
|
||||
- Public export via `bun/defs.bzl`
|
||||
- Focused output/minify tests (`//tests/bundle_test:all`)
|
||||
### 2) Create Bun repositories with the extension
|
||||
|
||||
Phase 6 bootstrap is in place:
|
||||
Still in `MODULE.bazel`, add:
|
||||
|
||||
- Source grouping rules `js_library` / `ts_library` (`/internal/js_library.bzl`)
|
||||
- Transitive `deps` propagation wired into `bun_bundle` and `bun_test`
|
||||
- Focused dependency-propagation tests (`//tests/library_test:all`)
|
||||
```starlark
|
||||
bun_ext = use_extension("@rules_bun//bun:extensions.bzl", "bun")
|
||||
|
||||
Phase 7 bootstrap is in place:
|
||||
use_repo(
|
||||
bun_ext,
|
||||
"bun_linux_x64",
|
||||
"bun_linux_aarch64",
|
||||
"bun_darwin_x64",
|
||||
"bun_darwin_aarch64",
|
||||
"bun_windows_x64",
|
||||
)
|
||||
```
|
||||
|
||||
- Bzlmod `bun_install` module extension (`/bun/extensions.bzl`) using Bazel 9-compatible extension/tag syntax
|
||||
- Focused module-extension shape test (`//tests/install_extension_test:all`)
|
||||
### 3) Register toolchains
|
||||
|
||||
Phase 8 bootstrap is in place:
|
||||
Also in `MODULE.bazel`, register:
|
||||
|
||||
- CI matrix workflow for linux-x64, darwin-arm64, and windows (`/.github/workflows/ci.yml`)
|
||||
- Bazel 9 pin in CI via `USE_BAZEL_VERSION=9.0.0`
|
||||
- Focused CI matrix shape test (`//tests/ci_test:all`)
|
||||
```starlark
|
||||
register_toolchains(
|
||||
"@rules_bun//bun:darwin_aarch64_toolchain",
|
||||
"@rules_bun//bun:darwin_x64_toolchain",
|
||||
"@rules_bun//bun:linux_aarch64_toolchain",
|
||||
"@rules_bun//bun:linux_x64_toolchain",
|
||||
"@rules_bun//bun:windows_x64_toolchain",
|
||||
)
|
||||
```
|
||||
|
||||
### 4) Load rules in `BUILD.bazel`
|
||||
|
||||
```starlark
|
||||
load(
|
||||
"@rules_bun//bun:defs.bzl",
|
||||
"bun_binary",
|
||||
"bun_bundle",
|
||||
"bun_test",
|
||||
"js_library",
|
||||
"ts_library",
|
||||
)
|
||||
```
|
||||
|
||||
### 5) (Optional) Use `bun_install` module extension
|
||||
|
||||
If you want Bazel-managed install repositories, add:
|
||||
|
||||
```starlark
|
||||
bun_install_ext = use_extension("@rules_bun//bun:extensions.bzl", "bun_install")
|
||||
|
||||
bun_install_ext.install(
|
||||
name = "npm",
|
||||
package_json = "//:package.json",
|
||||
bun_lockfile = "//:bun.lock",
|
||||
)
|
||||
|
||||
use_repo(bun_install_ext, "npm")
|
||||
```
|
||||
|
||||
### 6) Verify setup
|
||||
|
||||
Run one of your bun-backed targets, for example:
|
||||
|
||||
```bash
|
||||
bazel test //path/to:your_bun_test
|
||||
```
|
||||
|
||||
12
flake.lock
generated
12
flake.lock
generated
@@ -9,16 +9,16 @@
|
||||
"treefmt-nix": "treefmt-nix"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1772610504,
|
||||
"narHash": "sha256-uoMnjsab5IpZRZ/1mn5oVy4fRnAYn6b58E3FNa+jyQY=",
|
||||
"ref": "v1.0.4",
|
||||
"rev": "86a0792b6e54104e8cb33983cabc175aea8da464",
|
||||
"revCount": 33,
|
||||
"lastModified": 1772613315,
|
||||
"narHash": "sha256-RlPTOsyfVwuwEzvaMpwS+giOqQa6KQXMuSHyh1bctjk=",
|
||||
"ref": "v1.0.5",
|
||||
"rev": "e445e49baf8b44b385108cd4f26a14d8ccf9fd35",
|
||||
"revCount": 35,
|
||||
"type": "git",
|
||||
"url": "https://git.dgren.dev/eric/nix-flake-lib"
|
||||
},
|
||||
"original": {
|
||||
"ref": "v1.0.4",
|
||||
"ref": "v1.0.5",
|
||||
"type": "git",
|
||||
"url": "https://git.dgren.dev/eric/nix-flake-lib"
|
||||
}
|
||||
|
||||
44
flake.nix
44
flake.nix
@@ -3,12 +3,13 @@
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
||||
devshell-lib.url = "git+https://git.dgren.dev/eric/nix-flake-lib?ref=v1.0.4";
|
||||
devshell-lib.url = "git+https://git.dgren.dev/eric/nix-flake-lib?ref=v1.0.5";
|
||||
devshell-lib.inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
devshell-lib,
|
||||
...
|
||||
@@ -41,6 +42,7 @@
|
||||
bun
|
||||
bazel9
|
||||
bazel-buildtools
|
||||
self.packages.${system}.release
|
||||
];
|
||||
|
||||
features = {
|
||||
@@ -86,7 +88,7 @@
|
||||
name = "Bazel";
|
||||
bin = "${bazel9}/bin/bazel";
|
||||
versionCmd = "--version";
|
||||
color = "BLUE";
|
||||
color = "GREEN";
|
||||
}
|
||||
];
|
||||
|
||||
@@ -128,7 +130,43 @@
|
||||
release = devshell-lib.lib.mkRelease {
|
||||
inherit system;
|
||||
|
||||
release = [ ];
|
||||
release = [
|
||||
{
|
||||
run = ''
|
||||
sed -E -i 's#^([[:space:]]*version[[:space:]]*=[[:space:]]*")[^"]*(",)$#\1'"$FULL_VERSION"'\2#' "$ROOT_DIR/MODULE.bazel"
|
||||
'';
|
||||
}
|
||||
{
|
||||
run = ''
|
||||
README="$ROOT_DIR/README.md"
|
||||
TMP="$README.tmp"
|
||||
|
||||
awk -v stable="$BASE_VERSION" -v prerelease="$BASE_VERSION-rc.1" '
|
||||
{
|
||||
line = $0
|
||||
|
||||
if (line ~ /bazel_dep\(name = "rules_bun", version = "/ && line !~ /-rc\.1/) {
|
||||
sub(/version = "[^"]+"/, "version = \"" stable "\"", line)
|
||||
} else if (line ~ /bazel_dep\(name = "rules_bun", version = "/ && line ~ /-rc\.1/) {
|
||||
sub(/version = "[^"]+"/, "version = \"" prerelease "\"", line)
|
||||
} else if (line ~ /archive\/refs\/tags\/v/ && line !~ /-rc\.1/) {
|
||||
sub(/v[^"]+\.tar\.gz/, "v" stable ".tar.gz", line)
|
||||
} else if (line ~ /archive\/refs\/tags\/v/ && line ~ /-rc\.1/) {
|
||||
sub(/v[^"]+\.tar\.gz/, "v" prerelease ".tar.gz", line)
|
||||
} else if (line ~ /strip_prefix = "rules_bun-v/ && line !~ /-rc\.1/) {
|
||||
sub(/rules_bun-v[^"]+/, "rules_bun-v" stable, line)
|
||||
} else if (line ~ /strip_prefix = "rules_bun-v/ && line ~ /-rc\.1/) {
|
||||
sub(/rules_bun-v[^"]+/, "rules_bun-v" prerelease, line)
|
||||
} else if (line ~ /For channel\/pre-release tags \(for example `v.*-rc\.1`\), use the matching folder prefix:/) {
|
||||
sub(/`v[^`]+`/, "`v" prerelease "`", line)
|
||||
}
|
||||
|
||||
print line
|
||||
}
|
||||
' "$README" > "$TMP" && mv "$TMP" "$README"
|
||||
'';
|
||||
}
|
||||
];
|
||||
|
||||
postVersion = ''
|
||||
echo "Released $FULL_TAG"
|
||||
|
||||
Reference in New Issue
Block a user