diff --git a/BeefBoot/BootApp.cpp b/BeefBoot/BootApp.cpp index 8a502248..78596e90 100644 --- a/BeefBoot/BootApp.cpp +++ b/BeefBoot/BootApp.cpp @@ -26,7 +26,7 @@ BF_IMPORT void BF_CALLTYPE Debugger_FullReportMemory(); BF_IMPORT void BF_CALLTYPE BfCompiler_Delete(void* bfCompiler); BF_EXPORT void BF_CALLTYPE BfCompiler_SetOptions(void* bfCompiler, void* hotProject, int hotIdx, - int machineType, int toolsetType, int simdSetting, int allocStackCount, int maxWorkerThreads, + const char* targetTriple, int toolsetType, int simdSetting, int allocStackCount, int maxWorkerThreads, Beefy::BfCompilerOptionFlags optionFlags, const char* mallocLinkName, const char* freeLinkName); BF_IMPORT void BF_CALLTYPE BfCompiler_ClearBuildCache(void* bfCompiler); BF_IMPORT bool BF_CALLTYPE BfCompiler_Compile(void* bfCompiler, void* bfPassInstance, const char* outputPath); @@ -163,6 +163,14 @@ BootApp::BootApp() mToolset = BfToolsetType_GNU; #endif mEmitIR = false; + +#ifdef BF_PLATFORM_WINDOWS + mTargetTriple = "x86_64-pc-windows-msvc"; +#elif defined BF_PLATFORM_OSX + mTargetTriple = "x86_64-apple-macosx10.14.0"; +#else + mTargetTriple = "x86_64-unknown-linux-gnu"; +#endif GetConsoleColor(gConsoleFGColor, gConsoleBGColor); } @@ -829,7 +837,7 @@ bool BootApp::Compile() if (maxWorkerThreads <= 1) maxWorkerThreads = 6; - BfCompiler_SetOptions(mCompiler, NULL, 0, BfMachineType_x64, mToolset, BfSIMDSetting_SSE2, 1, maxWorkerThreads, optionFlags, "malloc", "free"); + BfCompiler_SetOptions(mCompiler, NULL, 0, mTargetTriple.c_str(), mToolset, BfSIMDSetting_SSE2, 1, maxWorkerThreads, optionFlags, "malloc", "free"); if (mIsCERun) { diff --git a/BeefBoot/BootApp.h b/BeefBoot/BootApp.h index 2e94deb3..c6628c41 100644 --- a/BeefBoot/BootApp.h +++ b/BeefBoot/BootApp.h @@ -35,6 +35,7 @@ public: FileStream mLogFile; Verbosity mVerbosity; BfTargetType mTargetType; + String mTargetTriple; bool mHadCmdLine; bool mShowedHelp; bool mHadErrors; diff --git a/BeefBuild/src/BuildApp.bf b/BeefBuild/src/BuildApp.bf index 3f958d4f..6b17027e 100644 --- a/BeefBuild/src/BuildApp.bf +++ b/BeefBuild/src/BuildApp.bf @@ -276,7 +276,7 @@ namespace BeefBuild let options = gApp.GetCurProjectOptions(mWorkspace.mStartupProject); let targetPaths = scope List(); defer ClearAndDeleteItems(targetPaths); - this.[Friend]GetTargetPaths(mWorkspace.mStartupProject, workspaceOptions, options, targetPaths); + this.[Friend]GetTargetPaths(mWorkspace.mStartupProject, gApp.mPlatformName, workspaceOptions, options, targetPaths); if (targetPaths.IsEmpty) return; diff --git a/BeefySysLib/platform/linux/LinuxCommon.cpp b/BeefySysLib/platform/linux/LinuxCommon.cpp index 08e396a6..e946cc13 100644 --- a/BeefySysLib/platform/linux/LinuxCommon.cpp +++ b/BeefySysLib/platform/linux/LinuxCommon.cpp @@ -1831,7 +1831,7 @@ BFP_EXPORT int64 BFP_CALLTYPE BfpFile_Seek(BfpFile* file, int64 offset, BfpFileS whence = SEEK_CUR; else whence = SEEK_END; - return seek64(file->mHandle, offset, whence); + return lseek64(file->mHandle, offset, whence); } BFP_EXPORT void BFP_CALLTYPE BfpFile_Truncate(BfpFile* file) diff --git a/IDE/src/BuildContext.bf b/IDE/src/BuildContext.bf index 04227eef..ae95d8c7 100644 --- a/IDE/src/BuildContext.bf +++ b/IDE/src/BuildContext.bf @@ -113,7 +113,7 @@ namespace IDE else { customCmd.Append("%exec "); - gApp.ResolveConfigString(workspaceOptions, project, options, origCustomCmd, "custom command", customCmd); + gApp.ResolveConfigString(gApp.mPlatformName, workspaceOptions, project, options, origCustomCmd, "custom command", customCmd); } if (customCmd.IsWhiteSpace) @@ -203,7 +203,8 @@ namespace IDE #if BF_PLATFORM_WINDOWS String[] mingwFiles; String fromDir; - if (workspaceOptions.mMachineType == Workspace.MachineType.x86) + + if (Workspace.PlatformType.GetPtrSizeByName(gApp.mPlatformName) == 4) { fromDir = scope:: String(llvmDir, "i686-w64-mingw32/bin/"); mingwFiles = scope:: String[] { "libgcc_s_dw2-1.dll", "libstdc++-6.dll" }; @@ -297,7 +298,7 @@ namespace IDE if (workspaceOptions.mToolsetType == .GNU) { - if (workspaceOptions.mMachineType == Workspace.MachineType.x86) + if (Workspace.PlatformType.GetPtrSizeByName(gApp.mPlatformName) == 4) { } else @@ -310,7 +311,7 @@ namespace IDE } else // Microsoft { - if (workspaceOptions.mMachineType == Workspace.MachineType.x86) + if (Workspace.PlatformType.GetPtrSizeByName(gApp.mPlatformName) == 4) { //linkLine.Append("-L\"C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.10586.0\\ucrt\\x86\" "); for (var libPath in gApp.mSettings.mVSSettings.mLib32Paths) @@ -334,7 +335,7 @@ namespace IDE if (options.mBuildOptions.mOtherLinkFlags.Length != 0) { var linkFlags = scope String(); - gApp.ResolveConfigString(workspaceOptions, project, options, options.mBuildOptions.mOtherLinkFlags, "link flags", linkFlags); + gApp.ResolveConfigString(gApp.mPlatformName, workspaceOptions, project, options, options.mBuildOptions.mOtherLinkFlags, "link flags", linkFlags); linkLine.Append(linkFlags, " "); } @@ -384,7 +385,7 @@ namespace IDE if ((!dynName) || (options.mBuildOptions.mBeefLibType != .Static)) { outRt.Append("Beef", IDEApp.sRTVersionStr, "RT"); - outRt.Append((workspaceOptions.mMachineType == .x86) ? "32" : "64"); + outRt.Append((Workspace.PlatformType.GetPtrSizeByName(gApp.mPlatformName) == 4) ? "32" : "64"); switch (options.mBuildOptions.mBeefLibType) { case .Dynamic: @@ -405,7 +406,7 @@ namespace IDE if ((workspaceOptions.mEnableObjectDebugFlags) || (workspaceOptions.mAllocType == .Debug)) { outDbg.Append("Beef", IDEApp.sRTVersionStr, "Dbg"); - outDbg.Append((workspaceOptions.mMachineType == .x86) ? "32" : "64"); + outDbg.Append((Workspace.PlatformType.GetPtrSizeByName(gApp.mPlatformName) == 4) ? "32" : "64"); if (options.mBuildOptions.mBeefLibType == .DynamicDebug) outDbg.Append("_d"); outDbg.Append(dynName ? ".dll" : ".lib"); @@ -436,6 +437,8 @@ namespace IDE bool QueueProjectMSLink(Project project, String targetPath, String configName, Workspace.Options workspaceOptions, Project.Options options, String objectsArg) { + bool is64Bit = Workspace.PlatformType.GetPtrSizeByName(gApp.mPlatformName) == 8; + String llvmDir = scope String(IDEApp.sApp.mInstallDir); IDEUtils.FixFilePath(llvmDir); llvmDir.Append("llvm/"); @@ -560,7 +563,7 @@ namespace IDE { let depProjectOptions = gApp.GetCurProjectOptions(depProject); var linkFlags = scope String(); - gApp.ResolveConfigString(workspaceOptions, depProject, depProjectOptions, depProjectOptions.mBuildOptions.mOtherLinkFlags, "link flags", linkFlags); + gApp.ResolveConfigString(gApp.mPlatformName, workspaceOptions, depProject, depProjectOptions, depProjectOptions.mBuildOptions.mOtherLinkFlags, "link flags", linkFlags); if (!linkFlags.IsWhiteSpace) linkLine.Append(linkFlags, " "); } @@ -602,7 +605,7 @@ namespace IDE if (!minRTModName.IsEmpty) minRTModName.Insert(0, "_"); - if (workspaceOptions.mMachineType == .x86) + if (!is64Bit) linkLine.Append(gApp.mInstallDir, @"lib\x86\msvcrt.lib Beef", IDEApp.sRTVersionStr,"MinRT32", minRTModName, ".lib "); else linkLine.Append(gApp.mInstallDir, @"lib\x64\msvcrt.lib Beef", IDEApp.sRTVersionStr,"MinRT64", minRTModName, ".lib "); @@ -634,7 +637,7 @@ namespace IDE else linkLine.Append("-opt:noref "); - if (workspaceOptions.mMachineType == .x86) + if (!is64Bit) { for (var libPath in gApp.mSettings.mVSSettings.mLib32Paths) { @@ -660,7 +663,7 @@ namespace IDE if (options.mBuildOptions.mOtherLinkFlags.Length != 0) { var linkFlags = scope String(); - gApp.ResolveConfigString(workspaceOptions, project, options, options.mBuildOptions.mOtherLinkFlags, "link flags", linkFlags); + gApp.ResolveConfigString(gApp.mPlatformName, workspaceOptions, project, options, options.mBuildOptions.mOtherLinkFlags, "link flags", linkFlags); linkLine.Append(linkFlags, " "); } @@ -710,7 +713,7 @@ namespace IDE resOutPath.Append(projectBuildDir, "\\Resource.res"); String iconPath = scope String(); - gApp.ResolveConfigString(workspaceOptions, project, options, winOptions.mIconFile, "icon file", iconPath); + gApp.ResolveConfigString(gApp.mPlatformName, workspaceOptions, project, options, winOptions.mIconFile, "icon file", iconPath); // Generate resource Result CreateResourceFile() @@ -742,7 +745,7 @@ namespace IDE } String manifestPath = scope String(); - gApp.ResolveConfigString(workspaceOptions, project, options, winOptions.mManifestFile, "manifest file", manifestPath); + gApp.ResolveConfigString(gApp.mPlatformName, workspaceOptions, project, options, winOptions.mManifestFile, "manifest file", manifestPath); if (!manifestPath.IsWhiteSpace) { Path.GetAbsolutePath(scope String(manifestPath), project.mProjectDir, manifestPath..Clear()); @@ -766,7 +769,7 @@ namespace IDE IDEUtils.AppendWithOptionalQuotes(linkLine, resOutPath); } - let binPath = (workspaceOptions.mMachineType == .x86) ? gApp.mSettings.mVSSettings.mBin32Path : gApp.mSettings.mVSSettings.mBin64Path; + let binPath = (!is64Bit) ? gApp.mSettings.mVSSettings.mBin32Path : gApp.mSettings.mVSSettings.mBin64Path; if (binPath.IsWhiteSpace) { gApp.OutputErrorLine("Visual Studio tool path not configured. Check Visual Studio configuration in File\\Preferences\\Settings."); @@ -876,10 +879,10 @@ namespace IDE } else { - gApp.ResolveConfigString(workspaceOptions, project, options, options.mBuildOptions.mTargetDirectory, "target directory", outputDir); + gApp.ResolveConfigString(gApp.mPlatformName, workspaceOptions, project, options, options.mBuildOptions.mTargetDirectory, "target directory", outputDir); Path.GetAbsolutePath(project.mProjectDir, outputDir, absOutputDir); outputDir = absOutputDir; - gApp.ResolveConfigString(workspaceOptions, project, options, "$(TargetPath)", "target path", targetPath); + gApp.ResolveConfigString(gApp.mPlatformName, workspaceOptions, project, options, "$(TargetPath)", "target path", targetPath); } IDEUtils.FixFilePath(targetPath); if (!File.Exists(targetPath)) diff --git a/IDE/src/Compiler/BfCompiler.bf b/IDE/src/Compiler/BfCompiler.bf index 00f80b6d..e65b1ef7 100644 --- a/IDE/src/Compiler/BfCompiler.bf +++ b/IDE/src/Compiler/BfCompiler.bf @@ -96,7 +96,7 @@ namespace IDE.Compiler [StdCall, CLink] static extern void BfCompiler_SetOptions(void* bfCompiler, - void* hotProject, int32 hotIdx, int32 machineType, int32 toolsetType, int32 simdSetting, int32 allocStackCount, int32 maxWorkerThreads, + void* hotProject, int32 hotIdx, char8* targetTriple, int32 toolsetType, int32 simdSetting, int32 allocStackCount, int32 maxWorkerThreads, OptionFlags optionsFlags, char8* mallocName, char8* freeName); [StdCall, CLink] @@ -240,12 +240,12 @@ namespace IDE.Compiler } public void SetOptions(BfProject hotProject, int32 hotIdx, - int32 machineType, int32 toolsetType, int32 simdSetting, int32 allocStackCount, int32 maxWorkerThreads, + String targetTriple, int32 toolsetType, int32 simdSetting, int32 allocStackCount, int32 maxWorkerThreads, OptionFlags optionFlags, String mallocFuncName, String freeFuncName) { BfCompiler_SetOptions(mNativeBfCompiler, (hotProject != null) ? hotProject.mNativeBfProject : null, hotIdx, - machineType, toolsetType, simdSetting, allocStackCount, maxWorkerThreads, optionFlags, mallocFuncName, freeFuncName); + targetTriple, toolsetType, simdSetting, allocStackCount, maxWorkerThreads, optionFlags, mallocFuncName, freeFuncName); } public void ForceRebuild() @@ -464,6 +464,8 @@ namespace IDE.Compiler //Debug.WriteLine("HandleOptions"); var options = IDEApp.sApp.GetCurWorkspaceOptions(); + String targetTriple = scope .(); + Workspace.PlatformType.GetTargetTripleByName(gApp.mPlatformName, options.mToolsetType, targetTriple); bool enableObjectDebugFlags = options.mEnableObjectDebugFlags; bool emitObjectAccessCheck = options.mEmitObjectAccessCheck && enableObjectDebugFlags; @@ -527,7 +529,7 @@ namespace IDE.Compiler //Debug.WriteLine("HandleOptions SetOptions:{0:X}", (int)optionFlags); SetOptions(hotBfProject, hotIdx, - (int32)options.mMachineType, (int32)options.mToolsetType, (int32)options.mBfSIMDSetting, (int32)options.mAllocStackTraceDepth, (int32)gApp.mSettings.mCompilerSettings.mWorkerThreads, + targetTriple, (int32)options.mToolsetType, (int32)options.mBfSIMDSetting, (int32)options.mAllocStackTraceDepth, (int32)gApp.mSettings.mCompilerSettings.mWorkerThreads, optionFlags, mallocLinkName, freeLinkName); if (!mIsResolveOnly) diff --git a/IDE/src/IDEApp.bf b/IDE/src/IDEApp.bf index 653e6f5c..761950e9 100644 --- a/IDE/src/IDEApp.bf +++ b/IDE/src/IDEApp.bf @@ -107,6 +107,9 @@ namespace IDE #elif BF_PLATFORM_LINUX public static readonly String sPlatform64Name = "Linux64"; public static readonly String sPlatform32Name = "Linux32"; +#elif BF_PLATFORM_OSX + public static readonly String sPlatform64Name = "macOS"; + public static readonly String sPlatform32Name = null; #else public static readonly String sPlatform64Name = "Unknown64"; public static readonly String sPlatform32Name = "Unknown32"; @@ -1859,7 +1862,7 @@ namespace IDE if (!options.mDebugOptions.mCommand.IsWhiteSpace) { String execCmd = scope .(); - ResolveConfigString(workspaceOptions, project, options, options.mDebugOptions.mCommand, "command", execCmd); + ResolveConfigString(mPlatformName, workspaceOptions, project, options, options.mDebugOptions.mCommand, "command", execCmd); String initialDir = scope .(); Path.GetDirectoryPath(execCmd, initialDir); @@ -2548,8 +2551,10 @@ namespace IDE } List platforms = scope List(); - platforms.Add(IDEApp.sPlatform32Name); - platforms.Add(IDEApp.sPlatform64Name); + if (IDEApp.sPlatform32Name != null) + platforms.Add(IDEApp.sPlatform32Name); + if (IDEApp.sPlatform64Name != null) + platforms.Add(IDEApp.sPlatform64Name); List configs = scope List(); configs.Add("Debug"); @@ -6887,7 +6892,7 @@ namespace IDE if (workspaceOptions.mAllowHotSwapping) macroList.Add("BF_ALLOW_HOT_SWAPPING"); - bool is64Bits = workspaceOptions.mMachineType.PtrSize == 8; + bool is64Bits = Workspace.PlatformType.GetPtrSizeByName(gApp.mPlatformName) == 8; if (is64Bits) { @@ -8191,7 +8196,7 @@ namespace IDE return passInstance; } - public bool DoResolveConfigString(Workspace.Options workspaceOptions, Project project, Project.Options options, StringView configString, String error, String result) + public bool DoResolveConfigString(String platformName, Workspace.Options workspaceOptions, Project project, Project.Options options, StringView configString, String error, String result) { int i = result.Length; result.Append(configString); @@ -8265,7 +8270,7 @@ namespace IDE { String unresolvedStr = scope .(); str.UnQuoteString(unresolvedStr); - if (!DoResolveConfigString(workspaceOptions, project, options, unresolvedStr, error, arg)) + if (!DoResolveConfigString(platformName, workspaceOptions, project, options, unresolvedStr, error, arg)) return false; } else @@ -8325,14 +8330,14 @@ namespace IDE if (project.IsDebugSession) { let targetPath = scope:ReplaceBlock String(); - DoResolveConfigString(workspaceOptions, project, options, options.mBuildOptions.mTargetName, error, targetPath); + DoResolveConfigString(platformName, workspaceOptions, project, options, options.mBuildOptions.mTargetName, error, targetPath); newString = scope:ReplaceBlock String(); Path.GetDirectoryPath(targetPath, newString); break; } String targetDir = scope String(); - DoResolveConfigString(workspaceOptions, project, options, options.mBuildOptions.mTargetDirectory, error, targetDir); + DoResolveConfigString(platformName, workspaceOptions, project, options, options.mBuildOptions.mTargetDirectory, error, targetDir); newString = scope:ReplaceBlock String(); Path.GetAbsolutePath(targetDir, project.mProjectDir, newString); } @@ -8341,17 +8346,17 @@ namespace IDE if (project.IsDebugSession) { newString = scope:ReplaceBlock String(); - DoResolveConfigString(workspaceOptions, project, options, options.mBuildOptions.mTargetName, error, newString); + DoResolveConfigString(platformName, workspaceOptions, project, options, options.mBuildOptions.mTargetName, error, newString); break; } String targetDir = scope String(); - DoResolveConfigString(workspaceOptions, project, options, options.mBuildOptions.mTargetDirectory, error, targetDir); + DoResolveConfigString(platformName, workspaceOptions, project, options, options.mBuildOptions.mTargetDirectory, error, targetDir); newString = scope:ReplaceBlock String(); Path.GetAbsolutePath(targetDir, project.mProjectDir, newString); Utils.GetDirWithSlash(newString); - if (!DoResolveConfigString(workspaceOptions, project, options, options.mBuildOptions.mTargetName, error, newString)) + if (!DoResolveConfigString(platformName, workspaceOptions, project, options, options.mBuildOptions.mTargetName, error, newString)) return false; #if BF_PLATFORM_WINDOWS if (project.mGeneralOptions.mTargetType == .BeefLib) @@ -8405,7 +8410,7 @@ namespace IDE #endif } case "VSToolPath": - if (workspaceOptions.mMachineType.PtrSize == 4) + if (Workspace.PlatformType.GetPtrSizeByName(platformName) == 4) newString = gApp.mSettings.mVSSettings.mBin32Path; else newString = gApp.mSettings.mVSSettings.mBin64Path; @@ -8472,10 +8477,10 @@ namespace IDE return !hadError; } - public bool ResolveConfigString(Workspace.Options workspaceOptions, Project project, Project.Options options, StringView configString, String errorContext, String outResult) + public bool ResolveConfigString(String platformName, Workspace.Options workspaceOptions, Project project, Project.Options options, StringView configString, String errorContext, String outResult) { String errorString = scope String(); - if (!DoResolveConfigString(workspaceOptions, project, options, configString, errorString, outResult)) + if (!DoResolveConfigString(platformName, workspaceOptions, project, options, configString, errorString, outResult)) { OutputErrorLine("Invalid macro in {0}: {1}", errorContext, errorString); return false; @@ -8586,7 +8591,7 @@ namespace IDE if (options.mCOptions.mCompilerType == Project.CCompilerType.GCC) { - if (workspaceOptions.mMachineType == Workspace.MachineType.x86) + if (Workspace.PlatformType.GetPtrSizeByName(gApp.mPlatformName) == 4) clangOptions.Append("-m32 "); else clangOptions.Append("-m64 "); @@ -8594,7 +8599,7 @@ namespace IDE else { clangOptions.Append("--target="); - GetTargetName(workspaceOptions, clangOptions); + Workspace.PlatformType.GetTargetTripleByName(gApp.mPlatformName, workspaceOptions.mToolsetType, clangOptions); clangOptions.Append(" "); if (workspaceOptions.mToolsetType == .GNU) @@ -8719,37 +8724,10 @@ namespace IDE project.mNeedsTargetRebuild = true; } - void GetTargetName(Workspace.Options workspaceOptions, String str) - { -#if BF_PLATFORM_WINDOWS - if (workspaceOptions.mToolsetType == .GNU) - { - if (workspaceOptions.mMachineType == Workspace.MachineType.x86) - str.Append("i686-pc-windows-gnu"); - else - str.Append("x86_64-pc-windows-gnu"); - } - else - { - if (workspaceOptions.mMachineType == Workspace.MachineType.x86) - str.Append("i686-pc-windows-msvc"); - else - str.Append("x86_64-pc-windows-msvc"); - } -#elif BF_PLATFORM_LINUX - if (workspaceOptions.mMachineType == Workspace.MachineType.x86) - str.Append("i686-unknown-linux-gnu"); - else - str.Append("x86_64-unknown-linux-gnu"); -#else - -#endif - } - - void GetTargetPaths(Project project, Workspace.Options workspaceOptions, Project.Options options, List outPaths) + void GetTargetPaths(Project project, String platformName, Workspace.Options workspaceOptions, Project.Options options, List outPaths) { String targetPath = scope String(); - ResolveConfigString(workspaceOptions, project, options, "$(TargetPath)", "Target path", targetPath); + ResolveConfigString(platformName, workspaceOptions, project, options, "$(TargetPath)", "Target path", targetPath); outPaths.Add(new String(targetPath)); #if BF_PLATFORM_WINDOWS @@ -9566,16 +9544,16 @@ namespace IDE //options.mDebugOptions.mCommand String launchPath = scope String(); - ResolveConfigString(workspaceOptions, project, options, options.mDebugOptions.mCommand, "debug command", launchPath); + ResolveConfigString(mPlatformName, workspaceOptions, project, options, options.mDebugOptions.mCommand, "debug command", launchPath); String arguments = scope String(); - ResolveConfigString(workspaceOptions, project, options, "$(Arguments)", "debug command arguments", arguments); + ResolveConfigString(mPlatformName, workspaceOptions, project, options, "$(Arguments)", "debug command arguments", arguments); String workingDirRel = scope String(); - ResolveConfigString(workspaceOptions, project, options, "$(WorkingDir)", "debug working directory", workingDirRel); + ResolveConfigString(mPlatformName, workspaceOptions, project, options, "$(WorkingDir)", "debug working directory", workingDirRel); var workingDir = scope String(); Path.GetAbsolutePath(workingDirRel, project.mProjectDir, workingDir); String targetPath = scope .(); - ResolveConfigString(workspaceOptions, project, options, "$(TargetPath)", "Target path", targetPath); + ResolveConfigString(mPlatformName, workspaceOptions, project, options, "$(TargetPath)", "Target path", targetPath); IDEUtils.FixFilePath(launchPath); IDEUtils.FixFilePath(targetPath); @@ -10708,7 +10686,7 @@ namespace IDE let options = GetCurProjectOptions(project); if (options == null) continue; - GetTargetPaths(project, workspaceOptions, options, projectFiles); + GetTargetPaths(project, mPlatformName, workspaceOptions, options, projectFiles); for (let filePath in projectFiles) { diff --git a/IDE/src/Project.bf b/IDE/src/Project.bf index 041cedad..21b09601 100644 --- a/IDE/src/Project.bf +++ b/IDE/src/Project.bf @@ -1235,8 +1235,10 @@ namespace IDE public void SetupDefaultConfigs() { List platforms = scope List(); - platforms.Add(IDEApp.sPlatform32Name); - platforms.Add(IDEApp.sPlatform64Name); + if (IDEApp.sPlatform32Name != null) + platforms.Add(IDEApp.sPlatform32Name); + if (IDEApp.sPlatform64Name != null) + platforms.Add(IDEApp.sPlatform64Name); List configs = scope List(); configs.Add("Debug"); diff --git a/IDE/src/ScriptManager.bf b/IDE/src/ScriptManager.bf index 9e416e5c..102c61ea 100644 --- a/IDE/src/ScriptManager.bf +++ b/IDE/src/ScriptManager.bf @@ -415,7 +415,7 @@ namespace IDE String newStr = scope:: .(); String err = scope .(); - if (!gApp.DoResolveConfigString(workspaceOptions, project, projectOptions, str, err, newStr)) + if (!gApp.DoResolveConfigString("", workspaceOptions, project, projectOptions, str, err, newStr)) { Fail(scope String()..AppendF("Unknown macro string '{}' in '{}'", err, str)); } @@ -1193,7 +1193,7 @@ namespace IDE let workspaceOptions = gApp.GetCurWorkspaceOptions(); let options = gApp.GetCurProjectOptions(checkProject); - gApp.[Friend]GetTargetPaths(checkProject, workspaceOptions, options, targetPaths); + gApp.[Friend]GetTargetPaths(checkProject, gApp.mPlatformName, workspaceOptions, options, targetPaths); if (!targetPaths.IsEmpty) { diff --git a/IDE/src/Workspace.bf b/IDE/src/Workspace.bf index aa2989bd..893f9d34 100644 --- a/IDE/src/Workspace.bf +++ b/IDE/src/Workspace.bf @@ -69,6 +69,35 @@ namespace IDE #unwarn return .Unknown; } + + public static int GetPtrSizeByName(String name) + { + if (name.EndsWith("32")) + return 4; + return 8; + } + + public static bool GetTargetTripleByName(String name, ToolsetType toolsetType, String outTriple) + { + switch (name) + { + case "Win32": + outTriple.Append((toolsetType == .GNU) ? "i686-pc-windows-gnu" : "i686-pc-windows-msvc"); + case "Win64": + outTriple.Append((toolsetType == .GNU) ? "x86_64-pc-windows-gnu" : "x86_64-pc-windows-msvc"); + case "Linux32": + outTriple.Append("i686-unknown-linux-gnu"); + case "Linux64": + outTriple.Append("x86_64-unknown-linux-gnu"); + case "macOS": + outTriple.Append("x86_64-apple-macosx10.14.0"); + case "iOS": + outTriple.Append("arm64-apple-ios13.1"); + default: + return false; + } + return true; + } } public enum ToolsetType @@ -157,8 +186,6 @@ namespace IDE public class Options { [Reflect] - public MachineType mMachineType = MachineType.x86; - [Reflect] public ToolsetType mToolsetType; [Reflect] public BuildKind mBuildKind; @@ -234,7 +261,6 @@ namespace IDE public void CopyFrom(Workspace.Options prev) { - mMachineType = prev.mMachineType; mToolsetType = prev.mToolsetType; mBuildKind = prev.mBuildKind; @@ -568,11 +594,6 @@ namespace IDE data.RemoveIfEmpty(); } - MachineType defaultMachineType = .x64; - if (platformName == "Win32") - defaultMachineType = .x86; - - data.ConditionalAdd("MachineType", options.mMachineType, defaultMachineType); data.ConditionalAdd("Toolset", options.mToolsetType, ToolsetType.Default); data.ConditionalAdd("BuildKind", options.mBuildKind, isTest ? .Test : .Normal); data.ConditionalAdd("BfSIMDSetting", options.mBfSIMDSetting, .SSE2); @@ -720,11 +741,6 @@ namespace IDE options.mCSIMDSetting = .SSE2; options.mCOptimizationLevel = isRelease ? .O2 : .O0; - MachineType defaultMachineType = .x64; - if (platformName == "Win32") - defaultMachineType = .x86; - - options.mMachineType = defaultMachineType; options.mBuildKind = isTest ? .Test : .Normal; //TODO: @@ -779,11 +795,6 @@ namespace IDE options.mPreprocessorMacros.Add(str); } - MachineType defaultMachineType = .x64; - if (platformName == "Win32") - defaultMachineType = .x86; - - options.mMachineType = data.GetEnum("MachineType", defaultMachineType); options.mToolsetType = data.GetEnum("Toolset", ToolsetType.Default); options.mBuildKind = data.GetEnum("BuildKind", isTest ? .Test : .Normal); options.mBfSIMDSetting = data.GetEnum("BfSIMDSetting", .SSE2); diff --git a/IDE/src/ui/LaunchDialog.bf b/IDE/src/ui/LaunchDialog.bf index c527fc15..ac6a1300 100644 --- a/IDE/src/ui/LaunchDialog.bf +++ b/IDE/src/ui/LaunchDialog.bf @@ -123,7 +123,7 @@ namespace IDE.ui if (inStr == null) return false; - gApp.ResolveConfigString(workspaceOptions, gApp.mWorkspace.mStartupProject, options, inStr, "", outString); + gApp.ResolveConfigString(gApp.mPlatformName, workspaceOptions, gApp.mWorkspace.mStartupProject, options, inStr, "", outString); return true; } return false; diff --git a/IDEHelper/Compiler/BfCompiler.cpp b/IDEHelper/Compiler/BfCompiler.cpp index 06fd325d..3b612ecf 100644 --- a/IDEHelper/Compiler/BfCompiler.cpp +++ b/IDEHelper/Compiler/BfCompiler.cpp @@ -8123,7 +8123,7 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_HotResolve_Finish(BfCompiler* bfCom } BF_EXPORT void BF_CALLTYPE BfCompiler_SetOptions(BfCompiler* bfCompiler, BfProject* hotProject, int hotIdx, - int machineType, int toolsetType, int simdSetting, int allocStackCount, int maxWorkerThreads, + const char* targetTriple, int toolsetType, int simdSetting, int allocStackCount, int maxWorkerThreads, BfCompilerOptionFlags optionFlags, char* mallocLinkName, char* freeLinkName) { BfLogSys(bfCompiler->mSystem, "BfCompiler_SetOptions\n"); @@ -8135,7 +8135,15 @@ BF_EXPORT void BF_CALLTYPE BfCompiler_SetOptions(BfCompiler* bfCompiler, BfProje options->mErrorString.Clear(); options->mHotProject = hotProject; options->mHotCompileIdx = hotIdx; - options->mMachineType = (BfMachineType)machineType; + options->mTargetTriple = targetTriple; + + if (options->mTargetTriple.StartsWith("x86_64-")) + options->mMachineType = BfMachineType_x64; + else if (options->mTargetTriple.StartsWith("i686-")) + options->mMachineType = BfMachineType_x86; + else + options->mMachineType = BfMachineType_x64; // Default + bfCompiler->mCodeGen.SetMaxThreads(maxWorkerThreads); if (!bfCompiler->mIsResolveOnly) diff --git a/IDEHelper/Compiler/BfCompiler.h b/IDEHelper/Compiler/BfCompiler.h index 90a5c546..c4fb7edd 100644 --- a/IDEHelper/Compiler/BfCompiler.h +++ b/IDEHelper/Compiler/BfCompiler.h @@ -93,6 +93,7 @@ public: int32 mForceRebuildIdx; BfCompileOnDemandKind mCompileOnDemandKind; + String mTargetTriple; BfMachineType mMachineType; BfToolsetType mToolsetType; BfSIMDSetting mSIMDSetting; diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index 375369fe..c22dab2a 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -241,6 +241,8 @@ bool BfMethodMatcher::InferGenericArgument(BfMethodInstance* methodInstance, BfT { if (argType == NULL) return false; + if (argType->IsVar()) + return false; if (wantType->IsGenericParam()) { @@ -248,7 +250,7 @@ bool BfMethodMatcher::InferGenericArgument(BfMethodInstance* methodInstance, BfT BfType* methodGenericTypeConstraint = NULL; auto _SetGeneric = [&]() - { + { if (mCheckMethodGenericArguments[wantGenericParam->mGenericParamIdx] != argType) { if (methodGenericTypeConstraint != NULL) @@ -1347,6 +1349,9 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* typeInstance, BfMethodDef* che genericArg = mModule->GetPrimitiveStructType(primType->mTypeDef->mTypeCode); } + if (genericArg == NULL) + goto NoMatch; + //SetAndRestoreValue ignoreError(mModule->mIgnoreErrors, true); if (!mModule->CheckGenericConstraints(BfGenericParamSource(methodInstance), genericArg, NULL, genericParams[checkGenericIdx], genericArgumentsSubstitute, NULL)) { diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 2369c976..d0ee0a5f 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -954,30 +954,32 @@ void BfModule::FinishInit() mBfIRBuilder->Start(mModuleName, mCompiler->mSystem->mPtrSize, IsOptimized()); -#ifdef BF_PLATFORM_WINDOWS - if (mCompiler->mOptions.mToolsetType == BfToolsetType_GNU) - { - if (mCompiler->mOptions.mMachineType == BfMachineType_x86) - mBfIRBuilder->Module_SetTargetTriple("i686-pc-windows-gnu"); - else - mBfIRBuilder->Module_SetTargetTriple("x86_64-pc-windows-gnu"); - } - else //if (mCompiler->mOptions.mToolsetType == BfToolsetType_Microsoft) - { - if (mCompiler->mOptions.mMachineType == BfMachineType_x86) - mBfIRBuilder->Module_SetTargetTriple("i686-pc-windows-msvc"); - else - mBfIRBuilder->Module_SetTargetTriple("x86_64-pc-windows-msvc"); - } -#elif defined BF_PLATFORM_LINUX - if (mCompiler->mOptions.mMachineType == BfMachineType_x86) - mBfIRBuilder->Module_SetTargetTriple("i686-unknown-linux-gnu"); - else - mBfIRBuilder->Module_SetTargetTriple("x86_64-unknown-linux-gnu"); -#else - // Leave it default - mBfIRBuilder->Module_SetTargetTriple(""); -#endif + mBfIRBuilder->Module_SetTargetTriple(mCompiler->mOptions.mTargetTriple); + +// #ifdef BF_PLATFORM_WINDOWS +// if (mCompiler->mOptions.mToolsetType == BfToolsetType_GNU) +// { +// if (mCompiler->mOptions.mMachineType == BfMachineType_x86) +// mBfIRBuilder->Module_SetTargetTriple("i686-pc-windows-gnu"); +// else +// mBfIRBuilder->Module_SetTargetTriple("x86_64-pc-windows-gnu"); +// } +// else //if (mCompiler->mOptions.mToolsetType == BfToolsetType_Microsoft) +// { +// if (mCompiler->mOptions.mMachineType == BfMachineType_x86) +// mBfIRBuilder->Module_SetTargetTriple("i686-pc-windows-msvc"); +// else +// mBfIRBuilder->Module_SetTargetTriple("x86_64-pc-windows-msvc"); +// } +// #elif defined BF_PLATFORM_LINUX +// if (mCompiler->mOptions.mMachineType == BfMachineType_x86) +// mBfIRBuilder->Module_SetTargetTriple("i686-unknown-linux-gnu"); +// else +// mBfIRBuilder->Module_SetTargetTriple("x86_64-unknown-linux-gnu"); +// #else +// // Leave it default +// mBfIRBuilder->Module_SetTargetTriple(""); +// #endif mBfIRBuilder->SetBackend(IsTargetingBeefBackend());