public PostProcessor(DotNetAssembly[] processors, NPath outputDirectory) { OutputDirectory = outputDirectory; NPath srcDir = Path.GetFullPath(Path.Combine(Package.PackagePath, "Editor/Unity.Build.Classic.Private/Incremental/ILPostProcessing~")); var processorRunnerProgram = new CSharpProgram() { FileName = "ILPostProcessorRunner.exe", Sources = { srcDir, }, References = { EditorApplication.applicationContentsPath + "/Managed/Unity.CompilationPipeline.Common.dll" }, GenerateXmlDoc = XmlDocMode.Disabled, ProjectFilePath = $"{srcDir}/ILProcessor.gen.csproj", CopyReferencesNextToTarget = true, Framework = { Framework.Framework471 } }; _processorRunner = processorRunnerProgram.SetupDefault(); _processorRunnableProgram = new DotNetRunnableProgram(new DotNetAssembly(_processorRunner.Path, Framework.NetStandard20)); _builtProcessors = processors.Select(a => a.DeployTo(Configuration.RootArtifactsPath.Combine("postprocessors"))).ToArray(); _builtProcessorsDependenciesAndSelf = _builtProcessors.SelectMany(bp => bp.RecursiveRuntimeDependenciesIncludingSelf).Distinct().ToArray(); _inputFilesFromPostProcessor = _processorRunner.RecursiveRuntimeDependenciesIncludingSelf.Concat(_builtProcessorsDependenciesAndSelf).Select(p => p.Path).ToArray(); //we are in a funky situation today where user code is compiled against .net standard 2, but unityengine assemblies are compiled against .net47. Postprocessors //need to be able to deep-resolve any typereference, and it's going to encounter references to both netstandard.dll as well as mscorlib.dll and system.dll. We're going //to allow all these typereferences to resolve by resolving against the reference assemblies for both these profiles. _bclFiles = Framework471.Singleton.ReferenceAssemblies.Concat(Netstandard20.Singleton.ReferenceAssemblies).Select(a => a.Path).ToArray(); }
static CSharpProgram SetUp(string directoryName, bool isSourceGenerator = true, params CSharpProgram[] extraReferences) { var csharpProgram = new CSharpProgram { Path = isSourceGenerator ? $"../{directoryName}SourceGenerator.dll" : $"../{directoryName}.dll", Sources = { directoryName }, References = { new NPath("Infrastructure").Files("*.dll"), Framework.NetStandard20.ReferenceAssemblies }, CopyReferencesNextToTarget = false, Framework = { Framework.FrameworkNone }, WarningsAsErrors = false }; csharpProgram.References.Add(extraReferences); csharpProgram.SetupDefault(); csharpProgram.ProjectFile.RedirectMSBuildBuildTargetToBee = true; var bee = new NPath(typeof(Bee.Core.Architecture).Assembly.Location); var isWin = Environment.OSVersion.Platform == PlatformID.Win32Windows || Environment.OSVersion.Platform == PlatformID.Win32NT; csharpProgram.ProjectFile.BuildCommand.Set(new Shell.ExecuteArgs() { Arguments = isWin ? "-no-colors" : "bee.exe -no-colors", Executable = isWin ? bee : "mono", WorkingDirectory = bee.Parent }); return(csharpProgram); }
private static Dictionary <Assembly, (CSharpProgram program, DotNetAssembly assembly)> SetupCSharpProgramsFor(BuildContext context, List <Assembly> assembliesToCompile) { var classicSharedData = context.GetValue <ClassicSharedData>(); var extraScriptingDefines = classicSharedData.Customizers.SelectMany(c => c.ProvidePlayerScriptingDefines()).ToArray(); var unityAssemblyToCSharpProgramAndBuiltAssembly = new Dictionary <Assembly, (CSharpProgram program, DotNetAssembly assembly)>(); foreach (var assemblyToCompile in assembliesToCompile) { var referencedPrebuiltAssemblies = assemblyToCompile.compiledAssemblyReferences //we're going to provide .net bcl ourselves .Where(f => !IsBclAssembly(f)) //in the compilationgraph, for some reason assemblies like Assembly-CSharp.dll get returned as if they reference all editor assemblies. very annoying. //fortunattely all these references follow a similar pattern, in that they are always referenced from Library/ScriptAssemblies. we're going to filter these out too. .Where(f => !f.Contains("Library/ScriptAssemblies/")) .Select(Path.GetFullPath) .ToNPaths(); var mydefines = assemblyToCompile.defines.ToList(); //todo: we shouldd respect the project's target framework settings mydefines.Remove("NET_4_6"); var csharpProgram = new CSharpProgram() { FileName = assemblyToCompile.name + ".dll", Sources = { assemblyToCompile.sourceFiles.Select(Path.GetFullPath).ToNPaths() }, Defines = { mydefines, "ENABLE_INCREMENTAL_PIPELINE", extraScriptingDefines }, CopyReferencesNextToTarget = false, References = { referencedPrebuiltAssemblies, assemblyToCompile.assemblyReferences.Select(r => unityAssemblyToCSharpProgramAndBuiltAssembly[r].program) }, LanguageVersion = "7.3", IgnoredWarnings = { 169 }, WarningsAsErrors = false, Framework = { Framework.NetStandard20 }, Unsafe = true, }; var builtAssembly = csharpProgram.SetupDefault(); unityAssemblyToCSharpProgramAndBuiltAssembly.Add(assemblyToCompile, (csharpProgram, builtAssembly)); } return(unityAssemblyToCSharpProgramAndBuiltAssembly); }
private static void SetupCSharpHelloWorld() { // Declare a CSharpProgram (a managed assembly - executable or dll) var program = new CSharpProgram { //build into here please: Path = "build/helloworld_csharp.exe", //with these sources (they'll be globbed if they're directories") Sources = { "helloworld_csharp" } }; //and set it up to build in the default configuration (debug, with an auto-selected compiler) program.SetupDefault(); //that's it, building csharp is too easy. }
static void Main() { CSharpProgram.DefaultConfig = new CSharpProgramConfiguration(CSharpCodeGen.Debug, Csc.Latest); CSharpProgram commonLib = SetUp("Common", isSourceGenerator: false); new VisualStudioSolution { Path = "SourceGenerators.gen.sln", Projects = { SetUp("AuthoringComponent", isSourceGenerator: true, commonLib), SetUp("JobEntity", isSourceGenerator: true, commonLib), SetUp("LambdaJobs", isSourceGenerator: true, commonLib), StandaloneBeeDriver.BuildProgramProjectFile } }.Setup(); }
private BindGem() { Program = new CSharpProgram() { Sources = { BuildProgram.BeeRoot.Parent.Combine("BindGem~") }, Path = "artifacts/bindgem/bindgem.exe", References = { new SystemReference("System.Xml.Linq"), new SystemReference("System.Xml"), new NPath($"{BuildProgram.LowLevelRoot}/UnsafeUtilityPatcher").Files("*.dll"), StevedoreUnityCecil.Paths, TypeRegistrationTool.EntityBuildUtils }, LanguageVersion = "7.3", WarningsAsErrors = false, CopyReferencesNextToTarget = true, ProjectFilePath = $"BindGem.csproj", }; BuiltBindGemProgram = Program.SetupDefault(); }
private static CSharpProgram _ilPostProcessorRunnerProgram() { var ilppRunnerDir = BuildProgram.BeeRoot.Parent.Combine("ILPostProcessing~/ILPostProcessorRunner"); // Since we will be running ILPostProcessors in a separate executable, we need to pull in the assembly references from the execution // environment the ILPostProcessors would have run in normally (i.e. the editor) var assemblyReferences = new List <NPath>(); foreach (var ilppAsm in BuildProgram.ILPostProcessorAssemblies) { foreach (var asm in ilppAsm.RecursiveRuntimeDependenciesIncludingSelf) { if ((asm.Path.FileNameWithoutExtension != "mscorlib" && asm.Path.FileNameWithoutExtension != "netstandard") && asm.Path.FileNameWithoutExtension != BuildProgram.UnityCompilationPipeline.Path.FileNameWithoutExtension) { assemblyReferences.Add(asm.Path.ResolveWithFileSystem()); } } } var ilPostProcessorRunner = new CSharpProgram() { FileName = "ILPostProcessorRunner.exe", Sources = { ilppRunnerDir }, Unsafe = true, LanguageVersion = "7.3", References = { BuildProgram.UnityCompilationPipeline }, ProjectFilePath = "ILPostProcessorRunner.csproj", Framework = { Framework.Framework471 }, IgnoredWarnings = { 3270 }, SupportFiles = { assemblyReferences }, }; return(ilPostProcessorRunner); }
public override DotNetAssembly SetupSpecificConfiguration(CSharpProgramConfiguration config) { var nonPatchedUnsafeUtility = base.SetupSpecificConfiguration(config); var builtPatcher = new CSharpProgram() { Path = "artifacts/UnsafeUtilityPatcher/UnsafeUtilityPatcher.exe", Sources = { $"{BuildProgram.LowLevelRoot}/UnsafeUtilityPatcher" }, Defines = { "NDESK_OPTIONS" }, Framework = { Bee.DotNet.Framework.Framework471 }, References = { MonoCecil.Paths, }, LanguageVersion = "7.3" }.SetupDefault(); var outDir = nonPatchedUnsafeUtility.Path.Parent.Combine("patched"); NPath nPath = outDir.Combine(nonPatchedUnsafeUtility.Path.FileName); var builtPatcherProgram = new DotNetRunnableProgram(builtPatcher); var args = new[] { $"--output={nPath}", $"--assembly={nonPatchedUnsafeUtility.Path}", }; var result = new DotNetAssembly(nPath, nonPatchedUnsafeUtility.Framework, nonPatchedUnsafeUtility.DebugFormat, nPath.ChangeExtension("pdb"), nonPatchedUnsafeUtility.RuntimeDependencies, nonPatchedUnsafeUtility.ReferenceAssemblyPath); Backend.Current.AddAction("Patch", result.Paths, nonPatchedUnsafeUtility.Paths.Concat(builtPatcher.Paths).ToArray(), builtPatcherProgram.InvocationString, args); return(result); }
static void Main(string[] path) { var bee = new NPath(typeof(CSharpProgram).Assembly.Location); StevedoreGlobalSettings.Instance = new StevedoreGlobalSettings { // Manifest entries always override artifact IDs hard-coded in Bee // Setting EnforceManifest to true will also ensure no artifacts // are used without being listed in a manifest. EnforceManifest = true, Manifest = { bee.Parent.Combine("manifest.stevedore").ToString(), }, }; //The stevedore global manifest will override DownloadableCsc.Csc72 artifacts and use Csc73 CSharpConfig = new CSharpProgramConfiguration(CSharpCodeGen.Release, DownloadableCsc.Csc72, HostPlatform.IsWindows ? (DebugFormat)DebugFormat.Pdb : DebugFormat.PortablePdb); var asmdefsFile = new NPath("asmdefs.json").MakeAbsolute(); var asmDefInfo = JObject.Parse(asmdefsFile.ReadAllText()); var asmDefs = asmDefInfo["asmdefs"].Value <JArray>(); var asmDefFullPaths = asmDefs.Select(a => new NPath(a["FullPath"].Value <string>())); var buildProgram = new CSharpProgram() { Path = path[0], Sources = { bee.Parent.Combine("BuildProgramSources"), asmDefFullPaths.SelectMany(a => HarvestBeeFilesFrom(a.Parent)) }, Framework = { Framework.Framework471 }, LanguageVersion = "7.2", References = { bee }, ProjectFile = { Path = NPath.CurrentDirectory.Combine("buildprogram.gen.csproj") } }; ((TundraBackend)Backend.Current).AddExtensionToBeScannedByHashInsteadOfTimeStamp("json", "config"); buildProgram.ProjectFile.AddCustomLinkRoot(bee.Parent.Combine("BuildProgramSources"), "."); buildProgram.SetupSpecificConfiguration(CSharpConfig); var buildProgrambuildProgram = new CSharpProgram() { FileName = "buildprogrambuildprogram.exe", Sources = { bee.Parent.Combine("BuildProgramBuildProgramSources") }, LanguageVersion = "7.2", Framework = { Framework.Framework471 }, References = { bee } }; buildProgrambuildProgram.SetupSpecificConfiguration(CSharpConfig); new VisualStudioSolution() { Path = "build.gen.sln", Projects = { buildProgram, buildProgrambuildProgram } }.Setup(); }
static BindGemResult BindGemOutputFor(CSharpProgram inputProgram, NativeProgramConfiguration config) => BindGemOutputFor(inputProgram, ((DotsRuntimeNativeProgramConfiguration)config).CSharpConfig);
static BindGemResult BindGemOutputFor(CSharpProgram inputProgram, CSharpProgramConfiguration config) => SupportsBindgem(inputProgram.FileName) ? MakeBindGemResultFor(inputProgram.FileName, config) : null;