summary refs log tree commit diff
path: root/pkgs/development/tools/parsing/tree-sitter/default.nix
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2020-12-24 02:58:08 +0100
committerProfpatsch <mail@profpatsch.de>2020-12-24 17:11:04 +0100
commitc505e57173cd71a9de599b2cbffd17ec7d8e7f64 (patch)
tree759e84ba3bbd4d67dc1b9059ccd5fe900d9102fd /pkgs/development/tools/parsing/tree-sitter/default.nix
parentfb875dcf6fbadafb41c64d9f4e1ef056f127bcb3 (diff)
downloadnixpkgs-c505e57173cd71a9de599b2cbffd17ec7d8e7f64.tar
nixpkgs-c505e57173cd71a9de599b2cbffd17ec7d8e7f64.tar.gz
nixpkgs-c505e57173cd71a9de599b2cbffd17ec7d8e7f64.tar.bz2
nixpkgs-c505e57173cd71a9de599b2cbffd17ec7d8e7f64.tar.lz
nixpkgs-c505e57173cd71a9de599b2cbffd17ec7d8e7f64.tar.xz
nixpkgs-c505e57173cd71a9de599b2cbffd17ec7d8e7f64.tar.zst
nixpkgs-c505e57173cd71a9de599b2cbffd17ec7d8e7f64.zip
tree-sitter: patch out web-ui by default, to drop emscripten
The tree-sitter build closure is pretty lean by default, but the
optional web-ui requires emscripten to compile the web interface
javascript/wasm code.

This is clearly not worth the increase in build closure size, and
since emscripten is broken more often than not, let’s patch it out by
default. If somebody /really/ needs the web-ui, there is a
`webUISupport` flag.
Diffstat (limited to 'pkgs/development/tools/parsing/tree-sitter/default.nix')
-rw-r--r--pkgs/development/tools/parsing/tree-sitter/default.nix27
1 files changed, 17 insertions, 10 deletions
diff --git a/pkgs/development/tools/parsing/tree-sitter/default.nix b/pkgs/development/tools/parsing/tree-sitter/default.nix
index 37811943a6d..57c12cce93e 100644
--- a/pkgs/development/tools/parsing/tree-sitter/default.nix
+++ b/pkgs/development/tools/parsing/tree-sitter/default.nix
@@ -2,10 +2,12 @@
 , fetchgit, fetchFromGitHub, fetchurl
 , writeShellScript, runCommand, which
 , rustPlatform, jq, nix-prefetch-git, xe, curl, emscripten
+, Security
 , callPackage
+
 , enableShared ? true
 , enableStatic ? false
-, Security
+, webUISupport ? false
 }:
 
 # TODO: move to carnix or https://github.com/kolloch/crate2nix
@@ -54,20 +56,25 @@ in rustPlatform.buildRustPackage {
   pname = "tree-sitter";
   inherit src version cargoSha256;
 
-  buildInputs = lib.optionals stdenv.isDarwin [ Security ];
-
-  nativeBuildInputs = [ emscripten which ];
-
-  postPatch = ''
-    # needed for the tests
-    rm -rf test/fixtures/grammars
-    ln -s ${grammars} test/fixtures/grammars
+  buildInputs =
+    lib.optionals stdenv.isDarwin [ Security ];
+  nativeBuildInputs =
+    [ which ]
+    ++ lib.optionals webUISupport [ emscripten ];
+
+  postPatch = lib.optionalString (!webUISupport) ''
+    # remove web interface
+    sed -e '/pub mod web_ui/d' \
+        -i cli/src/lib.rs
+    sed -e 's/web_ui,//' \
+        -e 's/web_ui::serve(&current_dir.*$/println!("ERROR: web-ui is not available in this nixpkgs build; enable the webUISupport"); std::process::exit(1);/' \
+        -i cli/src/main.rs
   '';
 
   # Compile web assembly with emscripten. The --debug flag prevents us from
   # minifying the JavaScript; passing it allows us to side-step more Node
   # JS dependencies for installation.
-  preBuild = ''
+  preBuild = lib.optionalString webUISupport ''
     bash ./script/build-wasm --debug
   '';