Skip to content

Commit

Permalink
fix: vendor build for older and faster LuaJIT
Browse files Browse the repository at this point in the history
There's some regression in LuaJIT performance where the key metric that
indicates if a build is slow or fast is file size, where smaller DLLs
are faster.

Use a specific older commit c7db8255e1eb59f933fac7bc9322f0e4f8ddc6e6 of
LuaJIT in a local vcpkg-ports tree to mitigate runtime problems with
gem dropdowns for now.
  • Loading branch information
zao committed Mar 26, 2024
1 parent 59c5f59 commit 7f48a16
Show file tree
Hide file tree
Showing 11 changed files with 353 additions and 2 deletions.
4 changes: 2 additions & 2 deletions vcpkg-configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
{
"kind": "filesystem",
"path": "vcpkg-ports",
"baseline": "2022-08-14",
"packages": []
"baseline": "2024-03-26",
"packages": ["luajit"]
}
]
}
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\"
86 changes: 86 additions & 0 deletions vcpkg-ports/ports/luajit/2023-04-16/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/sh

set -e

LJARCH=
LUAJIT_BUILDMODE=
LUAJIT_BUILDVM_X=
LUAJIT_DASM_ARCHS=
LUAJIT_PREFIX=
for OPTION; do
case "${OPTION}" in
--prefix=*)
LUAJIT_PREFIX="${OPTION#--prefix=}"
;;
BUILDMODE=*)
LUAJIT_BUILDMODE="${OPTION#BUILDMODE=}"
;;
BUILDVM_X=*)
LUAJIT_BUILDVM_X="${OPTION#BUILDVM_X=}"
;;
DASM_ARCHS=*)
LUAJIT_DASM_ARCHS="${OPTION#DASM_ARCHS=}"
;;
LJARCH=*)
LJARCH="${OPTION#LJARCH=}"
;;
esac
done

cat > Makefile.vcpkg <<END_MAKEFILE ;
COMMON_OPTIONS += 'E=@:' 'Q='
COMMON_OPTIONS += 'BUILDMODE=${LUAJIT_BUILDMODE}'
COMMON_OPTIONS += 'PREFIX=${LUAJIT_PREFIX}'
COMMON_OPTIONS += 'INSTALL_TNAME=luajit'
BUILD_OPTIONS += 'CC=${CC}'
BUILD_OPTIONS += 'CCDEBUG='
BUILD_OPTIONS += 'CFLAGS=${CPPFLAGS} ${CFLAGS}'
BUILD_OPTIONS += 'LDFLAGS=${LDFLAGS}'
BUILD_OPTIONS += 'LIBS=${LIBS}'
ifeq (${LJARCH},)
# native
BUILDVM_PREFIX = ${LUAJIT_PREFIX}/manual-tools/luajit
DASM_ARCHS = ${LUAJIT_DASM_ARCHS}
else
# cross
BUILD_OPTIONS += 'HOST_CC=:'
BUILD_OPTIONS += 'BUILDVM_T='
BUILD_OPTIONS += 'BUILDVM_X=${LUAJIT_BUILDVM_X}'
endif
# used by src/Makefile, best effort from manual '<CC> [-m32] -E src/lj_arch.h -dM'
TARGET_TESTARCH_COMMON += 'LJ_LE 1' 'LJ_HASJIT 1' 'LJ_HASFFI 1' 'LJ_ARCH_HASFPU 1' 'LJ_ABI_SOFTFP 0'
TARGET_TESTARCH_COMMON_32 += \$(TARGET_TESTARCH_COMMON) 'LJ_ARCH_BITS 32'
TARGET_TESTARCH_COMMON_64 += \$(TARGET_TESTARCH_COMMON) 'LJ_ARCH_BITS 64' 'LJ_TARGET_GC64 1'
TARGET_TESTARCH_arm = \$(TARGET_TESTARCH_COMMON_32) LJ_TARGET_ARM
TARGET_TESTARCH_arm64 = \$(TARGET_TESTARCH_COMMON_64) LJ_TARGET_ARM64 'LJ_ARCH_VERSION 80'
TARGET_TESTARCH_x86 = \$(TARGET_TESTARCH_COMMON_32) LJ_TARGET_X86
TARGET_TESTARCH_x64 = \$(TARGET_TESTARCH_COMMON_64) LJ_TARGET_X64 'LJ_FR2 1'
all:
\$(MAKE) clean \$(COMMON_OPTIONS) \$(BUILD_OPTIONS)
\$(MAKE) all \$(COMMON_OPTIONS) \$(BUILD_OPTIONS)
for DA in \$(DASM_ARCHS); do \\
rm -f src/host/buildvm_arch.h src/host/*.o; \\
case "\$\$DA" in \\
arm) TARGET_TESTARCH="\$(TARGET_TESTARCH_arm)" ;; \\
arm64) TARGET_TESTARCH="\$(TARGET_TESTARCH_arm64)" ;; \\
x86) TARGET_TESTARCH="\$(TARGET_TESTARCH_x86)" ;; \\
x64) TARGET_TESTARCH="\$(TARGET_TESTARCH_x64)" ;; \\
esac ; \\
\$(MAKE) -C src host/buildvm-\$\$DA\$(EXECUTABLE_SUFFIX) \$(COMMON_OPTIONS) \$(BUILD_OPTIONS) \\
BUILDVM_T=host/buildvm-\$\$DA\$(EXECUTABLE_SUFFIX) "TARGET_TESTARCH=\$\${TARGET_TESTARCH}" \\
|| exit 1; \\
done
install:
\$(MAKE) install \$(COMMON_OPTIONS)
for DA in \$(DASM_ARCHS); do \\
mkdir -p "\$\${DESTDIR}\$(BUILDVM_PREFIX)"; \\
install -m 0755 "src/host/buildvm-\$\$DA\$(EXECUTABLE_SUFFIX)" "\$\${DESTDIR}\$(BUILDVM_PREFIX)/buildvm-\$\$DA\$(EXECUTABLE_SUFFIX)" || exit 1 ; \\
done
END_MAKEFILE
24 changes: 24 additions & 0 deletions vcpkg-ports/ports/luajit/2023-04-16/luajit.pc.win.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Package information for LuaJIT to be used by pkg-config.
majver=2
minver=1
relver=0
version=${majver}.${minver}.${relver}-beta3
abiver=51

prefix=@PREFIX@
multilib=lib
exec_prefix=${prefix}
libdir=${exec_prefix}/${multilib}
libname=lua${abiver}
includedir=${prefix}/include/luajit

INSTALL_LMOD=${prefix}/share/lua/${abiver}
INSTALL_CMOD=${prefix}/${multilib}/lua/${abiver}

Name: LuaJIT
Description: Just-in-time compiler for Lua
URL: https://luajit.org
Version: ${version}
Requires:
Libs: -L${libdir} -l${libname}
Cflags: -I${includedir} @LJIT_MSVC_PC_CFLAGS@
31 changes: 31 additions & 0 deletions vcpkg-ports/ports/luajit/2023-04-16/msvcbuild.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
diff --git a/src/msvcbuild.bat b/src/msvcbuild.bat
index 045965f8..8b0a4ace 100644
--- a/src/msvcbuild.bat
+++ b/src/msvcbuild.bat
@@ -69,10 +69,9 @@ buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
@set BUILDTYPE=debug
@set LJCOMPILE=%LJCOMPILE% /Zi %DEBUGCFLAGS%
: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
+%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL lj_*.c lib_*.c /Fdlua51.pdb
@if errorlevel 1 goto :BAD
%LJLINK% /DLL /out:%LJDLLNAME% lj_*.obj lib_*.obj
@if errorlevel 1 goto :BAD
@@ -92,7 +91,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% luajit.c /Fdluajit.pdb
@if errorlevel 1 goto :BAD
%LJLINK% /out:luajit.exe luajit.obj %LJLIBNAME%
@if errorlevel 1 goto :BAD
@@ -114,4 +113,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
108 changes: 108 additions & 0 deletions vcpkg-ports/ports/luajit/2023-04-16/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
set(extra_patches "")
if (VCPKG_TARGET_IS_OSX)
list(APPEND extra_patches 005-do-not-pass-ld-e-macosx.patch)
endif()

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO LuaJIT/LuaJIT
REF c7db8255e1eb59f933fac7bc9322f0e4f8ddc6e6 #2023-04-16
SHA512 fffe87ea87cbf9e9614d1bd0d95746655528787ea92a4aa26f9dcd8e5c02fb330ce0092419e8444c3a2f8bcd575c2d580bbcc81295d8fe6bd4d9b48072ff2609
HEAD_REF master
PATCHES
msvcbuild.patch
003-do-not-set-macosx-deployment-target.patch
${extra_patches}
)

vcpkg_cmake_get_vars(cmake_vars_file)
include("${cmake_vars_file}")

if(VCPKG_DETECTED_MSVC)
# Due to lack of better MSVC cross-build support, just always build the host
# minilua tool with the target toolchain. This will work for native builds and
# for targeting x86 from x64 hosts. (UWP and ARM64 is unsupported.)
vcpkg_list(SET options)
set(PKGCONFIG_CFLAGS "")
if (VCPKG_LIBRARY_LINKAGE STREQUAL "static")
list(APPEND options "MSVCBUILD_OPTIONS=static")
else()
set(PKGCONFIG_CFLAGS "/DLUA_BUILD_AS_DLL=1")
endif()

vcpkg_install_nmake(SOURCE_PATH "${SOURCE_PATH}"
PROJECT_NAME "${CMAKE_CURRENT_LIST_DIR}/Makefile.nmake"
OPTIONS
${options}
)

configure_file("${CMAKE_CURRENT_LIST_DIR}/luajit.pc.win.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/luajit.pc" @ONLY)
if(NOT VCPKG_BUILD_TYPE)
configure_file("${CMAKE_CURRENT_LIST_DIR}/luajit.pc.win.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/luajit.pc" @ONLY)
endif()

vcpkg_copy_pdbs()
else()
vcpkg_list(SET options)
if(VCPKG_CROSSCOMPILING)
list(APPEND options
"LJARCH=${VCPKG_TARGET_ARCHITECTURE}"
"BUILDVM_X=${CURRENT_HOST_INSTALLED_DIR}/manual-tools/${PORT}/buildvm-${VCPKG_TARGET_ARCHITECTURE}${VCPKG_HOST_EXECUTABLE_SUFFIX}"
)
endif()

vcpkg_list(SET make_options "EXECUTABLE_SUFFIX=${VCPKG_TARGET_EXECUTABLE_SUFFIX}")
set(strip_options "") # cf. src/Makefile
if(VCPKG_TARGET_IS_OSX)
vcpkg_list(APPEND make_options "TARGET_SYS=Darwin")
set(strip_options " -x")
elseif(VCPKG_TARGET_IS_IOS)
vcpkg_list(APPEND make_options "TARGET_SYS=iOS")
set(strip_options " -x")
elseif(VCPKG_TARGET_IS_LINUX)
vcpkg_list(APPEND make_options "TARGET_SYS=Linux")
elseif(VCPKG_TARGET_IS_WINDOWS)
vcpkg_list(APPEND make_options "TARGET_SYS=Windows")
set(strip_options " --strip-unneeded")
endif()

set(dasm_archs "")
if("buildvm-32" IN_LIST FEATURES)
string(APPEND dasm_archs " arm x86")
endif()
if("buildvm-64" IN_LIST FEATURES)
string(APPEND dasm_archs " arm64 x64")
endif()

file(COPY "${CMAKE_CURRENT_LIST_DIR}/configure" DESTINATION "${SOURCE_PATH}")
vcpkg_configure_make(SOURCE_PATH "${SOURCE_PATH}"
COPY_SOURCE
OPTIONS
"BUILDMODE=${VCPKG_LIBRARY_LINKAGE}"
${options}
OPTIONS_RELEASE
"DASM_ARCHS=${dasm_archs}"
)
vcpkg_install_make(
MAKEFILE "Makefile.vcpkg"
OPTIONS
${make_options}
"TARGET_AR=${VCPKG_DETECTED_CMAKE_AR} rcus"
"TARGET_STRIP=${VCPKG_DETECTED_CMAKE_STRIP}${strip_options}"
)
endif()

file(REMOVE_RECURSE
"${CURRENT_PACKAGES_DIR}/debug/include"
"${CURRENT_PACKAGES_DIR}/debug/lib/lua"
"${CURRENT_PACKAGES_DIR}/debug/share"
"${CURRENT_PACKAGES_DIR}/lib/lua"
"${CURRENT_PACKAGES_DIR}/share/lua"
"${CURRENT_PACKAGES_DIR}/share/man"
)

vcpkg_copy_tools(TOOL_NAMES luajit AUTO_CLEAN)

vcpkg_fixup_pkgconfig()

vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYRIGHT")
49 changes: 49 additions & 0 deletions vcpkg-ports/ports/luajit/2023-04-16/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "luajit",
"version-date": "2023-04-16",
"port-version": 0,
"description": "LuaJIT is a Just-In-Time (JIT) compiler for the Lua programming language.",
"homepage": "https://github.com/LuaJIT/LuaJIT",
"license": "MIT",
"supports": "!uwp & !(arm64 & windows)",
"dependencies": [
{
"name": "luajit",
"host": true,
"features": [
"buildvm-64"
],
"platform": "!native & (arm64 | x64) & (!windows | mingw)"
},
{
"name": "luajit",
"host": true,
"features": [
"buildvm-32"
],
"platform": "!native & ((arm & !arm64) | x86) & (!windows | mingw)"
},
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
},
{
"name": "vcpkg-cmake-get-vars",
"host": true
}
],
"features": {
"buildvm-32": {
"description": "Install host tools for 32 bit targets",
"supports": "native & ((arm & !arm64) | x86) & (!windows | mingw)"
},
"buildvm-64": {
"description": "Install host tools for 64 bit targets",
"supports": "native & (arm64 | x64) & (!windows | mingw)"
}
}
}
3 changes: 3 additions & 0 deletions vcpkg-ports/versions/baseline.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"2022-08-14": {
"luajit": { "baseline": "2022-08-11", "port-version": 1 }
},
"2024-03-26": {
"luajit": { "baseline": "2023-04-16", "port-version": 0 }
}
}
5 changes: 5 additions & 0 deletions vcpkg-ports/versions/l-/luajit.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"version-date": "2023-04-16",
"port-version": 0,
"path": "$/ports/luajit/2023-04-16"
},
{
"version-date": "2022-08-11",
"port-version": 1,
Expand Down

0 comments on commit 7f48a16

Please sign in to comment.