Skip to content

Commit

Permalink
Merge pull request #48 from zao/fix/vendor-luajit-build
Browse files Browse the repository at this point in the history
fix: vendor older and faster LuaJIT build
  • Loading branch information
Wires77 authored Mar 27, 2024
2 parents 2d4782f + 8b8d575 commit df9f3be
Show file tree
Hide file tree
Showing 16 changed files with 670 additions and 1 deletion.
10 changes: 9 additions & 1 deletion vcpkg-configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@
"default-registry": {
"kind": "builtin",
"baseline": "4cfabe769eaceb209ea37267e8c50c43b86a4a7b"
}
},
"registries": [
{
"kind": "filesystem",
"path": "vcpkg-ports",
"baseline": "2024-03-26",
"packages": ["luajit"]
}
]
}
120 changes: 120 additions & 0 deletions vcpkg-ports/ports/luajit/2022-08-11_1/001-fix-build-path.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
diff --git a/src/msvcbuild.bat b/src/msvcbuild.bat
index aab4ef1..ff9df57 100644
--- a/src/msvcbuild.bat
+++ b/src/msvcbuild.bat
@@ -15,19 +15,20 @@
@setlocal
@rem Add more debug flags here, e.g. DEBUGCFLAGS=/DLUA_USE_APICHECK
@set DEBUGCFLAGS=
-@set LJCOMPILE=cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_STDIO_INLINE=__declspec(dllexport)__inline
+@set SOURCEDIR=%1
+@set LJCOMPILE=cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_STDIO_INLINE=__declspec(dllexport)__inline /I%SOURCEDIR%
@set LJLINK=link /nologo
@set LJMT=mt /nologo
@set LJLIB=lib /nologo /nodefaultlib
-@set DASMDIR=..\dynasm
+@set DASMDIR=%SOURCEDIR%\..\dynasm
@set DASM=%DASMDIR%\dynasm.lua
@set DASC=vm_x64.dasc
@set LJDLLNAME=lua51.dll
@set LJLIBNAME=lua51.lib
@set BUILDTYPE=release
-@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c lib_buffer.c
+@set ALL_LIB=%SOURCEDIR%\lib_base.c %SOURCEDIR%\lib_math.c %SOURCEDIR%\lib_bit.c %SOURCEDIR%\lib_string.c %SOURCEDIR%\lib_table.c %SOURCEDIR%\lib_io.c %SOURCEDIR%\lib_os.c %SOURCEDIR%\lib_package.c %SOURCEDIR%\lib_debug.c %SOURCEDIR%\lib_jit.c %SOURCEDIR%\lib_ffi.c %SOURCEDIR%\lib_buffer.c

-%LJCOMPILE% host\minilua.c
+%LJCOMPILE% %SOURCEDIR%\host\minilua.c /Fdminilua.pdb
@if errorlevel 1 goto :BAD
%LJLINK% /out:minilua.exe minilua.obj
@if errorlevel 1 goto :BAD
@@ -51,7 +52,7 @@ if exist minilua.exe.manifest^
-minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h %DASC%
+minilua %DASM% -LN %DASMFLAGS% -o %SOURCEDIR%\host\buildvm_arch.h %SOURCEDIR%\%DASC%
@if errorlevel 1 goto :BAD

-%LJCOMPILE% /I "." /I %DASMDIR% host\buildvm*.c
+%LJCOMPILE% /I "." /I %DASMDIR% %SOURCEDIR%\host\buildvm*.c /Fdbuildvm.pdb
@if errorlevel 1 goto :BAD
%LJLINK% /out:buildvm.exe buildvm*.obj
@if errorlevel 1 goto :BAD
@@ -60,41 +61,41 @@ if exist buildvm.exe.manifest^

buildvm -m peobj -o lj_vm.obj
@if errorlevel 1 goto :BAD
-buildvm -m bcdef -o lj_bcdef.h %ALL_LIB%
+buildvm -m bcdef -o %SOURCEDIR%\lj_bcdef.h %ALL_LIB%
@if errorlevel 1 goto :BAD
-buildvm -m ffdef -o lj_ffdef.h %ALL_LIB%
+buildvm -m ffdef -o %SOURCEDIR%\lj_ffdef.h %ALL_LIB%
@if errorlevel 1 goto :BAD
-buildvm -m libdef -o lj_libdef.h %ALL_LIB%
+buildvm -m libdef -o %SOURCEDIR%\lj_libdef.h %ALL_LIB%
@if errorlevel 1 goto :BAD
-buildvm -m recdef -o lj_recdef.h %ALL_LIB%
+buildvm -m recdef -o %SOURCEDIR%\lj_recdef.h %ALL_LIB%
@if errorlevel 1 goto :BAD
-buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB%
+buildvm -m vmdef -o %SOURCEDIR%\jit\vmdef.lua %ALL_LIB%
@if errorlevel 1 goto :BAD
-buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
+buildvm -m folddef -o %SOURCEDIR%\lj_folddef.h %SOURCEDIR%\lj_opt_fold.c
@if errorlevel 1 goto :BAD

-@if "%1" neq "debug" goto :NODEBUG
+@set LJLINK=%LJLINK% /debug
+@if "%2" neq "debug" goto :NODEBUG
@shift
@set BUILDTYPE=debug
@set LJCOMPILE=%LJCOMPILE% /Zi %DEBUGCFLAGS%
-@set LJLINK=%LJLINK% /opt:ref /opt:icf /incremental:no
:NODEBUG
@set LJLINK=%LJLINK% /%BUILDTYPE%
-@if "%1"=="amalg" goto :AMALGDLL
-@if "%1"=="static" goto :STATIC
-%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL lj_*.c lib_*.c
+@if "%2"=="amalg" goto :AMALGDLL
+@if "%2"=="static" goto :STATIC
+%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL %SOURCEDIR%\lj_*.c %SOURCEDIR%\lib_*.c /Fdlua51.pdb
@if errorlevel 1 goto :BAD
%LJLINK% /DLL /out:%LJDLLNAME% lj_*.obj lib_*.obj
@if errorlevel 1 goto :BAD
@goto :MTDLL
:STATIC
-%LJCOMPILE% lj_*.c lib_*.c
+%LJCOMPILE% %SOURCEDIR%\lj_*.c %SOURCEDIR%\lib_*.c /Fdlua51.pdb
@if errorlevel 1 goto :BAD
%LJLIB% /OUT:%LJLIBNAME% lj_*.obj lib_*.obj
@if errorlevel 1 goto :BAD
@goto :MTDLL
:AMALGDLL
-%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL ljamalg.c
+%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL %SOURCEDIR%\ljamalg.c
@if errorlevel 1 goto :BAD
%LJLINK% /DLL /out:%LJDLLNAME% ljamalg.obj lj_vm.obj
@if errorlevel 1 goto :BAD
@@ -102,7 +103,7 @@ buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
if exist %LJDLLNAME%.manifest^
%LJMT% -manifest %LJDLLNAME%.manifest -outputresource:%LJDLLNAME%;2

-%LJCOMPILE% luajit.c
+%LJCOMPILE% %SOURCEDIR%\luajit.c /Fdluajit.pdb
@if errorlevel 1 goto :BAD
%LJLINK% /out:luajit.exe luajit.obj %LJLIBNAME%
@if errorlevel 1 goto :BAD
@@ -110,8 +111,8 @@ if exist luajit.exe.manifest^
%LJMT% -manifest luajit.exe.manifest -outputresource:luajit.exe

@del *.obj *.manifest minilua.exe buildvm.exe
-@del host\buildvm_arch.h
-@del lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h
+@del %SOURCEDIR%\host\buildvm_arch.h
+@del %SOURCEDIR%\lj_bcdef.h %SOURCEDIR%\lj_ffdef.h %SOURCEDIR%\lj_libdef.h %SOURCEDIR%\lj_recdef.h %SOURCEDIR%\lj_folddef.h
@echo.
@echo === Successfully built LuaJIT for Windows/%LJARCH% ===

@@ -124,4 +125,5 @@ if exist luajit.exe.manifest^
@goto :END
:FAIL
@echo You must open a "Visual Studio Command Prompt" to run this script
+exit 1
:END
44 changes: 44 additions & 0 deletions vcpkg-ports/ports/luajit/2022-08-11_1/002-fix-crt-linkage.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
diff --git a/src/msvcbuild.bat b/src/msvcbuild.bat
index ff9df57..912bdc9 100644
--- a/src/msvcbuild.bat
+++ b/src/msvcbuild.bat
@@ -74,22 +74,25 @@ buildvm -m vmdef -o %SOURCEDIR%\jit\vmdef.lua %ALL_LIB%
buildvm -m folddef -o %SOURCEDIR%\lj_folddef.h %SOURCEDIR%\lj_opt_fold.c
@if errorlevel 1 goto :BAD

+@if "%2"=="static" set CRT_LINKAGE=/MT
+@if "%2"=="dynamic" set CRT_LINKAGE=/MD
@set LJLINK=%LJLINK% /debug
-@if "%2" neq "debug" goto :NODEBUG
+@if "%3" neq "debug" goto :NODEBUG
@shift
@set BUILDTYPE=debug
@set LJCOMPILE=%LJCOMPILE% /Zi %DEBUGCFLAGS%
+@set CRT_LINKAGE=%CRT_LINKAGE%d
:NODEBUG
@set LJLINK=%LJLINK% /%BUILDTYPE%
-@if "%2"=="amalg" goto :AMALGDLL
-@if "%2"=="static" goto :STATIC
-%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL %SOURCEDIR%\lj_*.c %SOURCEDIR%\lib_*.c /Fdlua51.pdb
+@if "%3"=="amalg" goto :AMALGDLL
+@if "%3"=="static" goto :STATIC
+%LJCOMPILE% %CRT_LINKAGE% /DLUA_BUILD_AS_DLL %SOURCEDIR%\lj_*.c %SOURCEDIR%\lib_*.c /Fdlua51.pdb
@if errorlevel 1 goto :BAD
%LJLINK% /DLL /out:%LJDLLNAME% lj_*.obj lib_*.obj
@if errorlevel 1 goto :BAD
@goto :MTDLL
:STATIC
-%LJCOMPILE% %SOURCEDIR%\lj_*.c %SOURCEDIR%\lib_*.c /Fdlua51.pdb
+%LJCOMPILE% %CRT_LINKAGE% %SOURCEDIR%\lj_*.c %SOURCEDIR%\lib_*.c /Fdlua51.pdb
@if errorlevel 1 goto :BAD
%LJLIB% /OUT:%LJLIBNAME% lj_*.obj lib_*.obj
@if errorlevel 1 goto :BAD
@@ -103,7 +106,7 @@ buildvm -m folddef -o %SOURCEDIR%\lj_folddef.h %SOURCEDIR%\lj_opt_fold.c
if exist %LJDLLNAME%.manifest^
%LJMT% -manifest %LJDLLNAME%.manifest -outputresource:%LJDLLNAME%;2

-%LJCOMPILE% %SOURCEDIR%\luajit.c /Fdluajit.pdb
+%LJCOMPILE% %CRT_LINKAGE% %SOURCEDIR%\luajit.c /Fdluajit.pdb
@if errorlevel 1 goto :BAD
%LJLINK% /out:luajit.exe luajit.obj %LJLIBNAME%
@if errorlevel 1 goto :BAD
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/src/Makefile b/src/Makefile
index 30d64be..b753ea1 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -316,9 +316,6 @@ ifeq (,$(shell $(TARGET_CC) -o /dev/null -c -x c /dev/null -fno-stack-protector
TARGET_XCFLAGS+= -fno-stack-protector
endif
ifeq (Darwin,$(TARGET_SYS))
- ifeq (,$(MACOSX_DEPLOYMENT_TARGET))
- $(error missing: export MACOSX_DEPLOYMENT_TARGET=XX.YY)
- endif
TARGET_STRIP+= -x
TARGET_XCFLAGS+= -DLUAJIT_UNWIND_EXTERNAL
TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
109 changes: 109 additions & 0 deletions vcpkg-ports/ports/luajit/2022-08-11_1/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO LuaJIT/LuaJIT
REF 633f265f67f322cbe2c5fd11d3e46d968ac220f7 #2022-08-11
SHA512 0a1d79ab7d2de6894bcff33309e015fdba0ea67cf0425d75b9301a30006039e81b527178dbb3485e1adea177ffe062e6fcef74307f8e725678e70562d57d1a5b
HEAD_REF master
PATCHES
001-fix-build-path.patch
002-fix-crt-linkage.patch
003-do-not-set-macosx-deployment-target.patch
)

if (VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
set (LJIT_STATIC "")
else()
set (LJIT_STATIC "static")
endif()

if (NOT VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL debug)
message(STATUS "Building ${TARGET_TRIPLET}-dbg")
file(REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")
file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")

if (VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
vcpkg_execute_required_process_repeat(
COUNT 1
COMMAND "${SOURCE_PATH}/src/msvcbuild.bat" ${SOURCE_PATH}/src ${VCPKG_CRT_LINKAGE} debug ${LJIT_STATIC}
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg"
LOGNAME build-${TARGET_TRIPLET}-dbg
)

file(INSTALL "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/luajit.exe" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/tools")
file(INSTALL "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/lua51.lib" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib")

if (VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
file(INSTALL "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/lua51.dll" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/bin")
file(COPY "${CURRENT_PACKAGES_DIR}/debug/bin/lua51.dll" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/tools")
endif()

vcpkg_copy_pdbs()
else()
vcpkg_execute_build_process(
COMMAND make -j${VCPKG_CONCURRENCY} -f ${SOURCE_PATH}/Makefile clean
WORKING_DIRECTORY ${SOURCE_PATH}
LOGNAME clean-${TARGET_TRIPLET}-debug
)
vcpkg_execute_build_process(
COMMAND make -j${VCPKG_CONCURRENCY} -f ${SOURCE_PATH}/Makefile PREFIX=${CURRENT_PACKAGES_DIR}/debug CCDEBUG=-g3 CFLAGS=-O0 BUILDMODE=${VCPKG_LIBRARY_LINKAGE} install
WORKING_DIRECTORY ${SOURCE_PATH}
LOGNAME build-${TARGET_TRIPLET}-debug
)
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/lib/lua")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/bin")
endif()
endif()

if (NOT VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL release)
message(STATUS "Building ${TARGET_TRIPLET}-rel")
file(REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")
file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")

if (VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
vcpkg_execute_required_process_repeat(
COUNT 1
COMMAND "${SOURCE_PATH}/src/msvcbuild.bat" ${SOURCE_PATH}/src ${VCPKG_CRT_LINKAGE} ${LJIT_STATIC}
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel"
LOGNAME build-${TARGET_TRIPLET}-rel
)

file(INSTALL "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/luajit.exe" DESTINATION "${CURRENT_PACKAGES_DIR}/tools")
file(INSTALL "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/lua51.lib" DESTINATION "${CURRENT_PACKAGES_DIR}/lib")

if (VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
file(INSTALL "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/lua51.dll" DESTINATION "${CURRENT_PACKAGES_DIR}/bin")
vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools)
endif()

vcpkg_copy_pdbs()
else()
vcpkg_execute_build_process(
COMMAND make -j${VCPKG_CONCURRENCY} -f ${SOURCE_PATH}/Makefile clean
WORKING_DIRECTORY ${SOURCE_PATH}
LOGNAME clean-${TARGET_TRIPLET}-rel
)
vcpkg_execute_build_process(
COMMAND make -j${VCPKG_CONCURRENCY} -f ${SOURCE_PATH}/Makefile PREFIX=${CURRENT_PACKAGES_DIR} CCDEBUG= BUILDMODE=${VCPKG_LIBRARY_LINKAGE} install
WORKING_DIRECTORY ${SOURCE_PATH}
LOGNAME build-${TARGET_TRIPLET}-rel
)
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/share/lua" "${CURRENT_PACKAGES_DIR}/lib/lua")
endif()
endif()

if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin")
endif()

file(INSTALL "${SOURCE_PATH}/src/lua.h" DESTINATION "${CURRENT_PACKAGES_DIR}/include/${PORT}")
file(INSTALL "${SOURCE_PATH}/src/luajit.h" DESTINATION "${CURRENT_PACKAGES_DIR}/include/${PORT}")
file(INSTALL "${SOURCE_PATH}/src/luaconf.h" DESTINATION "${CURRENT_PACKAGES_DIR}/include/${PORT}")
file(INSTALL "${SOURCE_PATH}/src/lualib.h" DESTINATION "${CURRENT_PACKAGES_DIR}/include/${PORT}")
file(INSTALL "${SOURCE_PATH}/src/lauxlib.h" DESTINATION "${CURRENT_PACKAGES_DIR}/include/${PORT}")
file(INSTALL "${SOURCE_PATH}/src/lua.hpp" DESTINATION "${CURRENT_PACKAGES_DIR}/include/${PORT}")

vcpkg_fixup_pkgconfig()

file(INSTALL "${SOURCE_PATH}/COPYRIGHT" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
9 changes: 9 additions & 0 deletions vcpkg-ports/ports/luajit/2022-08-11_1/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "luajit",
"version-date": "2022-08-11",
"port-version": 1,
"description": "LuaJIT is a Just-In-Time (JIT) compiler for the Lua programming language.",
"homepage": "https://github.com/LuaJIT/LuaJIT",
"license": "MIT",
"supports": "!uwp"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/src/Makefile b/src/Makefile
index c4d0b14d..2c9769b9 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -302,9 +302,6 @@ ifeq (,$(shell $(TARGET_CC) -o /dev/null -c -x c /dev/null -fno-stack-protector
TARGET_XCFLAGS+= -fno-stack-protector
endif
ifeq (Darwin,$(TARGET_SYS))
- ifeq (,$(MACOSX_DEPLOYMENT_TARGET))
- $(error missing: export MACOSX_DEPLOYMENT_TARGET=XX.YY)
- endif
TARGET_STRIP+= -x
TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
TARGET_DYNXLDOPTS=
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
diff --git a/etc/luajit.pc b/etc/luajit.pc
index 39e1e57..3837d3b 100644
--- a/etc/luajit.pc
+++ b/etc/luajit.pc
@@ -21,5 +21,5 @@ URL: https://luajit.org
Version: ${version}
Requires:
Libs: -L${libdir} -l${libname}
-Libs.private: -Wl,-E -lm -ldl
+Libs.private: -lm -ldl
Cflags: -I${includedir}
20 changes: 20 additions & 0 deletions vcpkg-ports/ports/luajit/2023-04-16/Makefile.nmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
all:
@echo _CL_ = $(_CL_)
@echo _LINK_ = $(_LINK_)
cd src && .\msvcbuild.bat $(MSVCBUILD_OPTIONS)

install: src/luajit.exe
-mkdir "$(INSTALLDIR)"
-mkdir "$(INSTALLDIR)\bin"
copy src\luajit.exe "$(INSTALLDIR)\bin\"
if exist src\lua51.dll copy src\lua51.dll "$(INSTALLDIR)\bin\"
-mkdir "$(INSTALLDIR)\lib"
copy src\lua51.lib "$(INSTALLDIR)\lib\"
-mkdir "$(INSTALLDIR)\include"
-mkdir "$(INSTALLDIR)\include\luajit"
copy src/lua.h "$(INSTALLDIR)\include\luajit\"
copy src/luajit.h "$(INSTALLDIR)\include\luajit\"
copy src/luaconf.h "$(INSTALLDIR)\include\luajit\"
copy src/lualib.h "$(INSTALLDIR)\include\luajit\"
copy src/lauxlib.h "$(INSTALLDIR)\include\luajit\"
copy src/lua.hpp "$(INSTALLDIR)\include\luajit\"
Loading

0 comments on commit df9f3be

Please sign in to comment.