git.iko.soy/typeable/nixpkgs
on master help sign in
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.

commitc505e57173cd71a9de599b2cbffd17ec7d8e7f64 authorProfpatsch <mail@profpatsch.de> dateThu 24 Dec 2020, 02:58 (6 years ago) parentfb875dc
1 file changed+17−10
pkgs/development/tools/parsing/tree-sitter/default.nix+17−10
pkgs/development/tools/parsing/tree-sitter/default.nix+17−10
@@ -2,10 +2,12 @@
22, fetchgit, fetchFromGitHub, fetchurl
33, writeShellScript, runCommand, which
44, rustPlatform, jq, nix-prefetch-git, xe, curl, emscripten
5+, Security
56, callPackage
7+
68, enableShared ? true
79, enableStatic ? false
8−, Security
10+, webUISupport ? false
911}:
1012
1113# TODO: move to carnix or https://github.com/kolloch/crate2nix
@@ -54,20 +56,25 @@ in rustPlatform.buildRustPackage {
5456 pname = "tree-sitter";
5557 inherit src version cargoSha256;
5658
57− buildInputs = lib.optionals stdenv.isDarwin [ Security ];
58−
59− nativeBuildInputs = [ emscripten which ];
60−
61− postPatch = ''
62− # needed for the tests
63− rm -rf test/fixtures/grammars
64− ln -s ${grammars} test/fixtures/grammars
59+ buildInputs =
60+ lib.optionals stdenv.isDarwin [ Security ];
61+ nativeBuildInputs =
62+ [ which ]
63+ ++ lib.optionals webUISupport [ emscripten ];
64+
65+ postPatch = lib.optionalString (!webUISupport) ''
66+ # remove web interface
67+ sed -e '/pub mod web_ui/d' \
68+ -i cli/src/lib.rs
69+ sed -e 's/web_ui,//' \
70+ -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);/' \
71+ -i cli/src/main.rs
6572 '';
6673
6774 # Compile web assembly with emscripten. The --debug flag prevents us from
6875 # minifying the JavaScript; passing it allows us to side-step more Node
6976 # JS dependencies for installation.
70− preBuild = ''
77+ preBuild = lib.optionalString webUISupport ''
7178 bash ./script/build-wasm --debug
7279 '';
7380