From d992204d8c96165b9a63a87ff61ea4860c93033f Mon Sep 17 00:00:00 2001 From: Jarrad Hope Date: Wed, 31 Dec 2025 18:20:30 -0500 Subject: [PATCH] luajit: enable MinGW build LuaJIT's build needs an explicit Windows target when cross compiling to MinGW. Without this it can emit ELF-specific assembler directives (e.g. .hidden/.type/.size), which fail with the PE/COFF toolchain. Also provide an install-time compatibility copy from src/luajit.exe to src/luajit, since the upstream install rule expects the non-.exe name. --- .../interpreters/luajit/default.nix | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkgs/development/interpreters/luajit/default.nix b/pkgs/development/interpreters/luajit/default.nix index a0f902f5200e..95211f41f6fb 100644 --- a/pkgs/development/interpreters/luajit/default.nix +++ b/pkgs/development/interpreters/luajit/default.nix @@ -93,11 +93,25 @@ stdenv.mkDerivation (finalAttrs: { "CROSS=${stdenv.cc.targetPrefix}" "HOST_CC=${buildStdenv.cc}/bin/cc" ] + # LuaJIT's build system needs an explicit target on MinGW, otherwise it can + # emit ELF-specific assembler directives (e.g. .hidden/.type/.size) that the + # PE/COFF toolchain doesn't accept. + ++ lib.optionals stdenv.hostPlatform.isMinGW [ + "TARGET_SYS=Windows" + ] ++ lib.optional enableJITDebugModule "INSTALL_LJLIBD=$(INSTALL_LMOD)" ++ lib.optional stdenv.hostPlatform.isStatic "BUILDMODE=static"; enableParallelBuilding = true; env.NIX_CFLAGS_COMPILE = toString XCFLAGS; + # The LuaJIT build produces `src/luajit.exe` on Windows targets, but the + # upstream install rule expects `src/luajit`. Provide a compatibility copy. + preInstall = lib.optionalString stdenv.hostPlatform.isMinGW '' + if [[ -e src/luajit.exe && ! -e src/luajit ]]; then + cp -p src/luajit.exe src/luajit + fi + ''; + postInstall = '' mkdir -p $out/nix-support cp ${ @@ -152,7 +166,9 @@ stdenv.mkDerivation (finalAttrs: { description = "High-performance JIT compiler for Lua 5.1"; homepage = "https://luajit.org/"; license = lib.licenses.mit; - platforms = lib.platforms.linux ++ lib.platforms.darwin; + # MSYS2 ships LuaJIT for mingw-w64, and nixpkgs consumers (like phosphor) + # need it in Windows cross builds. + platforms = lib.platforms.linux ++ lib.platforms.darwin ++ lib.platforms.windows; badPlatforms = [ "loongarch64-linux" # See https://github.com/LuaJIT/LuaJIT/issues/1278 "riscv64-linux" # See https://github.com/LuaJIT/LuaJIT/issues/628