Browse Source

Seems almost to good to be true but: remove the dependency on C++ Builder by using MSVC instead. Apparently Delphi has been able to read COFF .obj files it generates since XE2 already. Works like a charm!

Fixes the main issue with C++ Builder (besides it being obscure): its Community Edition can't be installed when Delphi Community Edition is also installed.
Martijn Laan 1 year ago
parent
commit
41f294b0ea

+ 18 - 18
Projects/Src/Setup/LZMADecomp.pas

@@ -65,8 +65,8 @@ type
 
   PLZMAISzAlloc = ^TLZMAISzAlloc;
   TLZMAISzAlloc = record
-    Alloc: function(p: PLZMAISzAlloc; size: Cardinal): Pointer;
-    Free: procedure(p: PLZMAISzAlloc; address: Pointer);
+    Alloc: function(p: PLZMAISzAlloc; size: Cardinal): Pointer; cdecl;
+    Free: procedure(p: PLZMAISzAlloc; address: Pointer); cdecl;
   end;
 
 const
@@ -98,29 +98,29 @@ const
 
 function IS_LzmaDec_Init(var state: TLZMA1InternalDecoderState;
   stateSize: Cardinal; const props; propsSize: Cardinal;
-  const alloc: TLZMAISzAlloc): TLZMASRes; external;
+  const alloc: TLZMAISzAlloc): TLZMASRes; cdecl; external name '_IS_LzmaDec_Init';
 function LzmaDec_DecodeToBuf(var state: TLZMA1InternalDecoderState; var dest;
   var destLen: Cardinal; const src; var srcLen: Cardinal; finishMode: Integer;
-  var status: Integer): TLZMASRes; external;
+  var status: Integer): TLZMASRes; cdecl; external name '_LzmaDec_DecodeToBuf';
 procedure LzmaDec_Free(var state: TLZMA1InternalDecoderState;
-  const alloc: TLZMAISzAlloc); external;
+  const alloc: TLZMAISzAlloc); cdecl; external name '_LzmaDec_Free';
 
 function IS_Lzma2Dec_Init(var state: TLZMA2InternalDecoderState;
-  stateSize: Cardinal; prop: Byte; const alloc: TLZMAISzAlloc): TLZMASRes;
-  external;
+  stateSize: Cardinal; prop: Byte; const alloc: TLZMAISzAlloc): TLZMASRes; cdecl;
+  external name '_IS_Lzma2Dec_Init';
 function Lzma2Dec_DecodeToBuf(var state: TLZMA2InternalDecoderState; var dest;
   var destLen: Cardinal; const src; var srcLen: Cardinal; finishMode: Integer;
-  var status: Integer): TLZMASRes; external;
+  var status: Integer): TLZMASRes; cdecl; external name '_Lzma2Dec_DecodeToBuf';
 procedure IS_Lzma2Dec_Free(var state: TLZMA2InternalDecoderState;
-  const alloc: TLZMAISzAlloc); external;
+  const alloc: TLZMAISzAlloc); cdecl; external name '_IS_Lzma2Dec_Free';
 
-procedure LzmaDec_Allocate; external;
-procedure LzmaDec_AllocateProbs; external;
-procedure LzmaDec_DecodeToDic; external;
-procedure LzmaDec_FreeProbs; external;
-procedure LzmaDec_Init; external;
-procedure LzmaDec_InitDicAndState; external;
-procedure LzmaProps_Decode; external;
+procedure LzmaDec_Allocate; cdecl; external name '_LzmaDec_Allocate';
+procedure LzmaDec_AllocateProbs; cdecl; external name '_LzmaDec_AllocateProbs';
+procedure LzmaDec_DecodeToDic; cdecl; external name'_LzmaDec_DecodeToDic';
+procedure LzmaDec_FreeProbs; cdecl; external name '_LzmaDec_FreeProbs';
+procedure LzmaDec_Init; cdecl; external name '_LzmaDec_Init';
+procedure LzmaDec_InitDicAndState; cdecl; external name '_LzmaDec_InitDicAndState';
+procedure LzmaProps_Decode; cdecl; external name '_LzmaProps_Decode';
 
 procedure LZMADecompInternalError(const Msg: String);
 begin
@@ -132,7 +132,7 @@ begin
   raise ECompressDataError.CreateFmt(SLZMADecompDataError, [Id]);
 end;
 
-function LZMAAllocFunc(p: PLZMAISzAlloc; size: Cardinal): Pointer;
+function LZMAAllocFunc(p: PLZMAISzAlloc; size: Cardinal): Pointer; cdecl;
 begin
   if (size <> 0) and (size <= Cardinal(MaxDictionarySize)) then
     Result := VirtualAlloc(nil, size, MEM_COMMIT, PAGE_READWRITE)
@@ -140,7 +140,7 @@ begin
     Result := nil;
 end;
 
-procedure LZMAFreeFunc(p: PLZMAISzAlloc; address: Pointer);
+procedure LZMAFreeFunc(p: PLZMAISzAlloc; address: Pointer); cdecl;
 begin
   if Assigned(address) then
     VirtualFree(address, 0, MEM_RELEASE);

BIN
Projects/Src/Setup/Lzma2Decode/ISLzma2Dec.obj


BIN
Projects/Src/Setup/Lzma2Decode/ISLzmaDec.obj


+ 49 - 0
Projects/Src/Setup/Lzma2Decode/compile.bat

@@ -0,0 +1,49 @@
+@echo off
+
+rem  Inno Setup
+rem  Copyright (C) 1997-2024 Jordan Russell
+rem  Portions by Martijn Laan
+rem  For conditions of distribution and use, see LICENSE.TXT.
+rem
+rem  Batch file to compile LzmaDecodeInno.c
+
+setlocal
+
+cd /d %~dp0
+
+if exist compilesettings.bat goto compilesettingsfound
+:compilesettingserror
+echo compilesettings.bat is missing or incomplete. It needs to be created
+echo with the following line, adjusted for your system:
+echo.
+echo   set VSTOOLSROOT=C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools
+goto failed2
+
+:compilesettingsfound
+set VSTOOLSROOT=
+call .\compilesettings.bat
+if "%VSTOOLSROOT%"=="" goto compilesettingserror
+
+rem -------------------------------------------------------------------------
+
+set __VSCMD_ARG_NO_LOGO=1
+set VSCMD_SKIP_SENDTELEMETRY=1
+
+echo - Calling VsDevCmd.bat
+call "%VSTOOLSROOT%\VsDevCmd.bat"
+if errorlevel 1 goto exit
+echo.
+
+echo - Compiling ISLzmaDec.c and ISLzma2Dec.c
+cl /c /O2 /Gd /GS- ISLzmaDec.c ISLzma2Dec.c
+if errorlevel 1 goto failed
+
+echo Success!
+goto exit
+
+:failed
+echo *** FAILED ***
+:failed2
+exit /b 1
+
+:exit

+ 0 - 9
Projects/Src/Setup/Lzma2Decode/compiling.txt

@@ -1,9 +0,0 @@
-ISLzmaDec.obj and ISLzma2Dec.obj are compiled using the
-Borland C++Builder 6 compiler ("Borland C++ 5.6.4 for Win32")
-as follows:
-
-bcc32 -c -pr -O2 ISLzmaDec.c ISLzma2Dec.c
-
-Add -v if you wish to enable source-level debugging, which
-makes it possible to step through the C code from within
-Delphi.

+ 5 - 5
Projects/Src/SetupLdr/LZMADecompSmall.pas

@@ -84,7 +84,7 @@ end;
 
 type
   TLzmaInCallback = record
-    Read: function(obj: Pointer; var buffer: Pointer; var bufferSize: Cardinal): Integer;
+    Read: function(obj: Pointer; var buffer: Pointer; var bufferSize: Cardinal): Integer; cdecl;
   end;
 
 const
@@ -95,12 +95,12 @@ const
 
 function LzmaMyDecodeProperties(var vs: TLZMAInternalDecoderState;
   vsSize: Integer; const propsData; propsDataSize: Integer;
-  var outPropsSize: LongWord; var outDictionarySize: LongWord): Integer; external;
+  var outPropsSize: LongWord; var outDictionarySize: LongWord): Integer; cdecl; external name '_LzmaMyDecodeProperties';
 procedure LzmaMyDecoderInit(var vs: TLZMAInternalDecoderState;
-  probsPtr: Pointer; dictionaryPtr: Pointer); external;
+  probsPtr: Pointer; dictionaryPtr: Pointer); cdecl; external name '_LzmaMyDecoderInit';
 function LzmaDecode(var vs: TLZMAInternalDecoderState;
   var inCallback: TLzmaInCallback; var outStream; outSize: Cardinal;
-  var outSizeProcessed: Cardinal): Integer; external;
+  var outSizeProcessed: Cardinal): Integer; cdecl; external name '_LzmaDecode';
 
 type
   TLZMADecompressorCallbackData = record
@@ -108,7 +108,7 @@ type
     Instance: TLZMA1SmallDecompressor;
   end;
 
-function ReadFunc(obj: Pointer; var buffer: Pointer; var bufferSize: Cardinal): Integer;
+function ReadFunc(obj: Pointer; var buffer: Pointer; var bufferSize: Cardinal): Integer; cdecl;
 begin
   TLZMADecompressorCallbackData(obj^).Instance.DoRead(buffer, bufferSize);
   { Don't bother returning any sort of failure code, because if DoRead failed,

BIN
Projects/Src/SetupLdr/LzmaDecode/LzmaDecodeInno.obj


+ 49 - 0
Projects/Src/SetupLdr/LzmaDecode/compile.bat

@@ -0,0 +1,49 @@
+@echo off
+
+rem  Inno Setup
+rem  Copyright (C) 1997-2024 Jordan Russell
+rem  Portions by Martijn Laan
+rem  For conditions of distribution and use, see LICENSE.TXT.
+rem
+rem  Batch file to compile LzmaDecodeInno.c
+
+setlocal
+
+cd /d %~dp0
+
+if exist compilesettings.bat goto compilesettingsfound
+:compilesettingserror
+echo compilesettings.bat is missing or incomplete. It needs to be created
+echo with the following line, adjusted for your system:
+echo.
+echo   set VSTOOLSROOT=C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools
+goto failed2
+
+:compilesettingsfound
+set VSTOOLSROOT=
+call .\compilesettings.bat
+if "%VSTOOLSROOT%"=="" goto compilesettingserror
+
+rem -------------------------------------------------------------------------
+
+set __VSCMD_ARG_NO_LOGO=1
+set VSCMD_SKIP_SENDTELEMETRY=1
+
+echo - Calling VsDevCmd.bat
+call "%VSTOOLSROOT%\VsDevCmd.bat"
+if errorlevel 1 goto exit
+echo.
+
+echo - Compiling LzmaDecodeInno.c
+cl /c /O2 /D_LZMA_OUT_READ /D_LZMA_IN_CB /Gd LzmaDecodeInno.c
+if errorlevel 1 goto failed
+
+echo Success!
+goto exit
+
+:failed
+echo *** FAILED ***
+:failed2
+exit /b 1
+
+:exit

+ 0 - 10
Projects/Src/SetupLdr/LzmaDecode/compiling.txt

@@ -1,10 +0,0 @@
-LzmaDecodeInno.obj is compiled using the Borland C++Builder 6
-compiler ("Borland C++ 5.6.4 for Win32") as follows:
-
-bcc32 -c -pr -O2 -D_LZMA_OUT_READ -D_LZMA_IN_CB LzmaDecodeInno.c
-
-Add -v if you wish to enable source-level debugging, which
-makes it possible to step through the C code from within
-Delphi.
-
--JR

+ 5 - 4
README.md

@@ -210,9 +210,10 @@ Compiled by Visual Studio 2005 from the [Projects\Helper] directory and then
 stored in a compiled resource file.
 
 **Projects\Src\Setup\Lzma2Decode\ISLzmaDec.obj**, **Projects\Src\Setup\Lzma2Decode\ISLzma2Dec.obj** -
-See [Projects\Src\Setup\Lzma2Decode\compiling.txt].
+Compiled by Visual Studio 2022 from the [Projects\Src\Setup\Lzma2Decode] directory.
 
-**Projects\Src\SetupLdr\LzmaDecode\LzmaDecodeInno.obj** - See [Projects\Src\SetupLdr\LzmaDecode\compiling.txt].
+**Projects\Src\SetupLdr\LzmaDecode\LzmaDecodeInno.obj** - Compiled by Visual Studio
+2022 from the [Projects\Src\SetupLdr\LzmaDecode] directory.
 
 **Examples\MyProg.exe**, **Examples\MyProg-x64.exe**, **Examples\MyProg-Arm64.exe** -
 Compiled by Visual Studio 2022 from the [Examples\MyProg] directory.
@@ -275,7 +276,7 @@ workflow will be triggered automatically.
 [Examples\MyProg]: <Examples/MyProg>
 [Projects\Src]: <Projects/Src>
 [Projects\Src\Compil32]: <Projects/Src/Compil32>
-[Projects\Src\Setup\Lzma2Decode\compiling.txt]: <Projects/Src/Setup/Lzma2Decode/compiling.txt>
-[Projects\Src\SetupLdr\LzmaDecode\compiling.txt]: <Projects/Src/SetupLdr/LzmaDecode/compiling.txt>
+[Projects\Src\Setup\Lzma2Decode]: <Projects/Src/Setup/Lzma2Decode>
+[Projects\Src\SetupLdr\LzmaDecode]: <Projects/Src/SetupLdr/LzmaDecode>
 [7-Zip]: https://www.7-zip.org/
 [secret]: https://docs.github.com/en/actions/security-guides/encrypted-secrets