Skip to content

Commit

Permalink
Added ability to use system lua
Browse files Browse the repository at this point in the history
  • Loading branch information
samsinsane committed Dec 3, 2024
1 parent 1c7b11b commit 8a8f9e9
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
if: matrix.depsrc == 'system'
run: |
sudo apt-get update
sudo apt-get -y install libcurl4-openssl-dev libzip-dev
sudo apt-get -y install libcurl4-openssl-dev libzip-dev liblua5.3-dev
- name: Build
run: PLATFORM=${{ matrix.platform }} CONFIG=${{ matrix.config }} PREMAKE_OPTS="--curl-src=${{ matrix.depsrc }} --zlib-src=${{ matrix.depsrc }}" ./Bootstrap.sh
run: PLATFORM=${{ matrix.platform }} CONFIG=${{ matrix.config }} PREMAKE_OPTS="--lib-src=${{ matrix.depsrc }}" ./Bootstrap.sh
- name: Test
run: bin/${{ matrix.config }}/premake5 test --test-all
- name: Docs check
Expand Down
16 changes: 8 additions & 8 deletions Bootstrap.mak
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ mingw-clean: nix-clean

mingw: mingw-clean
mkdir -p build/bootstrap
$(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -I"$(LUA_DIR)" -I"$(LUASHIM_DIR)" $(SRC) -lole32 -lversion
$(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -DLUA_STATICLIB -I"$(LUA_DIR)" -I"$(LUASHIM_DIR)" $(SRC) -lole32 -lversion
./build/bootstrap/premake_bootstrap embed
./build/bootstrap/premake_bootstrap --arch=$(PLATFORM) --os=windows --to=build/bootstrap --cc=mingw $(PREMAKE_OPTS) gmake2
$(MAKE) -C build/bootstrap -j`getconf _NPROCESSORS_ONLN` config=$(CONFIG)_$(PLATFORM:x86=win32)
Expand All @@ -100,7 +100,7 @@ osx-clean: nix-clean

osx: osx-clean
mkdir -p build/bootstrap
$(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -DLUA_USE_MACOSX -I"$(LUA_DIR)" -I"$(LUASHIM_DIR)" -framework CoreServices -framework Foundation -framework Security -lreadline $(SRC)
$(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -DLUA_STATICLIB -DLUA_USE_MACOSX -I"$(LUA_DIR)" -I"$(LUASHIM_DIR)" -framework CoreServices -framework Foundation -framework Security -lreadline $(SRC)
./build/bootstrap/premake_bootstrap embed
./build/bootstrap/premake_bootstrap --arch=$(PLATFORM) --to=build/bootstrap $(PREMAKE_OPTS) gmake2
$(MAKE) -C build/bootstrap -j`getconf _NPROCESSORS_ONLN` config=$(CONFIG)
Expand All @@ -109,7 +109,7 @@ linux-clean: nix-clean

linux: linux-clean
mkdir -p build/bootstrap
$(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -DLUA_USE_POSIX -DLUA_USE_DLOPEN -I"$(LUA_DIR)" -I"$(LUASHIM_DIR)" $(SRC) -lm -ldl -lrt -luuid
$(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -DLUA_STATICLIB -DLUA_USE_POSIX -DLUA_USE_DLOPEN -I"$(LUA_DIR)" -I"$(LUASHIM_DIR)" $(SRC) -lm -ldl -lrt -luuid
./build/bootstrap/premake_bootstrap embed
./build/bootstrap/premake_bootstrap --to=build/bootstrap $(PREMAKE_OPTS) gmake2
$(MAKE) -C build/bootstrap -j`getconf _NPROCESSORS_ONLN` config=$(CONFIG)
Expand All @@ -118,7 +118,7 @@ bsd-clean: nix-clean

bsd: bsd-clean
mkdir -p build/bootstrap
$(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -DLUA_USE_POSIX -DLUA_USE_DLOPEN -I"$(LUA_DIR)" -I"$(LUASHIM_DIR)" $(SRC) -lm
$(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -DLUA_STATICLIB -DLUA_USE_POSIX -DLUA_USE_DLOPEN -I"$(LUA_DIR)" -I"$(LUASHIM_DIR)" $(SRC) -lm
./build/bootstrap/premake_bootstrap embed
./build/bootstrap/premake_bootstrap --to=build/bootstrap $(PREMAKE_OPTS) gmake2
$(MAKE) -C build/bootstrap -j`getconf NPROCESSORS_ONLN` config=$(CONFIG)
Expand All @@ -127,7 +127,7 @@ solaris-clean: nix-clean

solaris: solaris-clean
mkdir -p build/bootstrap
$(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -DLUA_USE_POSIX -DLUA_USE_DLOPEN -I"$(LUA_DIR)" -I"$(LUASHIM_DIR)" $(SRC) -lm
$(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -DLUA_STATICLIB -DLUA_USE_POSIX -DLUA_USE_DLOPEN -I"$(LUA_DIR)" -I"$(LUASHIM_DIR)" $(SRC) -lm
./build/bootstrap/premake_bootstrap embed
./build/bootstrap/premake_bootstrap --to=build/bootstrap $(PREMAKE_OPTS) gmake2
$(MAKE) -C build/bootstrap -j`getconf NPROCESSORS_ONLN` config=$(CONFIG)
Expand All @@ -136,14 +136,14 @@ haiku-clean: nix-clean

haiku: haiku-clean
mkdir -p build/bootstrap
$(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -DLUA_USE_POSIX -DLUA_USE_DLOPEN -D_BSD_SOURCE -I"$(LUA_DIR)" -I"$(LUASHIM_DIR)" $(SRC) -lbsd
$(CC) -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -DLUA_STATICLIB -DLUA_USE_POSIX -DLUA_USE_DLOPEN -D_BSD_SOURCE -I"$(LUA_DIR)" -I"$(LUASHIM_DIR)" $(SRC) -lbsd
./build/bootstrap/premake_bootstrap embed
./build/bootstrap/premake_bootstrap --to=build/bootstrap $(PREMAKE_OPTS) gmake2
$(MAKE) -C build/bootstrap -j`getconf _NPROCESSORS_ONLN` config=$(CONFIG)

windows-base: windows-clean
if not exist build\bootstrap (mkdir build\bootstrap)
cl /Fo.\build\bootstrap\ /Fe.\build\bootstrap\premake_bootstrap.exe /DPREMAKE_NO_BUILTIN_SCRIPTS /I"$(LUA_DIR)" /I"$(LUASHIM_DIR)" user32.lib ole32.lib advapi32.lib $(SRC)
cl /Fo.\build\bootstrap\ /Fe.\build\bootstrap\premake_bootstrap.exe /DPREMAKE_NO_BUILTIN_SCRIPTS /DLUA_STATICLIB /I"$(LUA_DIR)" /I"$(LUASHIM_DIR)" user32.lib ole32.lib advapi32.lib $(SRC)
.\build\bootstrap\premake_bootstrap.exe embed
.\build\bootstrap\premake_bootstrap --arch=$(PLATFORM) --to=build/bootstrap $(PREMAKE_OPTS) $(MSDEV)

Expand All @@ -158,7 +158,7 @@ cosmo-clean: nix-clean

cosmo: cosmo-clean
mkdir -p build/bootstrap
cosmocc -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -DLUA_USE_POSIX -DLUA_USE_DLOPEN -I"$(LUA_DIR)" -I"$(LUASHIM_DIR)" $(SRC) -lm -ldl -lrt
cosmocc -o build/bootstrap/premake_bootstrap -DPREMAKE_NO_BUILTIN_SCRIPTS -DLUA_STATICLIB -DLUA_USE_POSIX -DLUA_USE_DLOPEN -I"$(LUA_DIR)" -I"$(LUASHIM_DIR)" $(SRC) -lm -ldl -lrt
./build/bootstrap/premake_bootstrap embed
./build/bootstrap/premake_bootstrap --to=build/bootstrap --cc=cosmocc gmake2
$(MAKE) -C build/bootstrap -j`getconf _NPROCESSORS_ONLN` config=$(CONFIG)
54 changes: 49 additions & 5 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,39 @@
description = "Disable Luasocket 3rd party lib"
}

newoption {
trigger = "lua-src",
description = "Specify the source of the Lua 3rd party library",
allowed = {
{ "contrib", "Uses Lua in contrib folder" },
{ "system", "Uses Lua from the host system" },
},
default = "contrib",
}

newoption {
trigger = "lib-src",
description = "Specify the source of all 3rd party libraries",
allowed = {
{ "none", "Disables all optional 3rd party libraries" },
{ "contrib", "Uses 3rd party libraries in contrib folder" },
{ "system", "Uses 3rd party libraries from the host system" },
}
}
if _OPTIONS["lib-src"] == "none" then
_OPTIONS["curl-src"] = "none"
_OPTIONS["zlib-src"] = "none"
-- Lua is not optional
elseif _OPTIONS["lib-src"] == "contrib" then
_OPTIONS["curl-src"] = "contrib"
_OPTIONS["zlib-src"] = "contrib"
_OPTIONS["lua-src"] = "contrib"
elseif _OPTIONS["lib-src"] == "system" then
_OPTIONS["curl-src"] = "system"
_OPTIONS["zlib-src"] = "system"
_OPTIONS["lua-src"] = "system"
end

newoption {
trigger = "bytecode",
description = "Embed scripts as bytecode instead of stripped source code"
Expand Down Expand Up @@ -173,6 +206,9 @@
filter { "options:curl-src=contrib" }
defines { "CURL_STATICLIB" }

filter { "options:lua-src=contrib" }
defines { "LUA_STATICLIB" }

filter { "system:macosx", "options:arch=ARM or arch=ARM64" }
buildoptions { "-arch arm64" }
linkoptions { "-arch arm64" }
Expand Down Expand Up @@ -227,8 +263,14 @@
targetname "premake5"
language "C"
kind "ConsoleApp"
includedirs { "contrib/lua/src", "contrib/luashim" }
links { "lua-lib" }
includedirs { "contrib/luashim" }

filter { "options:lua-src=contrib" }
includedirs { "contrib/lua/src" }
links { "lua-lib" }
filter { "options:lua-src=system" }
links { "lua5.3" }
filter {}

-- optional 3rd party libraries
filter { "options:zlib-src=contrib" }
Expand Down Expand Up @@ -327,8 +369,10 @@ if premake.action.supports("None") then
end
-- optional 3rd party libraries
group "contrib"
include "contrib/lua"
include "contrib/luashim"
if _OPTIONS["lua-src"] == "contrib" then
include "contrib/lua"
include "contrib/luashim"
end

if _OPTIONS["zlib-src"] == "contrib" then
include "contrib/zlib"
Expand All @@ -340,7 +384,7 @@ end
include "contrib/curl"
end

if _OPTIONS["cc"] ~= "cosmocc" then
if _OPTIONS["lua-src"] == "contrib" and _OPTIONS["cc"] ~= "cosmocc" then
group "Binary Modules"
include "binmodules/example"

Expand Down
4 changes: 4 additions & 0 deletions src/host/curl_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
#ifdef PREMAKE_CURL

#include "buffered_io.h"
#ifdef LUA_STATICLIB
#include "lua.h"
#else
#include <lua5.3/lua.h>
#endif

#define _MPRINTF_REPLACE /* use curl functions only */
#include <curl/curl.h>
Expand Down
6 changes: 6 additions & 0 deletions src/host/premake.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
*/

#define lua_c
#ifdef LUA_STATICLIB
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#else
#include <lua5.3/lua.h>
#include <lua5.3/lauxlib.h>
#include <lua5.3/lualib.h>
#endif

#include <stdint.h>
#include <stdlib.h>
Expand Down

0 comments on commit 8a8f9e9

Please sign in to comment.