Skip to content

Commit

Permalink
tree-sitter: patch out web-ui by default, to drop emscripten
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Profpatsch committed Dec 24, 2020
1 parent fb875dc commit c505e57
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions pkgs/development/tools/parsing/tree-sitter/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
'';

Expand Down

0 comments on commit c505e57

Please sign in to comment.