Skip to content

Commit

Permalink
Merge pull request #539 from a740g/llvm-mingw-backend
Browse files Browse the repository at this point in the history
Update setup_mingw.cmd to use LLVM MinGW on all versions of Windows
  • Loading branch information
a740g authored Sep 15, 2024
2 parents 7abeaaa + 11dca93 commit 4a7e17d
Show file tree
Hide file tree
Showing 6 changed files with 861 additions and 98 deletions.
59 changes: 22 additions & 37 deletions setup_mingw.cmd
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
@rem QB64-PE MINGW setup script
@rem QB64-PE MinGW setup script
@rem
@rem This NT command script downloads and extracts the latest copy of MINGW binaries from:
@rem https://github.com/niXman/mingw-builds-binaries/releases
@rem So, the filenames in 'URL' variable should be updated to the latest stable builds when those are available
@rem This NT command script downloads and extracts the latest copy of LLVM MinGW binaries from:
@rem https://github.com/mstorsjo/llvm-mingw/releases
@rem
@rem Specifying 32 for argument 1 on a 64-bit system will force a 32-bit MINGW setup
@rem Specifying 32 for argument 1 on a 64-bit system will force a 32-bit MinGW setup
@rem
@echo off

Expand All @@ -16,20 +15,17 @@ if errorlevel 1 (
goto end
)

rem Change to the correct drive letter
%~d0

rem Change to the correct path
cd %~dp0
rem Change to the correct drive & path
cd /d %~dp0

rem Check if the C++ compiler is there and skip downloading if it exists
if exist "internal\c\c_compiler\bin\c++.exe" (
echo.
echo Info: MINGW detected. Skipping setup.
echo Info: MinGW detected. Skipping setup.
goto end
)

rem Create the c_compiler directory that should contain the MINGW binaries
rem Create the c_compiler directory that should contain the MinGW binaries
mkdir internal\c\c_compiler

rem Check if were able to create the directory
Expand Down Expand Up @@ -64,7 +60,8 @@ if "%~1" == "32" set BITS=32
echo %ARCH%-%BITS% platform selected.

rem Set some critical variables before we move to the actual setup part
rem MINGW_DIR is actually the internal directory name inside the zip / 7z file
rem The filenames in 'URL' variable should be updated to the latest stable builds when those are available
rem MINGW_DIR is actually the internal directory name inside the zip file
rem It needs to be updated whenever the toolchains are updated
if "%ARCH%" == "ARM" (
if %BITS% == 64 (
Expand All @@ -74,39 +71,27 @@ if "%ARCH%" == "ARM" (
set URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20240619/llvm-mingw-20240619-ucrt-armv7.zip"
set MINGW_DIR=llvm-mingw-20240619-ucrt-armv7
)
set MINGW_TEMP_FILE=temp.zip
) else (
if %BITS% == 64 (
set URL="https://github.com/niXman/mingw-builds-binaries/releases/download/13.2.0-rt_v11-rev0/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0.7z"
set MINGW_DIR=mingw64
set URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20240619/llvm-mingw-20240619-ucrt-x86_64.zip"
set MINGW_DIR=llvm-mingw-20240619-ucrt-x86_64
) else (
set URL="https://github.com/niXman/mingw-builds-binaries/releases/download/13.2.0-rt_v11-rev0/i686-13.2.0-release-win32-dwarf-msvcrt-rt_v11-rev0.7z"
set MINGW_DIR=mingw32
)
set MINGW_TEMP_FILE=temp.7z
set URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20240619/llvm-mingw-20240619-msvcrt-i686.zip"
set MINGW_DIR=llvm-mingw-20240619-msvcrt-i686
)
)

rem Download MingW files
rem Download LLVM-MinGW package using curl. curl is available in Windows 10 and above since build 17063
rem https://devblogs.microsoft.com/commandline/tar-and-curl-come-to-windows/
set MINGW_TEMP_FILE=temp.zip
if exist %MINGW_TEMP_FILE% del %MINGW_TEMP_FILE%
echo Downloading %URL%...
curl -L %URL% -o %MINGW_TEMP_FILE%

rem Extract MingW files
if "%ARCH%" == "ARM" (
rem Use tar to extract the zip file on Windows on ARM. tar is available in Windows since build 17063
rem And this includes all ARM64 Windows versions
echo Extracting C++ Compiler...
tar -xvf %MINGW_TEMP_FILE%
) else (
rem Download 7zr.exe. We'll need this to extract the MINGW archive
echo Downloading 7zr.exe...
curl -L https://www.7-zip.org/a/7zr.exe -o 7zr.exe

rem Extract the MINGW binaries
echo Extracting C++ Compiler...
7zr.exe x %MINGW_TEMP_FILE% -y
del 7zr.exe
)
rem Extract LLVM-MinGW files using tar. tar is available in Windows 10 and above since build 17063
rem https://devblogs.microsoft.com/commandline/tar-and-curl-come-to-windows/
echo Extracting C++ Compiler...
tar -xvf %MINGW_TEMP_FILE%

rem Move the binaries to internal\c\c_compiler\
echo Moving C++ compiler...
Expand Down
28 changes: 22 additions & 6 deletions source/qb64pe.bas
Original file line number Diff line number Diff line change
Expand Up @@ -12595,14 +12595,22 @@ IF os$ = "WIN" THEN
IF n > 1 THEN a$ = "Unable to resolve multiple instances of sub/function '" + ResolveStaticFunction_Name(x) + "' in '" + ResolveStaticFunction_File(x) + "'": GOTO errmes

IF n = 0 THEN 'attempt to locate simple function name without brackets
s$ = " " + ResolveStaticFunction_Name(x)
s$ = ResolveStaticFunction_Name(x)
fh = OpenBuffer%("I", nm_output_file$)
ConvBufToLnxMacEol fh
DO UNTIL EndOfBuf%(fh)
a$ = ReadBufLine$(fh)
IF LEN(a$) THEN
'search for SPACE+functionname
x1 = INSTR(a$, s$)
IF RIGHT$(a$, LEN(s$)) = s$ THEN
' clang's nm outputs LF line endings
IF OS_BITS = 32 THEN
' On 32-bit Windows function names are decorated by a leading underscore
' gcc's nm hides the leading underscore in the output, whereas clang's nm does not
x1 = (RIGHT$(a$, LEN(s$) + 1) = " " + s$) _ORELSE (RIGHT$(a$, LEN(s$) + 2) = " _" + s$)
ELSE
x1 = (RIGHT$(a$, LEN(s$) + 1) = " " + s$)
END IF
IF x1 THEN
fh2 = FREEFILE
IF ResolveStaticFunction_Method(x) = 1 THEN
OPEN tmpdir$ + "global.txt" FOR APPEND AS #fh2
Expand Down Expand Up @@ -12649,14 +12657,22 @@ IF os$ = "WIN" THEN
END IF

IF n = 0 THEN 'a C dynamic object library?
s$ = " " + ResolveStaticFunction_Name(x)
s$ = ResolveStaticFunction_Name(x)
fh = OpenBuffer%("I", nm_output_file_dynamic$)
ConvBufToLnxMacEol fh
DO UNTIL EndOfBuf%(fh)
a$ = ReadBufLine$(fh)
IF LEN(a$) THEN
'search for SPACE+functionname
x1 = INSTR(a$, s$)
IF RIGHT$(a$, LEN(s$)) = s$ THEN
' clang's nm outputs LF line endings
IF OS_BITS = 32 THEN
' On 32-bit Windows function names are decorated by a leading underscore
' gcc's nm hides the leading underscore in the output, whereas clang's nm does not
x1 = (RIGHT$(a$, LEN(s$) + 1) = " " + s$) _ORELSE (RIGHT$(a$, LEN(s$) + 2) = " _" + s$)
ELSE
x1 = (RIGHT$(a$, LEN(s$) + 1) = " " + s$)
END IF
IF x1 THEN
fh2 = FREEFILE
IF ResolveStaticFunction_Method(x) = 1 THEN
OPEN tmpdir$ + "global.txt" FOR APPEND AS #fh2
Expand Down
9 changes: 4 additions & 5 deletions source/utilities/s-buffer/readme.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
This is a massively reduced version of "The Simplebuffer System" library
by RhoSigma. The full package with many more functions for bookmarking,
searching, copy'n'paste and EOL conversion, inclusive documentation and
examples is part of the author's "Libraries Collection" and can be found
for download at the respective forum thread here:
This is the full fledged version of "The Simplebuffer System" library
by RhoSigma. The documentation and examples are part of the author's
"Libraries Collection" and can be found for download at the respective
forum thread here:
https://qb64phoenix.com/forum/forumdisplay.php?fid=23

Note: The sb_qb64_extension.bi/.bm files are not part of the buffer system.
Expand Down
29 changes: 28 additions & 1 deletion source/utilities/s-buffer/simplebuffer.bi
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,34 @@
'| ## ## # | ._.' |
'| ## ###### | Sources & Documents placed in the Public Domain. |
'+---------------+---------------------------------------------------+
'| |
'| === simplebuffer.bi === |
'| |
'| == Definitions required for the routines in simplebuffer.bm. |
'| |
'+-------------------------------------------------------------------+
'| Done by RhoSigma, R.Heyder, provided AS IS, use at your own risk. |
'| Find me in the QB64 Forum or mail to [email protected] for |
'| any questions or suggestions. Thanx for your interest in my work. |
'+-------------------------------------------------------------------+

'--- The internal array for data storage
'-----
'never access this directly, use functions in simplebuffer.bm
REDIM SHARED simplebuffer_array$(0 TO 10599) 'init for 100 buffers
REDIM SHARED simplebuffer_array$(0 TO 10599)

'--- Simplebuffer Errors (most FUNCTIONs)
'-----
'initializer error returns
CONST SBE_NoMoreBuffers = -1
CONST SBE_NoMoreIDs = -2
CONST SBE_EmptyFind = -3
'operational error returns
CONST SBE_UnknownMode = -11
CONST SBE_OutOfBounds = -12
CONST SBE_BadIDNumber = -13
CONST SBE_UnusedID = -14
CONST SBE_ClearedID = -15

'--- Simplebuffer Modes (SeekBuf) ---
'-----
Expand All @@ -28,6 +43,18 @@ CONST SBM_PosRestore = -21
CONST SBM_BufStart = -22
CONST SBM_BufCurrent = -23
CONST SBM_BufEnd = -24
CONST SBM_LineStart = -25
CONST SBM_LineEnd = -26

'--- Simplebuffer Flags (FindBufFwd/Rev) ---
'-----
'use for method% argument
CONST SBF_FullData = 0
CONST SBF_Delimiter = 1
CONST SBF_InvDelimiter = -1
'use for treat% argument
CONST SBF_AsWritten = 0
CONST SBF_IgnoreCase = -1

'$INCLUDE: 'sb_qb64pe_extension.bi'

Loading

0 comments on commit 4a7e17d

Please sign in to comment.