From 57832e625c556e77aba380ef0280c6f88c62e9cd Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Mon, 19 Apr 2021 10:55:08 +0000 Subject: [PATCH 1/5] lua: don't always set LUA_USE_LINUX This is supposed to be automatically set by Lua's Makefile if PLAT is set appropriately, but it was being overridden by us overridding CFLAGS. Setting it manually was a hack. The correct thing to do was to make sure SYSCFLAGS (where Lua's Makefile puts LUA_USE_LINUX) was still included in our custom CFLAGS. --- pkgs/development/interpreters/lua-5/interpreter.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/interpreters/lua-5/interpreter.nix b/pkgs/development/interpreters/lua-5/interpreter.nix index 35a074add09..9cad009d426 100644 --- a/pkgs/development/interpreters/lua-5/interpreter.nix +++ b/pkgs/development/interpreters/lua-5/interpreter.nix @@ -49,7 +49,7 @@ self = stdenv.mkDerivation rec { configurePhase = '' runHook preConfigure - makeFlagsArray+=(CFLAGS="-DLUA_USE_LINUX -O2 -fPIC${if compat then " -DLUA_COMPAT_ALL" else ""}" ) + makeFlagsArray+=(CFLAGS='-O2 -fPIC${lib.optionalString compat " -DLUA_COMPAT_ALL"} $(SYSCFLAGS)' ) makeFlagsArray+=(${lib.optionalString stdenv.isDarwin "CC=\"$CC\""}${lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) " 'AR=${stdenv.hostPlatform.config}-ar rcu'"}) installFlagsArray=( TO_BIN="lua luac" INSTALL_DATA='cp -d' \ From 936b27b5d4a64f6e9ce3728bdaa8a78490236e6b Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Mon, 19 Apr 2021 11:02:16 +0000 Subject: [PATCH 2/5] lua: support non-Linux non-Darwin operating systems --- .../interpreters/lua-5/interpreter.nix | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pkgs/development/interpreters/lua-5/interpreter.nix b/pkgs/development/interpreters/lua-5/interpreter.nix index 9cad009d426..4b257c20900 100644 --- a/pkgs/development/interpreters/lua-5/interpreter.nix +++ b/pkgs/development/interpreters/lua-5/interpreter.nix @@ -11,6 +11,15 @@ let luaPackages = callPackage ../../lua-modules {lua=self; overrides=packageOverrides;}; +plat = if stdenv.isLinux then "linux" + else if stdenv.isDarwin then "macosx" + else if stdenv.hostPlatform.isMinGW then "mingw" + else if stdenv.isFreeBSD then "freebsd" + else if stdenv.isSunOS then "solaris" + else if stdenv.hostPlatform.isBSD then "bsd" + else if stdenv.hostPlatform.isUnix then "posix" + else "generic"; + self = stdenv.mkDerivation rec { pname = "lua"; luaversion = with sourceVersion; "${major}.${minor}"; @@ -36,11 +45,8 @@ self = stdenv.mkDerivation rec { "R=${version}" "LDFLAGS=-fPIC" "V=${luaversion}" - ] ++ (if stdenv.isDarwin then [ - "PLAT=macosx" - ] else [ - "PLAT=linux" - ]) ++ (if stdenv.buildPlatform != stdenv.hostPlatform then [ + "PLAT=${plat}" + ] ++ (if stdenv.buildPlatform != stdenv.hostPlatform then [ "CC=${stdenv.hostPlatform.config}-gcc" "RANLIB=${stdenv.hostPlatform.config}-ranlib" ] else []) From 34f8d7e15a3ca5762c84f867f70773674b002cb2 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Mon, 19 Apr 2021 11:38:01 +0000 Subject: [PATCH 3/5] lua: one dso patch to rule them all We do this same patch in three different ways for four different Lua versions, even though the structure of the Makefile barely changes between releases. We can easily consolidate this by just modifying the Makefile ourselves instead of using patches (Makefiles are very amenable to this). --- .../interpreters/lua-5/default.nix | 28 +-------- .../interpreters/lua-5/interpreter.nix | 8 +++ .../interpreters/lua-5/liblua.so.patch | 60 ------------------- .../lua-5/{lua-5.3-dso.make => lua-dso.make} | 4 -- 4 files changed, 11 insertions(+), 89 deletions(-) delete mode 100644 pkgs/development/interpreters/lua-5/liblua.so.patch rename pkgs/development/interpreters/lua-5/{lua-5.3-dso.make => lua-dso.make} (89%) diff --git a/pkgs/development/interpreters/lua-5/default.nix b/pkgs/development/interpreters/lua-5/default.nix index 3a52d58ffab..ae5d76aa36c 100644 --- a/pkgs/development/interpreters/lua-5/default.nix +++ b/pkgs/development/interpreters/lua-5/default.nix @@ -1,27 +1,10 @@ # similar to interpreters/python/default.nix { stdenv, lib, callPackage, fetchurl, fetchpatch }: -let - dsoPatch51 = fetchurl { - url = "https://projects.archlinux.org/svntogit/packages.git/plain/trunk/lua-arch.patch?h=packages/lua51"; - sha256 = "11fcyb4q55p4p7kdb8yp85xlw8imy14kzamp2khvcyxss4vw8ipw"; - name = "lua-arch.patch"; - }; - dsoPatch52 = fetchurl { - url = "https://projects.archlinux.org/svntogit/packages.git/plain/trunk/liblua.so.patch?h=packages/lua52"; - sha256 = "1by1dy4ql61f5c6njq9ibf9kaqm3y633g2q8j54iyjr4cxvqwqz9"; - name = "lua-arch.patch"; - }; - -in rec { +rec { lua5_4 = callPackage ./interpreter.nix { sourceVersion = { major = "5"; minor = "4"; patch = "2"; }; hash = "0ksj5zpj74n0jkamy3di1p6l10v4gjnd2zjnb453qc6px6bhsmqi"; - patches = [ - # build lua as a shared library as well, MIT-licensed from - # https://github.com/archlinux/svntogit-packages/tree/packages/lua/trunk - ./liblua.so.patch - ]; }; lua5_4_compat = lua5_4.override({ @@ -35,11 +18,6 @@ in rec { patches = lib.optionals stdenv.isDarwin [ ./5.2.darwin.patch ]; - postConfigure = lib.optionalString (!stdenv.isDarwin) '' - cat ${./lua-5.3-dso.make} >> src/Makefile - sed -e 's/ALL_T *= */& $(LUA_SO)/' -i src/Makefile - ''; - postBuild = lib.optionalString (!stdenv.isDarwin) '' ( cd src; make $makeFlags "''${makeFlagsArray[@]}" liblua.so ) ''; @@ -53,7 +31,7 @@ in rec { lua5_2 = callPackage ./interpreter.nix { sourceVersion = { major = "5"; minor = "2"; patch = "4"; }; hash = "0jwznq0l8qg9wh5grwg07b5cy3lzngvl5m2nl1ikp6vqssmf9qmr"; - patches = if stdenv.isDarwin then [ ./5.2.darwin.patch ] else [ dsoPatch52 ]; + patches = lib.optional stdenv.isDarwin ./5.2.darwin.patch; }; lua5_2_compat = lua5_2.override({ @@ -64,7 +42,7 @@ in rec { lua5_1 = callPackage ./interpreter.nix { sourceVersion = { major = "5"; minor = "1"; patch = "5"; }; hash = "2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333"; - patches = (if stdenv.isDarwin then [ ./5.1.darwin.patch ] else [ dsoPatch51 ]) + patches = (lib.optional stdenv.isDarwin ./5.1.darwin.patch) ++ [ ./CVE-2014-5461.patch ]; }; diff --git a/pkgs/development/interpreters/lua-5/interpreter.nix b/pkgs/development/interpreters/lua-5/interpreter.nix index 4b257c20900..cb31bf52eeb 100644 --- a/pkgs/development/interpreters/lua-5/interpreter.nix +++ b/pkgs/development/interpreters/lua-5/interpreter.nix @@ -38,6 +38,14 @@ self = stdenv.mkDerivation rec { inherit patches; + postPatch = lib.optionalString (!stdenv.isDarwin) '' + # Add a target for a shared library to the Makefile. + sed -e '1s/^/LUA_SO = liblua.so/' \ + -e 's/ALL_T *= */&$(LUA_SO) /' \ + -i src/Makefile + cat ${./lua-dso.make} >> src/Makefile + ''; + # see configurePhase for additional flags (with space) makeFlags = [ "INSTALL_TOP=${placeholder "out"}" diff --git a/pkgs/development/interpreters/lua-5/liblua.so.patch b/pkgs/development/interpreters/lua-5/liblua.so.patch deleted file mode 100644 index 197832116c1..00000000000 --- a/pkgs/development/interpreters/lua-5/liblua.so.patch +++ /dev/null @@ -1,60 +0,0 @@ -diff --git a/Makefile b/Makefile -index 416f444..eeaff03 100644 ---- a/Makefile -+++ b/Makefile -@@ -52,7 +52,7 @@ R= $V.0 - all: $(PLAT) - - $(PLATS) help test clean: -- @cd src && $(MAKE) $@ -+ @cd src && $(MAKE) $@ V=$(V) R=$(R) - - install: dummy - cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD) -diff --git a/src/Makefile b/src/Makefile -index 514593d..372a6dc 100644 ---- a/src/Makefile -+++ b/src/Makefile -@@ -33,6 +33,7 @@ CMCFLAGS= -Os - PLATS= guess aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris - - LUA_A= liblua.a -+LUA_SO= liblua.so - CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o - LIB_O= lauxlib.o lbaselib.o lcorolib.o ldblib.o liolib.o lmathlib.o loadlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o linit.o - BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS) -@@ -44,7 +45,7 @@ LUAC_T= luac - LUAC_O= luac.o - - ALL_O= $(BASE_O) $(LUA_O) $(LUAC_O) --ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T) -+ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T) $(LUA_SO) - ALL_A= $(LUA_A) - - # Targets start here. -@@ -60,6 +61,12 @@ $(LUA_A): $(BASE_O) - $(AR) $@ $(BASE_O) - $(RANLIB) $@ - -+$(LUA_SO): $(CORE_O) $(LIB_O) -+ $(CC) -shared -ldl -Wl,-soname,$(LUA_SO).$(V) -o $@.$(R) $? -lm $(MYLDFLAGS) -+ ln -sf $(LUA_SO).$(R) $(LUA_SO).$(V) -+ ln -sf $(LUA_SO).$(R) $(LUA_SO) -+ -+ - $(LUA_T): $(LUA_O) $(LUA_A) - $(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS) - -diff --git a/src/luaconf.h b/src/luaconf.h -index bdf927e..7e15198 100644 ---- a/src/luaconf.h -+++ b/src/luaconf.h -@@ -227,7 +227,7 @@ - - #else /* }{ */ - --#define LUA_ROOT "/usr/local/" -+#define LUA_ROOT "/usr/" - #define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR "/" - #define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR "/" - diff --git a/pkgs/development/interpreters/lua-5/lua-5.3-dso.make b/pkgs/development/interpreters/lua-5/lua-dso.make similarity index 89% rename from pkgs/development/interpreters/lua-5/lua-5.3-dso.make rename to pkgs/development/interpreters/lua-5/lua-dso.make index c70dbc4f9cc..d49c6bff498 100644 --- a/pkgs/development/interpreters/lua-5/lua-5.3-dso.make +++ b/pkgs/development/interpreters/lua-5/lua-dso.make @@ -1,8 +1,4 @@ - -LUA_SO=liblua.so - $(LUA_SO): $(CORE_O) $(LIB_O) $(CC) -shared -ldl -Wl,-soname,$(LUA_SO).$(V) -o $@.$(R) $? -lm $(MYLDFLAGS) ln -sf $(LUA_SO).$(R) $(LUA_SO).$(V) ln -sf $(LUA_SO).$(R) $(LUA_SO) - From 8abdf1db65fa89ec4be64a36fc3daf4d5c5b2c73 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Mon, 19 Apr 2021 11:04:11 +0000 Subject: [PATCH 4/5] lua: don't try to -ldl -lm on non-Linux OSes On other OSes, like NetBSD, these are part of libc. Fortunately, the Lua Makefile already knows about this, and has a SYSLIBS variable we can use for this. --- pkgs/development/interpreters/lua-5/lua-dso.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/interpreters/lua-5/lua-dso.make b/pkgs/development/interpreters/lua-5/lua-dso.make index d49c6bff498..11ac71fd819 100644 --- a/pkgs/development/interpreters/lua-5/lua-dso.make +++ b/pkgs/development/interpreters/lua-5/lua-dso.make @@ -1,4 +1,4 @@ $(LUA_SO): $(CORE_O) $(LIB_O) - $(CC) -shared -ldl -Wl,-soname,$(LUA_SO).$(V) -o $@.$(R) $? -lm $(MYLDFLAGS) + $(CC) -shared $(SYSLIBS) -Wl,-soname,$(LUA_SO).$(V) -o $@.$(R) $? $(MYLDFLAGS) ln -sf $(LUA_SO).$(R) $(LUA_SO).$(V) ln -sf $(LUA_SO).$(R) $(LUA_SO) From 25d4f0d334ef4a24a11a41dafd3595c26d954f41 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Mon, 19 Apr 2021 11:09:36 +0000 Subject: [PATCH 5/5] lua: use stdenv.cc.targetPrefix This evaluates to an empty string when not cross compiling, so by using this instead of stdenv.hostPlatform.config we can eliminate a conditional. --- pkgs/development/interpreters/lua-5/interpreter.nix | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkgs/development/interpreters/lua-5/interpreter.nix b/pkgs/development/interpreters/lua-5/interpreter.nix index cb31bf52eeb..973e9296435 100644 --- a/pkgs/development/interpreters/lua-5/interpreter.nix +++ b/pkgs/development/interpreters/lua-5/interpreter.nix @@ -54,17 +54,15 @@ self = stdenv.mkDerivation rec { "LDFLAGS=-fPIC" "V=${luaversion}" "PLAT=${plat}" - ] ++ (if stdenv.buildPlatform != stdenv.hostPlatform then [ - "CC=${stdenv.hostPlatform.config}-gcc" - "RANLIB=${stdenv.hostPlatform.config}-ranlib" - ] else []) - ; + "CC=${stdenv.cc.targetPrefix}cc" + "RANLIB=${stdenv.cc.targetPrefix}ranlib" + ]; configurePhase = '' runHook preConfigure makeFlagsArray+=(CFLAGS='-O2 -fPIC${lib.optionalString compat " -DLUA_COMPAT_ALL"} $(SYSCFLAGS)' ) - makeFlagsArray+=(${lib.optionalString stdenv.isDarwin "CC=\"$CC\""}${lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) " 'AR=${stdenv.hostPlatform.config}-ar rcu'"}) + makeFlagsArray+=(${lib.optionalString stdenv.isDarwin "CC=\"$CC\""}${lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) " 'AR=${stdenv.cc.targetPrefix}ar rcu'"}) installFlagsArray=( TO_BIN="lua luac" INSTALL_DATA='cp -d' \ TO_LIB="${if stdenv.isDarwin then "liblua.${version}.dylib" else "liblua.a liblua.so liblua.so.${luaversion} liblua.so.${version}"}" )