Skip to content

Commit

Permalink
build: use tsdl
Browse files Browse the repository at this point in the history
  • Loading branch information
stackmystack committed Sep 5, 2024
1 parent b7eccf4 commit 9d097b0
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 312 deletions.
41 changes: 26 additions & 15 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,42 @@ on:

jobs:
build:
name: ${{ matrix.platform }} (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
target:
- { os: ubuntu-latest, platform: linux-x64 }
- { os: macos-latest, platform: macos-arm64 }
runs-on: ${{ matrix.target.os }}
env:
PLATFORM: ${{ matrix.target.platform }}
TREE_SITTER_VERSION: 0.22.6
platform:
# - linux-arm
# - linux-arm64
- linux-x64
# - linux-x86
- macos-arm64
# - macos-x64

include:
# - { platform: linux-arm , os: ubuntu-latest }
# - { platform: linux-arm64 , os: ubuntu-latest }
- { platform: linux-x64, os: ubuntu-latest }
# - { platform: linux-x86 , os: ubuntu-latest }
- { platform: macos-arm64, os: macos-14 }
# - { platform: macos-x64 , os: macos-12 }
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Build for ${{ matrix.target.platform }}
- name: Download tsdl
run: |
curl -o tsdl.gz -L "https://github.com/stackmystack/tsdl/releases/latest/download/tsdl-${{ matrix.platform }}.gz"
gunzip tsdl.gz
chmod +x tsdl
- name: Build
run: |
./lang d
./tsdl build --out-dir lib/${{ matrix.platform}}
- name: Prepare git # To get tags from `git describe`
run: |
git fetch --prune --unshallow
- name: Make .deb
if: matrix.target.os == 'ubuntu-latest'
run: |
./package/deb
- name: Make zip and tar
- name: Package parsers
run: |
./package/zip
./pkg
- name: Release
uses: softprops/action-gh-release@v1
with:
Expand Down
65 changes: 2 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,6 @@

[![cd](https://github.com/Faveod/tree-sitter-parsers/actions/workflows/cd.yml/badge.svg)](https://github.com/Faveod/tree-sitter-parsers/actions/workflows/cd.yml)

This repository contains a script to create your favourite shared library
`tree-sitter-{parser}`.
Some parsers built with [tsdl](httsp://github.com/stackmystack/tsdl).

The official repositories don't have a `Makefile` for generated parsers, so this
is like a special `Makefile`.

We also have the libraries pushed as artifacts through CI/CD. Check
[Releases](https://github.com/Faveod/tree-sitter-parsers/releases).

This repository was created for
[`ruby-tree-sitter`](https://github.com/Faveod/ruby-tree-sitter).
## Usage

``` console
./lang javascript
./lang java ruby php
```

## Tree-Sitter version

The script will clone `tree-sitter` and then checkout some tag (I will try to
keep it updated to latest). But if it finds a `tree-sitter` dir, it will not do
anything to it. **so if you want to build agains a specific tag or commit, just
`cd` into `tree-sitter` and do yout thing**.

## Parser versions

Instead of defaulting to cloning parsers and building them from `HEAD`, or from
the latest release tag, the script `lang` will look for a file `ref` where
parser commit `SHA1` is specified. Actually anything you can pass to `git
checkout` will be accepted.

If `ref` was not found, `lang` will use `HEAD`.

The releases will contain a copy of the used `ref`.

## Artefacts

The output of `./lang LANGUAGE` is in `lib/libtree-sitter-LANGUAGE.{dylib, so}`.

# Supported Archs

This is not true as of now, please refer to the releases. They should be
available once more in the future.

## Linux

- x86_64-linux-gnu
- arm-linux-gnueabi
- arm-linux-gnueabihf
- aarch64-linux-gnu
- mipsel-linux-gnu
- powerpc64le-linux-gnu

## Macos

- x86_64-intel

NO SUPPORT FOR ARM (M1, M2, etc). Will land sometime soon, maybe. This requres a
patch to `tree-sitter`'s makefile itself.

## Windows

no.
Check [Releases](https://github.com/Faveod/tree-sitter-parsers/releases).
45 changes: 0 additions & 45 deletions clean

This file was deleted.

162 changes: 0 additions & 162 deletions lang

This file was deleted.

15 changes: 15 additions & 0 deletions parsers.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
tree-sitter-version = "0.22.6"

[parsers]
bash = "7331995b19b8f8aba2d5e26deb51d2195c18bc94"
c = "212a80f86452bb1316324fa0db730cf52f29e05a"
cobol = { ref = "c7a36d749e7f1db021588259f2b1b765e59d0c12", from = "https://github.com/yutaro-sakamoto/tree-sitter-cobol" }
embedded-template = "203f7bd3c1bbfbd98fc19add4b8fcb213c059205"
html = "949b78051835564bca937565241e5e337d838502"
java = "953abfc8bb3eb2f578e1f461edba4a9885f974b8"
javascript = "4928d3d18019a848906855476fde2dc8be030217"
json = "3fef30de8aee74600f25ec2e319b62a1a870d51e"
php = "575a0801f430c8672db70b73493c033a9dcfc328"
python = "82f5c9937fe4300b4bec3ee0e788d642c77aab2c"
ruby = "788a63ca1b7619288980aaafd37d890ee2469421"
rust = "9c84af007b0f144954adb26b3f336495cbb320a7"
38 changes: 38 additions & 0 deletions pkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# /usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

arch=$(dpkg-architecture -q DEB_BUILD_ARCH)
version_num=$(git describe --tags --abbrev=0 | sed -E 's/v([0-9]+\.[0-9]+)/\1/')
commit_count=$(git rev-list --count --first-parent HEAD)

version="$version_num.$commit_count"
echo

pkg='tree-sitter-parsers'
pkg_name="$pkg-$version_num-$arch"
rm -rf "$pkg"

debian="$pkg/DEBIAN"
mkdir -p "$debian"

dst="$pkg/usr/local/lib"
mkdir -p "$dst"

cat <<-EOF > "$debian/control"
Package: $pkg
Version: $version
Architecture: $arch
Maintainer: Firas al-Khalil <firas.al-khalil@faveod.com>
Description: A bunch of tree-sitter parsers.
EOF

cp "lib/$PLATFORM/*.so" "$dst"

zip "lib/$pkg_name.zip" "$dst/*"
tar -cvzf "lib/$pkg_name.tar.gz" "$dst/*"

if test "$(uname)" = "Linux" && test -f /etc/lsb-release && grep -q "Ubuntu" /etc/lsb-release; then
dpkg-deb -Z none --build "$pkg" "lib/$pkg_name.deb"
fi
Loading

0 comments on commit 9d097b0

Please sign in to comment.