on master help sign in
fetch and compile tree-sitter grammars in helix-term build

This restores much of the behavior that existed before this PR: helix will build the grammars when compiling. The difference is that now fetching is also done during the build phase and is done much more quickly - both shallow and in parallel.

commitb157c5a8a4472cff68de3a9be66e220dc4b80a9f authorMichael Davis <mcarsondavis@gmail.com> dateMon 21 Feb 2022, 06:39 (5 years ago) parent6fcab90
5 files changed+17−35
.github/workflows/build.yml+4−17 .github/workflows/release.yml−14 flake.nix+2 helix-term/Cargo.toml+3−4 helix-term/build.rs+8
.github/workflows/build.yml+4−17
@@ -77,27 +77,14 @@ jobs:
7777 path: target
7878 key: ${{ runner.os }}-v2-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
7979
80+ - name: Copy minimal languages config
81+ run: cp .github/workflows/languages.toml ./languages.toml
82+
8083 - name: Cache test tree-sitter grammar
8184 uses: actions/cache@v2.1.7
8285 with:
8386 path: runtime/grammars
84− key: ${{ runner.os }}-v2-tree-sitter-grammars-${{ hashFiles('**/Cargo.lock') }}
85−
86− - run: cp .github/workflows/languages.toml ./languages.toml
87−
88− - name: Download test tree-sitter grammar
89− uses: actions-rs/cargo@v1
90− with:
91− use-cross: ${{ matrix.cross }}
92− command: run
93− args: -- --fetch-grammars
94−
95− - name: Build test tree-sitter grammar
96− uses: actions-rs/cargo@v1
97− with:
98− use-cross: ${{ matrix.cross }}
99− command: run
100− args: -- --build-grammars
87+ key: ${{ runner.os }}-v2-tree-sitter-grammars-${{ hashFiles('languages.toml') }}
10188
10289 - name: Run cargo test
10390 uses: actions-rs/cargo@v1
.github/workflows/release.yml−14
@@ -62,20 +62,6 @@ jobs:
6262 target: ${{ matrix.target }}
6363 override: true
6464
65− - name: Fetch tree-sitter grammars
66− uses: actions-rs/cargo@v1
67− with:
68− use-cross: ${{ matrix.cross }}
69− command: run
70− args: --release --locked --target ${{ matrix.target }} -- --fetch-grammars
71−
72− - name: Build tree-sitter grammars
73− uses: actions-rs/cargo@v1
74− with:
75− use-cross: ${{ matrix.cross }}
76− command: run
77− args: --release --locked --target ${{ matrix.target }} -- --build-grammars
78−
7965 - name: Run cargo test
8066 uses: actions-rs/cargo@v1
8167 with:
flake.nix+2
@@ -35,6 +35,8 @@
3535 overrides = {
3636 crateOverrides = common: _: rec {
3737 helix-term = prev: {
38+ # disable fetching and building of tree-sitter grammars in the helix-term build.rs
39+ HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
3840 buildInputs = (prev.buildInputs or [ ]) ++ [ common.cCompiler.cc.lib ];
3941 nativeBuildInputs = (prev.nativeBuildInputs or [ ]) ++ [ common.pkgs.makeWrapper ];
4042 preConfigure = ''
helix-term/Cargo.toml+3−4
@@ -67,9 +67,8 @@ grep-searcher = "0.1.8"
6767# Remove once retain_mut lands in stable rust
6868retain_mut = "0.1.7"
6969
70−# compiling grammars
71−cc = { version = "1" }
72−threadpool = { version = "1.0" }
73−
7470[target.'cfg(not(windows))'.dependencies] # https://github.com/vorner/signal-hook/issues/100
7571signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] }
72+
73+[build-dependencies]
74+helix-loader = { version = "0.6", path = "../helix-loader" }
helix-term/build.rs+8
@@ -1,3 +1,4 @@
1+use helix_loader::grammar::{build_grammars, fetch_grammars};
12use std::borrow::Cow;
23use std::process::Command;
34
@@ -14,5 +15,12 @@ fn main() {
1415 None => env!("CARGO_PKG_VERSION").into(),
1516 };
1617
18+ if std::env::var("HELIX_DISABLE_AUTO_GRAMMAR_BUILD").is_err() {
19+ fetch_grammars().expect("Failed to fetch tree-sitter grammars");
20+ build_grammars().expect("Failed to compile tree-sitter grammars");
21+ }
22+
23+ println!("cargo:rerun-if-changed=../runtime/grammars/");
24+
1725 println!("cargo:rustc-env=VERSION_AND_GIT_HASH={}", version);
1826}