diff --git a/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs b/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs index d1bf766df..921a1e43f 100644 --- a/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs +++ b/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs @@ -157,79 +157,60 @@ namespace Flax.Build var outputPath = Path.GetDirectoryName(buildData.Target.GetOutputFilePath(buildOptions)); var outputFile = Path.Combine(outputPath, name + ".dll"); var outputDocFile = Path.Combine(outputPath, name + ".xml"); - string monoRoot, monoPath = null, cscPath, referenceAssemblies, referenceAnalyzers, dotnetPath = "dotnet"; + string cscPath, referenceAssemblies; +#if USE_NETCORE + var dotnetSdk = DotNetSdk.Instance; + if (!dotnetSdk.IsValid) + throw new Exception("Cannot compile C# without .NET SDK"); + string dotnetPath = "dotnet", referenceAnalyzers; +#else + string monoRoot, monoPath; +#endif switch (buildPlatform) { case TargetPlatform.Windows: { - monoRoot = Path.Combine(Globals.EngineRoot, "Source", "Platforms", "Editor", "Windows", "Mono"); - - // Prefer installed Roslyn C# compiler over Mono one - cscPath = Path.Combine(Path.GetDirectoryName(VCEnvironment.MSBuildPath), "Roslyn", "csc.exe"); - #if USE_NETCORE - var dotnetSdk = DotNetSdk.Instance; - if (dotnetSdk.IsValid) - { - // Use dotnet - dotnetPath = Path.Combine(dotnetSdk.RootPath, "dotnet.exe"); - cscPath = Path.Combine(dotnetSdk.RootPath, @$"sdk\{dotnetSdk.VersionName}\Roslyn\bincore\csc.dll"); - referenceAssemblies = Path.Combine(dotnetSdk.RootPath, @$"shared\Microsoft.NETCore.App\{dotnetSdk.RuntimeVersionName}\"); - referenceAnalyzers = Path.Combine(dotnetSdk.RootPath, @$"packs\Microsoft.NETCore.App.Ref\{dotnetSdk.RuntimeVersionName}\analyzers\dotnet\cs\"); - } - else -#endif - { - // Fallback to Mono binaries - monoPath = Path.Combine(monoRoot, "bin", "mono.exe"); + dotnetPath = Path.Combine(dotnetSdk.RootPath, "dotnet.exe"); + cscPath = Path.Combine(dotnetSdk.RootPath, @$"sdk\{dotnetSdk.VersionName}\Roslyn\bincore\csc.dll"); + referenceAssemblies = Path.Combine(dotnetSdk.RootPath, @$"shared\Microsoft.NETCore.App\{dotnetSdk.RuntimeVersionName}\"); + referenceAnalyzers = Path.Combine(dotnetSdk.RootPath, @$"packs\Microsoft.NETCore.App.Ref\{dotnetSdk.RuntimeVersionName}\analyzers\dotnet\cs\"); +#else + monoRoot = Path.Combine(Globals.EngineRoot, "Source", "Platforms", "Editor", "Windows", "Mono"); + monoPath = Path.Combine(monoRoot, "bin", "mono.exe"); + cscPath = Path.Combine(Path.GetDirectoryName(VCEnvironment.MSBuildPath), "Roslyn", "csc.exe"); + if (!File.Exists(cscPath)) cscPath = Path.Combine(monoRoot, "lib", "mono", "4.5", "csc.exe"); - referenceAssemblies = Path.Combine(monoRoot, "lib", "mono", "4.5-api"); - referenceAnalyzers = ""; - } + referenceAssemblies = Path.Combine(monoRoot, "lib", "mono", "4.5-api"); +#endif break; } case TargetPlatform.Linux: { #if USE_NETCORE - var dotnetSdk = DotNetSdk.Instance; - if (dotnetSdk.IsValid) - { - // Use dotnet - cscPath = Path.Combine(dotnetSdk.RootPath, $"sdk/{dotnetSdk.VersionName}/Roslyn/bincore/csc.dll"); - referenceAssemblies = Path.Combine(dotnetSdk.RootPath, $"shared/Microsoft.NETCore.App/{dotnetSdk.RuntimeVersionName}/"); - referenceAnalyzers = Path.Combine(dotnetSdk.RootPath, $"packs/Microsoft.NETCore.App.Ref/{dotnetSdk.RuntimeVersionName}/analyzers/dotnet/cs/"); - } - else + cscPath = Path.Combine(dotnetSdk.RootPath, $"sdk/{dotnetSdk.VersionName}/Roslyn/bincore/csc.dll"); + referenceAssemblies = Path.Combine(dotnetSdk.RootPath, $"shared/Microsoft.NETCore.App/{dotnetSdk.RuntimeVersionName}/"); + referenceAnalyzers = Path.Combine(dotnetSdk.RootPath, $"packs/Microsoft.NETCore.App.Ref/{dotnetSdk.RuntimeVersionName}/analyzers/dotnet/cs/"); +#else + 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"); #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: { #if USE_NETCORE - var dotnetSdk = DotNetSdk.Instance; - if (dotnetSdk.IsValid) - { - // Use dotnet - cscPath = Path.Combine(dotnetSdk.RootPath, $"sdk/{dotnetSdk.VersionName}/Roslyn/bincore/csc.dll"); - referenceAssemblies = Path.Combine(dotnetSdk.RootPath, $"shared/Microsoft.NETCore.App/{dotnetSdk.RuntimeVersionName}/"); - referenceAnalyzers = Path.Combine(dotnetSdk.RootPath, $"packs/Microsoft.NETCore.App.Ref/{dotnetSdk.RuntimeVersionName}/analyzers/dotnet/cs/"); - } - else + cscPath = Path.Combine(dotnetSdk.RootPath, $"sdk/{dotnetSdk.VersionName}/Roslyn/bincore/csc.dll"); + referenceAssemblies = Path.Combine(dotnetSdk.RootPath, $"shared/Microsoft.NETCore.App/{dotnetSdk.RuntimeVersionName}/"); + referenceAnalyzers = Path.Combine(dotnetSdk.RootPath, $"packs/Microsoft.NETCore.App.Ref/{dotnetSdk.RuntimeVersionName}/analyzers/dotnet/cs/"); +#else + monoRoot = Path.Combine(Globals.EngineRoot, "Source", "Platforms", "Editor", "Mac", "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"); #endif - { - monoRoot = Path.Combine(Globals.EngineRoot, "Source", "Platforms", "Editor", "Mac", "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; } default: throw new InvalidPlatformException(buildPlatform); @@ -305,6 +286,12 @@ namespace Flax.Build task.InfoMessage = "Compiling " + outputFile; task.Cost = task.PrerequisiteFiles.Count; + // The "/shared" flag enables the compiler server support: + // https://github.com/dotnet/roslyn/blob/main/docs/compilers/Compiler%20Server.md +#if USE_NETCORE + task.CommandPath = dotnetPath; + task.CommandArguments = $"exec \"{cscPath}\" /noconfig /shared @\"{responseFile}\""; +#else if (monoPath != null) { task.CommandPath = monoPath; @@ -312,17 +299,10 @@ namespace Flax.Build } else { - // The "/shared" flag enables the compiler server support: - // https://github.com/dotnet/roslyn/blob/main/docs/compilers/Compiler%20Server.md - -#if USE_NETCORE - task.CommandPath = dotnetPath; - task.CommandArguments = $"exec \"{cscPath}\" /noconfig /shared @\"{responseFile}\""; -#else task.CommandPath = cscPath; task.CommandArguments = $"/noconfig /shared @\"{responseFile}\""; -#endif } +#endif BuildDotNetAssembly?.Invoke(graph, buildData, buildOptions, task, binaryModule); diff --git a/Source/Tools/Flax.Build/Deploy/Configuration.cs b/Source/Tools/Flax.Build/Deploy/Configuration.cs deleted file mode 100644 index aa098acf7..000000000 --- a/Source/Tools/Flax.Build/Deploy/Configuration.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. - -namespace Flax.Build -{ - public static partial class Configuration - { - /// - /// Package deployment output path. - /// - [CommandLine("deployOutput", "Package deployment output path.")] - public static string DeployOutput; - - /// - /// Builds and packages the editor. - /// - [CommandLine("deployEditor", "Builds and packages the editor.")] - public static bool DeployEditor; - - /// - /// Builds and packages the platforms data. - /// - [CommandLine("deployPlatforms", "Builds and packages the platforms data.")] - public static bool DeployPlatforms; - - /// - /// Certificate file path for binaries signing. - /// - [CommandLine("deployCert", "Certificate file path for binaries signing.")] - public static string DeployCert; - - /// - /// Certificate file password for binaries signing. - /// - [CommandLine("deployCertPass", "Certificate file password for binaries signing.")] - public static string DeployCertPass; - } -} diff --git a/Source/Tools/Flax.Build/Deploy/Deployer.cs b/Source/Tools/Flax.Build/Deploy/Deployer.cs index 3daa99a04..d7e3f6c43 100644 --- a/Source/Tools/Flax.Build/Deploy/Deployer.cs +++ b/Source/Tools/Flax.Build/Deploy/Deployer.cs @@ -5,6 +5,42 @@ using System.IO; using System.Text; using Flax.Build; +namespace Flax.Build +{ + public static partial class Configuration + { + /// + /// Package deployment output path. + /// + [CommandLine("deployOutput", "Package deployment output path.")] + public static string DeployOutput; + + /// + /// Builds and packages the editor. + /// + [CommandLine("deployEditor", "Builds and packages the editor.")] + public static bool DeployEditor; + + /// + /// Builds and packages the platforms data. + /// + [CommandLine("deployPlatforms", "Builds and packages the platforms data.")] + public static bool DeployPlatforms; + + /// + /// Certificate file path for binaries signing. + /// + [CommandLine("deployCert", "Certificate file path for binaries signing.")] + public static string DeployCert; + + /// + /// Certificate file password for binaries signing. + /// + [CommandLine("deployCertPass", "Certificate file password for binaries signing.")] + public static string DeployCertPass; + } +} + namespace Flax.Deploy { /// diff --git a/Source/Tools/Flax.Build/Deploy/Deployment.Editor.cs b/Source/Tools/Flax.Build/Deploy/Deployment.Editor.cs index 46c1eccd5..0fe0cc89d 100644 --- a/Source/Tools/Flax.Build/Deploy/Deployment.Editor.cs +++ b/Source/Tools/Flax.Build/Deploy/Deployment.Editor.cs @@ -49,37 +49,33 @@ namespace Flax.Deploy var src = Path.Combine(RootPath, binariesSubDir); var dst = Path.Combine(OutputPath, binariesSubDir); - DeployFile(src, dst, "Flax.Build.exe"); - CodeSign(Path.Combine(dst, "Flax.Build.exe")); - DeployFile(src, dst, "Flax.Build.xml"); + var buildToolExe = Platform.BuildTargetPlatform == TargetPlatform.Windows ? "Flax.Build.exe" : "Flax.Build"; + DeployFile(src, dst, buildToolExe); + CodeSign(Path.Combine(dst, buildToolExe)); + var buildToolDll = "Flax.Build.dll"; + DeployFile(src, dst,buildToolDll); + CodeSign(Path.Combine(dst, buildToolDll)); + DeployFile(src, dst, "Flax.Build.xml", true); + DeployFile(src, dst, "Flax.Build.pdb"); + DeployFile(src, dst, "Flax.Build.deps.json"); + DeployFile(src, dst, "Flax.Build.runtimeconfig.json"); DeployFile(src, dst, "Ionic.Zip.Reduced.dll"); DeployFile(src, dst, "Newtonsoft.Json.dll"); DeployFile(src, dst, "Mono.Cecil.dll"); + DeployFile(src, dst, "Microsoft.CodeAnalysis.dll"); + DeployFile(src, dst, "Microsoft.CodeAnalysis.CSharp.dll"); + DeployFile(src, dst, "Microsoft.VisualStudio.Setup.Configuration.Interop.dll"); } // Deploy content DeployFolder(RootPath, OutputPath, "Content"); - // Deploy Mono runtime data files - switch (Platform.BuildTargetPlatform) - { - case TargetPlatform.Windows: - DeployFolder(RootPath, OutputPath, "Source/Platforms/Editor/Windows/Mono"); - break; - case TargetPlatform.Linux: - DeployFolder(RootPath, OutputPath, "Source/Platforms/Editor/Linux/Mono"); - break; - case TargetPlatform.Mac: - DeployFolder(RootPath, OutputPath, "Source/Platforms/Editor/Mac/Mono"); - break; - default: throw new InvalidPlatformException(Platform.BuildTargetPlatform); - } - // Deploy DotNet deps { var subDir = "Source/Platforms/DotNet"; DeployFile(RootPath, OutputPath, subDir, "Newtonsoft.Json.dll"); DeployFile(RootPath, OutputPath, subDir, "Newtonsoft.Json.xml"); + DeployFile(RootPath, OutputPath, Path.Combine(subDir, "AOT"), "Newtonsoft.Json.dll"); } // Deploy sources @@ -130,7 +126,7 @@ namespace Flax.Deploy // Compress if (Configuration.DontCompress) return; - + Log.Info(string.Empty); Log.Info("Compressing editor files..."); string editorPackageZipPath; @@ -199,6 +195,12 @@ namespace Flax.Deploy var dst = Path.Combine(OutputPath, binariesSubDir); Directory.CreateDirectory(dst); + DeployFile(src, dst, "FlaxEditor.Build.json"); + DeployFile(src, dst, "FlaxEngine.CSharp.runtimeconfig.json"); + DeployFile(src, dst, "FlaxEngine.CSharp.pdb"); + DeployFile(src, dst, "FlaxEngine.CSharp.xml"); + DeployFile(src, dst, "Newtonsoft.Json.pdb"); + if (Platform.BuildTargetPlatform == TargetPlatform.Windows) { var dstDebug = Path.Combine(Deployer.PackageOutputPath, "EditorDebugSymbols/Win64/" + configuration); @@ -215,11 +217,7 @@ namespace Flax.Deploy // Deploy binaries DeployFile(src, dst, editorExeName); CodeSign(Path.Combine(dst, editorExeName)); - DeployFile(src, dst, "FlaxEditor.Build.json"); DeployFile(src, dst, "FlaxEditor.lib"); - DeployFile(src, dst, "FlaxEngine.CSharp.pdb"); - DeployFile(src, dst, "FlaxEngine.CSharp.xml"); - DeployFile(src, dst, "Newtonsoft.Json.pdb"); DeployFiles(src, dst, "*.dll"); CodeSign(Path.Combine(dst, "FlaxEngine.CSharp.dll")); @@ -237,10 +235,6 @@ namespace Flax.Deploy { // Deploy binaries DeployFile(src, dst, "FlaxEditor"); - DeployFile(src, dst, "FlaxEditor.Build.json"); - DeployFile(src, dst, "FlaxEngine.CSharp.pdb"); - DeployFile(src, dst, "FlaxEngine.CSharp.xml"); - DeployFile(src, dst, "Newtonsoft.Json.pdb"); DeployFiles(src, dst, "*.dll"); DeployFiles(src, dst, "*.so"); DeployFile(src, dst, "Logo.png"); @@ -253,10 +247,6 @@ namespace Flax.Deploy { // Deploy binaries DeployFile(src, dst, "FlaxEditor"); - DeployFile(src, dst, "FlaxEditor.Build.json"); - DeployFile(src, dst, "FlaxEngine.CSharp.pdb"); - DeployFile(src, dst, "FlaxEngine.CSharp.xml"); - DeployFile(src, dst, "Newtonsoft.Json.pdb"); DeployFile(src, dst, "MoltenVK_icd.json"); DeployFiles(src, dst, "*.dll"); DeployFiles(src, dst, "*.dylib"); diff --git a/Source/Tools/Flax.Build/Deploy/Deployment.Platforms.cs b/Source/Tools/Flax.Build/Deploy/Deployment.Platforms.cs index 7f0df032c..832d6deb3 100644 --- a/Source/Tools/Flax.Build/Deploy/Deployment.Platforms.cs +++ b/Source/Tools/Flax.Build/Deploy/Deployment.Platforms.cs @@ -69,7 +69,7 @@ namespace Flax.Deploy var packageZipPath = Path.Combine(Deployer.PackageOutputPath, platformName + ".zip"); Utilities.FileDelete(packageZipPath); -#if true +#if false using (var zip = new Ionic.Zip.ZipFile()) { zip.AddDirectory(dst); diff --git a/Source/Tools/Flax.Build/Deploy/Deployment.Utils.cs b/Source/Tools/Flax.Build/Deploy/Deployment.Utils.cs index 3ca6951b2..f580365b7 100644 --- a/Source/Tools/Flax.Build/Deploy/Deployment.Utils.cs +++ b/Source/Tools/Flax.Build/Deploy/Deployment.Utils.cs @@ -20,7 +20,7 @@ namespace Flax.Deploy Log.Verbose("Deploy file " + filename); - File.Copy(files[i], Path.Combine(dst, filename)); + File.Copy(files[i], Path.Combine(dst, filename), true); } } diff --git a/Source/Tools/Flax.Build/Deploy/FlaxBuild.cs b/Source/Tools/Flax.Build/Deploy/FlaxBuild.cs index 9fdf56f0c..7d3a31061 100644 --- a/Source/Tools/Flax.Build/Deploy/FlaxBuild.cs +++ b/Source/Tools/Flax.Build/Deploy/FlaxBuild.cs @@ -14,26 +14,13 @@ namespace Flax.Deploy public static void Build(string root, string target, TargetPlatform platform, TargetArchitecture architecture, TargetConfiguration configuration) { var buildPlatform = Platform.BuildPlatform.Target; - var flaxBuildTool = Path.Combine(Globals.EngineRoot, "Binaries/Tools/Flax.Build.exe"); + var flaxBuildTool = Path.Combine(Globals.EngineRoot, buildPlatform == TargetPlatform.Windows ? "Binaries/Tools/Flax.Build.exe" : "Binaries/Tools/Flax.Build"); var format = "-build -buildtargets={0} -log -logfile= -perf -platform={1} -arch={2} -configuration={3}"; - if (buildPlatform == TargetPlatform.Linux) - { - format = format.Replace("-", "--"); - } var cmdLine = string.Format(format, target, platform, architecture, configuration); if (!string.IsNullOrEmpty(Configuration.Compiler)) cmdLine += " -compiler=" + Configuration.Compiler; - int result; - if (buildPlatform == TargetPlatform.Windows) - { - result = Utilities.Run(flaxBuildTool, cmdLine, null, root); - } - else - { - result = Utilities.Run("mono", flaxBuildTool + " " + cmdLine, null, root); - } - + int result = Utilities.Run(flaxBuildTool, cmdLine, null, root); if (result != 0) { throw new Exception(string.Format("Unable to build target {0}. Flax.Build failed. See log to learn more.", target));