From 75f2c1b1f1035330374de6cc9db9016e3c048a37 Mon Sep 17 00:00:00 2001 From: Stanislav Asunkin <1353637+stasjok@users.noreply.github.com> Date: Sun, 11 May 2025 12:30:50 +0300 Subject: [PATCH] modules/performance: ensure dependencies of lua packages also compiled Previously only extraLuaPackages themselves were byte-compiled, not theirs dependencies. This commit fixes that by compiling lua packages recursively. It uses byte-compile-lua-lib.nix shared file. Also this commit uses the shared stub lua libraries for extraLuaPackages byte-compiling test. --- modules/top-level/output.nix | 3 ++- .../plugins/byte-compile-lua-lib.nix | 19 ++++++++++++------- modules/top-level/plugins/default.nix | 4 ++-- .../modules/performance/byte-compile-lua.nix | 17 +++++++---------- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/modules/top-level/output.nix b/modules/top-level/output.nix index 8f1d1332..3d880a35 100644 --- a/modules/top-level/output.nix +++ b/modules/top-level/output.nix @@ -172,9 +172,10 @@ in config = let # Optionally byte compile lua library + inherit (import ./plugins/byte-compile-lua-lib.nix { inherit lib pkgs; }) byteCompileLuaPackages; extraLuaPackages = if config.performance.byteCompileLua.enable && config.performance.byteCompileLua.luaLib then - ps: map builders.byteCompileLuaDrv (config.extraLuaPackages ps) + ps: byteCompileLuaPackages (config.extraLuaPackages ps) else config.extraLuaPackages; diff --git a/modules/top-level/plugins/byte-compile-lua-lib.nix b/modules/top-level/plugins/byte-compile-lua-lib.nix index 0d50cf6b..eab3a59e 100644 --- a/modules/top-level/plugins/byte-compile-lua-lib.nix +++ b/modules/top-level/plugins/byte-compile-lua-lib.nix @@ -1,9 +1,4 @@ -/* - Byte compiling of lua dependencies of normalized plugin list - - Inputs: List of normalized plugins - Outputs: List of normalized plugins with all the propagatedBuildInputs byte-compiled -*/ +# Utilities for byte compiling of lua dependencies { lib, pkgs }: let builders = lib.nixvim.builders.withPkgs pkgs; @@ -40,4 +35,14 @@ let # Byte-compile derivation (but only if it's a lua module) and its dependencies byteCompile = drv: byteCompileDeps (mapLuaModule builders.byteCompileLuaDrv drv); in -mapNormalizedPlugins byteCompileDeps +{ + # byteCompilePluginDeps compiles propagatedBuildInputs recursively + # Inputs: List of normalized plugins + # Outputs: List of normalized plugins with all the propagatedBuildInputs byte-compiled + byteCompilePluginDeps = mapNormalizedPlugins byteCompileDeps; + + # byteCompileLuaPackages compiles packages and its propagatedBuildInputs + # Inputs: List of lua packages + # Outputs: List of byte-compiled packages along with all the propagatedBuildInputs + byteCompileLuaPackages = map byteCompile; +} diff --git a/modules/top-level/plugins/default.nix b/modules/top-level/plugins/default.nix index b20e98d7..fef96f61 100644 --- a/modules/top-level/plugins/default.nix +++ b/modules/top-level/plugins/default.nix @@ -35,7 +35,7 @@ in byteCompilePlugins = import ./byte-compile-plugins.nix { inherit lib pkgs; }; shouldCompileLuaLib = byteCompileCfg.enable && byteCompileCfg.luaLib; - byteCompileLuaLib = import ./byte-compile-lua-lib.nix { inherit lib pkgs; }; + inherit (import ./byte-compile-lua-lib.nix { inherit lib pkgs; }) byteCompilePluginDeps; shouldCombinePlugins = config.performance.combinePlugins.enable; combinePlugins = import ./combine-plugins.nix { @@ -50,7 +50,7 @@ in lib.pipe config.extraPlugins ( [ normalizePlugins ] ++ lib.optionals shouldCompilePlugins [ byteCompilePlugins ] - ++ lib.optionals shouldCompileLuaLib [ byteCompileLuaLib ] + ++ lib.optionals shouldCompileLuaLib [ byteCompilePluginDeps ] ++ lib.optionals shouldCombinePlugins [ combinePlugins ] ); }; diff --git a/tests/test-sources/modules/performance/byte-compile-lua.nix b/tests/test-sources/modules/performance/byte-compile-lua.nix index 40c3c01b..c836bd06 100644 --- a/tests/test-sources/modules/performance/byte-compile-lua.nix +++ b/tests/test-sources/modules/performance/byte-compile-lua.nix @@ -308,20 +308,17 @@ in luaLib = true; }; - extraLuaPackages = - ps: with ps; [ - say - argparse - ]; + extraLuaPackages = _: pluginStubs.libPack; extraConfigLuaPost = '' + ${pluginStubs.libChecks} + ${isByteCompiledFun} - -- Lua modules are importable and byte compiled - local say = require("say") - test_lualib_file(say.set, true) - local argparse = require("argparse") - test_lualib_file(argparse("test").parse, true) + -- Lua modules are byte-compiled + ${lib.concatMapStringsSep "\n" ( + name: "test_lualib_file(require('${name}').name, true)" + ) pluginStubs.libNames} ''; };