mirror of
https://github.com/tree-sitter/tree-sitter.git
synced 2026-09-09 23:26:20 -04:00
chore: remove Nix flake
Problem: The committed Nix flake is not used by the standard tooling in this repo and therefore bitrots freely, which increases maintenance burden on the (non-Nix-using) maintainers. We also don't maintain packaging for other distros in-repo. Solution: Drop the Nix files from the repo and (as follow-up) move the Nix packaging to an out-of-core project.
This commit is contained in:
parent
e5cbeb74eb
commit
527cfc460a
4
.envrc
4
.envrc
|
|
@ -1,4 +0,0 @@
|
|||
source_up_if_exists
|
||||
if [ -z "${IN_NIX_SHELL:-}" ]; then
|
||||
use flake .
|
||||
fi
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
{
|
||||
lib,
|
||||
src,
|
||||
rustPlatform,
|
||||
version,
|
||||
clang,
|
||||
libclang,
|
||||
cmake,
|
||||
pkg-config,
|
||||
nodejs_22,
|
||||
test-grammars,
|
||||
stdenv,
|
||||
installShellFiles,
|
||||
}:
|
||||
let
|
||||
canRunHost = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
|
||||
in
|
||||
rustPlatform.buildRustPackage {
|
||||
pname = "tree-sitter-cli";
|
||||
|
||||
inherit src version;
|
||||
|
||||
cargoBuildFlags = [ "--all-features" ];
|
||||
|
||||
nativeBuildInputs = [
|
||||
clang
|
||||
cmake
|
||||
pkg-config
|
||||
nodejs_22
|
||||
]
|
||||
++ lib.optionals canRunHost [ installShellFiles ];
|
||||
|
||||
cargoLock.lockFile = ../../Cargo.lock;
|
||||
|
||||
env.LIBCLANG_PATH = "${libclang.lib}/lib";
|
||||
|
||||
preBuild = ''
|
||||
rm -rf test/fixtures
|
||||
mkdir -p test/fixtures
|
||||
cp -r ${test-grammars}/fixtures/* test/fixtures/
|
||||
chmod -R u+w test/fixtures
|
||||
'';
|
||||
|
||||
preCheck = "export HOME=$TMPDIR";
|
||||
doCheck = canRunHost;
|
||||
|
||||
postInstall = lib.optionalString canRunHost ''
|
||||
installShellCompletion --cmd tree-sitter \
|
||||
--bash <($out/bin/tree-sitter complete --shell bash) \
|
||||
--zsh <($out/bin/tree-sitter complete --shell zsh) \
|
||||
--fish <($out/bin/tree-sitter complete --shell fish)
|
||||
'';
|
||||
|
||||
meta = {
|
||||
description = "Tree-sitter CLI - A tool for developing, testing, and using Tree-sitter parsers";
|
||||
longDescription = ''
|
||||
Tree-sitter is a parser generator tool and an incremental parsing library.
|
||||
It can build a concrete syntax tree for a source file and efficiently update
|
||||
the syntax tree as the source file is edited. This package provides the CLI
|
||||
tool for developing, testing, and using Tree-sitter parsers.
|
||||
'';
|
||||
homepage = "https://tree-sitter.github.io/tree-sitter";
|
||||
changelog = "https://github.com/tree-sitter/tree-sitter/releases/tag/v${version}";
|
||||
license = lib.licenses.mit;
|
||||
maintainers = with lib.maintainers; [ amaanq ];
|
||||
platforms = lib.platforms.all;
|
||||
mainProgram = "tree-sitter";
|
||||
};
|
||||
}
|
||||
|
|
@ -70,7 +70,6 @@ pub fn run(args: BumpVersion) -> Result<()> {
|
|||
update_crates(¤t_version, &next_version)?;
|
||||
update_makefile(&next_version)?;
|
||||
update_cmake(&next_version)?;
|
||||
update_nix(&next_version)?;
|
||||
update_npm(&next_version)?;
|
||||
update_zig(&next_version)?;
|
||||
tag_next_version(&next_version)?;
|
||||
|
|
@ -86,7 +85,6 @@ fn tag_next_version(next_version: &Version) -> Result<()> {
|
|||
"Cargo.toml",
|
||||
"Makefile",
|
||||
"build.zig.zon",
|
||||
"flake.nix",
|
||||
"crates/cli/Cargo.toml",
|
||||
"crates/cli/npm/package.json",
|
||||
"crates/cli/npm/package-lock.json",
|
||||
|
|
@ -170,26 +168,6 @@ fn update_cmake(next_version: &Version) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn update_nix(next_version: &Version) -> Result<()> {
|
||||
let nix = std::fs::read_to_string("flake.nix")?;
|
||||
let nix = nix
|
||||
.lines()
|
||||
.map(|line| {
|
||||
if line.trim_start().starts_with("version =") {
|
||||
format!(" version = \"{next_version}\";")
|
||||
} else {
|
||||
line.to_string()
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
+ "\n";
|
||||
|
||||
std::fs::write("flake.nix", nix)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_crates(current_version: &Version, next_version: &Version) -> Result<()> {
|
||||
let mut cmd = std::process::Command::new("cargo");
|
||||
cmd.arg("workspaces").arg("version");
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
{
|
||||
stdenv,
|
||||
lib,
|
||||
version,
|
||||
mdbook,
|
||||
}:
|
||||
stdenv.mkDerivation {
|
||||
inherit version;
|
||||
|
||||
src = ./.;
|
||||
pname = "tree-sitter-docs";
|
||||
|
||||
nativeBuildInputs = [ mdbook ];
|
||||
|
||||
buildPhase = ''
|
||||
mdbook build
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/share/doc
|
||||
cp -r book $out/share/doc/tree-sitter
|
||||
'';
|
||||
|
||||
meta = {
|
||||
description = "Tree-sitter documentation";
|
||||
homepage = "https://tree-sitter.github.io/tree-sitter";
|
||||
license = lib.licenses.mit;
|
||||
};
|
||||
}
|
||||
27
flake.lock
27
flake.lock
|
|
@ -1,27 +0,0 @@
|
|||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1788039129,
|
||||
"narHash": "sha256-pa4Q0qErvCvzCaaUph7Sm37RhR4xvPrYI8Lgz6k85+A=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "d2f67949798825fe853f7c5d0492b8bf016d3f88",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
436
flake.nix
436
flake.nix
|
|
@ -1,436 +0,0 @@
|
|||
{
|
||||
description = "Tree-sitter - A parser generator tool and an incremental parsing library";
|
||||
|
||||
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
|
||||
outputs =
|
||||
inputs:
|
||||
let
|
||||
inherit (inputs.nixpkgs) lib;
|
||||
inherit (inputs) self;
|
||||
systems = [
|
||||
"x86_64-linux"
|
||||
"aarch64-linux"
|
||||
"x86_64-darwin"
|
||||
"aarch64-darwin"
|
||||
];
|
||||
eachSystem = lib.genAttrs systems;
|
||||
pkgsFor = inputs.nixpkgs.legacyPackages;
|
||||
|
||||
version = "0.28.0";
|
||||
|
||||
fs = lib.fileset;
|
||||
src = fs.toSource {
|
||||
root = ./.;
|
||||
fileset = fs.difference (fs.gitTracked ./.) (
|
||||
fs.unions [
|
||||
./.envrc
|
||||
./flake.lock
|
||||
./FUNDING.json
|
||||
./README.md
|
||||
(fs.fileFilter (file: lib.strings.hasInfix ".git" file.name) ./.)
|
||||
(fs.fileFilter (file: file.hasExt "nix") ./.)
|
||||
]
|
||||
);
|
||||
};
|
||||
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 = {
|
||||
bash = "sha256-vRaN/mNfpR+hdv2HVS1bzaW0o+HGjizRFsk3iinICJE=";
|
||||
c = "sha256-gmzbdwvrKSo6C1fqTJFGxy8x0+T+vUTswm7F5sojzKc=";
|
||||
cpp = "sha256-tP5Tu747V8QMCEBYwOEmMQUm8OjojpJdlRmjcJTbe2k=";
|
||||
embedded-template = "sha256-nBQain0Lc21jOgQFfvkyq615ZmT8qdMxtqIoUcOcO3A=";
|
||||
go = "sha256-y7bTET8ypPczPnMVlCaiZuswcA7vFrDOc2jlbfVk5Sk=";
|
||||
html = "sha256-Pd5Me1twLGOrRB3pSMVX9M8VKenTK0896aoLznjNkGo=";
|
||||
java = "sha256-OvEO1BLZLjP3jt4gar18kiXderksFKO0WFXDQqGLRIY=";
|
||||
javascript = "sha256-2Jj/SUG+k8lHlGSuPZvHjJojvQFgDiZHZzH8xLu7suE=";
|
||||
jsdoc = "sha256-Azzb2zBjAfwbEmAEO1YqhpaxtzbXmRjfIzRla2Hx+24=";
|
||||
json = "sha256-DNZC2cTy1C8OaMOpEHM6NoRtOIbLaBf0CLXXWCKODlw=";
|
||||
php = "sha256-jI7yzcoHS/tNxUqJI4aD1rdEZV3jMn1GZD0J+81Dyf0=";
|
||||
python = "sha256-71Od4sUsxGEvTwmXX8hBvzqD55hnXkVJublrhp1GICg=";
|
||||
ruby = "sha256-iu3MVJl0Qr/Ba+aOttmEzMiVY6EouGi5wGOx5ofROzA=";
|
||||
rust = "sha256-y3sJURlSTM7LRRN5WGIAeslsdRZU522Tfcu6dnXH/XQ=";
|
||||
typescript = "sha256-CU55+YoFJb6zWbJnbd38B7iEGkhukSVpBN7sli6GkGY=";
|
||||
};
|
||||
|
||||
grammarSpecs = lib.listToAttrs (
|
||||
map (fixture: {
|
||||
name = lib.elemAt fixture 0;
|
||||
value = {
|
||||
rev = lib.elemAt fixture 1;
|
||||
sha256 = grammarHashes.${lib.elemAt fixture 0};
|
||||
};
|
||||
}) fixturesJson
|
||||
);
|
||||
filesWithExtension =
|
||||
ext:
|
||||
fs.toSource {
|
||||
root = ./.;
|
||||
fileset = fs.fileFilter (file: (file.hasExt ext) && file.type == "regular") ./.;
|
||||
};
|
||||
in
|
||||
{
|
||||
packages = eachSystem (
|
||||
system:
|
||||
let
|
||||
pkgs = pkgsFor.${system};
|
||||
crossTargets = {
|
||||
aarch64-linux = pkgs.pkgsCross.aarch64-multiplatform;
|
||||
armv7l-linux = pkgs.pkgsCross.armv7l-hf-multiplatform;
|
||||
x86_64-linux = pkgs.pkgsCross.gnu64;
|
||||
i686-linux = pkgs.pkgsCross.gnu32;
|
||||
loongarch64 = pkgs.pkgsCross.loongarch64-linux;
|
||||
mips = pkgs.pkgsCross.mips-linux-gnu;
|
||||
mips64 = pkgs.pkgsCross.mips64-linux-gnuabi64;
|
||||
musl64 = pkgs.pkgsCross.musl64;
|
||||
powerpc64-linux = pkgs.pkgsCross.ppc64;
|
||||
riscv32 = pkgs.pkgsCross.riscv32;
|
||||
riscv64 = pkgs.pkgsCross.riscv64;
|
||||
s390x = pkgs.pkgsCross.s390x;
|
||||
|
||||
x86_64-windows = pkgs.pkgsCross.mingwW64;
|
||||
}
|
||||
// (lib.optionalAttrs pkgs.stdenv.hostPlatform.isDarwin {
|
||||
x86_64-darwin = pkgs.pkgsCross.x86_64-darwin;
|
||||
aarch64-darwin = pkgs.pkgsCross.aarch64-darwin;
|
||||
});
|
||||
|
||||
# nixpkgs marks compiler-rt broken for riscv32
|
||||
cliCrossTargets = lib.removeAttrs crossTargets [ "riscv32" ];
|
||||
in
|
||||
{
|
||||
default = self.packages.${system}.cli;
|
||||
|
||||
docs = pkgs.callPackage ./docs/package.nix { inherit version; };
|
||||
|
||||
test-grammars =
|
||||
let
|
||||
fetchGrammar =
|
||||
name: rev: sha256:
|
||||
pkgs.fetchFromGitHub {
|
||||
owner = "tree-sitter";
|
||||
repo = "tree-sitter-${name}";
|
||||
inherit rev sha256;
|
||||
};
|
||||
|
||||
testGrammars = lib.mapAttrs (name: spec: fetchGrammar name spec.rev spec.sha256) grammarSpecs;
|
||||
in
|
||||
pkgs.stdenv.mkDerivation {
|
||||
inherit src version;
|
||||
|
||||
pname = "test-grammars";
|
||||
|
||||
buildPhase = ''
|
||||
mkdir -p test/fixtures/grammars
|
||||
${lib.concatMapStrings (name: ''
|
||||
cp -r ${testGrammars.${name}} test/fixtures/grammars/${name}
|
||||
'') (lib.attrNames testGrammars)}
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out
|
||||
cp -r test/fixtures $out/fixtures
|
||||
'';
|
||||
};
|
||||
|
||||
wasm-test-grammars = pkgs.callPackage ./lib/binding_web/wasm-test-grammars.nix {
|
||||
inherit src version;
|
||||
inherit (self.packages.${system}) cli test-grammars;
|
||||
wasi-sdk = wasiSdkFor pkgs;
|
||||
};
|
||||
|
||||
web-tree-sitter = pkgs.callPackage ./lib/binding_web/package.nix {
|
||||
inherit src version npmDepsHash;
|
||||
inherit (self.packages.${system}) wasm-test-grammars;
|
||||
};
|
||||
|
||||
lib = pkgs.callPackage ./lib/package.nix {
|
||||
inherit src version;
|
||||
};
|
||||
|
||||
cli = pkgs.callPackage ./crates/cli/package.nix {
|
||||
inherit src version;
|
||||
inherit (self.packages.${system}) test-grammars;
|
||||
};
|
||||
}
|
||||
// (lib.mapAttrs' (arch: pkg: {
|
||||
name = "cli-${arch}";
|
||||
value = pkg.callPackage ./crates/cli/package.nix {
|
||||
inherit src version;
|
||||
inherit (self.packages.${system}) test-grammars;
|
||||
};
|
||||
}) cliCrossTargets)
|
||||
// (lib.mapAttrs' (arch: pkg: {
|
||||
name = "lib-${arch}";
|
||||
value = pkg.callPackage ./lib/package.nix {
|
||||
inherit src version;
|
||||
};
|
||||
}) crossTargets)
|
||||
);
|
||||
|
||||
apps = eachSystem (
|
||||
system:
|
||||
let
|
||||
pkgs = pkgsFor.${system};
|
||||
in
|
||||
{
|
||||
default = self.apps.${system}.cli;
|
||||
|
||||
cli = {
|
||||
type = "app";
|
||||
program = "${lib.getExe self.packages.${system}.cli}";
|
||||
meta.description = "Tree-sitter CLI for developing, testing, and using parsers";
|
||||
};
|
||||
|
||||
docs = {
|
||||
type = "app";
|
||||
program = lib.getExe (
|
||||
pkgs.writeShellScriptBin "docs" ''
|
||||
echo "📚 Serving documentation at http://localhost:3000"
|
||||
cd docs && ${lib.getExe pkgs.mdbook} serve
|
||||
''
|
||||
);
|
||||
meta.description = "Serve Tree-sitter documentation locally";
|
||||
};
|
||||
|
||||
format = {
|
||||
type = "app";
|
||||
program = lib.getExe (
|
||||
pkgs.writeShellScriptBin "format-all" ''
|
||||
set -e
|
||||
echo "Formatting..."
|
||||
echo ""
|
||||
echo "→ Rust..."
|
||||
${lib.getExe pkgs.cargo} fmt --all
|
||||
echo "→ Nix..."
|
||||
find . -name '*.nix' -exec ${lib.getExe pkgs.nixfmt} {} +
|
||||
echo "→ Web (TypeScript/JavaScript)..."
|
||||
cd lib/binding_web && ${pkgs.nodejs_22}/bin/npm install --silent && ${pkgs.nodejs_22}/bin/npm run lint:fix
|
||||
cd ../..
|
||||
echo ""
|
||||
echo "Formatting complete"
|
||||
''
|
||||
);
|
||||
meta.description = "Format all Rust and Nix code";
|
||||
};
|
||||
|
||||
lint = {
|
||||
type = "app";
|
||||
program = lib.getExe (
|
||||
pkgs.writeShellScriptBin "lint-all" ''
|
||||
set -e
|
||||
echo "Linting code..."
|
||||
echo ""
|
||||
echo "→ Checking Rust formatting..."
|
||||
${lib.getExe pkgs.cargo} fmt --all --check
|
||||
echo "→ Running clippy..."
|
||||
${lib.getExe pkgs.cargo} clippy --workspace --all-targets -- -D warnings
|
||||
echo "→ Checking Nix formatting..."
|
||||
find . -name '*.nix' -exec ${lib.getExe pkgs.nixfmt} --check {} +
|
||||
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 ../..
|
||||
echo ""
|
||||
echo "Linting complete"
|
||||
''
|
||||
);
|
||||
meta.description = "Run all linting checks";
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
checks = eachSystem (
|
||||
system:
|
||||
let
|
||||
pkgs = pkgsFor.${system};
|
||||
in
|
||||
{
|
||||
inherit (self.packages.${system})
|
||||
cli
|
||||
lib
|
||||
web-tree-sitter
|
||||
;
|
||||
|
||||
nix-fmt = pkgs.runCommand "nix-fmt-check" { } ''
|
||||
find ${filesWithExtension "nix"} -name '*.nix' \
|
||||
-exec ${lib.getExe self.formatter.${system}} --check {} +
|
||||
touch $out
|
||||
'';
|
||||
rust-fmt =
|
||||
pkgs.runCommand "rust-fmt-check"
|
||||
{
|
||||
nativeBuildInputs = with pkgs; [
|
||||
cargo
|
||||
rustfmt
|
||||
];
|
||||
}
|
||||
''
|
||||
export HOME=$TMPDIR
|
||||
cd ${src}
|
||||
cargo fmt --all --check
|
||||
touch $out
|
||||
'';
|
||||
|
||||
rust-clippy = pkgs.rustPlatform.buildRustPackage {
|
||||
inherit src version;
|
||||
|
||||
pname = "rust-clippy-check";
|
||||
|
||||
cargoLock.lockFile = ./Cargo.lock;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
pkg-config
|
||||
clippy
|
||||
cmake
|
||||
clang
|
||||
libclang
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
export HOME=$TMPDIR
|
||||
export LIBCLANG_PATH="${pkgs.libclang.lib}/lib"
|
||||
cargo xtask clippy
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
touch $out
|
||||
'';
|
||||
|
||||
doCheck = false;
|
||||
};
|
||||
|
||||
web-lint = pkgs.buildNpmPackage {
|
||||
inherit src version npmDepsHash;
|
||||
|
||||
pname = "web-tree-sitter-lint";
|
||||
|
||||
postPatch = ''
|
||||
cp lib/binding_web/package{,-lock}.json .
|
||||
'';
|
||||
|
||||
buildPhase = ''
|
||||
cd lib/binding_web
|
||||
npm run lint
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
touch $out
|
||||
'';
|
||||
|
||||
meta.description = "Lint check for web-tree-sitter TypeScript/JavaScript code";
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
formatter = eachSystem (system: pkgsFor.${system}.nixfmt);
|
||||
|
||||
devShells = eachSystem (
|
||||
system:
|
||||
let
|
||||
pkgs = pkgsFor.${system};
|
||||
in
|
||||
{
|
||||
default = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
cargo
|
||||
rustc
|
||||
clippy
|
||||
rust-analyzer
|
||||
rustfmt
|
||||
cargo-llvm-cov
|
||||
|
||||
cmake
|
||||
gnumake
|
||||
pkg-config
|
||||
llvm
|
||||
clang
|
||||
clang-tools
|
||||
libclang
|
||||
|
||||
nodejs_22
|
||||
typescript
|
||||
emscripten
|
||||
binaryen
|
||||
lld
|
||||
pkgsCross.wasi32.stdenv.cc
|
||||
|
||||
mdbook
|
||||
mdbook-admonish
|
||||
|
||||
git
|
||||
nixfmt
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
export PATH="${pkgs.clang-tools}/bin:$PATH"
|
||||
echo "Tree-sitter Dev Environment"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo ""
|
||||
echo "Packages:"
|
||||
echo " nix build .#cli - Build CLI tool"
|
||||
echo " nix build .#lib - Build C library"
|
||||
echo " nix build .#web-tree-sitter - Build WASM bindings"
|
||||
echo " nix build .#docs - Build documentation"
|
||||
echo ""
|
||||
echo "Cross-compilation:"
|
||||
echo " Build for other platforms using .#cli-<target> for the CLI,"
|
||||
echo " and .#lib-<target> for the library (e.g. nix build .#cli-aarch64-linux)."
|
||||
echo ""
|
||||
echo " Available targets:"
|
||||
echo " aarch64-linux - ARM64 Linux"
|
||||
echo " armv7l-linux - ARMv7 Linux"
|
||||
echo " x86_64-linux - x86_64 Linux"
|
||||
echo " i686-linux - i686 Linux"
|
||||
echo " loongarch64 - LoongArch64 Linux"
|
||||
echo " mips - MIPS Linux"
|
||||
echo " mips64 - MIPS64 Linux"
|
||||
echo " musl64 - x86_64 MUSL Linux"
|
||||
echo " powerpc64-linux - PowerPC64 Linux"
|
||||
echo " riscv32 - RISC-V 32-bit Linux"
|
||||
echo " riscv64 - RISC-V 64-bit Linux"
|
||||
echo " s390x - s390x Linux"
|
||||
echo " x86_64-windows - x86_64 Windows"
|
||||
echo " x86_64-darwin - x86_64 macOS (Darwin only)"
|
||||
echo " aarch64-darwin - ARM64 macOS (Darwin only)"
|
||||
echo ""
|
||||
echo "Apps:"
|
||||
echo " nix run .#cli - Run tree-sitter CLI"
|
||||
echo " nix run .#docs - Serve docs locally"
|
||||
echo " nix run .#format - Format all code"
|
||||
echo " nix run .#lint - Run all linting checks"
|
||||
echo ""
|
||||
echo "Tests & Checks:"
|
||||
echo " nix flake check - Run all tests and checks"
|
||||
echo ""
|
||||
echo "Version: ${version}"
|
||||
'';
|
||||
|
||||
env = {
|
||||
RUST_BACKTRACE = 1;
|
||||
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
|
||||
LLVM_COV = "${pkgs.llvm}/bin/llvm-cov";
|
||||
LLVM_PROFDATA = "${pkgs.llvm}/bin/llvm-profdata";
|
||||
TREE_SITTER_WASI_SDK_PATH = "${wasiSdkFor pkgs}";
|
||||
TREE_SITTER_BINARYEN_PATH = "${pkgs.binaryen}";
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
{
|
||||
wasm-test-grammars,
|
||||
lib,
|
||||
buildNpmPackage,
|
||||
rustPlatform,
|
||||
cargo,
|
||||
pkg-config,
|
||||
emscripten,
|
||||
src,
|
||||
version,
|
||||
npmDepsHash,
|
||||
}:
|
||||
buildNpmPackage {
|
||||
inherit src version npmDepsHash;
|
||||
|
||||
pname = "web-tree-sitter";
|
||||
|
||||
nativeBuildInputs = [
|
||||
rustPlatform.cargoSetupHook
|
||||
cargo
|
||||
pkg-config
|
||||
emscripten
|
||||
];
|
||||
|
||||
cargoDeps = rustPlatform.importCargoLock {
|
||||
lockFile = ../../Cargo.lock;
|
||||
};
|
||||
|
||||
# emscripten is super behind here compared to nixpkgs upstream
|
||||
doCheck = false;
|
||||
|
||||
postPatch = ''
|
||||
cp lib/binding_web/package{,-lock}.json .
|
||||
cp LICENSE lib/binding_web/
|
||||
'';
|
||||
|
||||
buildPhase = ''
|
||||
pushd lib/binding_web
|
||||
|
||||
CJS=true npm run build
|
||||
CJS=true npm run build:debug
|
||||
npm run build:debug
|
||||
npm run build
|
||||
|
||||
popd
|
||||
|
||||
mkdir -p target/release
|
||||
|
||||
for grammar in ${wasm-test-grammars}/*.wasm; do
|
||||
if [ -f "$grammar" ]; then
|
||||
cp "$grammar" target/release/
|
||||
fi
|
||||
done
|
||||
'';
|
||||
|
||||
checkPhase = ''
|
||||
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 = {
|
||||
description = "WebAssembly bindings to the Tree-sitter parsing library.";
|
||||
longDescription = ''
|
||||
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
|
||||
the syntax tree as the source file is edited. This package provides the WebAssembly bindings
|
||||
and a JavaScript API for using them in web browsers
|
||||
'';
|
||||
homepage = "https://tree-sitter.github.io/tree-sitter";
|
||||
changelog = "https://github.com/tree-sitter/tree-sitter/releases/tag/v${version}";
|
||||
license = lib.licenses.mit;
|
||||
maintainers = with lib.maintainers; [ amaanq ];
|
||||
platforms = lib.platforms.all;
|
||||
};
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
{
|
||||
binaryen,
|
||||
cli,
|
||||
lib,
|
||||
lld,
|
||||
nodejs_22,
|
||||
src,
|
||||
stdenv,
|
||||
test-grammars,
|
||||
version,
|
||||
wasi-sdk,
|
||||
}:
|
||||
let
|
||||
grammars = [
|
||||
"bash"
|
||||
"c"
|
||||
"cpp"
|
||||
"embedded-template"
|
||||
"html"
|
||||
"javascript"
|
||||
"json"
|
||||
"python"
|
||||
"rust"
|
||||
"typescript"
|
||||
];
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
inherit src version;
|
||||
|
||||
pname = "wasm-test-grammars";
|
||||
|
||||
nativeBuildInputs = [
|
||||
binaryen
|
||||
cli
|
||||
lld
|
||||
nodejs_22
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
export HOME=$TMPDIR
|
||||
export TREE_SITTER_WASI_SDK_PATH=${wasi-sdk}
|
||||
export TREE_SITTER_BINARYEN_PATH=${binaryen}
|
||||
export NIX_LDFLAGS=""
|
||||
|
||||
cp -r ${test-grammars}/fixtures .
|
||||
chmod -R u+w fixtures
|
||||
|
||||
for grammar in ${lib.concatStringsSep " " grammars}; do
|
||||
if [ -d "fixtures/grammars/$grammar" ]; then
|
||||
echo "Building WASM for $grammar"
|
||||
|
||||
if [ "$grammar" = "typescript" ]; then
|
||||
tree-sitter build --wasm -o "tree-sitter-typescript.wasm" "fixtures/grammars/$grammar/typescript"
|
||||
tree-sitter build --wasm -o "tree-sitter-tsx.wasm" "fixtures/grammars/$grammar/tsx"
|
||||
else
|
||||
tree-sitter build --wasm -o "tree-sitter-$grammar.wasm" "fixtures/grammars/$grammar"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out
|
||||
for wasm in *.wasm; do
|
||||
if [ -f "$wasm" ]; then
|
||||
echo "Installing $wasm"
|
||||
cp "$wasm" $out/
|
||||
fi
|
||||
done
|
||||
'';
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
{
|
||||
stdenv,
|
||||
cmake,
|
||||
pkg-config,
|
||||
src,
|
||||
version,
|
||||
lib,
|
||||
}:
|
||||
stdenv.mkDerivation {
|
||||
inherit src version;
|
||||
pname = "tree-sitter";
|
||||
|
||||
nativeBuildInputs = [
|
||||
cmake
|
||||
pkg-config
|
||||
];
|
||||
|
||||
sourceRoot = "source";
|
||||
|
||||
cmakeFlags = [
|
||||
"-DBUILD_SHARED_LIBS=ON"
|
||||
"-DCMAKE_INSTALL_LIBDIR=lib"
|
||||
"-DCMAKE_INSTALL_INCLUDEDIR=include"
|
||||
"-DTREE_SITTER_FEATURE_WASM=OFF"
|
||||
];
|
||||
|
||||
enableParallelBuilding = true;
|
||||
|
||||
postInstall = ''
|
||||
mkdir -p $out/{lib/pkgconfig,share/tree-sitter}
|
||||
substituteInPlace $out/lib/pkgconfig/tree-sitter.pc \
|
||||
--replace-fail "\''${prefix}" "$out" 2>/dev/null
|
||||
'';
|
||||
|
||||
meta = {
|
||||
description = "Tree-sitter incremental parsing library";
|
||||
longDescription = ''
|
||||
Tree-sitter is a parser generator tool and an incremental parsing library.
|
||||
It can build a concrete syntax tree for a source file and efficiently update
|
||||
the syntax tree as the source file is edited. This package provides the core
|
||||
C library that can be used to parse source code using Tree-sitter grammars.
|
||||
'';
|
||||
homepage = "https://tree-sitter.github.io/tree-sitter";
|
||||
changelog = "https://github.com/tree-sitter/tree-sitter/releases/tag/v${version}";
|
||||
license = lib.licenses.mit;
|
||||
maintainers = [ lib.maintainers.amaanq ];
|
||||
platforms = lib.platforms.all;
|
||||
};
|
||||
}
|
||||
Loading…
Reference in a new issue