Skip to content

Commit

Permalink
fix: use luarocks-build-treesitter-parser-cpp build backend
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Aug 11, 2024
1 parent aa1a1a7 commit 4d75efc
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 65 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake . -Lv
6 changes: 5 additions & 1 deletion .github/rockspec.template
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ dependencies = $dependencies

test_dependencies = $test_dependencies

build_dependencies = {
'luarocks-build-treesitter-parser-cpp',
}

source = {
url = repo_url .. '/archive/' .. git_ref .. '.zip',
dir = '$repo_name-' .. '$archive_dir_suffix',
Expand All @@ -32,7 +36,7 @@ if modrev == 'scm' or modrev == 'dev' then
end

build = {
type = "treesitter-parser",
type = "treesitter-parser-cpp",
lang = "norg",
sources = { "src/parser.c", "src/scanner.cc" },
copy_directories = $copy_directories,
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/luarocks.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Push to Luarocks

on:
release:
types:
- created
push:
release:
types:
- created
tags:
- '*'
workflow_dispatch:
Expand All @@ -28,11 +28,11 @@ jobs:
luaVersion: "5.1"
- name: Install Luarocks
uses: hishamhm/gh-actions-luarocks@master
- name: Install `luarocks-build-treesitter-parser` Package
- name: Install `luarocks-build-treesitter-parser-cpp` Package
run: |
luarocks --verbose --local --lua-version=5.1 install luarocks-build-treesitter-parser
luarocks --verbose --local --lua-version=5.1 install luarocks-build-treesitter-parser-cpp
- name: LuaRocks Upload
uses: nvim-neorocks/luarocks-tag-release@v5
uses: nvim-neorocks/luarocks-tag-release@v7
env:
LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }}
with:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Cargo.lock
package-lock.json
yarn.lock
*.log
result/
result*
*.wasm
*.o
.direnv
55 changes: 26 additions & 29 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 43 additions & 26 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,31 +1,48 @@
{
description = "tree-sitter parser for Neorg";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
nixpkgs.url = "github:NixOS/nixpkgs";
flake-parts.url = "github:hercules-ci/flake-parts";
};
outputs = { self, nixpkgs, flake-utils, ... }@inputs:
let
defaultPackage = pkgs: pkgs.callPackage (nixpkgs + "/pkgs/development/tools/parsing/tree-sitter/grammar.nix") { } {
language = "norg";
source = ./.;
inherit (pkgs.tree-sitter) version;

outputs = inputs @ {
self,
nixpkgs,
flake-parts,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
perSystem = {system, ...}: let
pkgs = import nixpkgs {
inherit system;
overlays = [
self.overlays.default
];
};
in {
devShells.default = pkgs.mkShell {
name = "tree-sitter-norg devShell";
buildInputs = with pkgs;
with pkgs; [
nil
alejandra
clang
tree-sitter
];
};
packages = rec {
default = tree-sitter-norg;
inherit (pkgs.vimPlugins) tree-sitter-norg;
};
};
flake = {
overlays.default = import ./nix/overlay.nix {inherit self;};
};
in
(flake-utils.lib.eachDefaultSystem
(system:
let pkgs = import nixpkgs { inherit system; }; in
{
defaultPackage = defaultPackage pkgs;
devShell = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
nodejs
nodePackages.node-gyp
tree-sitter
];
};
})) // (let pkgs = import nixpkgs { }; in { defaultPackage = defaultPackage pkgs; });
};
}
27 changes: 27 additions & 0 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{self}: final: prev: let
luaPackage-override = luaself: luaprev: {
tree-sitter-norg = luaself.callPackage ({
buildLuarocksPackage,
fetchFromGitHub,
luaOlder,
luarocks-build-treesitter-parser-cpp,
}:
buildLuarocksPackage {
pname = "tree-sitter-norg";
version = "scm-1";
knownRockspec = "${self}/tree-sitter-norg-scm-1.rockspec";
src = self;
propagatedBuildInputs = [
luarocks-build-treesitter-parser-cpp
];
}) {};
};
in {
lua5_1 = prev.lua5_1.override {
packageOverrides = luaPackage-override;
};
lua51Packages = prev.lua51Packages // final.lua5_1.pkgs;
vimPlugins = prev.vimPlugins // {
tree-sitter-norg = final.neovimUtils.buildNeovimPlugin { luaAttr = "tree-sitter-norg"; };
};
}
9 changes: 7 additions & 2 deletions tree-sitter-norg-scm-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package = "tree-sitter-norg"

version = "scm-1"

rockspec_format = "3.0"

source = {
url = "git://github.com/nvim-neorg/tree-sitter-norg",
}
Expand All @@ -14,11 +16,14 @@ description = {

dependencies = {
"lua >= 5.1",
"luarocks-build-treesitter-parser >= 1.2.0",
}

build_dependencies = {
"luarocks-build-treesitter-parser-cpp",
}

build = {
type = "treesitter-parser",
type = "treesitter-parser-cpp",
lang = "norg",
sources = { "src/parser.c", "src/scanner.cc" },
}

0 comments on commit 4d75efc

Please sign in to comment.