1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-18 16:10:26 +02:00

Start of wasm support

This commit is contained in:
Brian Fiete 2020-08-06 09:24:37 -07:00
parent 053b302d42
commit b7b065855d
22 changed files with 487 additions and 35 deletions

View file

@ -527,6 +527,114 @@ namespace IDE
return true;
}
bool QueueProjectWasmLink(Project project, String targetPath, Workspace.Options workspaceOptions, Project.Options options, String objectsArg)
{
//bool isDebug = gApp.mConfigName.IndexOf("Debug", true) != -1;
//bool isMinGW = false;
//String error = scope String();
TestManager.ProjectInfo testProjectInfo = null;
if (gApp.mTestManager != null)
testProjectInfo = gApp.mTestManager.GetProjectInfo(project);
bool isExe = (project.mGeneralOptions.mTargetType != Project.TargetType.BeefLib) || (testProjectInfo != null);
bool isDynLib = project.mGeneralOptions.mTargetType == Project.TargetType.BeefDynLib;
if (isExe || isDynLib)
{
String linkLine = scope String();
linkLine.Append("-o ");
IDEUtils.AppendWithOptionalQuotes(linkLine, targetPath);
linkLine.Append(" ");
linkLine.Append(objectsArg);
List<String> libPaths = scope .();
defer ClearAndDeleteItems(libPaths);
List<String> depPaths = scope .();
defer ClearAndDeleteItems(depPaths);
AddLinkDeps(project, options, workspaceOptions, linkLine, libPaths, depPaths);
for (var libPath in libPaths)
{
IDEUtils.AppendWithOptionalQuotes(linkLine, libPath);
linkLine.Append(" ");
}
if (project.mNeedsTargetRebuild)
{
if (File.Delete(targetPath) case .Err)
{
gApp.OutputLine("Failed to delete {0}", targetPath);
return false;
}
if (options.mBuildOptions.mOtherLinkFlags.Length != 0)
{
var linkFlags = scope String();
gApp.ResolveConfigString(gApp.mPlatformName, workspaceOptions, project, options, options.mBuildOptions.mOtherLinkFlags, "link flags", linkFlags);
linkLine.Append(linkFlags, " ");
}
#if BF_PLATFORM_WINDOWS
String compilerExePath = scope String();
String llvmDir = scope String(IDEApp.sApp.mInstallDir);
IDEUtils.FixFilePath(llvmDir);
llvmDir.Append("llvm/");
compilerExePath.Append(llvmDir, "bin/wasm-ld.exe");
#else
String llvmDir = "";
bool isWSL = false;
String compilerExePath = "wasm-ld";
#endif
//compilerExePath.Set(@"C:\temp\emsdk\upstream\emscripten\emcc.bat");
if (!gApp.mSettings.mEmscriptenPath.IsEmpty)
{
compilerExePath.Append(gApp.mSettings.mEmscriptenPath);
if ((!compilerExePath.EndsWith('\\')) && (!compilerExePath.EndsWith('/')))
compilerExePath.Append("/");
}
compilerExePath.Append(@"emcc.bat");
//linkLine.Append(" c:\\Beef\\wasm\\BeefRT.a -s STRICT=1 -s USE_PTHREADS=1 -s ALIASING_FUNCTION_POINTERS=1 -s ASSERTIONS=0 -s DISABLE_EXCEPTION_CATCHING=0 -s DEMANGLE_SUPPORT=0 -s EVAL_CTORS=1 -s WASM=1 -s \"EXPORTED_FUNCTIONS=['_BeefMain','_BeefDone','_pthread_mutexattr_init','_pthread_mutex_init','_emscripten_futex_wake','_calloc','_sbrk']\"");
linkLine.Append(" c:\\Beef\\wasm\\BeefRT.a -s STRICT=1 -s USE_PTHREADS=1 -s ALIASING_FUNCTION_POINTERS=1 -s ASSERTIONS=0 -s DISABLE_EXCEPTION_CATCHING=0 -s DEMANGLE_SUPPORT=0 -s EVAL_CTORS=1 -s WASM=1");
String workingDir = scope String();
if (!llvmDir.IsEmpty)
{
workingDir.Append(llvmDir, "bin");
}
else
{
workingDir.Append(gApp.mInstallDir);
}
//linkLine.Append(" --no-entry --export-all");
var runCmd = gApp.QueueRun(compilerExePath, linkLine, workingDir, .UTF8);
runCmd.mOnlyIfNotFailed = true;
var tagetCompletedCmd = new IDEApp.TargetCompletedCmd(project);
tagetCompletedCmd.mOnlyIfNotFailed = true;
gApp.mExecutionQueue.Add(tagetCompletedCmd);
String logStr = scope String();
logStr.AppendF("IDE Process {0}\r\n", Platform.BfpProcess_GetCurrentId());
logStr.Append(linkLine);
String targetLogPath = scope String(targetPath, ".build.txt");
if (Utils.WriteTextFile(targetLogPath, logStr) case .Err)
gApp.OutputErrorLine("Failed to write {}", targetLogPath);
project.mLastDidBuild = true;
}
}
return true;
}
public static void GetPdbPath(String targetPath, Workspace.Options workspaceOptions, Project.Options options, String outPdbPath)
{
int lastDotPos = targetPath.LastIndexOf('.');
@ -1281,7 +1389,12 @@ namespace IDE
objectsArg.Append(" ");
}
if (workspaceOptions.mToolsetType == .GNU)
if (mPlatformType == .Wasm)
{
if (!QueueProjectWasmLink(project, targetPath, workspaceOptions, options, objectsArg))
return false;
}
else if (workspaceOptions.mToolsetType == .GNU)
{
if ((options.mBuildOptions.mBuildKind == .StaticLib) || (options.mBuildOptions.mBuildKind == .DynamicLib))
{

View file

@ -8422,7 +8422,7 @@ namespace IDE
if (relocType == .NotSet)
{
if (platform != .Windows)
if ((platform != .Windows) && (platform != .Wasm))
relocType = .PIC;
}
@ -8931,6 +8931,9 @@ namespace IDE
newString.Append(".dylib");
else
newString.Append(".a");
case .Wasm:
if (!newString.Contains('.'))
newString.Append(".html");
default:
if (options.mBuildOptions.mBuildKind == .DynamicLib)
newString.Append(".so");
@ -8952,6 +8955,9 @@ namespace IDE
case .macOS:
if (project.mGeneralOptions.mTargetType == .BeefDynLib)
newString.Append(".dylib");
case .Wasm:
if (!newString.Contains('.'))
newString.Append(".html");
default:
if (project.mGeneralOptions.mTargetType == .BeefDynLib)
newString.Append(".so");
@ -9005,6 +9011,11 @@ namespace IDE
case .iOS:
case .Linux:
newString.AppendF("./{} -lpthread -ldl -Wl,-rpath -Wl,$ORIGIN", rtName);
case .Wasm:
newString.Append(mInstallDir);
newString.Append("Beef", IDEApp.sRTVersionStr, "RT");
newString.Append((Workspace.PlatformType.GetPtrSizeByName(gApp.mPlatformName) == 4) ? "32" : "64");
newString.Append("_wasm.lib");
default:
}
@ -10062,6 +10073,8 @@ namespace IDE
case .Linux:
if (hostPlatform == .Windows)
canCompile = true; // Use WSL
case .Wasm:
canCompile = true;
default:
}

View file

@ -902,6 +902,7 @@ namespace IDE
public KeySettings mKeySettings = new .() ~ delete _;
public RecentFiles mRecentFiles = new RecentFiles() ~ delete _;
public String mWakaTimeKey = new .() ~ delete _;
public String mEmscriptenPath = new .() ~ delete _;
public bool mEnableDevMode;
public TutorialsFinished mTutorialsFinished = .();
@ -946,6 +947,8 @@ namespace IDE
mDebuggerSettings.Serialize(sd);
using (sd.CreateObject("VisualStudio"))
mVSSettings.Serialize(sd);
using (sd.CreateObject("Wasm"))
sd.Add("EmscriptenPath", mEmscriptenPath);
using (sd.CreateObject("RecentFiles"))
{
@ -1000,6 +1003,8 @@ namespace IDE
mDebuggerSettings.Deserialize(sd);
using (sd.Open("VisualStudio"))
mVSSettings.Deserialize(sd);
using (sd.Open("Wasm"))
sd.Get("EmscriptenPath", mEmscriptenPath);
using (sd.Open("RecentFiles"))
{

View file

@ -31,6 +31,7 @@ namespace IDE
case macOS;
case iOS;
case Android;
case Wasm;
public static PlatformType GetFromName(String name)
{
@ -40,6 +41,7 @@ namespace IDE
case "Linux32", "Linux64": return .Linux;
case "macOS": return .macOS;
case "iOS": return .iOS;
case "wasm32", "wasm64": return .Wasm;
default:
return TargetTriple.GetPlatformType(name);
}
@ -90,6 +92,10 @@ namespace IDE
outTriple.Append("x86_64-apple-macosx10.8.0");
case "iOS":
outTriple.Append("arm64-apple-ios");
case "wasm32":
outTriple.Append("wasm32-unknown-emscripten");
case "wasm64":
outTriple.Append("wasm64-unknown-emscripten");
default:
return false;
}
@ -824,7 +830,14 @@ namespace IDE
options.mEnableSideStack = false;
options.mAllowHotSwapping = false;
}
if (platformType == .Wasm)
{
options.mAllocType = .CRT;
options.mEnableObjectDebugFlags = false;
options.mEmitObjectAccessCheck = false;
}
options.mIncrementalBuild = !isRelease;
options.mAllocStackTraceDepth = 1;
@ -1100,10 +1113,10 @@ namespace IDE
configSelection.mConfig = new String(findConfig);
configSelection.mPlatform = new String(findPlatform);
options.mConfigSelections[project] = configSelection;
configSelection.mEnabled = true;
}
project.CreateConfig(findConfig, findPlatform);
configSelection.mEnabled = true;
}
}
}