From f601d73e6528b59dc42fca07f3b725c4a0186200 Mon Sep 17 00:00:00 2001 From: Jack Marsh <11052243+jackmarsh@users.noreply.github.com> Date: Tue, 3 Nov 2026 19:31:14 +0000 Subject: [PATCH 1/2] Add pinned Bun and OXLint native toolchains --- .github/workflows/ci.yaml | 24 ++++++ .plzconfig | 24 ++++++ README.md | 50 ++++++++++-- build_defs/BUILD | 6 ++ build_defs/native_tools.build_defs | 120 +++++++++++++++++++++++++++++ pleasew | 11 +-- test/BUILD | 12 +++ test/native_tools_test.sh | 16 ++++ third_party/bun/BUILD | 5 ++ third_party/oxlint/BUILD | 5 ++ 10 files changed, 260 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 build_defs/native_tools.build_defs create mode 100644 test/native_tools_test.sh create mode 100644 third_party/bun/BUILD create mode 100644 third_party/oxlint/BUILD diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..715686c --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,24 @@ +name: CI + +on: + pull_request: + push: + branches: [main] + +jobs: + toolchains: + strategy: + fail-fast: false + matrix: + runner: [ubuntu-22.04, ubuntu-24.04-arm, macos-15-intel, macos-15] + runs-on: ${{ matrix.runner }} + steps: + - uses: actions/checkout@v4 + - name: Build toolchains + run: ./pleasew build //third_party/node:node //third_party/bun:bun //third_party/oxlint:oxlint + - name: Test toolchains + run: ./pleasew test //test/... + - name: Format + run: ./pleasew format + - name: Check formatting + run: git diff --exit-code diff --git a/.plzconfig b/.plzconfig index fdc0b41..6b0dc4c 100644 --- a/.plzconfig +++ b/.plzconfig @@ -22,5 +22,29 @@ DefaultValue = 22.23.2 Help = Node.js version used when node_toolchain is called without an explicit version. Inherit = true +[PluginConfig "default_bun_version"] +ConfigKey = DefaultBunVersion +DefaultValue = 1.4.4 +Help = Bun version used when bun_toolchain is called without an explicit version. +Inherit = true + +[PluginConfig "default_oxlint_version"] +ConfigKey = DefaultOxlintVersion +DefaultValue = 1.91.0 +Help = OXLint version used when oxlint_toolchain is called without an explicit version. +Inherit = true + +[PluginConfig "bun_tool"] +ConfigKey = BunTool +DefaultValue = ///node//third_party/bun:bun|bun +Help = Build label for the Bun binary, from bun_toolchain. +Inherit = true + +[PluginConfig "oxlint_tool"] +ConfigKey = OxlintTool +DefaultValue = ///node//third_party/oxlint:oxlint|oxlint +Help = Build label for the OXLint binary, from oxlint_toolchain. +Inherit = true + [Plugin "node"] Target = //plugins:node diff --git a/README.md b/README.md index e3281eb..fe30616 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,10 @@ # node-rules -A Node.js toolchain for the [Please](https://please.build) build system. +A Node.js, Bun and OXLint toolchain for the [Please](https://please.build) build system. -This plugin does one thing: fetch a Node.js distribution for the host platform -and expose `node`, `npm`, `npx` and `corepack` as entry points. It has no -opinions about JavaScript, so a ruleset that needs a hermetic node can depend on -it without inheriting a build system for JS. +This plugin fetches pinned native executables for the host platform. It exposes +`node`, `npm`, `npx`, `corepack`, `bun` and `oxlint` as entry points. It has no +opinions about how JavaScript is built, checked or linted. ## Install @@ -37,6 +36,15 @@ node_toolchain( ) ``` +Declare Bun and OXLint in their own BUILD files: + +```python +subinclude("///node//build_defs:native_tools") + +bun_toolchain(name = "bun") +oxlint_toolchain(name = "oxlint") +``` + Then point the plugin config at it, so rules can find it: ```ini @@ -44,6 +52,8 @@ Then point the plugin config at it, so rules can find it: Target = //plugins:node NodeTool = //third_party/node:node|node NpmTool = //third_party/node:node|npm +BunTool = //third_party/bun:bun|bun +OxlintTool = //third_party/oxlint:oxlint|oxlint ``` ## Using it in a rule @@ -76,6 +86,25 @@ The Node.js tarball ships `bin/npm` as a symlink to a `.js` file carrying a there is not. The entry points therefore name the scripts themselves, and the downloaded tree is left byte-identical to what nodejs.org shipped. +`bun` and `oxlint` are native binaries. Declare them as tools and invoke them +directly; no host Node.js executable or package installation is needed: + +```python +subinclude("///node//build_defs:native_tools") + +build_rule( + name = "check", + srcs = ["src/example.ts"], + outs = ["check.stamp"], + tools = {"bun": [CONFIG.NODE.BUN_TOOL]}, + cmd = "$TOOLS_BUN --version > $OUT", +) +``` + +Subinclude `///node//build_defs:native_tools` in each BUILD file that reads the +native tool config keys. The default targets live in `third_party/bun/BUILD` +and `third_party/oxlint/BUILD` within this plugin. + ## Configuration | Config key | Default | Meaning | @@ -83,6 +112,10 @@ downloaded tree is left byte-identical to what nodejs.org shipped. | `NodeTool` | `///node//third_party/node:node\|node` | Build label for the node binary | | `NpmTool` | `///node//third_party/node:node\|npm` | Build label for the npm CLI | | `DefaultVersion` | `22.23.2` | Version used when `node_toolchain` is called without one | +| `BunTool` | `///node//third_party/bun:bun\|bun` | Build label for the Bun binary | +| `OxlintTool` | `///node//third_party/oxlint:oxlint\|oxlint` | Build label for the OXLint binary | +| `DefaultBunVersion` | `1.4.4` | Version used when `bun_toolchain` is called without one | +| `DefaultOxlintVersion` | `1.91.0` | Version used when `oxlint_toolchain` is called without one | ## Versions @@ -101,3 +134,10 @@ the generated block at the top of `build_defs/node.build_defs`. To use a release that is not pinned, pass `hashes` explicitly. Supported platforms: `linux-x64`, `linux-arm64`, `darwin-x64`, `darwin-arm64`. + +`bun_toolchain` and `oxlint_toolchain` carry SHA256 hashes of the official Bun +and OXLint release archives in `build_defs/native_tools.build_defs`. The same +four platforms are supported. Bun's x64 baseline archives work on CPUs without +AVX2. Linux OXLint uses the glibc archives. Unsupported platforms and versions +fail during rule evaluation. The exact version, archive URL and digest are in +the action command, so a pin change invalidates its cache key. diff --git a/build_defs/BUILD b/build_defs/BUILD index 0536860..093bc27 100644 --- a/build_defs/BUILD +++ b/build_defs/BUILD @@ -3,3 +3,9 @@ filegroup( srcs = ["node.build_defs"], visibility = ["PUBLIC"], ) + +filegroup( + name = "native_tools", + srcs = ["native_tools.build_defs"], + visibility = ["PUBLIC"], +) diff --git a/build_defs/native_tools.build_defs b/build_defs/native_tools.build_defs new file mode 100644 index 0000000..b263112 --- /dev/null +++ b/build_defs/native_tools.build_defs @@ -0,0 +1,120 @@ +"""Pinned native Bun and OXLint executables for Please actions. + +The distribution archive is checked before extraction. It is an action input +through the URL and digest in the command, and is not retained as an output. +""" + +BUN_VERSIONS = { + "1.4.4": { + "darwin-arm64": ("bun-darwin-aarch64.zip", "c240d7f0ccb90c263a849fcdb09b7ee62630d921348ed6aafda86b9d577bc510"), + "darwin-x64": ("bun-darwin-x64-baseline.zip", "d4a155adfbfd09155eb3ba05c9e3a544f39297d7a68616d3c7759f67ab5c47dc"), + "linux-arm64": ("bun-linux-aarch64.zip", "baa6bb36f51d6e58561e02bbea825038a9df454f673d6d776e8bbf86f8c7850e"), + "linux-x64": ("bun-linux-x64-baseline.zip", "e0446eb55995772eb9894bebae9a6be368d985a8b9271ee124486f9946eedd76"), + }, +} + +OXLINT_VERSIONS = { + "1.91.0": { + "darwin-arm64": ("oxlint-aarch64-apple-darwin.tar.gz", "d1f6037780a4d5e14a32d810083859ae691a5032f789381a5ff9b75f901f90e9"), + "darwin-x64": ("oxlint-x86_64-apple-darwin.tar.gz", "b422a6a5ffe753b117d7348a80e722ca35183ceb1b6c98766f0de14747727a26"), + "linux-arm64": ("oxlint-aarch64-unknown-linux-gnu.tar.gz", "c99c0e97edd40d5cd21840831d8eff2d4a5e84ce0cf73a6fdac58aaa9c1e1f20"), + "linux-x64": ("oxlint-x86_64-unknown-linux-gnu.tar.gz", "de059941526abeaab3c5aafa78caef80e5b4e7197274391d80cde38a1960a916"), + }, +} + + +def _native_platform(): + if CONFIG.OS not in ["linux", "darwin"]: + fail("native JS tools support linux and darwin only, not " + CONFIG.OS) + if CONFIG.ARCH == "amd64": + arch = "x64" + elif CONFIG.ARCH == "arm64": + arch = "arm64" + else: + fail("native JS tools do not support architecture " + CONFIG.ARCH) + return CONFIG.OS + "-" + arch + + +def _pinned_archive(versions:dict, tool:str, version:str): + if version not in versions: + fail("No pinned " + tool + " release " + version + ". Known versions: " + + ", ".join(sorted(versions.keys()))) + platform = _native_platform() + pins = versions[version] + if platform not in pins: + fail("No pinned " + tool + " archive for " + platform) + return pins[platform] + + +def _download_verified(url:str, digest:str): + """Return a POSIX shell command that fails before extracting a bad archive.""" + return " && ".join([ + "curl -fsSL --retry 5 --retry-delay 2 -o tool.archive '" + url + "'", + "digest=$(if command -v sha256sum >/dev/null 2>&1; then sha256sum tool.archive | awk '{print $1}'; else openssl dgst -sha256 tool.archive | awk '{print $NF}'; fi)", + "{ [ \"$digest\" = '" + digest + "' ] || { echo 'bad SHA256 for " + url + "' >&2; exit 1; }; }", + ]) + + +def bun_toolchain(name:str, version:str="", visibility:list=["PUBLIC"]): + """Download a pinned Bun binary for the host platform. + + The x64 archives are Bun's baseline builds, which do not require AVX2. + Consumers use the `bun` entry point, e.g. `:bun|bun`. + """ + version = version or CONFIG.NODE.DEFAULT_BUN_VERSION + pin = _pinned_archive(BUN_VERSIONS, "Bun", version) + archive = pin[0] + digest = pin[1] + directory = archive[:-4] + url = "https://github.com/oven-sh/bun/releases/download/bun-v" + version + "/" + archive + return build_rule( + name = name, + outs = [name], + local = True, + sandbox = False, + cmd = " && ".join([ + _download_verified(url, digest), + "mkdir -p _archive $OUT", + "unzip -q tool.archive -d _archive", + "mv _archive/" + directory + "/bun $OUT/bun", + "chmod +x $OUT/bun", + "rm -f tool.archive", + ]), + entry_points = {"bun": name + "/bun"}, + binary = True, + visibility = visibility, + labels = ["bun:" + version], + building_description = "Installing Bun...", + ) + + +def oxlint_toolchain(name:str, version:str="", visibility:list=["PUBLIC"]): + """Download a pinned OXLint binary for the host platform. + + Consumers use the `oxlint` entry point, e.g. `:oxlint|oxlint`. + """ + version = version or CONFIG.NODE.DEFAULT_OXLINT_VERSION + pin = _pinned_archive(OXLINT_VERSIONS, "OXLint", version) + archive = pin[0] + digest = pin[1] + executable = archive[:-7] + url = "https://github.com/oxc-project/oxc/releases/download/oxlint_v" + version + "/" + archive + return build_rule( + name = name, + outs = [name], + local = True, + sandbox = False, + cmd = " && ".join([ + _download_verified(url, digest), + "mkdir -p _archive $OUT", + "tar -xzf tool.archive -C _archive", + "mv _archive/" + executable + " $OUT/oxlint", + "chmod +x $OUT/oxlint", + "rm -f tool.archive", + ]), + entry_points = {"oxlint": name + "/oxlint"}, + binary = True, + visibility = visibility, + labels = ["oxlint:" + version], + building_description = "Installing OXLint...", + ) diff --git a/pleasew b/pleasew index 8e4c2f9..7f82534 100755 --- a/pleasew +++ b/pleasew @@ -22,14 +22,9 @@ DEFAULT_URL_BASE='https://get.please.build' OS="$(uname)" -if [ "${OS}" = 'Darwin' ]; then - # switch between mac amd64/arm64 - ARCH="$(uname -m)" -else - # default to amd64 on other operating systems - # because we only build intel binaries - ARCH='amd64' -fi +# Select the host architecture on Linux and macOS. Please publishes arm64 +# binaries for both, so a Linux arm64 runner must not receive an amd64 binary. +ARCH="$(uname -m)" case "${ARCH}" in aarch64_be|aarch64|armv8b|armv8l) ARCH='arm64' ;; diff --git a/test/BUILD b/test/BUILD index c74340d..aaa8476 100644 --- a/test/BUILD +++ b/test/BUILD @@ -11,3 +11,15 @@ build_rule( no_test_output = True, test_cmd = "$TEST third_party/node/node v22.23.2", ) + +build_rule( + name = "native_tools_test", + srcs = ["native_tools_test.sh"], + data = ["//third_party/bun:bun", "//third_party/oxlint:oxlint"], + outs = ["native_tools_test"], + cmd = "cp $SRCS $OUT", + binary = True, + test = True, + no_test_output = True, + test_cmd = "$TEST third_party/bun/bun 1.4.4 third_party/oxlint/oxlint 1.91.0", +) diff --git a/test/native_tools_test.sh b/test/native_tools_test.sh new file mode 100644 index 0000000..a20d32b --- /dev/null +++ b/test/native_tools_test.sh @@ -0,0 +1,16 @@ +#!/bin/sh +set -eu + +BUN="$(pwd)/$1/bun" +OXLINT="$(pwd)/$3/oxlint" + +got=$(env -i PATH=/usr/bin:/bin "$BUN" --version) +[ "$got" = "$2" ] || { echo "Bun: expected $2, got $got" >&2; exit 1; } + +got=$(env -i PATH=/usr/bin:/bin "$OXLINT" --version) +case "$got" in + *"$4"*) ;; + *) echo "OXLint: expected $4, got $got" >&2; exit 1 ;; +esac + +echo "native tool entry points are hermetic" diff --git a/third_party/bun/BUILD b/third_party/bun/BUILD new file mode 100644 index 0000000..90d0ce0 --- /dev/null +++ b/third_party/bun/BUILD @@ -0,0 +1,5 @@ +subinclude("//build_defs:native_tools") + +bun_toolchain( + name = "bun", +) diff --git a/third_party/oxlint/BUILD b/third_party/oxlint/BUILD new file mode 100644 index 0000000..2cf41c2 --- /dev/null +++ b/third_party/oxlint/BUILD @@ -0,0 +1,5 @@ +subinclude("//build_defs:native_tools") + +oxlint_toolchain( + name = "oxlint", +) From c8b6c1bdbcf69e2f487b0ddd6c7f9c3426863030 Mon Sep 17 00:00:00 2001 From: Jack Marsh <11052243+jackmarsh@users.noreply.github.com> Date: Tue, 3 Nov 2026 19:47:12 +0000 Subject: [PATCH 2/2] Split Bun and OXLint into dedicated toolchain rules --- .plzconfig | 12 --- README.md | 38 +++++---- build_defs/BUILD | 10 ++- build_defs/bun.build_defs | 62 +++++++++++++++ build_defs/native_tools.build_defs | 120 ----------------------------- build_defs/oxlint.build_defs | 61 +++++++++++++++ third_party/bun/BUILD | 3 +- third_party/oxlint/BUILD | 3 +- 8 files changed, 157 insertions(+), 152 deletions(-) create mode 100644 build_defs/bun.build_defs delete mode 100644 build_defs/native_tools.build_defs create mode 100644 build_defs/oxlint.build_defs diff --git a/.plzconfig b/.plzconfig index 6b0dc4c..0594068 100644 --- a/.plzconfig +++ b/.plzconfig @@ -22,18 +22,6 @@ DefaultValue = 22.23.2 Help = Node.js version used when node_toolchain is called without an explicit version. Inherit = true -[PluginConfig "default_bun_version"] -ConfigKey = DefaultBunVersion -DefaultValue = 1.4.4 -Help = Bun version used when bun_toolchain is called without an explicit version. -Inherit = true - -[PluginConfig "default_oxlint_version"] -ConfigKey = DefaultOxlintVersion -DefaultValue = 1.91.0 -Help = OXLint version used when oxlint_toolchain is called without an explicit version. -Inherit = true - [PluginConfig "bun_tool"] ConfigKey = BunTool DefaultValue = ///node//third_party/bun:bun|bun diff --git a/README.md b/README.md index fe30616..c51c529 100644 --- a/README.md +++ b/README.md @@ -36,13 +36,20 @@ node_toolchain( ) ``` -Declare Bun and OXLint in their own BUILD files: +Declare Bun in `third_party/bun/BUILD`: ```python -subinclude("///node//build_defs:native_tools") +subinclude("///node//build_defs:bun") -bun_toolchain(name = "bun") -oxlint_toolchain(name = "oxlint") +bun_toolchain(name = "bun", version = "1.4.4") +``` + +Declare OXLint in `third_party/oxlint/BUILD`: + +```python +subinclude("///node//build_defs:oxlint") + +oxlint_toolchain(name = "oxlint", version = "1.91.0") ``` Then point the plugin config at it, so rules can find it: @@ -90,7 +97,7 @@ downloaded tree is left byte-identical to what nodejs.org shipped. directly; no host Node.js executable or package installation is needed: ```python -subinclude("///node//build_defs:native_tools") +subinclude("///node//build_defs:bun") build_rule( name = "check", @@ -101,9 +108,9 @@ build_rule( ) ``` -Subinclude `///node//build_defs:native_tools` in each BUILD file that reads the -native tool config keys. The default targets live in `third_party/bun/BUILD` -and `third_party/oxlint/BUILD` within this plugin. +Subinclude `///node//build_defs:bun` or `///node//build_defs:oxlint` in each +BUILD file that reads the respective config key. The default targets live in +`third_party/bun/BUILD` and `third_party/oxlint/BUILD` within this plugin. ## Configuration @@ -114,8 +121,6 @@ and `third_party/oxlint/BUILD` within this plugin. | `DefaultVersion` | `22.23.2` | Version used when `node_toolchain` is called without one | | `BunTool` | `///node//third_party/bun:bun\|bun` | Build label for the Bun binary | | `OxlintTool` | `///node//third_party/oxlint:oxlint\|oxlint` | Build label for the OXLint binary | -| `DefaultBunVersion` | `1.4.4` | Version used when `bun_toolchain` is called without one | -| `DefaultOxlintVersion` | `1.91.0` | Version used when `oxlint_toolchain` is called without one | ## Versions @@ -135,9 +140,10 @@ that is not pinned, pass `hashes` explicitly. Supported platforms: `linux-x64`, `linux-arm64`, `darwin-x64`, `darwin-arm64`. -`bun_toolchain` and `oxlint_toolchain` carry SHA256 hashes of the official Bun -and OXLint release archives in `build_defs/native_tools.build_defs`. The same -four platforms are supported. Bun's x64 baseline archives work on CPUs without -AVX2. Linux OXLint uses the glibc archives. Unsupported platforms and versions -fail during rule evaluation. The exact version, archive URL and digest are in -the action command, so a pin change invalidates its cache key. +`bun_toolchain` and `oxlint_toolchain` carry SHA256 hashes of their official +release archives in `build_defs/bun.build_defs` and +`build_defs/oxlint.build_defs`. Each rule requires an explicit version. The +same four platforms are supported. Bun's x64 baseline archives work on CPUs +without AVX2. Linux OXLint uses the glibc archives. Unsupported platforms and +versions fail during rule evaluation. The exact version, archive URL and digest +are in the action command, so a pin change invalidates its cache key. diff --git a/build_defs/BUILD b/build_defs/BUILD index 093bc27..71f1e29 100644 --- a/build_defs/BUILD +++ b/build_defs/BUILD @@ -5,7 +5,13 @@ filegroup( ) filegroup( - name = "native_tools", - srcs = ["native_tools.build_defs"], + name = "bun", + srcs = ["bun.build_defs"], + visibility = ["PUBLIC"], +) + +filegroup( + name = "oxlint", + srcs = ["oxlint.build_defs"], visibility = ["PUBLIC"], ) diff --git a/build_defs/bun.build_defs b/build_defs/bun.build_defs new file mode 100644 index 0000000..8b5979d --- /dev/null +++ b/build_defs/bun.build_defs @@ -0,0 +1,62 @@ +"""Pinned Bun distribution for Please actions.""" + +# SHA256 values are from the immutable bun-v1.4.4 GitHub release assets. +# x64 uses Bun's baseline build so AVX2 is not required. +BUN_VERSIONS = { + "1.4.4": { + "darwin-arm64": ("bun-darwin-aarch64.zip", "c240d7f0ccb90c263a849fcdb09b7ee62630d921348ed6aafda86b9d577bc510"), + "darwin-x64": ("bun-darwin-x64-baseline.zip", "d4a155adfbfd09155eb3ba05c9e3a544f39297d7a68616d3c7759f67ab5c47dc"), + "linux-arm64": ("bun-linux-aarch64.zip", "baa6bb36f51d6e58561e02bbea825038a9df454f673d6d776e8bbf86f8c7850e"), + "linux-x64": ("bun-linux-x64-baseline.zip", "e0446eb55995772eb9894bebae9a6be368d985a8b9271ee124486f9946eedd76"), + }, +} + + +def _bun_platform(): + if CONFIG.OS not in ["linux", "darwin"]: + fail("bun_toolchain supports linux and darwin only, not " + CONFIG.OS) + if CONFIG.ARCH == "amd64": + arch = "x64" + elif CONFIG.ARCH == "arm64": + arch = "arm64" + else: + fail("bun_toolchain does not support architecture " + CONFIG.ARCH) + return CONFIG.OS + "-" + arch + + +def bun_toolchain(name:str, version:str, visibility:list=["PUBLIC"]): + """Download verified Bun and expose its native `bun` entry point. + + Usage: bun_toolchain(name = "bun", version = "1.4.4") + """ + if version not in BUN_VERSIONS: + fail("No pinned Bun hashes for " + version + ". Known versions: " + + ", ".join(sorted(BUN_VERSIONS.keys()))) + platform = _bun_platform() + pin = BUN_VERSIONS[version][platform] + archive = pin[0] + hash = pin[1] + url = "https://github.com/oven-sh/bun/releases/download/bun-v" + version + "/" + archive + directory = archive[:-4] + cmd = " && ".join([ + "curl -fsSL --retry 5 --retry-delay 2 -o bun.zip '" + url + "'", + "digest=$(if command -v sha256sum >/dev/null 2>&1; then sha256sum bun.zip | awk '{print $1}'; else openssl dgst -sha256 bun.zip | awk '{print $NF}'; fi)", + "{ [ \"$digest\" = '" + hash + "' ] || { echo 'bad hash for " + url + "' >&2; exit 1; }; }", + "mkdir -p _archive $OUT", + "unzip -q bun.zip -d _archive", + "mv _archive/" + directory + "/bun $OUT/bun", + "chmod +x $OUT/bun", + "rm -f bun.zip", + ]) + return build_rule( + name = name, + outs = [name], + cmd = cmd, + entry_points = {"bun": name + "/bun"}, + binary = True, + local = True, + sandbox = False, + visibility = visibility, + labels = ["bun:" + version], + building_description = "Installing Bun v" + version + "...", + ) diff --git a/build_defs/native_tools.build_defs b/build_defs/native_tools.build_defs deleted file mode 100644 index b263112..0000000 --- a/build_defs/native_tools.build_defs +++ /dev/null @@ -1,120 +0,0 @@ -"""Pinned native Bun and OXLint executables for Please actions. - -The distribution archive is checked before extraction. It is an action input -through the URL and digest in the command, and is not retained as an output. -""" - -BUN_VERSIONS = { - "1.4.4": { - "darwin-arm64": ("bun-darwin-aarch64.zip", "c240d7f0ccb90c263a849fcdb09b7ee62630d921348ed6aafda86b9d577bc510"), - "darwin-x64": ("bun-darwin-x64-baseline.zip", "d4a155adfbfd09155eb3ba05c9e3a544f39297d7a68616d3c7759f67ab5c47dc"), - "linux-arm64": ("bun-linux-aarch64.zip", "baa6bb36f51d6e58561e02bbea825038a9df454f673d6d776e8bbf86f8c7850e"), - "linux-x64": ("bun-linux-x64-baseline.zip", "e0446eb55995772eb9894bebae9a6be368d985a8b9271ee124486f9946eedd76"), - }, -} - -OXLINT_VERSIONS = { - "1.91.0": { - "darwin-arm64": ("oxlint-aarch64-apple-darwin.tar.gz", "d1f6037780a4d5e14a32d810083859ae691a5032f789381a5ff9b75f901f90e9"), - "darwin-x64": ("oxlint-x86_64-apple-darwin.tar.gz", "b422a6a5ffe753b117d7348a80e722ca35183ceb1b6c98766f0de14747727a26"), - "linux-arm64": ("oxlint-aarch64-unknown-linux-gnu.tar.gz", "c99c0e97edd40d5cd21840831d8eff2d4a5e84ce0cf73a6fdac58aaa9c1e1f20"), - "linux-x64": ("oxlint-x86_64-unknown-linux-gnu.tar.gz", "de059941526abeaab3c5aafa78caef80e5b4e7197274391d80cde38a1960a916"), - }, -} - - -def _native_platform(): - if CONFIG.OS not in ["linux", "darwin"]: - fail("native JS tools support linux and darwin only, not " + CONFIG.OS) - if CONFIG.ARCH == "amd64": - arch = "x64" - elif CONFIG.ARCH == "arm64": - arch = "arm64" - else: - fail("native JS tools do not support architecture " + CONFIG.ARCH) - return CONFIG.OS + "-" + arch - - -def _pinned_archive(versions:dict, tool:str, version:str): - if version not in versions: - fail("No pinned " + tool + " release " + version + ". Known versions: " + - ", ".join(sorted(versions.keys()))) - platform = _native_platform() - pins = versions[version] - if platform not in pins: - fail("No pinned " + tool + " archive for " + platform) - return pins[platform] - - -def _download_verified(url:str, digest:str): - """Return a POSIX shell command that fails before extracting a bad archive.""" - return " && ".join([ - "curl -fsSL --retry 5 --retry-delay 2 -o tool.archive '" + url + "'", - "digest=$(if command -v sha256sum >/dev/null 2>&1; then sha256sum tool.archive | awk '{print $1}'; else openssl dgst -sha256 tool.archive | awk '{print $NF}'; fi)", - "{ [ \"$digest\" = '" + digest + "' ] || { echo 'bad SHA256 for " + url + "' >&2; exit 1; }; }", - ]) - - -def bun_toolchain(name:str, version:str="", visibility:list=["PUBLIC"]): - """Download a pinned Bun binary for the host platform. - - The x64 archives are Bun's baseline builds, which do not require AVX2. - Consumers use the `bun` entry point, e.g. `:bun|bun`. - """ - version = version or CONFIG.NODE.DEFAULT_BUN_VERSION - pin = _pinned_archive(BUN_VERSIONS, "Bun", version) - archive = pin[0] - digest = pin[1] - directory = archive[:-4] - url = "https://github.com/oven-sh/bun/releases/download/bun-v" + version + "/" + archive - return build_rule( - name = name, - outs = [name], - local = True, - sandbox = False, - cmd = " && ".join([ - _download_verified(url, digest), - "mkdir -p _archive $OUT", - "unzip -q tool.archive -d _archive", - "mv _archive/" + directory + "/bun $OUT/bun", - "chmod +x $OUT/bun", - "rm -f tool.archive", - ]), - entry_points = {"bun": name + "/bun"}, - binary = True, - visibility = visibility, - labels = ["bun:" + version], - building_description = "Installing Bun...", - ) - - -def oxlint_toolchain(name:str, version:str="", visibility:list=["PUBLIC"]): - """Download a pinned OXLint binary for the host platform. - - Consumers use the `oxlint` entry point, e.g. `:oxlint|oxlint`. - """ - version = version or CONFIG.NODE.DEFAULT_OXLINT_VERSION - pin = _pinned_archive(OXLINT_VERSIONS, "OXLint", version) - archive = pin[0] - digest = pin[1] - executable = archive[:-7] - url = "https://github.com/oxc-project/oxc/releases/download/oxlint_v" + version + "/" + archive - return build_rule( - name = name, - outs = [name], - local = True, - sandbox = False, - cmd = " && ".join([ - _download_verified(url, digest), - "mkdir -p _archive $OUT", - "tar -xzf tool.archive -C _archive", - "mv _archive/" + executable + " $OUT/oxlint", - "chmod +x $OUT/oxlint", - "rm -f tool.archive", - ]), - entry_points = {"oxlint": name + "/oxlint"}, - binary = True, - visibility = visibility, - labels = ["oxlint:" + version], - building_description = "Installing OXLint...", - ) diff --git a/build_defs/oxlint.build_defs b/build_defs/oxlint.build_defs new file mode 100644 index 0000000..8f6cf97 --- /dev/null +++ b/build_defs/oxlint.build_defs @@ -0,0 +1,61 @@ +"""Pinned OXLint distribution for Please actions.""" + +# SHA256 values are from the immutable oxlint_v1.91.0 GitHub release assets. +OXLINT_VERSIONS = { + "1.91.0": { + "darwin-arm64": ("oxlint-aarch64-apple-darwin.tar.gz", "d1f6037780a4d5e14a32d810083859ae691a5032f789381a5ff9b75f901f90e9"), + "darwin-x64": ("oxlint-x86_64-apple-darwin.tar.gz", "b422a6a5ffe753b117d7348a80e722ca35183ceb1b6c98766f0de14747727a26"), + "linux-arm64": ("oxlint-aarch64-unknown-linux-gnu.tar.gz", "c99c0e97edd40d5cd21840831d8eff2d4a5e84ce0cf73a6fdac58aaa9c1e1f20"), + "linux-x64": ("oxlint-x86_64-unknown-linux-gnu.tar.gz", "de059941526abeaab3c5aafa78caef80e5b4e7197274391d80cde38a1960a916"), + }, +} + + +def _oxlint_platform(): + if CONFIG.OS not in ["linux", "darwin"]: + fail("oxlint_toolchain supports linux and darwin only, not " + CONFIG.OS) + if CONFIG.ARCH == "amd64": + arch = "x64" + elif CONFIG.ARCH == "arm64": + arch = "arm64" + else: + fail("oxlint_toolchain does not support architecture " + CONFIG.ARCH) + return CONFIG.OS + "-" + arch + + +def oxlint_toolchain(name:str, version:str, visibility:list=["PUBLIC"]): + """Download verified OXLint and expose its native `oxlint` entry point. + + Usage: oxlint_toolchain(name = "oxlint", version = "1.91.0") + """ + if version not in OXLINT_VERSIONS: + fail("No pinned OXLint hashes for " + version + ". Known versions: " + + ", ".join(sorted(OXLINT_VERSIONS.keys()))) + platform = _oxlint_platform() + pin = OXLINT_VERSIONS[version][platform] + archive = pin[0] + hash = pin[1] + url = "https://github.com/oxc-project/oxc/releases/download/oxlint_v" + version + "/" + archive + executable = archive[:-7] + cmd = " && ".join([ + "curl -fsSL --retry 5 --retry-delay 2 -o oxlint.tar.gz '" + url + "'", + "digest=$(if command -v sha256sum >/dev/null 2>&1; then sha256sum oxlint.tar.gz | awk '{print $1}'; else openssl dgst -sha256 oxlint.tar.gz | awk '{print $NF}'; fi)", + "{ [ \"$digest\" = '" + hash + "' ] || { echo 'bad hash for " + url + "' >&2; exit 1; }; }", + "mkdir -p _archive $OUT", + "tar -xzf oxlint.tar.gz -C _archive", + "mv _archive/" + executable + " $OUT/oxlint", + "chmod +x $OUT/oxlint", + "rm -f oxlint.tar.gz", + ]) + return build_rule( + name = name, + outs = [name], + cmd = cmd, + entry_points = {"oxlint": name + "/oxlint"}, + binary = True, + local = True, + sandbox = False, + visibility = visibility, + labels = ["oxlint:" + version], + building_description = "Installing OXLint v" + version + "...", + ) diff --git a/third_party/bun/BUILD b/third_party/bun/BUILD index 90d0ce0..50b27de 100644 --- a/third_party/bun/BUILD +++ b/third_party/bun/BUILD @@ -1,5 +1,6 @@ -subinclude("//build_defs:native_tools") +subinclude("//build_defs:bun") bun_toolchain( name = "bun", + version = "1.4.4", ) diff --git a/third_party/oxlint/BUILD b/third_party/oxlint/BUILD index 2cf41c2..db24134 100644 --- a/third_party/oxlint/BUILD +++ b/third_party/oxlint/BUILD @@ -1,5 +1,6 @@ -subinclude("//build_defs:native_tools") +subinclude("//build_defs:oxlint") oxlint_toolchain( name = "oxlint", + version = "1.91.0", )