1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 12:02:21 +02:00

Partially allowing WSL compilation

This commit is contained in:
Brian Fiete 2020-06-23 07:33:43 -07:00
parent 1758520193
commit 01d52131df
2 changed files with 96 additions and 48 deletions

View file

@ -262,17 +262,48 @@ namespace IDE
return true; return true;
} }
void WSLPathFix(String str)
{
for (int i = 1; i < str.Length - 1; i++)
{
if (str[i] == ':')
{
if (str[i - 1].IsLetter)
{
int j = i;
for ( ; j < str.Length; j++)
{
char8 cj = str[j];
if (cj == '\\')
str[j] = '/';
if ((cj.IsWhiteSpace) || (cj == '"'))
break;
}
str.Remove(i);
str[i - 1] = str[i - 1].ToLower;
str.Insert(i - 1, "/mnt/");
}
}
}
}
bool QueueProjectGNULink(Project project, String targetPath, Workspace.Options workspaceOptions, Project.Options options, String objectsArg) bool QueueProjectGNULink(Project project, String targetPath, Workspace.Options workspaceOptions, Project.Options options, String objectsArg)
{ {
bool isDebug = gApp.mConfigName.IndexOf("Debug", true) != -1; bool isDebug = gApp.mConfigName.IndexOf("Debug", true) != -1;
bool isMinGW = false;
#if BF_PLATFORM_WINDOWS #if BF_PLATFORM_WINDOWS
bool isWSL = mPlatformType == .Linux;
String llvmDir = scope String(IDEApp.sApp.mInstallDir); String llvmDir = scope String(IDEApp.sApp.mInstallDir);
IDEUtils.FixFilePath(llvmDir); IDEUtils.FixFilePath(llvmDir);
llvmDir.Append("llvm/"); llvmDir.Append("llvm/");
#else #else
String llvmDir = ""; String llvmDir = "";
bool isWSL = false;
#endif #endif
//String error = scope String(); //String error = scope String();
@ -329,37 +360,38 @@ namespace IDE
} }
else else
{ {
#if BF_PLATFORM_WINDOWS if (isMinGW)
String[] mingwFiles; {
String fromDir; String[] mingwFiles;
String fromDir;
if (mPtrSize == 4) if (mPtrSize == 4)
{ {
fromDir = scope:: String(llvmDir, "i686-w64-mingw32/bin/"); fromDir = scope:: String(llvmDir, "i686-w64-mingw32/bin/");
mingwFiles = scope:: String[] { "libgcc_s_dw2-1.dll", "libstdc++-6.dll" }; mingwFiles = scope:: String[] { "libgcc_s_dw2-1.dll", "libstdc++-6.dll" };
} }
else else
{ {
fromDir = scope:: String(llvmDir, "x86_64-w64-mingw32/bin/"); fromDir = scope:: String(llvmDir, "x86_64-w64-mingw32/bin/");
mingwFiles = scope:: String[] { "libgcc_s_seh-1.dll", "libstdc++-6.dll", "libwinpthread-1.dll" }; mingwFiles = scope:: String[] { "libgcc_s_seh-1.dll", "libstdc++-6.dll", "libwinpthread-1.dll" };
} }
for (var mingwFile in mingwFiles) for (var mingwFile in mingwFiles)
{ {
String fromPath = scope String(fromDir, mingwFile); String fromPath = scope String(fromDir, mingwFile);
//string toPath = projectBuildDir + "/" + mingwFile; //string toPath = projectBuildDir + "/" + mingwFile;
String toPath = scope String(); String toPath = scope String();
Path.GetDirectoryPath(targetPath, toPath); Path.GetDirectoryPath(targetPath, toPath);
toPath.Append("/", mingwFile); toPath.Append("/", mingwFile);
if (!File.Exists(toPath)) if (!File.Exists(toPath))
{
if (File.Copy(fromPath, toPath) case .Err)
{ {
gApp.OutputLineSmart("ERROR: Failed to copy mingw file {0}", fromPath); if (File.Copy(fromPath, toPath) case .Err)
return false; {
gApp.OutputLineSmart("ERROR: Failed to copy mingw file {0}", fromPath);
return false;
}
} }
} }
} }
#endif
} }
List<Project> depProjectList = scope List<Project>(); List<Project> depProjectList = scope List<Project>();
@ -399,24 +431,29 @@ namespace IDE
} }
} }
#if BF_PLATFORM_WINDOWS String gccExePath;
String gccExePath = "c:/mingw/bin/g++.exe"; String clangExePath;
String clangExePath = scope String(llvmDir, "bin/clang++.exe"); if (isMinGW)
#else {
String gccExePath = "/usr/bin/c++"; gccExePath = "c:/mingw/bin/g++.exe";
String clangExePath = scope String("/usr/bin/c++"); clangExePath = scope String(llvmDir, "bin/clang++.exe");
}
else
{
gccExePath = "/usr/bin/c++";
clangExePath = scope String("/usr/bin/c++");
if (File.Exists("/usr/bin/clang++")) if (File.Exists("/usr/bin/clang++"))
{ {
gccExePath = "/usr/bin/clang++"; gccExePath = "/usr/bin/clang++";
clangExePath = scope String("/usr/bin/clang++"); clangExePath = scope String("/usr/bin/clang++");
} }
else else
{ {
gccExePath = "/usr/bin/c++"; gccExePath = "/usr/bin/c++";
clangExePath = scope String("/usr/bin/c++"); clangExePath = scope String("/usr/bin/c++");
} }
#endif }
if (project.mNeedsTargetRebuild) if (project.mNeedsTargetRebuild)
{ {
@ -480,6 +517,14 @@ namespace IDE
workingDir.Append(gApp.mInstallDir); workingDir.Append(gApp.mInstallDir);
} }
if (isWSL)
{
linkLine.Insert(0, " ");
linkLine.Insert(0, compilerExePath);
compilerExePath = "wsl.exe";
WSLPathFix(linkLine);
}
var runCmd = gApp.QueueRun(compilerExePath, linkLine, workingDir, .UTF8); var runCmd = gApp.QueueRun(compilerExePath, linkLine, workingDir, .UTF8);
runCmd.mOnlyIfNotFailed = true; runCmd.mOnlyIfNotFailed = true;
var tagetCompletedCmd = new IDEApp.TargetCompletedCmd(project); var tagetCompletedCmd = new IDEApp.TargetCompletedCmd(project);

View file

@ -7606,7 +7606,8 @@ namespace IDE
{ {
OutputLine("Failed to execute \"{0}\"", inFileName); OutputLine("Failed to execute \"{0}\"", inFileName);
delete process; delete process;
return executionInstance; delete executionInstance;
return null;
} }
if (runFlags.HasFlag(.NoWait)) if (runFlags.HasFlag(.NoWait))
@ -10015,7 +10016,7 @@ namespace IDE
canCompile = false; canCompile = false;
} }
canCompile = true; canCompile = platform == hostPlatform;
switch (platform) switch (platform)
{ {
case .iOS: case .iOS:
@ -10024,8 +10025,10 @@ namespace IDE
canCompile = true; canCompile = true;
case .Unknown: case .Unknown:
canCompile = true; canCompile = true;
case .Linux:
if (hostPlatform == .Windows)
canCompile = true; // Use WSL
default: default:
canCompile = platform == hostPlatform;
} }
if (!canCompile) if (!canCompile)