From ee696544d079d3fb1699a838e2dcb7e61bffda8a Mon Sep 17 00:00:00 2001 From: Alexander M Pickering Date: Mon, 23 Sep 2024 14:15:46 -0500 Subject: Add patch to modify all_in_one and add hardcoded values --- all_in_one.patch | 38 +++++++++++++++++++++++ hardcoded.lua | 6 ++++ init | 94 +++++++++++++++++++++++++++++++++++++++++--------------- 3 files changed, 113 insertions(+), 25 deletions(-) create mode 100644 all_in_one.patch create mode 100644 hardcoded.lua diff --git a/all_in_one.patch b/all_in_one.patch new file mode 100644 index 0000000..234bcb7 --- /dev/null +++ b/all_in_one.patch @@ -0,0 +1,38 @@ +--- "binary/all_in_one.orig" 2024-09-23 13:31:16.489277700 -0500 ++++ "binary/all_in_one" 2024-09-23 13:31:14.032152500 -0500 +@@ -406,27 +406,6 @@ + fd:write(reindent_c(table.concat(out, "\n"))) + fd:close() + +- assert(deps.check_lua_incdir(cfg.variables)) +- assert(deps.check_lua_libdir(cfg.variables)) +- +- cmd = table.concat(filter_in(nonnull, { +- CC, "-o", TARGET_DIR .. "/" .. program_name .. ".exe", +- "-I", cfg.variables.LUA_INCDIR, +- if_platform("unix", "-rdynamic"), +- "-Os", +- c_filename, +- "-L", cfg.variables.LUA_LIBDIR, +- table.concat(a_files, " "), +- --if_platform("unix", cfg.variables.LUA_LIBDIR .. "/" .. cfg.variables.LUALIB:gsub("%.so.*$", ".a")), +- --if_platform("windows", "mingw/liblua.a"), -- FIXME +- cfg.variables.LUA_LIBDIR .. "/" .. cfg.variables.LUALIB:gsub("%.so.*$", ".a"), +- if_platform("unix", "-ldl"), +- if_platform("unix", "-lpthread"), +- if_platform("windows", "-mconsole -mwindows"), +- "-lm" +- }), " ") +- print(cmd) +- os.execute(cmd) + end + + -------------------------------------------------------------------------------- +@@ -500,4 +479,6 @@ + generate(MAIN_PROGRAM, "src", { EXCLUDE, "^bin/?" }) + end + +-main() ++cfg.init() ++fs.init() ++generate(MAIN_PROGRAM, "src", {EXCLUDE, "^bin/?"}) diff --git a/hardcoded.lua b/hardcoded.lua new file mode 100644 index 0000000..9be83d8 --- /dev/null +++ b/hardcoded.lua @@ -0,0 +1,6 @@ +return { + SYSTEM = "windows", + PROCESSOR = "x86", + FORCE_CONFIG = true, + IS_BINARY = true, +} diff --git a/init b/init index 26b3428..37e5393 100755 --- a/init +++ b/init @@ -3,25 +3,32 @@ if [ -e libluajit.a ]; then mv libluajit.a liblua.a fi -cd luarocks/binary -mkdir -p build-windows-deps-cicd/lib -cd build-windows-deps-cicd/lib -cp /root/liblua.a . -cp /root/libssl.a . -cp /root/libz.a . -cp /root/libbz2.a . -cd .. -mkdir bin -cd bin -cp /root/*.exe . - -mkdir -p windows-deps-cicd/lib +tar -xvzf lua-*.tar.gz --directory="lua" --strip-components=1 +mv hardcoded.lua luarocks/src/core/hardcoded.lua +cd luarocks +mkdir build-binary +patch -p1 -i /root/luarocks-packaging/all_in_one.patch +LUAROCKS_CROSS_COMPILING=1 lua5.4 binary/all_in_one -cd ../../.. -LUA_BINDIR=binary/build-windows-deps-cicd/bin -./configure --disable-incdir-check --with-lua=binary/build-windows-deps-cicd/bin --with-lua-lib=binary/build-windows-deps/lib -make -f binary/Makefile.windows BUILD_WINDOWS_DEPS_DIR= -LUAROCKS_CROSS_COMPILING=1 make binary LUA_DIR=binary/build-windows-deps-cicd/bin CC=gcc NM=nm BINARY_PLATFORM=windows +#cd luarocks/binary +# mkdir -p build-windows-deps-cicd/lib +# cd build-windows-deps-cicd/lib +# cp /root/liblua.a . +# cp /root/libssl.a . +# cp /root/libz.a . +# cp /root/libbz2.a . +# cd .. +# mkdir bin +# cd bin +# cp /root/*.exe . +# +# mkdir -p windows-deps-cicd/lib +# +# cd ../../.. +#LUA_BINDIR=binary/build-windows-deps-cicd/bin +#./configure --disable-incdir-check --with-lua=binary/build-windows-deps-cicd/bin --with-lua-lib=binary/build-windows-deps/lib +#make -f binary/Makefile.windows BUILD_WINDOWS_DEPS_DIR= +#LUAROCKS_CROSS_COMPILING=1 make binary LUA_DIR=binary/build-windows-deps-cicd/bin CC=gcc NM=nm BINARY_PLATFORM=windows # all_in_one generates a series of files: # dir .. "/luarocks/core/hardcoded.lua" # @@ -50,13 +57,50 @@ LUAROCKS_CROSS_COMPILING=1 make binary LUA_DIR=binary/build-windows-deps-cicd/bi # ---------------------- # Lets modify all_in_one: delete the last line that calls main() and replace it # with: -cfg.init() -cfg.variables.LUA_INCDIR_OK = true -cfg.variables.LUA_LIBDIR_OK = true -fs.init() -generate(MAIN_PROGRAM, "src", {EXCLUDE, "^bin/?"}) +# cfg.init() +# cfg.variables.LUA_INCDIR_OK = true +# cfg.variables.LUA_LIBDIR_OK = true +# fs.init() +# generate(MAIN_PROGRAM, "src", {EXCLUDE, "^bin/?"}) # Make the output directory -mkdir build-binary +# mkdir build-binary # Then call it like: -LUAROCKS_CROSS_COMPILING=1 lua5.4 binary/all_in_one +# LUAROCKS_CROSS_COMPILING=1 lua5.4 binary/all_in_one + +# Patches to make all_in_one work with lua 5.1: +# Lua 5.1 never defined LUA_OK, which all_in_one uses to check luaL_loadbuffer(), +# define it in the preamble if it doesn't already exist. + +#ifndef LUA_OK +#define LUA_OK 0 +#endif + +# Lua 5.1 doesn't define lua_copy or luaL_traceback, +# for lua_copy, we can rewrite with lua_replace() since we're moving the top element. +# line 137: lua_replace(L,3); +# +# Lua 5.1 doesn't define luaL_traceback(), here's what it looks like in 5.1 lua.c: +#ifndef luaL_traceback +# static inline void +# luaL_traceback(lua_State *L, lua_State *L1, const char *msg, int level){ +# lua_getfield(L, LUA_GLOBALSINDEX, "debug"); +# if(!lua_istable(L,-1)){ +# lua_pop(L,1); +# return; +# } +# lua_getfield(L, -1, "traceback"); +# if(!lua_isfunction(L,-1)){ +# lua_pop(L,2); +# return; +# } +# lua_pushthread(L1); +# lua_pushstring(L,msg); +# lua_pushnumber(L,level); +# lua_call(L,3,1); +# return; +# } +#endif + +# Finally, use gcc to build: +#gcc -o build-binary/luarocks.exe -Os build-binary/luarocks.exe.c -I/root/lua/src /root/libz2.a /root/libssl.a /root/libz.a /root/liblua.a -mconsole -mwindows -lm -- cgit v1.2.3-55-g6feb