@@ -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(¤t_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