Add Linux support for nethost module, build tool and build scripts
This commit is contained in:
@@ -10,8 +10,10 @@ if [ $testfilesize -le 1000 ]; then
|
||||
fi
|
||||
|
||||
# Compile the build tool.
|
||||
msbuild /nologo /verbosity:quiet "Source/Tools/Flax.Build/Flax.Build.csproj" /property:Configuration=Release /property:Platform=AnyCPU /target:Build,Publish /p:PublishDir=./Binaries/Tools
|
||||
dotnet msbuild /nologo /verbosity:quiet "Source/Tools/Flax.Build/Flax.Build.csproj" /target:Restore /property:RestorePackagesConfig=True /p:RuntimeIdentifier=linux-x64
|
||||
dotnet msbuild /nologo /verbosity:quiet "Source/Tools/Flax.Build/Flax.Build.csproj" /property:Configuration=Release /property:Platform=AnyCPU /target:Clean
|
||||
dotnet msbuild /nologo /verbosity:quiet "Source/Tools/Flax.Build/Flax.Build.csproj" /property:Configuration=Release /property:Platform=AnyCPU /target:Build,Publish /p:PublishDir=./Binaries/Tools /p:SelfContained=true /p:RuntimeIdentifier=linux-x64
|
||||
|
||||
# Run the build tool using the provided arguments.
|
||||
#mono --debug --debugger-agent=transport=dt_socket,server=y,address=127.0.0.1:55555 Binaries/Tools/Flax.Build.exe "$@"
|
||||
dotnet Binaries/Tools/Flax.Build.exe "$@"
|
||||
Binaries/Tools/Flax.Build "$@"
|
||||
|
||||
@@ -31,7 +31,7 @@ copy /y Cache\Intermediate\Build\Flax.Build.Files.txt Cache\Intermediate\Build\F
|
||||
%MSBUILD_PATH% /nologo /verbosity:quiet Source\Tools\Flax.Build\Flax.Build.csproj /target:Restore /property:RestorePackagesConfig=True
|
||||
%MSBUILD_PATH% /nologo /verbosity:quiet Source\Tools\Flax.Build\Flax.Build.csproj /property:Configuration=Release /property:Platform=AnyCPU /target:Clean
|
||||
:SkipClean
|
||||
%MSBUILD_PATH% /nologo /verbosity:quiet Source\Tools\Flax.Build\Flax.Build.csproj /property:Configuration=Release /property:Platform=AnyCPU /target:Build,Publish /p:PublishDir=C:\dev\Flax\FlaxEngine\Binaries\Tools /p:SelfContained=true /p:RuntimeIdentifier=win-x64
|
||||
%MSBUILD_PATH% /nologo /verbosity:quiet Source\Tools\Flax.Build\Flax.Build.csproj /property:Configuration=Release /property:Platform=AnyCPU /target:Build,Publish /p:PublishDir=Binaries\Tools /p:SelfContained=true /p:RuntimeIdentifier=win-x64
|
||||
::/p:PublishSingleFile=true /p:RuntimeIdentifier=win-x64
|
||||
if errorlevel 1 goto Error_CompilationFailed
|
||||
|
||||
|
||||
36
Source/ThirdParty/nethost/nethost.Build.cs
vendored
36
Source/ThirdParty/nethost/nethost.Build.cs
vendored
@@ -47,12 +47,16 @@ public class nethost : ThirdPartyModule
|
||||
|
||||
options.SourceFiles.Clear();
|
||||
|
||||
string arch = "x64"; //options.Architecture == TargetArchitecture.x64 ? "x64" : "x86";
|
||||
|
||||
string dotnetVersion;
|
||||
string appHostRuntimePath;
|
||||
|
||||
// NOTE: nethost is bundled with SDK, not runtime. Should C# scripting have a hard requirement for SDK to be installed?
|
||||
|
||||
if (options.Platform.Target == TargetPlatform.Windows)
|
||||
{
|
||||
// NOTE: nethost is bundled with SDK, not runtime. Should C# scripting have a hard requirement for SDK to be installed?
|
||||
|
||||
string arch = "x64"; //options.Architecture == TargetArchitecture.x64 ? "x64" : "x86";
|
||||
string os = $"win-{arch}";
|
||||
|
||||
using RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
|
||||
|
||||
@@ -62,7 +66,7 @@ public class nethost : ThirdPartyModule
|
||||
using RegistryKey runtimeKey = baseKey.OpenSubKey(@$"SOFTWARE\WOW6432Node\dotnet\Setup\InstalledVersions\{arch}\sharedfx\Microsoft.NETCore.App");
|
||||
string[] versions = runtimeKey.GetValueNames();
|
||||
|
||||
string dotnetVersion = versions.OrderByDescending(x => ParseVersion(x)).FirstOrDefault();
|
||||
dotnetVersion = versions.OrderByDescending(x => ParseVersion(x)).FirstOrDefault();
|
||||
|
||||
if (string.IsNullOrEmpty(dotnetPath))
|
||||
dotnetPath = Environment.GetEnvironmentVariable("DOTNET_ROOT");
|
||||
@@ -74,16 +78,32 @@ public class nethost : ThirdPartyModule
|
||||
if (majorVersion < 7)
|
||||
throw new Exception($"Unsupported dotnet version found, minimum version required is .NET 7 (found {dotnetVersion})");
|
||||
|
||||
appHostRuntimePath = String.Format("{0}packs\\Microsoft.NETCore.App.Host.win-{1}\\{2}\\runtimes\\win-{1}\\native", dotnetPath, arch, dotnetVersion);
|
||||
appHostRuntimePath = String.Format("{0}packs\\Microsoft.NETCore.App.Host.{1}\\{2}\\runtimes\\{1}\\native", dotnetPath, os, dotnetVersion);
|
||||
options.OutputFiles.Add(Path.Combine(appHostRuntimePath, "nethost.lib"));
|
||||
options.DependencyFiles.Add(Path.Combine(appHostRuntimePath, "nethost.dll"));
|
||||
options.PublicIncludePaths.Add(appHostRuntimePath);
|
||||
}
|
||||
else
|
||||
else if (options.Platform.Target == TargetPlatform.Linux)
|
||||
{
|
||||
// /etc/dotnet/install_location
|
||||
throw new InvalidPlatformException(options.Platform.Target);
|
||||
// TODO: Support /etc/dotnet/install_location
|
||||
string dotnetPath = "/usr/share/dotnet/";
|
||||
string os = $"linux-{arch}";
|
||||
|
||||
string[] versions = Directory.GetDirectories($"{dotnetPath}host/fxr/").Select(x => Path.GetFileName(x)).ToArray();
|
||||
|
||||
dotnetVersion = versions.OrderByDescending(x => ParseVersion(x)).FirstOrDefault();
|
||||
|
||||
int majorVersion = int.Parse(dotnetVersion.Substring(0, dotnetVersion.IndexOf(".")));
|
||||
if (majorVersion < 7)
|
||||
throw new Exception($"Unsupported dotnet version found, minimum version required is .NET 7 (found {dotnetVersion})");
|
||||
|
||||
appHostRuntimePath = String.Format("{0}packs/Microsoft.NETCore.App.Host.{1}/{2}/runtimes/{1}/native", dotnetPath, os, dotnetVersion);
|
||||
options.OutputFiles.Add(Path.Combine(appHostRuntimePath, "libnethost.a"));
|
||||
options.DependencyFiles.Add(Path.Combine(appHostRuntimePath, "libnethost.so"));
|
||||
options.PublicIncludePaths.Add(appHostRuntimePath);
|
||||
}
|
||||
else
|
||||
throw new InvalidPlatformException(options.Platform.Target);
|
||||
|
||||
options.PublicIncludePaths.Add(appHostRuntimePath);
|
||||
options.ScriptingAPI.Defines.Add("USE_NETCORE");
|
||||
|
||||
@@ -149,6 +149,20 @@ namespace Flax.Build
|
||||
|
||||
private static void BuildDotNet(TaskGraph graph, BuildData buildData, NativeCpp.BuildOptions buildOptions, string name, List<string> sourceFiles, HashSet<string> fileReferences = null, IGrouping<string, Module> binaryModule = null)
|
||||
{
|
||||
#if USE_NETCORE
|
||||
static Version ParseVersion(string version)
|
||||
{
|
||||
// Give precedence to final releases over release candidate / beta releases
|
||||
int rev = 9999;
|
||||
if (version.Contains("-")) // e.g. 7.0.0-rc.2.22472.3
|
||||
{
|
||||
version = version.Substring(0, version.IndexOf("-"));
|
||||
rev = 0;
|
||||
}
|
||||
Version ver = new Version(version);
|
||||
return new Version(ver.Major, ver.Minor, ver.Build, rev);
|
||||
}
|
||||
#endif
|
||||
// Setup build options
|
||||
var buildPlatform = Platform.BuildTargetPlatform;
|
||||
var outputPath = Path.GetDirectoryName(buildData.Target.GetOutputFilePath(buildOptions));
|
||||
@@ -165,21 +179,10 @@ namespace Flax.Build
|
||||
monoPath = null;
|
||||
cscPath = Path.Combine(Path.GetDirectoryName(VCEnvironment.MSBuildPath), "Roslyn", "csc.exe");
|
||||
|
||||
#if USE_NETCORE
|
||||
// dotnet
|
||||
if (WindowsPlatformBase.TryReadDirRegistryKey(@"HKEY_LOCAL_MACHINE\SOFTWARE\dotnet\Setup\InstalledVersions\x64\sharedhost", "Path", out string dotnetPath))
|
||||
{
|
||||
static Version ParseVersion(string version)
|
||||
{
|
||||
// Give precedence to final releases over release candidate / beta releases
|
||||
int rev = 9999;
|
||||
if (version.Contains("-")) // e.g. 7.0.0-rc.2.22472.3
|
||||
{
|
||||
version = version.Substring(0, version.IndexOf("-"));
|
||||
rev = 0;
|
||||
}
|
||||
Version ver = new Version(version);
|
||||
return new Version(ver.Major, ver.Minor, ver.Build, rev);
|
||||
}
|
||||
#pragma warning disable CA1416
|
||||
string arch = "x64";
|
||||
using RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
|
||||
@@ -189,13 +192,13 @@ namespace Flax.Build
|
||||
|
||||
string dotnetSdkVersion = sdkVersionsKey.GetValueNames().OrderByDescending(x => ParseVersion(x)).FirstOrDefault();
|
||||
string dotnetSharedfxVersion = sharedfxVersionsKey.GetValueNames().OrderByDescending(x => ParseVersion(x)).FirstOrDefault();
|
||||
string dotnetHostfxrVersion = (string)hostfxrKey.GetValue("Version");
|
||||
#pragma warning restore CA1416
|
||||
cscPath = @$"{dotnetPath}sdk\{dotnetSdkVersion}\Roslyn\bincore\csc.dll";
|
||||
referenceAssemblies = @$"{dotnetPath}shared\Microsoft.NETCore.App\{dotnetSharedfxVersion}\";
|
||||
referenceAnalyzers = @$"{dotnetPath}packs\Microsoft.NETCore.App.Ref\{dotnetSharedfxVersion}\analyzers\dotnet\cs\";
|
||||
}
|
||||
else //if (!File.Exists(cscPath))
|
||||
#endif
|
||||
{
|
||||
// Fallback to Mono binaries
|
||||
monoPath = Path.Combine(monoRoot, "bin", "mono.exe");
|
||||
@@ -206,12 +209,38 @@ namespace Flax.Build
|
||||
break;
|
||||
}
|
||||
case TargetPlatform.Linux:
|
||||
monoRoot = Path.Combine(Globals.EngineRoot, "Source", "Platforms", "Editor", "Linux", "Mono");
|
||||
monoPath = Path.Combine(monoRoot, "bin", "mono");
|
||||
cscPath = Path.Combine(monoRoot, "lib", "mono", "4.5", "csc.exe");
|
||||
referenceAssemblies = Path.Combine(monoRoot, "lib", "mono", "4.5-api");
|
||||
referenceAnalyzers = "";
|
||||
{
|
||||
#if USE_NETCORE
|
||||
// TODO: Support /etc/dotnet/install_location
|
||||
string dotnetPath = "/usr/share/dotnet/";
|
||||
string arch = "x64";
|
||||
string os = $"linux-{arch}";
|
||||
monoPath = null;
|
||||
|
||||
string[] sharedfxVersions = Directory.GetDirectories($"{dotnetPath}shared/Microsoft.NETCore.App/").Select(x => Path.GetFileName(x)).ToArray();
|
||||
string dotnetSharedfxVersion = sharedfxVersions.OrderByDescending(x => ParseVersion(x)).FirstOrDefault();
|
||||
|
||||
string[] sdkVersions = Directory.GetDirectories($"{dotnetPath}sdk/").Select(x => Path.GetFileName(x)).ToArray();
|
||||
string dotnetSdkVersion = sdkVersions.OrderByDescending(x => ParseVersion(x)).FirstOrDefault();
|
||||
|
||||
int majorVersion = int.Parse(dotnetSdkVersion.Substring(0, dotnetSdkVersion.IndexOf(".")));
|
||||
if (majorVersion >= 7)
|
||||
{
|
||||
cscPath = @$"{dotnetPath}sdk/{dotnetSdkVersion}/Roslyn/bincore/csc.dll";
|
||||
referenceAssemblies = @$"{dotnetPath}shared/Microsoft.NETCore.App/{dotnetSharedfxVersion}/";
|
||||
referenceAnalyzers = @$"{dotnetPath}packs/Microsoft.NETCore.App.Ref/{dotnetSharedfxVersion}/analyzers/dotnet/cs/";
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
monoRoot = Path.Combine(Globals.EngineRoot, "Source", "Platforms", "Editor", "Linux", "Mono");
|
||||
monoPath = Path.Combine(monoRoot, "bin", "mono");
|
||||
cscPath = Path.Combine(monoRoot, "lib", "mono", "4.5", "csc.exe");
|
||||
referenceAssemblies = Path.Combine(monoRoot, "lib", "mono", "4.5-api");
|
||||
referenceAnalyzers = "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TargetPlatform.Mac:
|
||||
monoRoot = Path.Combine(Globals.EngineRoot, "Source", "Platforms", "Editor", "Mac", "Mono");
|
||||
monoPath = Path.Combine(monoRoot, "bin", "mono");
|
||||
@@ -291,7 +320,7 @@ namespace Flax.Build
|
||||
// The "/shared" flag enables the compiler server support:
|
||||
// https://github.com/dotnet/roslyn/blob/main/docs/compilers/Compiler%20Server.md
|
||||
|
||||
task.CommandPath = "dotnet.exe";
|
||||
task.CommandPath = "dotnet";
|
||||
task.CommandArguments = $"exec \"{cscPath}\" /noconfig /shared @\"{responseFile}\"";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user