[luajit] Improve static and dynamic CRT support (#8929)

* [luajit] Improve static and dynamic CRT support

* [luajit] fix CRT linkage always static

* [luajit] Fix luajit.exe static build failure

* [luajit] Remove old patch

* [luajit] Remove old patch

Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
This commit is contained in:
Rémy Tassoux 2020-02-14 02:48:46 +01:00 committed by GitHub
parent c819b7f6bf
commit 76fba5ec78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 165 additions and 154 deletions

View File

@ -1,124 +1,119 @@
diff --git a/src/msvcbuild.bat b/src/msvcbuild.bat diff --git a/src/msvcbuild.bat b/src/msvcbuild.bat
index 6f64a49..ba77cd5 100644 index 42e3652..6a889e1 100644
--- a/src/msvcbuild.bat --- a/src/msvcbuild.bat
+++ b/src/msvcbuild.bat +++ b/src/msvcbuild.bat
@@ -14,17 +14,18 @@ @@ -14,17 +14,18 @@
@if not defined INCLUDE goto :FAIL @if not defined INCLUDE goto :FAIL
@setlocal @setlocal
-@set LJCOMPILE=cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_STDIO_INLINE=__declspec(dllexport)__inline -@set LJCOMPILE=cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_STDIO_INLINE=__declspec(dllexport)__inline
+@set SOURCEDIR=%1 +@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 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 LJLINK=link /nologo
@set LJMT=mt /nologo @set LJMT=mt /nologo
@set LJLIB=lib /nologo /nodefaultlib @set LJLIB=lib /nologo /nodefaultlib
-@set DASMDIR=..\dynasm -@set DASMDIR=..\dynasm
+@set DASMDIR=%SOURCEDIR%\..\dynasm +@set DASMDIR=%SOURCEDIR%\..\dynasm
@set DASM=%DASMDIR%\dynasm.lua @set DASM=%DASMDIR%\dynasm.lua
@set LJDLLNAME=lua51.dll @set LJDLLNAME=lua51.dll
@set LJLIBNAME=lua51.lib @set LJLIBNAME=lua51.lib
-@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 -@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
+@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 +@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
-%LJCOMPILE% host\minilua.c -%LJCOMPILE% host\minilua.c
+%LJCOMPILE% %SOURCEDIR%\host\minilua.c /Fdminilua.pdb +%LJCOMPILE% %SOURCEDIR%\host\minilua.c /Fdminilua.pdb
@if errorlevel 1 goto :BAD @if errorlevel 1 goto :BAD
%LJLINK% /out:minilua.exe minilua.obj %LJLINK% /out:minilua.exe minilua.obj
@if errorlevel 1 goto :BAD @if errorlevel 1 goto :BAD
@@ -38,10 +39,10 @@ if exist minilua.exe.manifest^ @@ -38,10 +39,10 @@ if exist minilua.exe.manifest^
@set DASMFLAGS=-D WIN -D JIT -D FFI @set DASMFLAGS=-D WIN -D JIT -D FFI
@set LJARCH=x86 @set LJARCH=x86
:X64 :X64
-minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_x86.dasc -minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_x86.dasc
+minilua %DASM% -LN %DASMFLAGS% -o %SOURCEDIR%\host\buildvm_arch.h %SOURCEDIR%\vm_x86.dasc +minilua %DASM% -LN %DASMFLAGS% -o %SOURCEDIR%\host\buildvm_arch.h %SOURCEDIR%\vm_x86.dasc
@if errorlevel 1 goto :BAD @if errorlevel 1 goto :BAD
-%LJCOMPILE% /I "." /I %DASMDIR% host\buildvm*.c -%LJCOMPILE% /I "." /I %DASMDIR% host\buildvm*.c
+%LJCOMPILE% /I "." /I %DASMDIR% %SOURCEDIR%\host\buildvm*.c /Fdbuildvm.pdb +%LJCOMPILE% /I "." /I %DASMDIR% %SOURCEDIR%\host\buildvm*.c /Fdbuildvm.pdb
@if errorlevel 1 goto :BAD @if errorlevel 1 goto :BAD
%LJLINK% /out:buildvm.exe buildvm*.obj %LJLINK% /out:buildvm.exe buildvm*.obj
@if errorlevel 1 goto :BAD @if errorlevel 1 goto :BAD
@@ -50,30 +51,30 @@ if exist buildvm.exe.manifest^ @@ -50,39 +51,39 @@ if exist buildvm.exe.manifest^
buildvm -m peobj -o lj_vm.obj buildvm -m peobj -o lj_vm.obj
@if errorlevel 1 goto :BAD @if errorlevel 1 goto :BAD
-buildvm -m bcdef -o lj_bcdef.h %ALL_LIB% -buildvm -m bcdef -o lj_bcdef.h %ALL_LIB%
+buildvm -m bcdef -o %SOURCEDIR%\lj_bcdef.h %ALL_LIB% +buildvm -m bcdef -o %SOURCEDIR%\lj_bcdef.h %ALL_LIB%
@if errorlevel 1 goto :BAD @if errorlevel 1 goto :BAD
-buildvm -m ffdef -o lj_ffdef.h %ALL_LIB% -buildvm -m ffdef -o lj_ffdef.h %ALL_LIB%
+buildvm -m ffdef -o %SOURCEDIR%\lj_ffdef.h %ALL_LIB% +buildvm -m ffdef -o %SOURCEDIR%\lj_ffdef.h %ALL_LIB%
@if errorlevel 1 goto :BAD @if errorlevel 1 goto :BAD
-buildvm -m libdef -o lj_libdef.h %ALL_LIB% -buildvm -m libdef -o lj_libdef.h %ALL_LIB%
+buildvm -m libdef -o %SOURCEDIR%\lj_libdef.h %ALL_LIB% +buildvm -m libdef -o %SOURCEDIR%\lj_libdef.h %ALL_LIB%
@if errorlevel 1 goto :BAD @if errorlevel 1 goto :BAD
-buildvm -m recdef -o lj_recdef.h %ALL_LIB% -buildvm -m recdef -o lj_recdef.h %ALL_LIB%
+buildvm -m recdef -o %SOURCEDIR%\lj_recdef.h %ALL_LIB% +buildvm -m recdef -o %SOURCEDIR%\lj_recdef.h %ALL_LIB%
@if errorlevel 1 goto :BAD @if errorlevel 1 goto :BAD
-buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB% -buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB%
+buildvm -m vmdef -o %SOURCEDIR%\jit\vmdef.lua %ALL_LIB% +buildvm -m vmdef -o %SOURCEDIR%\jit\vmdef.lua %ALL_LIB%
@if errorlevel 1 goto :BAD @if errorlevel 1 goto :BAD
-buildvm -m folddef -o lj_folddef.h lj_opt_fold.c -buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
+buildvm -m folddef -o %SOURCEDIR%\lj_folddef.h %SOURCEDIR%\lj_opt_fold.c +buildvm -m folddef -o %SOURCEDIR%\lj_folddef.h %SOURCEDIR%\lj_opt_fold.c
@if errorlevel 1 goto :BAD @if errorlevel 1 goto :BAD
-@if "%1" neq "debug" goto :NODEBUG -@if "%1" neq "debug" goto :NODEBUG
+@set LJLINK=%LJLINK% /debug +@set LJLINK=%LJLINK% /debug
+@if "%2" neq "debug" goto :NODEBUG +@if "%2" neq "debug" goto :NODEBUG
@shift @shift
@set LJCOMPILE=%LJCOMPILE% /Zi @set LJCOMPILE=%LJCOMPILE% /Zi
-@set LJLINK=%LJLINK% /debug -@set LJLINK=%LJLINK% /debug
@set DEBUG=1 :NODEBUG
:NODEBUG -@if "%1"=="amalg" goto :AMALGDLL
-@if "%1"=="amalg" goto :AMALGDLL -@if "%1"=="static" goto :STATIC
-@if "%1"=="static" goto :STATIC -%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL lj_*.c lib_*.c
+@if "%2"=="amalg" goto :AMALGDLL +@if "%2"=="amalg" goto :AMALGDLL
+@if "%2"=="static" goto :STATIC +@if "%2"=="static" goto :STATIC
@if "%DEBUG%"=="1" set LJCOMPILE=%LJCOMPILE% /MDd +%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL %SOURCEDIR%\lj_*.c %SOURCEDIR%\lib_*.c /Fdlua51.pdb
@if "%DEBUG%"=="" set LJCOMPILE=%LJCOMPILE% /MD @if errorlevel 1 goto :BAD
-%LJCOMPILE% /DLUA_BUILD_AS_DLL lj_*.c lib_*.c %LJLINK% /DLL /out:%LJDLLNAME% lj_*.obj lib_*.obj
+%LJCOMPILE% /DLUA_BUILD_AS_DLL %SOURCEDIR%\lj_*.c %SOURCEDIR%\lib_*.c /Fdlua51.pdb @if errorlevel 1 goto :BAD
@if errorlevel 1 goto :BAD @goto :MTDLL
%LJLINK% /DLL /out:%LJDLLNAME% lj_*.obj lib_*.obj :STATIC
@if errorlevel 1 goto :BAD -%LJCOMPILE% lj_*.c lib_*.c
@@ -81,13 +82,13 @@ buildvm -m folddef -o lj_folddef.h lj_opt_fold.c +%LJCOMPILE% %SOURCEDIR%\lj_*.c %SOURCEDIR%\lib_*.c /Fdlua51.pdb
:STATIC @if errorlevel 1 goto :BAD
@if "%DEBUG%"=="1" set LJCOMPILE=%LJCOMPILE% /MTd %LJLIB% /OUT:%LJLIBNAME% lj_*.obj lib_*.obj
@if "%DEBUG%"=="" set LJCOMPILE=%LJCOMPILE% /MT @if errorlevel 1 goto :BAD
-%LJCOMPILE% lj_*.c lib_*.c @goto :MTDLL
+%LJCOMPILE% %SOURCEDIR%\lj_*.c %SOURCEDIR%\lib_*.c /Fdlua51.pdb :AMALGDLL
@if errorlevel 1 goto :BAD -%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL ljamalg.c
%LJLIB% /OUT:%LJLIBNAME% lj_*.obj lib_*.obj +%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL %SOURCEDIR%\ljamalg.c
@if errorlevel 1 goto :BAD @if errorlevel 1 goto :BAD
@goto :MTDLL %LJLINK% /DLL /out:%LJDLLNAME% ljamalg.obj lj_vm.obj
:AMALGDLL @if errorlevel 1 goto :BAD
-%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL ljamalg.c @@ -90,7 +91,7 @@ buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
+%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL %SOURCEDIR%\ljamalg.c if exist %LJDLLNAME%.manifest^
@if errorlevel 1 goto :BAD %LJMT% -manifest %LJDLLNAME%.manifest -outputresource:%LJDLLNAME%;2
%LJLINK% /DLL /out:%LJDLLNAME% ljamalg.obj lj_vm.obj
@if errorlevel 1 goto :BAD -%LJCOMPILE% luajit.c
@@ -95,7 +96,7 @@ buildvm -m folddef -o lj_folddef.h lj_opt_fold.c +%LJCOMPILE% %SOURCEDIR%\luajit.c /Fdluajit.pdb
if exist %LJDLLNAME%.manifest^ @if errorlevel 1 goto :BAD
%LJMT% -manifest %LJDLLNAME%.manifest -outputresource:%LJDLLNAME%;2 %LJLINK% /out:luajit.exe luajit.obj %LJLIBNAME%
@if errorlevel 1 goto :BAD
-%LJCOMPILE% luajit.c @@ -98,8 +99,8 @@ if exist luajit.exe.manifest^
+%LJCOMPILE% %SOURCEDIR%\luajit.c /Fdluajit.pdb %LJMT% -manifest luajit.exe.manifest -outputresource:luajit.exe
@if errorlevel 1 goto :BAD
%LJLINK% /out:luajit.exe luajit.obj %LJLIBNAME% @del *.obj *.manifest minilua.exe buildvm.exe
@if errorlevel 1 goto :BAD -@del host\buildvm_arch.h
@@ -103,8 +104,8 @@ if exist luajit.exe.manifest^ -@del lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h
%LJMT% -manifest luajit.exe.manifest -outputresource:luajit.exe +@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
@del *.obj *.manifest minilua.exe buildvm.exe @echo.
-@del host\buildvm_arch.h @echo === Successfully built LuaJIT for Windows/%LJARCH% ===
-@del lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h
+@del %SOURCEDIR%\host\buildvm_arch.h @@ -112,4 +113,5 @@ if exist luajit.exe.manifest^
+@del %SOURCEDIR%\lj_bcdef.h %SOURCEDIR%\lj_ffdef.h %SOURCEDIR%\lj_libdef.h %SOURCEDIR%\lj_recdef.h %SOURCEDIR%\lj_folddef.h @goto :END
@echo. :FAIL
@echo === Successfully built LuaJIT for Windows/%LJARCH% === @echo You must open a "Visual Studio .NET Command Prompt" to run this script
+exit 1
@@ -117,4 +118,5 @@ if exist luajit.exe.manifest^ :END
@goto :END
:FAIL
@echo You must open a "Visual Studio .NET Command Prompt" to run this script
+exit 1
:END

View File

@ -1,26 +0,0 @@
diff --git a/src/msvcbuild.bat b/src/msvcbuild.bat
index bd0c4c5..95e1cf4 100644
--- a/src/msvcbuild.bat
+++ b/src/msvcbuild.bat
@@ -67,15 +67,20 @@ buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
@shift
@set LJCOMPILE=%LJCOMPILE% /Zi
@set LJLINK=%LJLINK% /debug
+@set DEBUG=1
:NODEBUG
@if "%1"=="amalg" goto :AMALGDLL
@if "%1"=="static" goto :STATIC
-%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL lj_*.c lib_*.c
+@if "%DEBUG%"=="1" set LJCOMPILE=%LJCOMPILE% /MDd
+@if "%DEBUG%"=="" set LJCOMPILE=%LJCOMPILE% /MD
+%LJCOMPILE% /DLUA_BUILD_AS_DLL lj_*.c lib_*.c
@if errorlevel 1 goto :BAD
%LJLINK% /DLL /out:%LJDLLNAME% lj_*.obj lib_*.obj
@if errorlevel 1 goto :BAD
@goto :MTDLL
:STATIC
+@if "%DEBUG%"=="1" set LJCOMPILE=%LJCOMPILE% /MTd
+@if "%DEBUG%"=="" set LJCOMPILE=%LJCOMPILE% /MT
%LJCOMPILE% lj_*.c lib_*.c
@if errorlevel 1 goto :BAD
%LJLIB% /OUT:%LJLIBNAME% lj_*.obj lib_*.obj

View File

@ -0,0 +1,42 @@
diff --git a/src/msvcbuild.bat b/src/msvcbuild.bat
index 6a889e1..08c4e3c 100644
--- a/src/msvcbuild.bat
+++ b/src/msvcbuild.bat
@@ -64,20 +64,23 @@ 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 LJCOMPILE=%LJCOMPILE% /Zi
+@set CRT_LINKAGE=%CRT_LINKAGE%d
:NODEBUG
-@if "%2"=="amalg" goto :AMALGDLL
+@if "%3"=="amalg" goto :AMALGDLL
-@if "%2"=="static" goto :STATIC
+@if "%3"=="static" goto :STATIC
-%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL %SOURCEDIR%\lj_*.c %SOURCEDIR%\lib_*.c /Fdlua51.pdb
+%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
@@ -94,7 +94,7 @@
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

View File

@ -7,8 +7,8 @@ vcpkg_from_github(
SHA512 65d982d7fe532a61335613f414f3b8fa5333747bdf7aefc2c2d52022d227594ade827639049b97e3c4ffae9f38f32cb15f1a17b1780fb0a943e1a3af05e2b576 SHA512 65d982d7fe532a61335613f414f3b8fa5333747bdf7aefc2c2d52022d227594ade827639049b97e3c4ffae9f38f32cb15f1a17b1780fb0a943e1a3af05e2b576
HEAD_REF master HEAD_REF master
PATCHES PATCHES
001-fixStaticBuild.patch 001-fix-build-path.patch
002-fix-build-path.patch 002-fix-crt-linkage.patch
) )
if (VCPKG_LIBRARY_LINKAGE STREQUAL dynamic) if (VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
@ -24,7 +24,7 @@ if (NOT VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL debug)
vcpkg_execute_required_process_repeat( vcpkg_execute_required_process_repeat(
COUNT 1 COUNT 1
COMMAND "${SOURCE_PATH}/src/msvcbuild.bat" ${SOURCE_PATH}/src debug ${LJIT_STATIC} COMMAND "${SOURCE_PATH}/src/msvcbuild.bat" ${SOURCE_PATH}/src ${VCPKG_CRT_LINKAGE} debug ${LJIT_STATIC}
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg" WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg"
LOGNAME build-${TARGET_TRIPLET}-dbg LOGNAME build-${TARGET_TRIPLET}-dbg
) )
@ -47,7 +47,7 @@ if (NOT VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL release)
vcpkg_execute_required_process_repeat(d8un vcpkg_execute_required_process_repeat(d8un
COUNT 1 COUNT 1
COMMAND "${SOURCE_PATH}/src/msvcbuild.bat" ${SOURCE_PATH}/src ${LJIT_STATIC} COMMAND "${SOURCE_PATH}/src/msvcbuild.bat" ${SOURCE_PATH}/src ${VCPKG_CRT_LINKAGE} ${LJIT_STATIC}
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel" WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel"
LOGNAME build-${TARGET_TRIPLET}-rel LOGNAME build-${TARGET_TRIPLET}-rel
) )