refactor: rework nix flake
Co-authored-by: Amaan Qureshi <amaanq12@gmail.com>
This commit is contained in:
parent
e9e4316569
commit
e4e643086b
12 changed files with 569 additions and 655 deletions
|
|
@ -1,115 +0,0 @@
|
|||
{
|
||||
perSystem =
|
||||
{
|
||||
self',
|
||||
pkgs,
|
||||
lib,
|
||||
src,
|
||||
version,
|
||||
crossTargets,
|
||||
...
|
||||
}:
|
||||
let
|
||||
buildCliFor =
|
||||
targetPkgs:
|
||||
let
|
||||
isCross = targetPkgs.stdenv.hostPlatform != pkgs.stdenv.buildPlatform;
|
||||
in
|
||||
targetPkgs.rustPlatform.buildRustPackage {
|
||||
inherit src version;
|
||||
pname = "tree-sitter-cli";
|
||||
|
||||
nativeBuildInputs = [
|
||||
pkgs.pkg-config
|
||||
pkgs.nodejs_22
|
||||
]
|
||||
++ lib.optionals (!isCross) [ pkgs.installShellFiles ];
|
||||
|
||||
cargoLock.lockFile = ../../Cargo.lock;
|
||||
|
||||
preBuild = ''
|
||||
rm -rf test/fixtures
|
||||
mkdir -p test/fixtures
|
||||
cp -r ${self'.packages.test-grammars}/fixtures/* test/fixtures/
|
||||
chmod -R u+w test/fixtures
|
||||
'';
|
||||
|
||||
preCheck = "export HOME=$TMPDIR";
|
||||
doCheck = !isCross;
|
||||
|
||||
postInstall = lib.optionalString (!isCross) ''
|
||||
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 = with lib; {
|
||||
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 = licenses.mit;
|
||||
maintainers = [ maintainers.amaanq ];
|
||||
platforms = platforms.all;
|
||||
mainProgram = "tree-sitter";
|
||||
};
|
||||
};
|
||||
|
||||
crossPackages = lib.mapAttrs (name: targetPkgs: buildCliFor targetPkgs) crossTargets;
|
||||
in
|
||||
{
|
||||
packages = {
|
||||
cli = buildCliFor pkgs;
|
||||
}
|
||||
// (lib.mapAttrs' (name: pkg: lib.nameValuePair "cli-${name}" pkg) crossPackages)
|
||||
// {
|
||||
rust-fmt =
|
||||
pkgs.runCommand "rust-fmt-check"
|
||||
{
|
||||
nativeBuildInputs = [
|
||||
pkgs.cargo
|
||||
pkgs.rustfmt
|
||||
];
|
||||
}
|
||||
''
|
||||
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 = [
|
||||
pkgs.pkg-config
|
||||
pkgs.clippy
|
||||
pkgs.cmake
|
||||
pkgs.clang
|
||||
pkgs.libclang
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
export HOME=$TMPDIR
|
||||
export LIBCLANG_PATH="${pkgs.libclang.lib}/lib"
|
||||
cargo xtask clippy
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
touch $out
|
||||
'';
|
||||
|
||||
doCheck = false;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
60
crates/cli/package.nix
Normal file
60
crates/cli/package.nix
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
{
|
||||
lib,
|
||||
src,
|
||||
rustPlatform,
|
||||
version,
|
||||
pkg-config,
|
||||
nodejs_22,
|
||||
test-grammars,
|
||||
stdenv,
|
||||
installShellFiles,
|
||||
}:
|
||||
let
|
||||
isCross = stdenv.targetPlatform == stdenv.buildPlatform;
|
||||
in
|
||||
rustPlatform.buildRustPackage {
|
||||
pname = "tree-sitter-cli";
|
||||
|
||||
inherit src version;
|
||||
|
||||
nativeBuildInputs = [
|
||||
pkg-config
|
||||
nodejs_22
|
||||
]
|
||||
++ lib.optionals (!isCross) [ installShellFiles ];
|
||||
|
||||
cargoLock.lockFile = ../../Cargo.lock;
|
||||
|
||||
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 = !isCross;
|
||||
|
||||
postInstall = lib.optionalString (!isCross) ''
|
||||
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";
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue