From 347b30f36f47d24931b848a6b12d6675f8934e29 Mon Sep 17 00:00:00 2001 From: winston Date: Sun, 26 Oct 2025 20:17:57 +0100 Subject: [PATCH 1/3] wasmtime: add version 29 wasmtime introduced breaking changes to the C API sometime between v33 and v36. Since both neovim and tree-sitter track the same version of wasmtime (v29.0.1) this adds a package tracking that major version. Loosening the `EXACT` specifier in neovim's CMakeLists worked until v33. --- pkgs/by-name/wa/wasmtime/package.nix | 34 +++++++++++++++++++++++++--- pkgs/top-level/all-packages.nix | 2 ++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/pkgs/by-name/wa/wasmtime/package.nix b/pkgs/by-name/wa/wasmtime/package.nix index 3788dee242c97..27afd7e0b184b 100644 --- a/pkgs/by-name/wa/wasmtime/package.nix +++ b/pkgs/by-name/wa/wasmtime/package.nix @@ -3,6 +3,7 @@ stdenv, rustPlatform, fetchFromGitHub, + fetchpatch, buildPackages, cmake, installShellFiles, @@ -10,23 +11,50 @@ nix-update-script, enableShared ? !stdenv.hostPlatform.isStatic, enableStatic ? stdenv.hostPlatform.isStatic, + majorVersion ? "38", }: rustPlatform.buildRustPackage (finalAttrs: { pname = "wasmtime"; - version = "38.0.3"; + version = + { + "29" = "29.0.1"; + "38" = "38.0.3"; + } + .${majorVersion}; src = fetchFromGitHub { owner = "bytecodealliance"; repo = "wasmtime"; tag = "v${finalAttrs.version}"; - hash = "sha256-eszpPYtueCuAMIVrWKagS1qFCWGd0rVFTsCqRYaSGu4="; + hash = + { + "29" = "sha256-BYTPBerWCDGqcN3TpMLhtL92f413IjCgGDQqQUu5D7Y="; + "38" = "sha256-eszpPYtueCuAMIVrWKagS1qFCWGd0rVFTsCqRYaSGu4="; + } + .${majorVersion}; fetchSubmodules = true; }; + cargoPatches = lib.optionals (lib.versionOlder finalAttrs.version "30") [ + (fetchpatch { + url = "https://github.com/bytecodealliance/wasmtime/commit/73ff15fb7f758c5f88952b1a0dc36a47f2665c4e.patch"; + hash = "sha256-S8mroaw8nSTH1sExHajeYZRF0SeEUz2w+xpOxTqRMas="; + }) + ]; + + cargoHash = + { + "29" = "sha256-oRkZHAovgS5i8ScXpvkLYkC3x0qxwAfmBd5EPjwgyEI="; + "38" = "sha256-agTF0GszX1f6oqo9oIPMD/GSmwbL8Ovg52TmtPq/z78="; + } + .${majorVersion}; + + # release predates the lint, causes a build failure + RUSTFLAGS = lib.optionalString (lib.versionOlder finalAttrs.version "30") "-Amismatched_lifetime_syntaxes"; + # Disable cargo-auditable until https://github.com/rust-secure-code/cargo-auditable/issues/124 is solved. auditable = false; - cargoHash = "sha256-agTF0GszX1f6oqo9oIPMD/GSmwbL8Ovg52TmtPq/z78="; cargoBuildFlags = [ "--package" "wasmtime-cli" diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 1b22561d3a3a6..806f0dc0a9275 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -4188,6 +4188,8 @@ with pkgs; stdenv = clangStdenv; }; + wasmtime_29 = pkgs.wasmtime.override { majorVersion = "29"; }; + woodpecker-agent = callPackage ../development/tools/continuous-integration/woodpecker/agent.nix { }; woodpecker-cli = callPackage ../development/tools/continuous-integration/woodpecker/cli.nix { }; From da62396d13ea0ca74bcbe76a9f081fe32553f488 Mon Sep 17 00:00:00 2001 From: winston Date: Mon, 31 Mar 2025 12:52:27 +0200 Subject: [PATCH 2/3] tree-sitter: add wasm feature --- .../tools/parsing/tree-sitter/default.nix | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/pkgs/development/tools/parsing/tree-sitter/default.nix b/pkgs/development/tools/parsing/tree-sitter/default.nix index 69f72f57d4e23..f6c4904196140 100644 --- a/pkgs/development/tools/parsing/tree-sitter/default.nix +++ b/pkgs/development/tools/parsing/tree-sitter/default.nix @@ -15,8 +15,11 @@ substitute, installShellFiles, buildPackages, + cmake, + wasmtime_29, enableShared ? !stdenv.hostPlatform.isStatic, enableStatic ? stdenv.hostPlatform.isStatic, + wasmSupport ? true, webUISupport ? false, extraGrammars ? { }, @@ -165,7 +168,6 @@ let ); allGrammars = builtins.attrValues builtGrammars; - in rustPlatform.buildRustPackage { pname = "tree-sitter"; @@ -173,15 +175,23 @@ rustPlatform.buildRustPackage { cargoHash = "sha256-4R5Y9yancbg/w3PhACtsWq0+gieUd2j8YnmEj/5eqkg="; + cargoBuildFeatures = lib.optionals wasmSupport [ "wasm" ]; + buildInputs = [ installShellFiles ] + ++ lib.optionals wasmSupport [ + wasmtime_29 + ] ++ lib.optionals webUISupport [ openssl ]; nativeBuildInputs = [ which ] + ++ lib.optionals wasmSupport [ + cmake + ] ++ lib.optionals webUISupport [ emscripten pkg-config @@ -198,6 +208,20 @@ rustPlatform.buildRustPackage { --replace-fail 'let emcc_name = if cfg!(windows) { "emcc.bat" } else { "emcc" };' 'let emcc_name = "${lib.getExe' emscripten "emcc"}";' ''; + cmakeDir = lib.optionalString wasmSupport "../lib"; + cmakeFlags = lib.optionals wasmSupport [ + (lib.cmakeBool "TREE_SITTER_FEATURE_WASM" true) + # these are needed so we don't need to patch https://github.com/tree-sitter/tree-sitter/blob/v0.25.3/lib/tree-sitter.pc.in#L1-L3 + (lib.cmakeFeature "CMAKE_INSTALL_INCLUDEDIR" "include") + (lib.cmakeFeature "CMAKE_INSTALL_LIBDIR" "lib") + ]; + + # cmakeConfigurePhase already runs preConfigure & postConfigure + configurePhase = lib.optionalString wasmSupport '' + runHook cmakeConfigurePhase + cd .. + ''; + # 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. @@ -207,8 +231,13 @@ rustPlatform.buildRustPackage { cargo run --package xtask -- build-wasm --debug ''; + postBuild = lib.optionalString wasmSupport '' + cmake --build $cmakeBuildDir + ''; + postInstall = '' PREFIX=$out make install + ${lib.optionalString wasmSupport "cmake --install $cmakeBuildDir"} ${lib.optionalString (!enableShared) "rm $out/lib/*.so{,.*}"} ${lib.optionalString (!enableStatic) "rm $out/lib/*.a"} '' From 118804a271096a57b2d374198bbd74cf92eaa990 Mon Sep 17 00:00:00 2001 From: winston Date: Thu, 22 May 2025 22:30:23 +0200 Subject: [PATCH 3/3] neovim: enable wasmtime --- pkgs/by-name/ne/neovim-unwrapped/package.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/ne/neovim-unwrapped/package.nix b/pkgs/by-name/ne/neovim-unwrapped/package.nix index 23ab00db9754a..c7f939d7a847e 100644 --- a/pkgs/by-name/ne/neovim-unwrapped/package.nix +++ b/pkgs/by-name/ne/neovim-unwrapped/package.nix @@ -24,6 +24,7 @@ nodejs ? null, fish ? null, python3 ? null, + wasmtime_29, }: stdenv.mkDerivation ( finalAttrs: @@ -159,6 +160,7 @@ stdenv.mkDerivation ( cmake gettext pkg-config + wasmtime_29 ]; # extra programs test via `make functionaltest` @@ -177,8 +179,12 @@ stdenv.mkDerivation ( pyEnv # for src/clint.py ]; + # loosen the version requirement for wasmtime to use the nixpkgs version + postPatch = '' + sed -i -E 's/find_package\(Wasmtime [0-9.]+ EXACT REQUIRED\)/find_package\(Wasmtime REQUIRED\)/' ./src/nvim/CMakeLists.txt + '' # nvim --version output retains compilation flags and references to build tools - postPatch = lib.optionalString (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' + + lib.optionalString (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' sed -i runtime/CMakeLists.txt \ -e "s|\".*/bin/nvim|\${stdenv.hostPlatform.emulator buildPackages} &|g" sed -i src/nvim/po/CMakeLists.txt \ @@ -194,6 +200,7 @@ stdenv.mkDerivation ( # third-party/CMakeLists.txt is not read at all. (lib.cmakeBool "USE_BUNDLED" false) (lib.cmakeBool "ENABLE_TRANSLATIONS" true) + (lib.cmakeBool "ENABLE_WASMTIME" true) ] ++ ( if lua.pkgs.isLuaJIT then