Merge branch 'vscode_csharp_build_tasks' of https://github.com/GoaLitiuM/FlaxEngine into GoaLitiuM-vscode_csharp_build_tasks

This commit is contained in:
Wojtek Figat
2023-10-01 12:28:30 +02:00

View File

@@ -155,9 +155,13 @@ namespace Flax.Build.Projects.VisualStudioCode
{ {
foreach (var project in solution.Projects) foreach (var project in solution.Projects)
{ {
// C++ project if (project.Name == "BuildScripts")
if (project.Type == TargetType.NativeCpp) continue;
{
// Skip duplicate build tasks
if (project.Name == "FlaxEngine" || (solution.MainProject.Name != "Flax" && solution.MainProject != project))
continue;
bool defaultTask = project == solution.MainProject; bool defaultTask = project == solution.MainProject;
foreach (var configuration in project.Configurations) foreach (var configuration in project.Configurations)
{ {
@@ -168,20 +172,17 @@ namespace Flax.Build.Projects.VisualStudioCode
json.AddField("label", name); json.AddField("label", name);
if (defaultTask && configuration.Configuration == TargetConfiguration.Development && configuration.Platform == Platform.BuildPlatform.Target) bool isDefaultTask = defaultTask && configuration.Configuration == TargetConfiguration.Development && configuration.Platform == Platform.BuildPlatform.Target;
{
defaultTask = false;
json.BeginObject("group"); json.BeginObject("group");
{ {
json.AddField("kind", "build"); json.AddField("kind", "build");
json.AddField("isDefault", true); json.AddField("isDefault", isDefaultTask);
} }
json.EndObject(); json.EndObject();
}
else if (isDefaultTask)
{ defaultTask = false;
json.AddField("group", "build");
}
switch (Platform.BuildPlatform.Target) switch (Platform.BuildPlatform.Target)
{ {
@@ -273,7 +274,6 @@ namespace Flax.Build.Projects.VisualStudioCode
} }
} }
} }
}
json.EndArray(); json.EndArray();
} }
json.EndRootObject(); json.EndRootObject();
@@ -281,6 +281,10 @@ namespace Flax.Build.Projects.VisualStudioCode
json.Save(Path.Combine(vsCodeFolder, "tasks.json")); json.Save(Path.Combine(vsCodeFolder, "tasks.json"));
} }
bool hasNativeProjects = solution.Projects.Any(x => x.Type == TargetType.NativeCpp);
bool hasMonoProjects = solution.Projects.Any(x => x.Type == TargetType.DotNet);
bool hasDotnetProjects = solution.Projects.Any(x => x.Type == TargetType.DotNetCore);
// Create launch file // Create launch file
using (var json = new JsonWriter()) using (var json = new JsonWriter())
{ {
@@ -292,9 +296,15 @@ namespace Flax.Build.Projects.VisualStudioCode
{ {
foreach (var project in solution.Projects) foreach (var project in solution.Projects)
{ {
if (project.Name == "BuildScripts")
continue;
// C++ project // C++ project
if (project.Type == TargetType.NativeCpp) if (project.Type == TargetType.NativeCpp)
{ {
// Skip generating launch profiles for plugins and dependencies
if (solution.MainProject.Name != "Flax" && project.Name != "Flax.Build" && solution.MainProject.WorkspaceRootPath != project.WorkspaceRootPath)
continue;
foreach (var configuration in project.Configurations) foreach (var configuration in project.Configurations)
{ {
var name = project.Name + '|' + configuration.Name; var name = project.Name + '|' + configuration.Name;
@@ -314,115 +324,49 @@ namespace Flax.Build.Projects.VisualStudioCode
json.AddField("preLaunchTask", name); json.AddField("preLaunchTask", name);
json.AddField("cwd", buildToolWorkspace); json.AddField("cwd", buildToolWorkspace);
switch (Platform.BuildPlatform.Target) WriteNativePlatformLaunchSettings(json, configuration.Platform);
if (outputType != TargetOutputType.Executable && configuration.Name.StartsWith("Editor."))
{ {
case TargetPlatform.Windows: if (configuration.Platform == TargetPlatform.Windows)
if (configuration.Platform == TargetPlatform.Windows && outputType != TargetOutputType.Executable && configuration.Name.StartsWith("Editor."))
{ {
var editorFolder = configuration.Architecture == TargetArchitecture.x64 ? "Win64" : "Win32"; var editorFolder = configuration.Architecture == TargetArchitecture.x64 ? "Win64" : "Win32";
json.AddField("program", Path.Combine(Globals.EngineRoot, "Binaries", "Editor", editorFolder, configuration.ConfigurationName, "FlaxEditor.exe")); json.AddField("program", Path.Combine(Globals.EngineRoot, "Binaries", "Editor", editorFolder, configuration.ConfigurationName, "FlaxEditor.exe"));
}
else if (configuration.Platform == TargetPlatform.Linux)
json.AddField("program", Path.Combine(Globals.EngineRoot, "Binaries", "Editor", "Linux", configuration.ConfigurationName, "FlaxEditor"));
else if (configuration.Platform == TargetPlatform.Mac)
json.AddField("program", Path.Combine(Globals.EngineRoot, "Binaries", "Editor", "Mac", configuration.ConfigurationName, "FlaxEditor"));
json.BeginArray("args"); json.BeginArray("args");
{ {
json.AddUnnamedField("-project"); json.AddUnnamedField("-project");
json.AddUnnamedField(buildToolWorkspace); json.AddUnnamedField(buildToolWorkspace);
json.AddUnnamedField("-skipCompile"); json.AddUnnamedField("-skipCompile");
if (hasMonoProjects)
{
json.AddUnnamedField("-debug"); json.AddUnnamedField("-debug");
json.AddUnnamedField("127.0.0.1:55555"); json.AddUnnamedField("127.0.0.1:55555");
} }
}
json.EndArray(); json.EndArray();
} }
else else
{ {
json.AddField("program", outputTargetFilePath); json.AddField("program", outputTargetFilePath);
json.BeginArray("args");
{
if (configuration.Platform == TargetPlatform.Linux || configuration.Platform == TargetPlatform.Mac)
json.AddUnnamedField("--std");
if (hasMonoProjects)
{
json.AddUnnamedField("-debug");
json.AddUnnamedField("127.0.0.1:55555");
} }
break;
case TargetPlatform.Linux:
if (configuration.Platform == TargetPlatform.Linux && (outputType != TargetOutputType.Executable || project.BaseName == "Flax") && configuration.Name.StartsWith("Editor."))
{
json.AddField("program", Path.Combine(Globals.EngineRoot, "Binaries", "Editor", "Linux", configuration.ConfigurationName, "FlaxEditor"));
} }
else json.EndArray();
{
json.AddField("program", outputTargetFilePath);
} }
if (configuration.Platform == TargetPlatform.Linux)
{
json.AddField("MIMode", "gdb");
json.BeginArray("setupCommands");
{
json.BeginObject();
json.AddField("description", "Enable pretty-printing for gdb");
json.AddField("text", "-enable-pretty-printing");
json.AddField("ignoreFailures", true);
json.EndObject();
// Ignore signals used by C# runtime
json.BeginObject();
json.AddField("description", "ignore SIG34 signal");
json.AddField("text", "handle SIG34 nostop noprint pass");
json.EndObject();
json.BeginObject();
json.AddField("description", "ignore SIG35 signal");
json.AddField("text", "handle SIG35 nostop noprint pass");
json.EndObject();
json.BeginObject();
json.AddField("description", "ignore SIG36 signal");
json.AddField("text", "handle SIG36 nostop noprint pass");
json.EndObject();
json.BeginObject();
json.AddField("description", "ignore SIG357 signal");
json.AddField("text", "handle SIG37 nostop noprint pass");
json.EndObject();
}
json.EndArray();
json.BeginArray("args");
{
json.AddUnnamedField("--std");
if (outputType != TargetOutputType.Executable && configuration.Name.StartsWith("Editor."))
{
json.AddUnnamedField("--project");
json.AddUnnamedField(buildToolWorkspace);
json.AddUnnamedField("--skipCompile");
}
}
json.EndArray();
}
break;
case TargetPlatform.Mac:
if (configuration.Platform == TargetPlatform.Mac && (outputType != TargetOutputType.Executable || project.BaseName == "Flax") && configuration.Name.StartsWith("Editor."))
{
json.AddField("program", Path.Combine(Globals.EngineRoot, "Binaries", "Editor", "Mac", configuration.ConfigurationName, "FlaxEditor"));
}
else
{
json.AddField("program", outputTargetFilePath);
}
if (configuration.Platform == TargetPlatform.Mac)
{
json.AddField("MIMode", "lldb");
json.BeginArray("args");
{
json.AddUnnamedField("--std");
if (outputType != TargetOutputType.Executable && configuration.Name.StartsWith("Editor."))
{
json.AddUnnamedField("--project");
json.AddUnnamedField(buildToolWorkspace);
json.AddUnnamedField("--skipCompile");
}
}
json.EndArray();
}
break;
}
switch (configuration.Platform)
{
case TargetPlatform.Windows:
json.AddField("stopAtEntry", false);
json.AddField("externalConsole", true);
break;
case TargetPlatform.Linux:
break;
}
json.AddField("visualizerFile", Path.Combine(Globals.EngineRoot, "Source", "flax.natvis")); json.AddField("visualizerFile", Path.Combine(Globals.EngineRoot, "Source", "flax.natvis"));
} }
json.EndObject(); json.EndObject();
@@ -431,16 +375,9 @@ namespace Flax.Build.Projects.VisualStudioCode
// C# project // C# project
else if (project.Type == TargetType.DotNetCore) else if (project.Type == TargetType.DotNetCore)
{ {
// TODO: Skip generating launch profiles for plugins and dependencies // Skip generating launch profiles for plugins and dependencies
if (solution.MainProject.WorkspaceRootPath != project.WorkspaceRootPath)
json.BeginObject(); continue;
{
json.AddField("type", "coreclr");
json.AddField("name", project.Name + " (C# attach Editor)");
json.AddField("request", "attach");
json.AddField("processName", "FlaxEditor");
}
json.EndObject();
foreach (var configuration in project.Configurations) foreach (var configuration in project.Configurations)
{ {
@@ -484,24 +421,54 @@ namespace Flax.Build.Projects.VisualStudioCode
json.EndObject(); json.EndObject();
} }
} }
// Mono C# project }
else if (project.Type == TargetType.DotNet) }
if (hasNativeProjects)
{ {
foreach (var configuration in project.Configurations) foreach (var platform in solution.Projects.SelectMany(x => x.Configurations).Select(x => x.Platform).Distinct())
{
json.BeginObject();
{
if (platform == TargetPlatform.Windows)
json.AddField("type", "cppvsdbg");
else
json.AddField("type", "cppdbg");
json.AddField("name", solution.Name + " (Attach Editor)");
json.AddField("request", "attach");
json.AddField("processId", "${command:pickProcess}"); // Does not seem to be possible to attach by process name?
WriteNativePlatformLaunchSettings(json, platform);
json.AddField("visualizerFile", Path.Combine(Globals.EngineRoot, "Source", "flax.natvis"));
}
json.EndObject();
}
}
if (hasDotnetProjects)
{
json.BeginObject();
{
json.AddField("type", "coreclr");
json.AddField("name", solution.Name + " (C# Attach Editor)");
json.AddField("request", "attach");
json.AddField("processName", "FlaxEditor");
}
json.EndObject();
}
if (hasMonoProjects)
{ {
json.BeginObject(); json.BeginObject();
{ {
json.AddField("type", "mono"); json.AddField("type", "mono");
json.AddField("name", project.Name + " (C# attach)" + '|' + configuration.Name); json.AddField("name", solution.Name + " (C# Attach)");
json.AddField("request", "attach"); json.AddField("request", "attach");
json.AddField("address", "localhost"); json.AddField("address", "localhost");
json.AddField("port", 55555); json.AddField("port", 55555);
} }
json.EndObject(); json.EndObject();
} }
}
}
}
json.EndArray(); json.EndArray();
} }
json.EndRootObject(); json.EndRootObject();
@@ -509,6 +476,59 @@ namespace Flax.Build.Projects.VisualStudioCode
json.Save(Path.Combine(vsCodeFolder, "launch.json")); json.Save(Path.Combine(vsCodeFolder, "launch.json"));
} }
static void WriteNativePlatformLaunchSettings(JsonWriter json, TargetPlatform platform)
{
switch (Platform.BuildPlatform.Target)
{
case TargetPlatform.Linux:
if (platform == TargetPlatform.Linux)
{
json.AddField("MIMode", "gdb");
json.BeginArray("setupCommands");
{
json.BeginObject();
json.AddField("description", "Enable pretty-printing for gdb");
json.AddField("text", "-enable-pretty-printing");
json.AddField("ignoreFailures", true);
json.EndObject();
// Ignore signals used by C# runtime
json.BeginObject();
json.AddField("description", "ignore SIG34 signal");
json.AddField("text", "handle SIG34 nostop noprint pass");
json.EndObject();
json.BeginObject();
json.AddField("description", "ignore SIG35 signal");
json.AddField("text", "handle SIG35 nostop noprint pass");
json.EndObject();
json.BeginObject();
json.AddField("description", "ignore SIG36 signal");
json.AddField("text", "handle SIG36 nostop noprint pass");
json.EndObject();
json.BeginObject();
json.AddField("description", "ignore SIG357 signal");
json.AddField("text", "handle SIG37 nostop noprint pass");
json.EndObject();
}
json.EndArray();
}
break;
case TargetPlatform.Mac:
if (platform == TargetPlatform.Mac)
{
json.AddField("MIMode", "lldb");
}
break;
}
switch (platform)
{
case TargetPlatform.Windows:
json.AddField("stopAtEntry", false);
json.AddField("externalConsole", true);
break;
}
}
// Create C++ properties file // Create C++ properties file
using (var json = new JsonWriter()) using (var json = new JsonWriter())
{ {