From 4b073bba8aedb59895bf73eb8e362510cfcf0adc Mon Sep 17 00:00:00 2001 From: Samuel Gomes Date: Wed, 5 Mar 2025 14:22:21 +0530 Subject: [PATCH 1/3] Initial windows system compiler support --- Makefile | 18 +++++++++++++----- internal/c/parts/network/http/build.mk | 15 +++++++++++---- source/qb64pe.bas | 14 +++++++++----- source/utilities/build.bas | 14 ++++++++------ 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index bd4620356..5c83dfca6 100644 --- a/Makefile +++ b/Makefile @@ -65,11 +65,19 @@ ifeq ($(OS),win) PATH_LIBQB := $(PATH_INTERNAL_C)\libqb SHELL := cmd CP := xcopy /E /C /H /R /Y - AR := $(PATH_INTERNAL_C)\c_compiler\bin\ar.exe - CC := $(PATH_INTERNAL_C)\c_compiler\bin\gcc.exe - CXX := $(PATH_INTERNAL_C)\c_compiler\bin\c++.exe - OBJCOPY := $(PATH_INTERNAL_C)\c_compiler\bin\objcopy.exe - WINDRES := $(PATH_INTERNAL_C)\c_compiler\bin\windres.exe + ifdef USE_SYSTEM_MINGW + AR := ar.exe + CC := gcc.exe + CXX := c++.exe + OBJCOPY := objcopy.exe + WINDRES := windres.exe + else + AR := $(PATH_INTERNAL_C)\c_compiler\bin\ar.exe + CC := $(PATH_INTERNAL_C)\c_compiler\bin\gcc.exe + CXX := $(PATH_INTERNAL_C)\c_compiler\bin\c++.exe + OBJCOPY := $(PATH_INTERNAL_C)\c_compiler\bin\objcopy.exe + WINDRES := $(PATH_INTERNAL_C)\c_compiler\bin\windres.exe + endif ICON_OBJ := $(PATH_INTERNAL_TEMP)\icon.o RM := del /Q MKDIR := mkdir diff --git a/internal/c/parts/network/http/build.mk b/internal/c/parts/network/http/build.mk index cccb70a13..3e7ef4dfc 100644 --- a/internal/c/parts/network/http/build.mk +++ b/internal/c/parts/network/http/build.mk @@ -6,10 +6,17 @@ CURL_LIB := $(PATH_INTERNAL_C)/parts/network/http/libcurl.a CURL_MAKE_FLAGS := CFG=-schannel CURL_MAKE_FLAGS += "CURL_CFLAG_EXTRAS=-DCURL_STATICLIB -DHTTP_ONLY" -CURL_MAKE_FLAGS += CC=../../../../c_compiler/bin/gcc.exe -CURL_MAKE_FLAGS += AR=../../../../c_compiler/bin/ar.exe -CURL_MAKE_FLAGS += RANLIB=../../../../c_compiler/bin/ranlib.exe -CURL_MAKE_FLAGS += STRIP=../../../../c_compiler/bin/strip.exe +ifdef USE_SYSTEM_MINGW + CURL_MAKE_FLAGS += CC=gcc.exe + CURL_MAKE_FLAGS += AR=ar.exe + CURL_MAKE_FLAGS += RANLIB=ranlib.exe + CURL_MAKE_FLAGS += STRIP=strip.exe +else + CURL_MAKE_FLAGS += CC=../../../../c_compiler/bin/gcc.exe + CURL_MAKE_FLAGS += AR=../../../../c_compiler/bin/ar.exe + CURL_MAKE_FLAGS += RANLIB=../../../../c_compiler/bin/ranlib.exe + CURL_MAKE_FLAGS += STRIP=../../../../c_compiler/bin/strip.exe +endif CURL_MAKE_FLAGS += libcurl_a_LIBRARY="../libcurl.a" CURL_MAKE_FLAGS += ARCH=w$(BITS) diff --git a/source/qb64pe.bas b/source/qb64pe.bas index efe8e6282..7e40e65ae 100644 --- a/source/qb64pe.bas +++ b/source/qb64pe.bas @@ -89,6 +89,7 @@ IF _DIREXISTS("internal") = 0 THEN END IF DIM SHARED Include_GDB_Debugging_Info 'set using "config.ini" or "Compiler settings" dialog +DIM SHARED UseSystemMinGW AS _BYTE DIM SHARED DEPENDENCY_LAST CONST DEPENDENCY_LOADFONT = 1: DEPENDENCY_LAST = DEPENDENCY_LAST + 1 @@ -12479,7 +12480,6 @@ mac = 0: IF MacOSX THEN mac = 1: o$ = "osx" ver$ = Version$ 'eg. "0.123" libs$ = "" makedeps$ = "" -make$ = GetMakeExecutable$ localpath$ = "internal\c\" @@ -12536,7 +12536,7 @@ ELSE escapedExe$ = _CHR_QUOTE + escapedExe$ + _CHR_QUOTE END IF -makeline$ = make$ + makedeps$ + " EXE=" + escapedExe$ +makeline$ = GetMakeExecutable$ + makedeps$ + " EXE=" + escapedExe$ makeline$ = makeline$ + " " + AddQuotes$("CXXFLAGS_EXTRA=" + CxxFlagsExtra$) makeline$ = makeline$ + " " + AddQuotes$("CFLAGS_EXTRA=" + CxxFlagsExtra$) makeline$ = makeline$ + " " + AddQuotes$("CXXLIBS_EXTRA=" + CxxLibsExtra$) @@ -12573,6 +12573,10 @@ ON ERROR GOTO qberror IF os$ = "WIN" THEN + IF UseSystemMinGW THEN + makeline$ = makeline$ + " " + AddQuotes$("USE_SYSTEM_MINGW=y") + END IF + makeline$ = makeline$ + " OS=win" 'resolve static function definitions and add to global.txt @@ -12583,7 +12587,7 @@ IF os$ = "WIN" THEN n = 0 IF NOT _FILEEXISTS(nm_output_file$) THEN - SHELL _HIDE "cmd /c internal\c\c_compiler\bin\nm.exe " + AddQuotes$(ResolveStaticFunction_File(x)) + " --demangle -g >" + AddQuotes$(nm_output_file$) + SHELL _HIDE "cmd /c " + GetCompilerPath$ + "nm.exe " + AddQuotes$(ResolveStaticFunction_File(x)) + " --demangle -g >" + AddQuotes$(nm_output_file$) END IF s$ = " " + ResolveStaticFunction_Name(x) + "(" fh = OpenBuffer%("I", nm_output_file$) @@ -12643,7 +12647,7 @@ IF os$ = "WIN" THEN IF n = 0 THEN 'a C++ dynamic object library? IF NOT _FILEEXISTS(nm_output_file_dynamic$) THEN - SHELL _HIDE "cmd /c internal\c\c_compiler\bin\nm.exe " + AddQuotes$(ResolveStaticFunction_File(x)) + " -D --demangle -g >" + AddQuotes$(nm_output_file_dynamic$) + SHELL _HIDE "cmd /c " + GetCompilerPath$ + "nm.exe " + AddQuotes$(ResolveStaticFunction_File(x)) + " -D --demangle -g >" + AddQuotes$(nm_output_file_dynamic$) END IF s$ = " " + ResolveStaticFunction_Name(x) + "(" fh = OpenBuffer%("I", nm_output_file$) @@ -12727,7 +12731,7 @@ IF os$ = "WIN" THEN PRINT #ffh, "echo Type 'quit' to exit" PRINT #ffh, "echo (the GDB debugger has many other useful commands, this advice is for beginners)" PRINT #ffh, "pause" - PRINT #ffh, "internal\c\c_compiler\bin\gdb.exe " + CHR$(34) + path.exe$ + file$ + extension$ + CHR$(34) + PRINT #ffh, GetCompilerPath$ + "gdb.exe " + CHR$(34) + path.exe$ + file$ + extension$ + CHR$(34) PRINT #ffh, "pause" CLOSE ffh END IF diff --git a/source/utilities/build.bas b/source/utilities/build.bas index f41c8f27a..7a55e42c0 100644 --- a/source/utilities/build.bas +++ b/source/utilities/build.bas @@ -3,15 +3,13 @@ ' Removes all the temporary build files (Various .o, .a, and ./internal/temp, among other things) ' SUB PurgeTemporaryBuildFiles (os AS STRING, mac AS LONG) - make$ = GetMakeExecutable$ - IF os = "WIN" THEN - SHELL _HIDE "cmd /c " + make$ + " OS=win clean" + SHELL _HIDE "cmd /c " + GetMakeExecutable$ + " OS=win clean" ELSEIF os = "LNX" THEN IF mac THEN - SHELL _HIDE make$ + " OS=osx clean" + SHELL _HIDE GetMakeExecutable$ + " OS=osx clean" ELSE - SHELL _HIDE make$ + " OS=lnx clean" + SHELL _HIDE GetMakeExecutable$ + " OS=lnx clean" END IF END IF END SUB @@ -21,12 +19,16 @@ END SUB ' FUNCTION GetMakeExecutable$ () IF os$ = "WIN" THEN - GetMakeExecutable$ = "internal\c\c_compiler\bin\mingw32-make.exe" + GetMakeExecutable$ = GetCompilerPath$ + "mingw32-make.exe" ELSE GetMakeExecutable$ = "make" END IF END FUNCTION +FUNCTION GetCompilerPath$ + GetCompilerPath$ = _IIF(UseSystemMinGW, "", "internal\c\c_compiler\bin\") +END FUNCTION + FUNCTION MakeNMOutputFilename$ (libfile AS STRING, dynamic AS LONG) IF dynamic THEN dyn$ = "_dynamic" ELSE dyn$ = "" From ed89b931d12af9ddb319299e8a9b7c98de6780af Mon Sep 17 00:00:00 2001 From: Samuel Gomes Date: Mon, 14 Apr 2025 21:39:45 +0530 Subject: [PATCH 2/3] Add UI and command line options for UseSystemMinGW --- setup_mingw.cmd | 16 ++++++++-------- source/ide/config/cfg_global.bas | 1 + source/ide/config/cfg_methods.bas | 6 ++++++ source/ide/ide_methods.bas | 27 +++++++++++++++++++++++++-- source/qb64pe.bas | 4 +++- 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/setup_mingw.cmd b/setup_mingw.cmd index c7274b617..cbaece2c6 100644 --- a/setup_mingw.cmd +++ b/setup_mingw.cmd @@ -65,19 +65,19 @@ 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 ( - set URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20250114/llvm-mingw-20250114-ucrt-aarch64.zip" - set MINGW_DIR=llvm-mingw-20250114-ucrt-aarch64 + set URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20250402/llvm-mingw-20250402-ucrt-aarch64.zip" + set MINGW_DIR=llvm-mingw-20250402-ucrt-aarch64 ) else ( - set URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20250114/llvm-mingw-20250114-ucrt-armv7.zip" - set MINGW_DIR=llvm-mingw-20250114-ucrt-armv7 + set URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20250402/llvm-mingw-20250402-ucrt-armv7.zip" + set MINGW_DIR=llvm-mingw-20250402-ucrt-armv7 ) ) else ( if %BITS% == 64 ( - set URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20250114/llvm-mingw-20250114-ucrt-x86_64.zip" - set MINGW_DIR=llvm-mingw-20250114-ucrt-x86_64 + set URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20250402/llvm-mingw-20250402-ucrt-x86_64.zip" + set MINGW_DIR=llvm-mingw-20250402-ucrt-x86_64 ) else ( - set URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20250114/llvm-mingw-20250114-ucrt-i686.zip" - set MINGW_DIR=llvm-mingw-20250114-ucrt-i686 + set URL="https://github.com/mstorsjo/llvm-mingw/releases/download/20250402/llvm-mingw-20250402-ucrt-i686.zip" + set MINGW_DIR=llvm-mingw-20250402-ucrt-i686 ) ) diff --git a/source/ide/config/cfg_global.bas b/source/ide/config/cfg_global.bas index f3d85635e..bdf03c7dd 100644 --- a/source/ide/config/cfg_global.bas +++ b/source/ide/config/cfg_global.bas @@ -33,6 +33,7 @@ DIM SHARED GenerateLicenseFile AS LONG DIM SHARED UseGuiDialogs AS _UNSIGNED LONG DIM SHARED DefaultTerminal AS STRING DIM SHARED LoggingEnabled AS _UNSIGNED LONG +DIM SHARED UseSystemMinGW AS LONG '===== Define and check settings location ===================================== ConfigFolder$ = "settings" 'relative config location inside the qb64pe main folder diff --git a/source/ide/config/cfg_methods.bas b/source/ide/config/cfg_methods.bas index cb164fd23..26e989932 100644 --- a/source/ide/config/cfg_methods.bas +++ b/source/ide/config/cfg_methods.bas @@ -605,5 +605,11 @@ SUB ReadInitialConfig ExtraLinkerFlags = ReadWriteStringSettingValue$(compilerSettingsSection$, "ExtraLinkerFlags", "") GenerateLicenseFile = ReadWriteBooleanSettingValue%(compilerSettingsSection$, "GenerateLicenseFile", 0) + + IF os$ = "WIN" THEN + UseSystemMinGW = ReadWriteBooleanSettingValue%(compilerSettingsSection$, "UseSystemMinGW", _FALSE) + ELSE + UseSystemMinGW = _TRUE ' always use the system compiler on non-Windows platforms + END IF END SUB diff --git a/source/ide/ide_methods.bas b/source/ide/ide_methods.bas index e9740304d..8d4c712da 100644 --- a/source/ide/ide_methods.bas +++ b/source/ide/ide_methods.bas @@ -15689,7 +15689,7 @@ FUNCTION ideCompilerSettingsBox '-------- init dialog box & objects -------- i = 0 - idepar p, 48, 15, "Compiler Settings" + idepar p, 48, _IIF(os$ = "WIN", 16, 15), "Compiler Settings" i = i + 1: ocpChk = i o(i).typ = 4 'check box @@ -15732,9 +15732,17 @@ FUNCTION ideCompilerSettingsBox o(i).x = 44: o(i).y = 12 o(i).txt = idenewtxt(CHR$(31)): o(i).rpt = 10 + IF os$ = "WIN" THEN + i = i + 1: uscChk = i + o(i).typ = 4 'check box + o(i).y = 14 + o(i).nam = idenewtxt("#Use system compiler") + o(i).sel = ABS(UseSystemMinGW) + END IF + i = i + 1: okBut = i: caBut = i + 1 o(i).typ = 3 'action buttons - o(i).y = 15 + o(i).y = _IIF(os$ = "WIN", 16, 15) o(i).txt = idenewtxt("#OK" + sep + "#Cancel"): o(i).dft = 1 '-------- end of init dialog box & objects -------- @@ -15863,6 +15871,17 @@ FUNCTION ideCompilerSettingsBox v% = VAL(idetxt(o(mppBox).txt)) IF MaxParallelProcesses <> v% THEN MaxParallelProcesses = v%: optChg% = -1 + IF os$ = "WIN" THEN + v% = o(uscChk).sel: IF v% <> 0 THEN v% = _TRUE + IF UseSystemMinGW <> v% THEN UseSystemMinGW = v%: optChg% = _TRUE + + ' Show a warning if the user is using the system MinGW compiler + IF UseSystemMinGW _ANDALSO optChg% THEN + retval = idemessagebox("Warning", "Using the system MinGW compiler may cause problems.", "#OK") + PCOPY 2, 1 + END IF + END IF + IF optChg% THEN 'save changes WriteConfigSetting compilerSettingsSection$, "OptimizeCppProgram", BoolToTFString$(OptimizeCppProgram) @@ -15874,6 +15893,10 @@ FUNCTION ideCompilerSettingsBox WriteConfigSetting compilerSettingsSection$, "MaxParallelProcesses", str2$(MaxParallelProcesses) + IF os$ = "WIN" THEN + WriteConfigSetting compilerSettingsSection$, "UseSystemMinGW", BoolToTFString$(UseSystemMinGW) + END IF + 'clean compiled files, since they may change due to the different settings PurgeTemporaryBuildFiles (os$), (MacOSX) diff --git a/source/qb64pe.bas b/source/qb64pe.bas index 9feb98cec..cf0f0651f 100644 --- a/source/qb64pe.bas +++ b/source/qb64pe.bas @@ -89,7 +89,6 @@ IF _DIREXISTS("internal") = 0 THEN END IF DIM SHARED Include_GDB_Debugging_Info 'set using "config.ini" or "Compiler settings" dialog -DIM SHARED UseSystemMinGW AS _BYTE DIM SHARED DEPENDENCY_LAST CONST DEPENDENCY_LOADFONT = 1: DEPENDENCY_LAST = DEPENDENCY_LAST + 1 @@ -13307,6 +13306,8 @@ FUNCTION ParseCMDLineArgs$ () IF MaxParallelProcesses <= 0 THEN CMDLineSettingsError "MaxCompilerProcesses must be graeter than zero.", 0, 1 CASE ":generatelicensefile" IF NOT ParseBooleanSetting&(token$, GenerateLicenseFile) THEN CMDLineSettingsError token$, 1, 1 + CASE ":usesystemcompiler" + IF NOT ParseBooleanSetting&(token$, UseSystemMinGW) THEN CMDLineSettingsError token$, 1, 1 CASE ":autoindent" IF NOT ParseBooleanSetting&(token$, IDEAutoIndent) THEN CMDLineSettingsError token$, 1, 1 DEFAutoIndent = IDEAutoIndent 'for restoring after '$FORMAT:OFF @@ -13418,6 +13419,7 @@ SUB CMDLineTemporarySettingsHelp PRINT " -f:ExtraLinkerFlags=[string] Extra flags for the Linker" PRINT " -f:MaxCompilerProcesses=[integer] Max C++ Compiler processes to use" PRINT " -f:GenerateLicenseFile=[true|false] Produce a license.txt file for program" + PRINT " -f:UseSystemCompiler=[true|false] Use the system C++ compiler instead of the bundled one (Windows only)" PRINT PRINT "Supported (-f) Layout settings:" PRINT " -f:AutoIndent=[true|false] Auto Indent lines" From e277254f1dc67f963993f4ed30c13dea75156910 Mon Sep 17 00:00:00 2001 From: Samuel Gomes Date: Tue, 15 Apr 2025 08:37:08 +0530 Subject: [PATCH 3/3] Format command line help text --- source/qb64pe.bas | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/qb64pe.bas b/source/qb64pe.bas index cf0f0651f..c7d8a1b20 100644 --- a/source/qb64pe.bas +++ b/source/qb64pe.bas @@ -13419,7 +13419,8 @@ SUB CMDLineTemporarySettingsHelp PRINT " -f:ExtraLinkerFlags=[string] Extra flags for the Linker" PRINT " -f:MaxCompilerProcesses=[integer] Max C++ Compiler processes to use" PRINT " -f:GenerateLicenseFile=[true|false] Produce a license.txt file for program" - PRINT " -f:UseSystemCompiler=[true|false] Use the system C++ compiler instead of the bundled one (Windows only)" + PRINT " -f:UseSystemCompiler=[true|false] Use the system C++ compiler instead of" + PRINT " the bundled one (Windows only)" PRINT PRINT "Supported (-f) Layout settings:" PRINT " -f:AutoIndent=[true|false] Auto Indent lines"