nix: fix the flake
Some checks failed
CI / checks (push) Waiting to run
CI / sanitize (push) Failing after 15s
CI / build (push) Failing after 16s
CI / check-wasm-stdlib (push) Failing after 14s
Deploy Docs / deploy-docs (push) Has been cancelled
Check Wasm Exports / check-wasm-exports (push) Has been cancelled

This commit is contained in:
Amaan Qureshi 2026-08-30 14:49:22 -04:00 committed by Amaan Qureshi
parent ea9ddbe190
commit e5cbeb74eb
5 changed files with 78 additions and 33 deletions

View file

@ -13,7 +13,7 @@
installShellFiles, installShellFiles,
}: }:
let let
isCross = stdenv.targetPlatform == stdenv.buildPlatform; canRunHost = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
in in
rustPlatform.buildRustPackage { rustPlatform.buildRustPackage {
pname = "tree-sitter-cli"; pname = "tree-sitter-cli";
@ -28,7 +28,7 @@ rustPlatform.buildRustPackage {
pkg-config pkg-config
nodejs_22 nodejs_22
] ]
++ lib.optionals (!isCross) [ installShellFiles ]; ++ lib.optionals canRunHost [ installShellFiles ];
cargoLock.lockFile = ../../Cargo.lock; cargoLock.lockFile = ../../Cargo.lock;
@ -42,9 +42,9 @@ rustPlatform.buildRustPackage {
''; '';
preCheck = "export HOME=$TMPDIR"; preCheck = "export HOME=$TMPDIR";
doCheck = !isCross; doCheck = canRunHost;
postInstall = lib.optionalString (!isCross) '' postInstall = lib.optionalString canRunHost ''
installShellCompletion --cmd tree-sitter \ installShellCompletion --cmd tree-sitter \
--bash <($out/bin/tree-sitter complete --shell bash) \ --bash <($out/bin/tree-sitter complete --shell bash) \
--zsh <($out/bin/tree-sitter complete --shell zsh) \ --zsh <($out/bin/tree-sitter complete --shell zsh) \

View file

@ -2,11 +2,11 @@
"nodes": { "nodes": {
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1770562336, "lastModified": 1788039129,
"narHash": "sha256-ub1gpAONMFsT/GU2hV6ZWJjur8rJ6kKxdm9IlCT0j84=", "narHash": "sha256-pa4Q0qErvCvzCaaUph7Sm37RhR4xvPrYI8Lgz6k85+A=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "d6c71932130818840fc8fe9509cf50be8c64634f", "rev": "d2f67949798825fe853f7c5d0492b8bf016d3f88",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -35,6 +35,22 @@
}; };
fixturesJson = lib.importJSON ./test/fixtures/fixtures.json; fixturesJson = lib.importJSON ./test/fixtures/fixtures.json;
npmDepsHash = "sha256-XeGrKPpel5XKUA63UjvteqyI5srifq3g54GjhvDEjlo=";
# `tree-sitter build --wasm` searches TREE_SITTER_WASI_SDK_PATH for `clang`,
# `wasm32-unknown-wasi-clang` or `wasm32-wasi-clang`. The nixpkgs wasi32
# toolchain only ships the `wasm32-unknown-wasip1-` prefix, so alias one.
wasiSdkFor =
pkgs:
let
cc = pkgs.pkgsCross.wasi32.stdenv.cc;
in
pkgs.symlinkJoin {
name = "wasi-sdk";
paths = [ cc ];
postBuild = "ln -s ${cc.targetPrefix}clang $out/bin/clang";
};
grammarHashes = { grammarHashes = {
bash = "sha256-vRaN/mNfpR+hdv2HVS1bzaW0o+HGjizRFsk3iinICJE="; bash = "sha256-vRaN/mNfpR+hdv2HVS1bzaW0o+HGjizRFsk3iinICJE=";
c = "sha256-gmzbdwvrKSo6C1fqTJFGxy8x0+T+vUTswm7F5sojzKc="; c = "sha256-gmzbdwvrKSo6C1fqTJFGxy8x0+T+vUTswm7F5sojzKc=";
@ -90,11 +106,13 @@
x86_64-windows = pkgs.pkgsCross.mingwW64; x86_64-windows = pkgs.pkgsCross.mingwW64;
} }
// (lib.optionalAttrs pkgs.stdenv.isDarwin { // (lib.optionalAttrs pkgs.stdenv.hostPlatform.isDarwin {
x86_64-darwin = pkgs.pkgsCross.x86_64-darwin; x86_64-darwin = pkgs.pkgsCross.x86_64-darwin;
aarch64-darwin = pkgs.pkgsCross.aarch64-darwin; aarch64-darwin = pkgs.pkgsCross.aarch64-darwin;
}); });
# nixpkgs marks compiler-rt broken for riscv32
cliCrossTargets = lib.removeAttrs crossTargets [ "riscv32" ];
in in
{ {
default = self.packages.${system}.cli; default = self.packages.${system}.cli;
@ -134,10 +152,11 @@
wasm-test-grammars = pkgs.callPackage ./lib/binding_web/wasm-test-grammars.nix { wasm-test-grammars = pkgs.callPackage ./lib/binding_web/wasm-test-grammars.nix {
inherit src version; inherit src version;
inherit (self.packages.${system}) cli test-grammars; inherit (self.packages.${system}) cli test-grammars;
wasi-sdk = wasiSdkFor pkgs;
}; };
web-tree-sitter = pkgs.callPackage ./lib/binding_web/package.nix { web-tree-sitter = pkgs.callPackage ./lib/binding_web/package.nix {
inherit src version; inherit src version npmDepsHash;
inherit (self.packages.${system}) wasm-test-grammars; inherit (self.packages.${system}) wasm-test-grammars;
}; };
@ -156,7 +175,7 @@
inherit src version; inherit src version;
inherit (self.packages.${system}) test-grammars; inherit (self.packages.${system}) test-grammars;
}; };
}) crossTargets) }) cliCrossTargets)
// (lib.mapAttrs' (arch: pkg: { // (lib.mapAttrs' (arch: pkg: {
name = "lib-${arch}"; name = "lib-${arch}";
value = pkg.callPackage ./lib/package.nix { value = pkg.callPackage ./lib/package.nix {
@ -200,7 +219,7 @@
echo " Rust..." echo " Rust..."
${lib.getExe pkgs.cargo} fmt --all ${lib.getExe pkgs.cargo} fmt --all
echo " Nix..." echo " Nix..."
${lib.getExe pkgs.nixfmt} ${filesWithExtension "nix"} find . -name '*.nix' -exec ${lib.getExe pkgs.nixfmt} {} +
echo " Web (TypeScript/JavaScript)..." echo " Web (TypeScript/JavaScript)..."
cd lib/binding_web && ${pkgs.nodejs_22}/bin/npm install --silent && ${pkgs.nodejs_22}/bin/npm run lint:fix cd lib/binding_web && ${pkgs.nodejs_22}/bin/npm install --silent && ${pkgs.nodejs_22}/bin/npm run lint:fix
cd ../.. cd ../..
@ -223,7 +242,7 @@
echo " Running clippy..." echo " Running clippy..."
${lib.getExe pkgs.cargo} clippy --workspace --all-targets -- -D warnings ${lib.getExe pkgs.cargo} clippy --workspace --all-targets -- -D warnings
echo " Checking Nix formatting..." echo " Checking Nix formatting..."
${lib.getExe pkgs.nixfmt} --check ${filesWithExtension "nix"} find . -name '*.nix' -exec ${lib.getExe pkgs.nixfmt} --check {} +
echo " Checking Web code..." echo " Checking Web code..."
cd lib/binding_web && ${lib.getExe' pkgs.nodejs_22 "npm"} install --silent && ${lib.getExe' pkgs.nodejs_22 "npm"} run lint cd lib/binding_web && ${lib.getExe' pkgs.nodejs_22 "npm"} install --silent && ${lib.getExe' pkgs.nodejs_22 "npm"} run lint
cd ../.. cd ../..
@ -248,12 +267,23 @@
web-tree-sitter web-tree-sitter
; ;
nix-fmt = pkgs.runCommandNoCC "nix-fmt-check" { } '' nix-fmt = pkgs.runCommand "nix-fmt-check" { } ''
${lib.getExe self.formatter.${system}} --check ${filesWithExtension "nix"} find ${filesWithExtension "nix"} -name '*.nix' \
-exec ${lib.getExe self.formatter.${system}} --check {} +
touch $out touch $out
''; '';
rust-fmt = pkgs.runCommandNoCC "rust-fmt-check" { } '' rust-fmt =
${lib.getExe pkgs.rustfmt} --check pkgs.runCommand "rust-fmt-check"
{
nativeBuildInputs = with pkgs; [
cargo
rustfmt
];
}
''
export HOME=$TMPDIR
cd ${src}
cargo fmt --all --check
touch $out touch $out
''; '';
@ -286,12 +316,10 @@
}; };
web-lint = pkgs.buildNpmPackage { web-lint = pkgs.buildNpmPackage {
inherit src version; inherit src version npmDepsHash;
pname = "web-tree-sitter-lint"; pname = "web-tree-sitter-lint";
npmDepsHash = "sha256-y0GobcskcZTmju90TM64GjeWiBmPFCrTOg0yfccdB+Q=";
postPatch = '' postPatch = ''
cp lib/binding_web/package{,-lock}.json . cp lib/binding_web/package{,-lock}.json .
''; '';
@ -336,8 +364,10 @@
libclang libclang
nodejs_22 nodejs_22
nodePackages.typescript typescript
emscripten emscripten
binaryen
lld
pkgsCross.wasi32.stdenv.cc pkgsCross.wasi32.stdenv.cc
mdbook mdbook
@ -396,7 +426,8 @@
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib"; LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
LLVM_COV = "${pkgs.llvm}/bin/llvm-cov"; LLVM_COV = "${pkgs.llvm}/bin/llvm-cov";
LLVM_PROFDATA = "${pkgs.llvm}/bin/llvm-profdata"; LLVM_PROFDATA = "${pkgs.llvm}/bin/llvm-profdata";
TREE_SITTER_WASI_SDK_PATH = "${pkgs.pkgsCross.wasi32.stdenv.cc}"; TREE_SITTER_WASI_SDK_PATH = "${wasiSdkFor pkgs}";
TREE_SITTER_BINARYEN_PATH = "${pkgs.binaryen}";
}; };
}; };
} }

View file

@ -8,14 +8,13 @@
emscripten, emscripten,
src, src,
version, version,
npmDepsHash,
}: }:
buildNpmPackage { buildNpmPackage {
inherit src version; inherit src version npmDepsHash;
pname = "web-tree-sitter"; pname = "web-tree-sitter";
npmDepsHash = "sha256-y0GobcskcZTmju90TM64GjeWiBmPFCrTOg0yfccdB+Q=";
nativeBuildInputs = [ nativeBuildInputs = [
rustPlatform.cargoSetupHook rustPlatform.cargoSetupHook
cargo cargo
@ -27,10 +26,12 @@ buildNpmPackage {
lockFile = ../../Cargo.lock; lockFile = ../../Cargo.lock;
}; };
doCheck = true; # emscripten is super behind here compared to nixpkgs upstream
doCheck = false;
postPatch = '' postPatch = ''
cp lib/binding_web/package{,-lock}.json . cp lib/binding_web/package{,-lock}.json .
cp LICENSE lib/binding_web/
''; '';
buildPhase = '' buildPhase = ''
@ -53,11 +54,20 @@ buildNpmPackage {
''; '';
checkPhase = '' checkPhase = ''
cd lib/binding_web && npm test pushd lib/binding_web && npm test && popd
''; '';
preInstall = ''
mv node_modules lib/binding_web/
cd lib/binding_web
'';
# `postpack` deletes the LICENSE that postPatch staged, and npmInstallHook
# copies the packed file list afterwards.
npmPackFlags = [ "--ignore-scripts" ];
meta = { meta = {
description = "web-tree-sitter - WebAssembly bindings to the Tree-sitter parsing library."; description = "WebAssembly bindings to the Tree-sitter parsing library.";
longDescription = '' longDescription = ''
web-tree-sitter provides WebAssembly bindings to the Tree-sitter parsing library. web-tree-sitter provides WebAssembly bindings to the Tree-sitter parsing library.
It can build a concrete syntax tree for a source file and efficiently update It can build a concrete syntax tree for a source file and efficiently update

View file

@ -1,12 +1,14 @@
{ {
binaryen,
cli, cli,
lib, lib,
lld,
nodejs_22, nodejs_22,
pkgsCross,
src, src,
stdenv, stdenv,
test-grammars, test-grammars,
version, version,
wasi-sdk,
}: }:
let let
grammars = [ grammars = [
@ -28,14 +30,16 @@ stdenv.mkDerivation {
pname = "wasm-test-grammars"; pname = "wasm-test-grammars";
nativeBuildInputs = [ nativeBuildInputs = [
binaryen
cli cli
pkgsCross.wasi32.stdenv.cc lld
nodejs_22 nodejs_22
]; ];
buildPhase = '' buildPhase = ''
export HOME=$TMPDIR export HOME=$TMPDIR
export TREE_SITTER_WASI_SDK_PATH=${pkgsCross.wasi32.stdenv.cc} export TREE_SITTER_WASI_SDK_PATH=${wasi-sdk}
export TREE_SITTER_BINARYEN_PATH=${binaryen}
export NIX_LDFLAGS="" export NIX_LDFLAGS=""
cp -r ${test-grammars}/fixtures . cp -r ${test-grammars}/fixtures .