Skip to content

Commit

Permalink
init: working implementation
Browse files Browse the repository at this point in the history
This is the first working implementation that I tested manually.

Formal tests to follow.
  • Loading branch information
stackmystack committed Sep 1, 2024
0 parents commit 778b5b0
Show file tree
Hide file tree
Showing 37 changed files with 3,228 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: 2
updates:
# Maintain dependencies for Cargo
- package-ecosystem: cargo
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10

# Maintain dependencies for GitHub Actions
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
groups:
minor:
update-types:
- "minor"
patch:
update-types:
- "patch"
41 changes: 41 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## Description

<!--- Describe your changes in detail -->

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->

## How Has This Been Tested?

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran to -->
<!--- see how your change affects other areas of the code, etc. -->

## Screenshots / Logs (if applicable)

## Types of Changes

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Documentation (no code change)
- [ ] Refactor (refactoring production code)
- [ ] Other <!--- (provide information) -->

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->

- [ ] My code follows the code style of this project.
- [ ] I have updated the documentation accordingly.
- [ ] I have formatted the code with [rustfmt](https://github.com/rust-lang/rustfmt).
- [ ] I checked the lints with [clippy](https://github.com/rust-lang/rust-clippy).
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.

<!--- Thank you for contributing to git-cliff! ⛰️ -->
18 changes: 18 additions & 0 deletions .github/scripts/cross.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

set -e

if test "$BUILD_CMD" != "cross"
then
echo "cross.sh - is a helper to assist only in cross compiling environments" >&2
echo "To use this tool set the BUILD_CMD env var to the \"cross\" value" >&2
exit 111
fi

if test -z "$CROSS_IMAGE"
then
echo "The CROSS_IMAGE env var should be provided" >&2
exit 111
fi

docker run --rm -v /home/runner:/home/runner -w "$PWD" "$CROSS_IMAGE" "$@"
106 changes: 106 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Build

on:
workflow_call

env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-D warnings"

jobs:
build:
name: ${{ matrix.platform }} (${{ matrix.target }}) (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 40
strategy:
fail-fast: false
matrix:
platform:
- linux-arm
- linux-arm64
- linux-x64
- linux-x86
- macos-arm64
- macos-x64

include:
# When adding a new `target`:
# 1. Define a new platform alias above
# 2. Add a new record to a matrix map in `cli/npm/install.js`
- { platform: linux-arm , target: arm-unknown-linux-gnueabi , os: ubuntu-latest }
- { platform: linux-arm64 , target: aarch64-unknown-linux-gnu , os: ubuntu-latest }
- { platform: linux-x64 , target: x86_64-unknown-linux-gnu , os: ubuntu-latest }
- { platform: linux-x86 , target: i686-unknown-linux-gnu , os: ubuntu-latest }
- { platform: macos-arm64 , target: aarch64-apple-darwin , os: macos-14 }
- { platform: macos-x64 , target: x86_64-apple-darwin , os: macos-12 }

env:
BUILD_CMD: cargo

defaults:
run:
shell: bash

steps:
- uses: actions/checkout@v4

- run: rustup toolchain install stable --profile minimal
- run: rustup target add ${{ matrix.target }}

- name: Install cross
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: taiki-e/install-action@v2
with:
tool: cross

- name: Build custom cross image
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
target="${{ matrix.target }}"
image=ghcr.io/cross-rs/$target:custom
echo "CROSS_IMAGE=$image" >> $GITHUB_ENV
echo "[target.$target]" >> Cross.toml
echo "image = \"$image\"" >> Cross.toml
echo "CROSS_CONFIG=$PWD/Cross.toml" >> $GITHUB_ENV
echo "FROM ghcr.io/cross-rs/$target:edge" >> Dockerfile
echo "RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash -" >> Dockerfile
echo "RUN apt-get update && apt-get -y install nodejs" >> Dockerfile
docker build -t $image .
- name: Setup env extras
if: ${{ matrix.os == 'ubuntu-latest' }}
env:
TARGET: ${{ matrix.target }}
run: |
PATH="$PWD/.github/scripts:$PATH"
echo "$PWD/.github/scripts" >> $GITHUB_PATH
echo "ROOT=$PWD" >> $GITHUB_ENV
echo "TARGET=$TARGET" >> $GITHUB_ENV
echo "BUILD_CMD=cross" >> $GITHUB_ENV
runner=$(BUILD_CMD=cross cross.sh bash -c "env | sed -nr '/^CARGO_TARGET_.*_RUNNER=/s///p'")
[ -n "$runner" ] && echo "CROSS_RUNNER=$runner" >> $GITHUB_ENV
- run: $BUILD_CMD build --release --target=${{ matrix.target }}

# It would have been great to test also the built binaries for each platform
# using cross, but I faced many issues, mainly on arm/aarch64:
# 1. assert_cmd should slip "--" between the command and its arguments
# 2. git, curl, chmod, etc … would work, but not tree-sitter-cli, for 2 reasons:
# 1. we need to recognize if we're being run with cross using CARGO_*_RUNNER envvar,
# and if so, we need to modify the command + slip "--" after its args
# 2. but even if we did, tree-sitter-cli itself invokes node directly, and that
# would not work because it doesn't recognize the runner.
#
# So I abandoned it. We have to rely on the fact that tree-sitter-cli is well tested
# on these platforms, and we need to make sure that tsdl itself runs well on linux/macOS.
- name: Upload CLI artifact
uses: actions/upload-artifact@v4
with:
name: tsdl.${{ matrix.platform }}
path: target/${{ matrix.target }}/release/tsdl
if-no-files-found: error
retention-days: 7
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI
on:
pull_request:
push:
branches:
- "master"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

jobs:
checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- run: rustup toolchain install stable --profile minimal

- name: Install just
uses: taiki-e/install-action@v2
with:
tool: just

- run: just lint

build:
uses: ./.github/workflows/build.yml

test:
uses: ./.github/workflows/test.yml
75 changes: 75 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Release
on:
workflow_dispatch:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+

jobs:
build:
uses: ./.github/workflows/build.yml

release:
name: Release
runs-on: ubuntu-latest
needs: build
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Display structure of downloaded files
run: ls -lR
working-directory: artifacts

- name: Prepare release artifacts
run: |
mkdir -p target
for platform in $(cd artifacts; ls | sed 's/^tsdl\.//'); do
exe=$(ls artifacts/tsdl.$platform/tsdl*)
gzip --stdout --name $exe > target/tsdl-$platform.gz
done
rm -rf artifacts
ls -l target/
- name: Install git-cliff
uses: taiki-e/install-action@git-cliff

- name: Generate changelog
run: git-cliff -vv --latest --strip header --output CHANGES.md

- name: Create release
uses: softprops/action-gh-release@v2
with:
name: ${{ github.ref_name }}
tag_name: ${{ github.ref_name }}
fail_on_unmatched_files: true
files: |
target/tsdl-*.gz
body_path: CHANGES.md

# crates_io:
# name: Publish CLI to Crates.io
# runs-on: ubuntu-latest
# needs: release
# steps:
# - uses: actions/checkout@v4

# - name: Setup Rust
# uses: actions-rs/toolchain@v1
# with:
# profile: minimal
# toolchain: stable
# override: true

# - name: Publish crates to Crates.io
# uses: katyo/publish-crates@v2
# with:
# registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Test

on:
workflow_call

env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-D warnings"

jobs:
build:
name: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 40
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest

defaults:
run:
shell: bash

steps:
- uses: actions/checkout@v4

- run: rustup toolchain install stable --profile minimal

- name: Install test tools
uses: taiki-e/install-action@v2
with:
tool: cargo-nextest,just

- run: just test
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# rust
debug/
target/
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# tsdl
parsers/
tmp/
parsers.toml
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## [unreleased]

### Other
- Working implementation


Loading

0 comments on commit 778b5b0

Please sign in to comment.