public static void CrossCompileAOTDirectory(BuildTarget buildTarget, CrossCompileOptions crossCompileOptions, string sourceAssembliesFolder, string targetCrossCompiledASMFolder, string pathExtension, string additionalOptions) { string text = BuildPipeline.GetBuildToolsDirectory(buildTarget); if (Application.platform == RuntimePlatform.OSXEditor) { text = Path.Combine(Path.Combine(text, pathExtension), "mono-xcompiler"); } else { text = Path.Combine(Path.Combine(text, pathExtension), "mono-xcompiler.exe"); } sourceAssembliesFolder = Path.Combine(Directory.GetCurrentDirectory(), sourceAssembliesFolder); targetCrossCompiledASMFolder = Path.Combine(Directory.GetCurrentDirectory(), targetCrossCompiledASMFolder); string[] files = Directory.GetFiles(sourceAssembliesFolder); for (int i = 0; i < files.Length; i++) { string path = files[i]; if (!(Path.GetExtension(path) != ".dll")) { string fileName = Path.GetFileName(path); string output = Path.Combine(targetCrossCompiledASMFolder, fileName + ".s"); if (EditorUtility.DisplayCancelableProgressBar("Building Player", "AOT cross compile " + fileName, 0.95f)) { throw new OperationCanceledException(); } MonoCrossCompile.CrossCompileAOT(buildTarget, text, sourceAssembliesFolder, crossCompileOptions, fileName, output, additionalOptions); } } }
public static (Shader vs, Shader fs, SpecializationConstant[] specializations) LoadSPIRV( GraphicsDevice gd, ResourceFactory factory, string vertexShaderName, string fragmentShaderName, ReadOnlySpan <SpecializationConstant> specializations) { byte[] vsBytes = LoadBytecode(GraphicsBackend.Vulkan, vertexShaderName, ShaderStages.Vertex); byte[] fsBytes = LoadBytecode(GraphicsBackend.Vulkan, fragmentShaderName, ShaderStages.Fragment); bool debug = false; #if DEBUG debug = true; #endif CrossCompileOptions options = GetOptions(gd, specializations); var dst = SpirvCompilation.CompileVertexFragment(vsBytes, fsBytes, CrossCompileTarget.HLSL); Shader[] shaders = factory.CreateFromSpirv( new ShaderDescription(ShaderStages.Vertex, vsBytes, "main", debug), new ShaderDescription(ShaderStages.Fragment, fsBytes, "main", debug), options); Shader vs = shaders[0]; Shader fs = shaders[1]; vs.Name = vertexShaderName + "-Vertex"; fs.Name = fragmentShaderName + "-Fragment"; return(vs, fs, options.Specializations); }
static public void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker, string stagingAreaDataManaged) { WriteCPlusPlusFileForStaticAOTModuleRegistration(buildTarget, file, crossCompileOptions, advancedLic, targetDevice, stripping, usedClassRegistry, checker, stagingAreaDataManaged, null); }
public static void CrossCompileAOTDirectory(BuildTarget buildTarget, CrossCompileOptions crossCompileOptions, string sourceAssembliesFolder, string targetCrossCompiledASMFolder, string pathExtension, string additionalOptions) { string buildToolsDirectory = BuildPipeline.GetBuildToolsDirectory(buildTarget); if (Application.platform == RuntimePlatform.OSXEditor) { buildToolsDirectory = Path.Combine(Path.Combine(buildToolsDirectory, pathExtension), "mono-xcompiler"); } else { buildToolsDirectory = Path.Combine(Path.Combine(buildToolsDirectory, pathExtension), "mono-xcompiler.exe"); } sourceAssembliesFolder = Path.Combine(Directory.GetCurrentDirectory(), sourceAssembliesFolder); targetCrossCompiledASMFolder = Path.Combine(Directory.GetCurrentDirectory(), targetCrossCompiledASMFolder); foreach (string str2 in Directory.GetFiles(sourceAssembliesFolder)) { if (Path.GetExtension(str2) == ".dll") { string fileName = Path.GetFileName(str2); string output = Path.Combine(targetCrossCompiledASMFolder, fileName + ".s"); if (EditorUtility.DisplayCancelableProgressBar("Building Player", "AOT cross compile " + fileName, 0.95f)) { throw new OperationCanceledException(); } CrossCompileAOT(buildTarget, buildToolsDirectory, sourceAssembliesFolder, crossCompileOptions, fileName, output, additionalOptions); } } }
static public bool CrossCompileAOTDirectoryParallel(BuildTarget buildTarget, CrossCompileOptions crossCompileOptions, string sourceAssembliesFolder, string targetCrossCompiledASMFolder, string additionalOptions) { return(CrossCompileAOTDirectoryParallel(buildTarget, crossCompileOptions, sourceAssembliesFolder, targetCrossCompiledASMFolder, "", additionalOptions)); }
public JobCompileAOT(BuildTarget target, string crossCompilerAbsolutePath, string assembliesAbsoluteDirectory, CrossCompileOptions crossCompileOptions, string input, string output, string additionalOptions) { this.m_target = target; this.m_crossCompilerAbsolutePath = crossCompilerAbsolutePath; this.m_assembliesAbsoluteDirectory = assembliesAbsoluteDirectory; this.m_crossCompileOptions = crossCompileOptions; this.m_input = input; this.m_output = output; this.m_additionalOptions = additionalOptions; }
public static bool CrossCompileAOTDirectoryParallel(BuildTarget buildTarget, CrossCompileOptions crossCompileOptions, string sourceAssembliesFolder, string targetCrossCompiledASMFolder, string pathExtension, string additionalOptions) { string text = BuildPipeline.GetBuildToolsDirectory(buildTarget); if (Application.platform == RuntimePlatform.OSXEditor) { text = Path.Combine(Path.Combine(text, pathExtension), "mono-xcompiler"); } else { text = Path.Combine(Path.Combine(text, pathExtension), "mono-xcompiler.exe"); } return MonoCrossCompile.CrossCompileAOTDirectoryParallel(text, buildTarget, crossCompileOptions, sourceAssembliesFolder, targetCrossCompiledASMFolder, additionalOptions); }
public static Shader[] LoadSet(GraphicsDevice gd, ResourceFactory factory, string name) { ShaderDescription vsDesc = new ShaderDescription( ShaderStages.Vertex, LoadBytes(name, ShaderStages.Vertex), "main"); ShaderDescription fsDesc = new ShaderDescription( ShaderStages.Fragment, LoadBytes(name, ShaderStages.Fragment), "main"); CrossCompileOptions options = GetCompileOptions(gd); return(factory.CreateFromSpirv(vsDesc, fsDesc, options)); }
public static bool CrossCompileAOTDirectoryParallel(BuildTarget buildTarget, CrossCompileOptions crossCompileOptions, string sourceAssembliesFolder, string targetCrossCompiledASMFolder, string pathExtension, string additionalOptions) { string text = BuildPipeline.GetBuildToolsDirectory(buildTarget); if (Application.platform == RuntimePlatform.OSXEditor) { text = Path.Combine(Path.Combine(text, pathExtension), "mono-xcompiler"); } else { text = Path.Combine(Path.Combine(text, pathExtension), "mono-xcompiler.exe"); } return(MonoCrossCompile.CrossCompileAOTDirectoryParallel(text, buildTarget, crossCompileOptions, sourceAssembliesFolder, targetCrossCompiledASMFolder, additionalOptions)); }
private void CompileShaders(ResourceFactory factory, CrossCompileOptions options) { var glyphVertexShaderDesc = new ShaderDescription( ShaderStages.Vertex, Encoding.UTF8.GetBytes(Shaders.GlyphTextVertex), "main"); var glyphFragmentShaderDesc = new ShaderDescription( ShaderStages.Fragment, Encoding.UTF8.GetBytes(Shaders.GlyphTextFragment), "main"); glyphShaders = factory.CreateFromSpirv(glyphVertexShaderDesc, glyphFragmentShaderDesc, options); var textVertexShaderDesc = new ShaderDescription( ShaderStages.Vertex, Encoding.UTF8.GetBytes(Shaders.TextVertex), "main"); var textFragmentShaderDesc = new ShaderDescription( ShaderStages.Fragment, Encoding.UTF8.GetBytes(Shaders.TextFragment), "main"); textShaders = factory.CreateFromSpirv(textVertexShaderDesc, textFragmentShaderDesc, options); }
public static void CrossCompileAOTDirectory(BuildTarget buildTarget, CrossCompileOptions crossCompileOptions, string sourceAssembliesFolder, string targetCrossCompiledASMFolder, string pathExtension, string additionalOptions) { string buildToolsDirectory = BuildPipeline.GetBuildToolsDirectory(buildTarget); string crossCompilerAbsolutePath = Application.platform != RuntimePlatform.OSXEditor ? Path.Combine(Path.Combine(buildToolsDirectory, pathExtension), "mono-xcompiler.exe") : Path.Combine(Path.Combine(buildToolsDirectory, pathExtension), "mono-xcompiler"); sourceAssembliesFolder = Path.Combine(Directory.GetCurrentDirectory(), sourceAssembliesFolder); targetCrossCompiledASMFolder = Path.Combine(Directory.GetCurrentDirectory(), targetCrossCompiledASMFolder); foreach (string file in Directory.GetFiles(sourceAssembliesFolder)) { if (!(Path.GetExtension(file) != ".dll")) { string fileName = Path.GetFileName(file); string output = Path.Combine(targetCrossCompiledASMFolder, fileName + ".s"); if (EditorUtility.DisplayCancelableProgressBar("Building Player", "AOT cross compile " + fileName, 0.95f)) throw new OperationCanceledException(); MonoCrossCompile.CrossCompileAOT(buildTarget, crossCompilerAbsolutePath, sourceAssembliesFolder, crossCompileOptions, fileName, output, additionalOptions); } } }
static public void CrossCompileAOTDirectory(BuildTarget buildTarget, CrossCompileOptions crossCompileOptions, string sourceAssembliesFolder, string targetCrossCompiledASMFolder, string pathExtension, string additionalOptions) { string crossCompilerPath = BuildPipeline.GetBuildToolsDirectory(buildTarget); if (Application.platform == RuntimePlatform.OSXEditor) { crossCompilerPath = Path.Combine(Path.Combine(crossCompilerPath, pathExtension), "mono-xcompiler"); } else { crossCompilerPath = Path.Combine(Path.Combine(crossCompilerPath, pathExtension), "mono-xcompiler.exe"); } sourceAssembliesFolder = Path.Combine(Directory.GetCurrentDirectory(), sourceAssembliesFolder); targetCrossCompiledASMFolder = Path.Combine(Directory.GetCurrentDirectory(), targetCrossCompiledASMFolder); // Generate AOT Files (using OSX cross-compiler) foreach (string fileName in Directory.GetFiles(sourceAssembliesFolder)) { if (Path.GetExtension(fileName) != ".dll") { continue; } // Cross AOT compile string inputPath = Path.GetFileName(fileName); string outputPath = Path.Combine(targetCrossCompiledASMFolder, inputPath + ".s"); if (EditorUtility.DisplayCancelableProgressBar("Building Player", "AOT cross compile " + inputPath, 0.95F)) { throw new OperationCanceledException(); } CrossCompileAOT(buildTarget, crossCompilerPath, sourceAssembliesFolder, crossCompileOptions, inputPath, outputPath, additionalOptions); } }
private void CreateResources() { // Veldrid.SPIRV is an additional library that complements Veldrid // by simplifying the development of cross-backend shaders, and is // currently the recommended approach to doing so: // // https://veldrid.dev/articles/portable-shaders.html // // If you decide against using it, you can try out Veldrid developer // mellinoe's other project, ShaderGen, or drive yourself crazy by // writing and maintaining custom shader code for each platform. byte[] vertexShaderSpirvBytes = LoadSpirvBytes(ShaderStages.Vertex); byte[] fragmentShaderSpirvBytes = LoadSpirvBytes(ShaderStages.Fragment); var options = new CrossCompileOptions(); switch (Surface.GraphicsDevice.BackendType) { // InvertVertexOutputY and FixClipSpaceZ address two major // differences between Veldrid's various graphics APIs, as // discussed here: // // https://veldrid.dev/articles/backend-differences.html // // Note that the only reason those options are useful in this // example project is that the vertices being drawn are stored // the way Vulkan stores vertex data. The options will therefore // properly convert from the Vulkan style to whatever's used by // the destination backend. If you store vertices in a different // coordinate system, these may not do anything for you, and // you'll need to handle the difference in your shader code. case GraphicsBackend.Metal: options.InvertVertexOutputY = true; break; case GraphicsBackend.Direct3D11: options.InvertVertexOutputY = true; break; case GraphicsBackend.OpenGL: options.FixClipSpaceZ = true; options.InvertVertexOutputY = true; break; default: break; } ResourceFactory factory = Surface.GraphicsDevice.ResourceFactory; var vertex = new ShaderDescription(ShaderStages.Vertex, vertexShaderSpirvBytes, "main", true); var fragment = new ShaderDescription(ShaderStages.Fragment, fragmentShaderSpirvBytes, "main", true); Shader[] shaders = factory.CreateFromSpirv(vertex, fragment, options); ResourceLayout modelMatrixLayout = factory.CreateResourceLayout( new ResourceLayoutDescription( new ResourceLayoutElementDescription( "ModelMatrix", ResourceKind.UniformBuffer, ShaderStages.Vertex))); ModelBuffer = factory.CreateBuffer( new BufferDescription(64, BufferUsage.UniformBuffer)); ModelMatrixSet = factory.CreateResourceSet(new ResourceSetDescription( modelMatrixLayout, ModelBuffer)); VertexPositionColor[] quadVertices = { new VertexPositionColor(new Vector2(-.75f, -.75f), RgbaFloat.Red), new VertexPositionColor(new Vector2(.75f, -.75f), RgbaFloat.Green), new VertexPositionColor(new Vector2(-.75f, .75f), RgbaFloat.Blue), new VertexPositionColor(new Vector2(.75f, .75f), RgbaFloat.Yellow) }; ushort[] quadIndices = { 0, 1, 2, 3 }; VertexBuffer = factory.CreateBuffer(new BufferDescription(4 * VertexPositionColor.SizeInBytes, BufferUsage.VertexBuffer)); IndexBuffer = factory.CreateBuffer(new BufferDescription(4 * sizeof(ushort), BufferUsage.IndexBuffer)); Surface.GraphicsDevice.UpdateBuffer(VertexBuffer, 0, quadVertices); Surface.GraphicsDevice.UpdateBuffer(IndexBuffer, 0, quadIndices); // Veldrid.SPIRV, when cross-compiling to HLSL, will always produce // TEXCOORD semantics; VertexElementSemantic.TextureCoordinate thus // becomes necessary to let D3D11 work alongside Vulkan and OpenGL. // // https://github.com/mellinoe/veldrid/issues/121 // var vertexLayout = new VertexLayoutDescription( new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2), new VertexElementDescription("Color", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float4)); Pipeline = factory.CreateGraphicsPipeline(new GraphicsPipelineDescription { BlendState = BlendStateDescription.SingleOverrideBlend, DepthStencilState = new DepthStencilStateDescription( depthTestEnabled: true, depthWriteEnabled: true, comparisonKind: ComparisonKind.LessEqual), RasterizerState = new RasterizerStateDescription( cullMode: FaceCullMode.Back, fillMode: PolygonFillMode.Solid, frontFace: FrontFace.Clockwise, depthClipEnabled: true, scissorTestEnabled: false), PrimitiveTopology = PrimitiveTopology.TriangleStrip, ResourceLayouts = new[] { modelMatrixLayout }, ShaderSet = new ShaderSetDescription( vertexLayouts: new VertexLayoutDescription[] { vertexLayout }, shaders: shaders), Outputs = Surface.Swapchain.Framebuffer.OutputDescription }); CommandList = factory.CreateCommandList(); }
public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker) { using (TextWriter textWriter = new StreamWriter(file)) { string[] assemblyFileNames = checker.GetAssemblyFileNames(); AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions(); bool flag = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic; ArrayList arrayList = MonoAOTRegistration.BuildNativeMethodList(assemblyDefinitions); if (buildTarget == BuildTarget.iOS) { textWriter.WriteLine("#include \"RegisterMonoModules.h\""); textWriter.WriteLine("#include <stdio.h>"); } textWriter.WriteLine(string.Empty); textWriter.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR"); textWriter.WriteLine("\t#define DECL_USER_FUNC(f) void f() __attribute__((weak_import))"); textWriter.WriteLine("\t#define REGISTER_USER_FUNC(f)\\"); textWriter.WriteLine("\t\tdo {\\"); textWriter.WriteLine("\t\tif(f != NULL)\\"); textWriter.WriteLine("\t\t\tmono_dl_register_symbol(#f, (void*)f);\\"); textWriter.WriteLine("\t\telse\\"); textWriter.WriteLine("\t\t\t::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\"); textWriter.WriteLine("\t\t}while(0)"); textWriter.WriteLine("#else"); textWriter.WriteLine("\t#define DECL_USER_FUNC(f) void f() "); textWriter.WriteLine("\t#if !defined(__arm64__)"); textWriter.WriteLine("\t#define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)"); textWriter.WriteLine("\t#else"); textWriter.WriteLine("\t\t#define REGISTER_USER_FUNC(f)"); textWriter.WriteLine("\t#endif"); textWriter.WriteLine("#endif"); textWriter.WriteLine("extern \"C\"\n{"); textWriter.WriteLine("\ttypedef void* gpointer;"); textWriter.WriteLine("\ttypedef int gboolean;"); if (buildTarget == BuildTarget.iOS) { textWriter.WriteLine("\tconst char*\t\t\tUnityIPhoneRuntimeVersion = \"{0}\";", Application.unityVersion); textWriter.WriteLine("\tvoid\t\t\t\tmono_dl_register_symbol (const char* name, void *addr);"); textWriter.WriteLine("#if !defined(__arm64__)"); textWriter.WriteLine("\textern int\t\t\tmono_ficall_flag;"); textWriter.WriteLine("#endif"); } textWriter.WriteLine("\tvoid\t\t\t\tmono_aot_register_module(gpointer *aot_info);"); textWriter.WriteLine("#if !(__ORBIS__)"); textWriter.WriteLine("#define DLL_EXPORT"); textWriter.WriteLine("#else"); textWriter.WriteLine("#define DLL_EXPORT __declspec(dllexport)"); textWriter.WriteLine("#endif"); textWriter.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)"); textWriter.WriteLine("\textern gboolean\t\tmono_aot_only;"); for (int i = 0; i < assemblyFileNames.Length; i++) { string arg = assemblyFileNames[i]; string text = assemblyDefinitions[i].Name.Name; text = text.Replace(".", "_"); text = text.Replace("-", "_"); text = text.Replace(" ", "_"); textWriter.WriteLine("\textern gpointer*\tmono_aot_module_{0}_info; // {1}", text, arg); } textWriter.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)"); foreach (string arg2 in arrayList) { textWriter.WriteLine("\tDECL_USER_FUNC({0});", arg2); } textWriter.WriteLine("}"); textWriter.WriteLine("DLL_EXPORT void RegisterMonoModules()"); textWriter.WriteLine("{"); textWriter.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)"); textWriter.WriteLine("\tmono_aot_only = true;"); if (buildTarget == BuildTarget.iOS) { textWriter.WriteLine("\tmono_ficall_flag = {0};", (!flag) ? "false" : "true"); } AssemblyDefinition[] array = assemblyDefinitions; for (int j = 0; j < array.Length; j++) { AssemblyDefinition assemblyDefinition = array[j]; string text2 = assemblyDefinition.Name.Name; text2 = text2.Replace(".", "_"); text2 = text2.Replace("-", "_"); text2 = text2.Replace(" ", "_"); textWriter.WriteLine("\tmono_aot_register_module(mono_aot_module_{0}_info);", text2); } textWriter.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)"); textWriter.WriteLine(string.Empty); if (buildTarget == BuildTarget.iOS) { foreach (string arg3 in arrayList) { textWriter.WriteLine("\tREGISTER_USER_FUNC({0});", arg3); } } textWriter.WriteLine("}"); textWriter.WriteLine(string.Empty); AssemblyDefinition assemblyDefinition2 = null; for (int k = 0; k < assemblyFileNames.Length; k++) { if (assemblyFileNames[k] == "UnityEngine.dll") { assemblyDefinition2 = assemblyDefinitions[k]; } } if (buildTarget == BuildTarget.iOS) { AssemblyDefinition[] assemblies = new AssemblyDefinition[] { assemblyDefinition2 }; MonoAOTRegistration.GenerateRegisterInternalCalls(assemblies, textWriter); MonoAOTRegistration.ResolveDefinedNativeClassesFromMono(assemblies, usedClassRegistry); MonoAOTRegistration.ResolveReferencedUnityEngineClassesFromMono(assemblyDefinitions, assemblyDefinition2, usedClassRegistry); if (stripping && usedClassRegistry != null) { MonoAOTRegistration.GenerateRegisterClassesForStripping(usedClassRegistry, textWriter); } else { MonoAOTRegistration.GenerateRegisterClasses(usedClassRegistry, textWriter); } } textWriter.Close(); } }
static void CrossCompileAOT(BuildTarget target, string crossCompilerAbsolutePath, string assembliesAbsoluteDirectory, CrossCompileOptions crossCompileOptions, string input, string output, string additionalOptions) { string arguments = ""; // We don't want debugging for non-script assemblies (anyway source code is not available for the end users) if (!IsDebugableAssembly(input)) { crossCompileOptions &= ~CrossCompileOptions.Debugging; crossCompileOptions &= ~CrossCompileOptions.LoadSymbols; } bool debugging = ((crossCompileOptions & CrossCompileOptions.Debugging) != 0); bool loadSymbols = ((crossCompileOptions & CrossCompileOptions.LoadSymbols) != 0); bool initDebugging = (debugging || loadSymbols); if (initDebugging) { arguments += "--debug "; } if (debugging) { // Do not put locals into registers when debugging arguments += "--optimize=-linears "; } arguments += "--aot=full,asmonly,"; if (initDebugging) { arguments += "write-symbols,"; } if ((crossCompileOptions & CrossCompileOptions.Debugging) != 0) { arguments += "soft-debug,"; } else if (!initDebugging) { arguments += "nodebug,"; } if (target != BuildTarget.iOS) { //arguments += "fail-if-methods-are-skipped,"; arguments += "print-skipped,"; } if (additionalOptions != null && additionalOptions.Trim().Length > 0) { arguments += additionalOptions.Trim() + ","; } string outputFileName = Path.GetFileName(output); // Mono outfile parameter doesnt take absolute paths, // So we temporarily write into the assembliesAbsoluteDirectory and move it away afterwards string outputTempPath = Path.Combine(assembliesAbsoluteDirectory, outputFileName); if ((crossCompileOptions & CrossCompileOptions.FastICall) != 0) { arguments += "ficall,"; } if ((crossCompileOptions & CrossCompileOptions.Static) != 0) { arguments += "static,"; } arguments += "outfile=\"" + outputFileName + "\" \"" + input + "\" "; System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = crossCompilerAbsolutePath; process.StartInfo.Arguments = arguments; process.StartInfo.EnvironmentVariables["MONO_PATH"] = assembliesAbsoluteDirectory; process.StartInfo.EnvironmentVariables["GAC_PATH"] = assembliesAbsoluteDirectory; process.StartInfo.EnvironmentVariables["GC_DONT_GC"] = "yes please"; if ((crossCompileOptions & CrossCompileOptions.ExplicitNullChecks) != 0) { process.StartInfo.EnvironmentVariables["MONO_DEBUG"] = "explicit-null-checks"; } process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; if (ArtifactsPath != null) { if (!Directory.Exists(ArtifactsPath)) { Directory.CreateDirectory(ArtifactsPath); } File.AppendAllText(ArtifactsPath + "output.txt", process.StartInfo.FileName + "\n"); File.AppendAllText(ArtifactsPath + "output.txt", process.StartInfo.Arguments + "\n"); File.AppendAllText(ArtifactsPath + "output.txt", assembliesAbsoluteDirectory + "\n"); File.AppendAllText(ArtifactsPath + "output.txt", outputTempPath + "\n"); File.AppendAllText(ArtifactsPath + "output.txt", input + "\n"); File.AppendAllText(ArtifactsPath + "houtput.txt", outputFileName + "\n\n"); File.Copy(assembliesAbsoluteDirectory + "\\" + input, ArtifactsPath + "\\" + input, true); } process.StartInfo.WorkingDirectory = assembliesAbsoluteDirectory; MonoProcessUtility.RunMonoProcess(process, "AOT cross compiler", outputTempPath); // For some reason we can't pass a full path to outfile, so we move the .s file after compilation instead File.Move(outputTempPath, output); //handle .def files if present for dlls if ((crossCompileOptions & CrossCompileOptions.Static) == 0) { string defOutputTempPath = Path.Combine(assembliesAbsoluteDirectory, outputFileName + ".def"); if (File.Exists(defOutputTempPath)) { File.Move(defOutputTempPath, output + ".def"); } } }
static public void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker, string stagingAreaDataManaged, IIl2CppPlatformProvider platformProvider) { // generate the Interal Call Summary file var icallSummaryPath = Path.Combine(stagingAreaDataManaged, "ICallSummary.txt"); var dlls = Directory.GetFiles(stagingAreaDataManaged, "UnityEngine.*Module.dll").Concat(new[] { Path.Combine(stagingAreaDataManaged, "UnityEngine.dll") }); var exe = Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Tools/InternalCallRegistrationWriter/InternalCallRegistrationWriter.exe"); var args = string.Format("-assembly=\"{0}\" -summary=\"{1}\"", dlls.Aggregate((dllArg, next) => dllArg + ";" + next), icallSummaryPath ); Runner.RunManagedProgram(exe, args); HashSet <UnityType> nativeClasses; HashSet <string> nativeModules; CodeStrippingUtils.GenerateDependencies(Path.GetDirectoryName(stagingAreaDataManaged), icallSummaryPath, usedClassRegistry, stripping, out nativeClasses, out nativeModules, platformProvider); using (TextWriter w = new StreamWriter(file)) { string[] fileNames = checker.GetAssemblyFileNames(); AssemblyDefinition[] assemblies = checker.GetAssemblyDefinitions(); bool fastICall = (crossCompileOptions & CrossCompileOptions.FastICall) != 0; ArrayList nativeMethods = BuildNativeMethodList(assemblies); if (buildTarget == BuildTarget.iOS) { w.WriteLine("#include \"RegisterMonoModules.h\""); w.WriteLine("#include <stdio.h>"); } w.WriteLine(""); w.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR"); w.WriteLine(" #define DECL_USER_FUNC(f) void f() __attribute__((weak_import))"); w.WriteLine(" #define REGISTER_USER_FUNC(f)\\"); w.WriteLine(" do {\\"); w.WriteLine(" if(f != NULL)\\"); w.WriteLine(" mono_dl_register_symbol(#f, (void*)f);\\"); w.WriteLine(" else\\"); w.WriteLine(" ::printf_console(\"Symbol \'%s\' not found. Maybe missing implementation for Simulator?\\n\", #f);\\"); w.WriteLine(" }while(0)"); w.WriteLine("#else"); w.WriteLine(" #define DECL_USER_FUNC(f) void f() "); w.WriteLine(" #if !defined(__arm64__)"); w.WriteLine(" #define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)"); w.WriteLine(" #else"); w.WriteLine(" #define REGISTER_USER_FUNC(f)"); w.WriteLine(" #endif"); w.WriteLine("#endif"); w.WriteLine("extern \"C\"\n{"); w.WriteLine(" typedef void* gpointer;"); w.WriteLine(" typedef int gboolean;"); if (buildTarget == BuildTarget.iOS) { w.WriteLine(" const char* UnityIPhoneRuntimeVersion = \"{0}\";", Application.unityVersion); w.WriteLine(" void mono_dl_register_symbol (const char* name, void *addr);"); w.WriteLine("#if !defined(__arm64__)"); w.WriteLine(" extern int mono_ficall_flag;"); w.WriteLine("#endif"); } w.WriteLine(" void mono_aot_register_module(gpointer *aot_info);"); w.WriteLine("#if __ORBIS__ || SN_TARGET_PSP2"); w.WriteLine("#define DLL_EXPORT __declspec(dllexport)"); // ps4 and psp2 need dllexport. w.WriteLine("#else"); w.WriteLine("#define DLL_EXPORT"); w.WriteLine("#endif"); w.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)"); w.WriteLine(" extern gboolean mono_aot_only;"); for (int q = 0; q < fileNames.Length; ++q) { string fileName = fileNames[q]; string assemblyName = assemblies[q].Name.Name; assemblyName = assemblyName.Replace(".", "_"); assemblyName = assemblyName.Replace("-", "_"); assemblyName = assemblyName.Replace(" ", "_"); w.WriteLine(" extern gpointer* mono_aot_module_{0}_info; // {1}", assemblyName, fileName); } w.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)"); foreach (string nmethod in nativeMethods) { w.WriteLine(" DECL_USER_FUNC({0});", nmethod); } w.WriteLine("}"); w.WriteLine("DLL_EXPORT void RegisterMonoModules()"); w.WriteLine("{"); w.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)"); w.WriteLine(" mono_aot_only = true;"); if (buildTarget == BuildTarget.iOS) { w.WriteLine(" mono_ficall_flag = {0};", fastICall ? "true" : "false"); } foreach (AssemblyDefinition definition in assemblies) { string assemblyName = definition.Name.Name; assemblyName = assemblyName.Replace(".", "_"); assemblyName = assemblyName.Replace("-", "_"); assemblyName = assemblyName.Replace(" ", "_"); w.WriteLine(" mono_aot_register_module(mono_aot_module_{0}_info);", assemblyName); } w.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)"); w.WriteLine(""); if (buildTarget == BuildTarget.iOS) { foreach (string nmethod in nativeMethods) { w.WriteLine(" REGISTER_USER_FUNC({0});", nmethod); } } w.WriteLine("}"); w.WriteLine(""); if (buildTarget == BuildTarget.iOS) { var inputAssemblies = new List <AssemblyDefinition>(); for (int i = 0; i < assemblies.Length; i++) { if (AssemblyHelper.IsUnityEngineModule(assemblies[i])) { inputAssemblies.Add(assemblies[i]); } } GenerateRegisterInternalCalls(inputAssemblies.ToArray(), w); GenerateRegisterModules(nativeClasses, nativeModules, w, stripping); if (stripping && usedClassRegistry != null) { GenerateRegisterClassesForStripping(nativeClasses, w); } else { GenerateRegisterClasses(nativeClasses, w); } } w.Close(); } }
public static bool CrossCompileAOTDirectoryParallel(string crossCompilerPath, BuildTarget buildTarget, CrossCompileOptions crossCompileOptions, string sourceAssembliesFolder, string targetCrossCompiledASMFolder, string additionalOptions) { sourceAssembliesFolder = Path.Combine(Directory.GetCurrentDirectory(), sourceAssembliesFolder); targetCrossCompiledASMFolder = Path.Combine(Directory.GetCurrentDirectory(), targetCrossCompiledASMFolder); int workerThreads = 1; int completionPortThreads = 1; ThreadPool.GetMaxThreads(out workerThreads, out completionPortThreads); List <MonoCrossCompile.JobCompileAOT> jobCompileAotList = new List <MonoCrossCompile.JobCompileAOT>(); List <ManualResetEvent> events = new List <ManualResetEvent>(); bool flag = true; List <string> stringList = new List <string>(((IEnumerable <string>)Directory.GetFiles(sourceAssembliesFolder)).Where <string>((Func <string, bool>)(path => Path.GetExtension(path) == ".dll"))); int count = stringList.Count; int filesFinished = 0; MonoCrossCompile.DisplayAOTProgressBar(count, filesFinished); long timeout = (long)Math.Min(1800000, (count + 3) * 1000 * 30); using (List <string> .Enumerator enumerator = stringList.GetEnumerator()) { while (enumerator.MoveNext()) { string fileName = Path.GetFileName(enumerator.Current); string output = Path.Combine(targetCrossCompiledASMFolder, fileName + ".s"); MonoCrossCompile.JobCompileAOT jobCompileAot = new MonoCrossCompile.JobCompileAOT(buildTarget, crossCompilerPath, sourceAssembliesFolder, crossCompileOptions, fileName, output, additionalOptions); jobCompileAotList.Add(jobCompileAot); events.Add(jobCompileAot.m_doneEvent); ThreadPool.QueueUserWorkItem(new WaitCallback(jobCompileAot.ThreadPoolCallback)); if (events.Count >= Environment.ProcessorCount) { flag = MonoCrossCompile.WaitForBuildOfFile(events, ref timeout); MonoCrossCompile.DisplayAOTProgressBar(count, filesFinished); ++filesFinished; if (!flag) { break; } } } } while (events.Count > 0) { flag = MonoCrossCompile.WaitForBuildOfFile(events, ref timeout); MonoCrossCompile.DisplayAOTProgressBar(count, filesFinished); ++filesFinished; if (!flag) { break; } } using (List <MonoCrossCompile.JobCompileAOT> .Enumerator enumerator = jobCompileAotList.GetEnumerator()) { while (enumerator.MoveNext()) { MonoCrossCompile.JobCompileAOT current = enumerator.Current; if (current.m_Exception != null) { UnityEngine.Debug.LogErrorFormat("Cross compilation job {0} failed.\n{1}", new object[2] { (object)current.m_input, (object)current.m_Exception }); flag = false; } } } return(flag); }
public static void CrossCompileAOTDirectory(BuildTarget buildTarget, CrossCompileOptions crossCompileOptions, string sourceAssembliesFolder, string targetCrossCompiledASMFolder, string additionalOptions) { MonoCrossCompile.CrossCompileAOTDirectory(buildTarget, crossCompileOptions, sourceAssembliesFolder, targetCrossCompiledASMFolder, string.Empty, additionalOptions); }
private static void CrossCompileAOT(BuildTarget target, string crossCompilerAbsolutePath, string assembliesAbsoluteDirectory, CrossCompileOptions crossCompileOptions, string input, string output, string additionalOptions) { string text = string.Empty; if (!MonoCrossCompile.IsDebugableAssembly(input)) { crossCompileOptions &= ~CrossCompileOptions.Debugging; crossCompileOptions &= ~CrossCompileOptions.LoadSymbols; } bool flag = (crossCompileOptions & CrossCompileOptions.Debugging) != CrossCompileOptions.Dynamic; bool flag2 = (crossCompileOptions & CrossCompileOptions.LoadSymbols) != CrossCompileOptions.Dynamic; bool flag3 = flag || flag2; if (flag3) { text += "--debug "; } if (flag) { text += "--optimize=-linears "; } text += "--aot=full,asmonly,"; if (flag3) { text += "write-symbols,"; } if ((crossCompileOptions & CrossCompileOptions.Debugging) != CrossCompileOptions.Dynamic) { text += "soft-debug,"; } else { if (!flag3) { text += "nodebug,"; } } if (target != BuildTarget.iOS) { text += "print-skipped,"; } if (additionalOptions != null & additionalOptions.Trim().Length > 0) { text = text + additionalOptions.Trim() + ","; } string fileName = Path.GetFileName(output); string text2 = Path.Combine(assembliesAbsoluteDirectory, fileName); if ((crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic) { text += "ficall,"; } if ((crossCompileOptions & CrossCompileOptions.Static) != CrossCompileOptions.Dynamic) { text += "static,"; } string text3 = text; text = string.Concat(new string[] { text3, "outfile=\"", fileName, "\" \"", input, "\" " }); Process process = new Process(); process.StartInfo.FileName = crossCompilerAbsolutePath; process.StartInfo.Arguments = text; process.StartInfo.EnvironmentVariables["MONO_PATH"] = assembliesAbsoluteDirectory; process.StartInfo.EnvironmentVariables["GAC_PATH"] = assembliesAbsoluteDirectory; process.StartInfo.EnvironmentVariables["GC_DONT_GC"] = "yes please"; if ((crossCompileOptions & CrossCompileOptions.ExplicitNullChecks) != CrossCompileOptions.Dynamic) { process.StartInfo.EnvironmentVariables["MONO_DEBUG"] = "explicit-null-checks"; } process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; if (MonoCrossCompile.ArtifactsPath != null) { if (!Directory.Exists(MonoCrossCompile.ArtifactsPath)) { Directory.CreateDirectory(MonoCrossCompile.ArtifactsPath); } File.AppendAllText(MonoCrossCompile.ArtifactsPath + "output.txt", process.StartInfo.FileName + "\n"); File.AppendAllText(MonoCrossCompile.ArtifactsPath + "output.txt", process.StartInfo.Arguments + "\n"); File.AppendAllText(MonoCrossCompile.ArtifactsPath + "output.txt", assembliesAbsoluteDirectory + "\n"); File.AppendAllText(MonoCrossCompile.ArtifactsPath + "output.txt", text2 + "\n"); File.AppendAllText(MonoCrossCompile.ArtifactsPath + "output.txt", input + "\n"); File.AppendAllText(MonoCrossCompile.ArtifactsPath + "houtput.txt", fileName + "\n\n"); File.Copy(assembliesAbsoluteDirectory + "\\" + input, MonoCrossCompile.ArtifactsPath + "\\" + input, true); } process.StartInfo.WorkingDirectory = assembliesAbsoluteDirectory; MonoProcessUtility.RunMonoProcess(process, "AOT cross compiler", text2); File.Move(text2, output); if ((crossCompileOptions & CrossCompileOptions.Static) == CrossCompileOptions.Dynamic) { string text4 = Path.Combine(assembliesAbsoluteDirectory, fileName + ".def"); if (File.Exists(text4)) { File.Move(text4, output + ".def"); } } }
public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker) { using (TextWriter output = (TextWriter) new StreamWriter(file)) { string[] assemblyFileNames = checker.GetAssemblyFileNames(); AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions(); bool flag = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic; ArrayList arrayList = MonoAOTRegistration.BuildNativeMethodList(assemblyDefinitions); if (buildTarget == BuildTarget.iOS) { output.WriteLine("#include \"RegisterMonoModules.h\""); output.WriteLine("#include <stdio.h>"); } output.WriteLine(string.Empty); output.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR"); output.WriteLine(" #define DECL_USER_FUNC(f) void f() __attribute__((weak_import))"); output.WriteLine(" #define REGISTER_USER_FUNC(f)\\"); output.WriteLine(" do {\\"); output.WriteLine(" if(f != NULL)\\"); output.WriteLine(" mono_dl_register_symbol(#f, (void*)f);\\"); output.WriteLine(" else\\"); output.WriteLine(" ::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\"); output.WriteLine(" }while(0)"); output.WriteLine("#else"); output.WriteLine(" #define DECL_USER_FUNC(f) void f() "); output.WriteLine(" #if !defined(__arm64__)"); output.WriteLine(" #define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)"); output.WriteLine(" #else"); output.WriteLine(" #define REGISTER_USER_FUNC(f)"); output.WriteLine(" #endif"); output.WriteLine("#endif"); output.WriteLine("extern \"C\"\n{"); output.WriteLine(" typedef void* gpointer;"); output.WriteLine(" typedef int gboolean;"); if (buildTarget == BuildTarget.iOS) { output.WriteLine(" const char* UnityIPhoneRuntimeVersion = \"{0}\";", (object) Application.unityVersion); output.WriteLine(" void mono_dl_register_symbol (const char* name, void *addr);"); output.WriteLine("#if !defined(__arm64__)"); output.WriteLine(" extern int mono_ficall_flag;"); output.WriteLine("#endif"); } output.WriteLine(" void mono_aot_register_module(gpointer *aot_info);"); output.WriteLine("#if __ORBIS__ || SN_TARGET_PSP2"); output.WriteLine("#define DLL_EXPORT __declspec(dllexport)"); output.WriteLine("#else"); output.WriteLine("#define DLL_EXPORT"); output.WriteLine("#endif"); output.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)"); output.WriteLine(" extern gboolean mono_aot_only;"); for (int index = 0; index < assemblyFileNames.Length; ++index) { string str1 = assemblyFileNames[index]; string str2 = ((AssemblyNameReference) assemblyDefinitions[index].get_Name()).get_Name().Replace(".", "_").Replace("-", "_").Replace(" ", "_"); output.WriteLine(" extern gpointer* mono_aot_module_{0}_info; // {1}", (object) str2, (object) str1); } output.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)"); foreach (string str in arrayList) output.WriteLine(" DECL_USER_FUNC({0});", (object) str); output.WriteLine("}"); output.WriteLine("DLL_EXPORT void RegisterMonoModules()"); output.WriteLine("{"); output.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)"); output.WriteLine(" mono_aot_only = true;"); if (buildTarget == BuildTarget.iOS) output.WriteLine(" mono_ficall_flag = {0};", !flag ? (object) "false" : (object) "true"); foreach (AssemblyDefinition assemblyDefinition in assemblyDefinitions) { string str = ((AssemblyNameReference) assemblyDefinition.get_Name()).get_Name().Replace(".", "_").Replace("-", "_").Replace(" ", "_"); output.WriteLine(" mono_aot_register_module(mono_aot_module_{0}_info);", (object) str); } output.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)"); output.WriteLine(string.Empty); if (buildTarget == BuildTarget.iOS) { foreach (string str in arrayList) output.WriteLine(" REGISTER_USER_FUNC({0});", (object) str); } output.WriteLine("}"); output.WriteLine(string.Empty); AssemblyDefinition unityEngine = (AssemblyDefinition) null; for (int index = 0; index < assemblyFileNames.Length; ++index) { if (assemblyFileNames[index] == "UnityEngine.dll") unityEngine = assemblyDefinitions[index]; } if (buildTarget == BuildTarget.iOS) { AssemblyDefinition[] assemblies = new AssemblyDefinition[1]{ unityEngine }; MonoAOTRegistration.GenerateRegisterInternalCalls(assemblies, output); MonoAOTRegistration.ResolveDefinedNativeClassesFromMono(assemblies, usedClassRegistry); MonoAOTRegistration.ResolveReferencedUnityEngineClassesFromMono(assemblyDefinitions, unityEngine, usedClassRegistry); MonoAOTRegistration.GenerateRegisterModules(usedClassRegistry, output, stripping); if (stripping && usedClassRegistry != null) MonoAOTRegistration.GenerateRegisterClassesForStripping(usedClassRegistry, output); else MonoAOTRegistration.GenerateRegisterClasses(usedClassRegistry, output); } output.Close(); } }
public static bool CrossCompileAOTDirectoryParallel(string crossCompilerPath, BuildTarget buildTarget, CrossCompileOptions crossCompileOptions, string sourceAssembliesFolder, string targetCrossCompiledASMFolder, string additionalOptions) { sourceAssembliesFolder = Path.Combine(Directory.GetCurrentDirectory(), sourceAssembliesFolder); targetCrossCompiledASMFolder = Path.Combine(Directory.GetCurrentDirectory(), targetCrossCompiledASMFolder); int workerThreads = 1; int completionPortThreads = 1; ThreadPool.GetMaxThreads(out workerThreads, out completionPortThreads); List<JobCompileAOT> list = new List<JobCompileAOT>(); List<ManualResetEvent> events = new List<ManualResetEvent>(); bool flag = true; if (<>f__am$cache1 == null) {
private static void CrossCompileAOT(BuildTarget target, string crossCompilerAbsolutePath, string assembliesAbsoluteDirectory, CrossCompileOptions crossCompileOptions, string input, string output, string additionalOptions) { string str = string.Empty; if (!IsDebugableAssembly(input)) { crossCompileOptions &= ~CrossCompileOptions.Debugging; crossCompileOptions &= ~CrossCompileOptions.LoadSymbols; } bool flag = (crossCompileOptions & CrossCompileOptions.Debugging) != CrossCompileOptions.Dynamic; bool flag2 = (crossCompileOptions & CrossCompileOptions.LoadSymbols) != CrossCompileOptions.Dynamic; bool flag3 = flag || flag2; if (flag3) { str = str + "--debug "; } if (flag) { str = str + "--optimize=-linears "; } str = str + "--aot=full,asmonly,"; if (flag3) { str = str + "write-symbols,"; } if ((crossCompileOptions & CrossCompileOptions.Debugging) != CrossCompileOptions.Dynamic) { str = str + "soft-debug,"; } else if (!flag3) { str = str + "nodebug,"; } if (target != BuildTarget.iOS) { str = str + "print-skipped,"; } if ((additionalOptions != null) & (additionalOptions.Trim().Length > 0)) { str = str + additionalOptions.Trim() + ","; } string fileName = Path.GetFileName(output); string resultingFile = Path.Combine(assembliesAbsoluteDirectory, fileName); if ((crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic) { str = str + "ficall,"; } if ((crossCompileOptions & CrossCompileOptions.Static) != CrossCompileOptions.Dynamic) { str = str + "static,"; } string str5 = str; string[] textArray1 = new string[] { str5, "outfile=\"", fileName, "\" \"", input, "\" " }; str = string.Concat(textArray1); Process process = new Process { StartInfo = { FileName = crossCompilerAbsolutePath, Arguments = str } }; process.StartInfo.EnvironmentVariables["MONO_PATH"] = assembliesAbsoluteDirectory; process.StartInfo.EnvironmentVariables["GAC_PATH"] = assembliesAbsoluteDirectory; process.StartInfo.EnvironmentVariables["GC_DONT_GC"] = "yes please"; if ((crossCompileOptions & CrossCompileOptions.ExplicitNullChecks) != CrossCompileOptions.Dynamic) { process.StartInfo.EnvironmentVariables["MONO_DEBUG"] = "explicit-null-checks"; } process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; if (ArtifactsPath != null) { if (!Directory.Exists(ArtifactsPath)) { Directory.CreateDirectory(ArtifactsPath); } File.AppendAllText(ArtifactsPath + "output.txt", process.StartInfo.FileName + "\n"); File.AppendAllText(ArtifactsPath + "output.txt", process.StartInfo.Arguments + "\n"); File.AppendAllText(ArtifactsPath + "output.txt", assembliesAbsoluteDirectory + "\n"); File.AppendAllText(ArtifactsPath + "output.txt", resultingFile + "\n"); File.AppendAllText(ArtifactsPath + "output.txt", input + "\n"); File.AppendAllText(ArtifactsPath + "houtput.txt", fileName + "\n\n"); File.Copy(assembliesAbsoluteDirectory + @"\" + input, ArtifactsPath + @"\" + input, true); } process.StartInfo.WorkingDirectory = assembliesAbsoluteDirectory; MonoProcessUtility.RunMonoProcess(process, "AOT cross compiler", resultingFile); File.Move(resultingFile, output); if ((crossCompileOptions & CrossCompileOptions.Static) == CrossCompileOptions.Dynamic) { string path = Path.Combine(assembliesAbsoluteDirectory, fileName + ".def"); if (File.Exists(path)) { File.Move(path, output + ".def"); } } }
public static bool CrossCompileAOTDirectoryParallel(string crossCompilerPath, BuildTarget buildTarget, CrossCompileOptions crossCompileOptions, string sourceAssembliesFolder, string targetCrossCompiledASMFolder, string additionalOptions) { sourceAssembliesFolder = Path.Combine(Directory.GetCurrentDirectory(), sourceAssembliesFolder); targetCrossCompiledASMFolder = Path.Combine(Directory.GetCurrentDirectory(), targetCrossCompiledASMFolder); int num = 1; int num2 = 1; ThreadPool.GetMaxThreads(out num, out num2); List<MonoCrossCompile.JobCompileAOT> list = new List<MonoCrossCompile.JobCompileAOT>(); List<ManualResetEvent> list2 = new List<ManualResetEvent>(); bool flag = true; List<string> list3 = new List<string>( from path in Directory.GetFiles(sourceAssembliesFolder) where Path.GetExtension(path) == ".dll" select path); int count = list3.Count; int num3 = 0; MonoCrossCompile.DisplayAOTProgressBar(count, num3); long num4 = (long)Math.Min(1800000, (count + 3) * 1000 * 30); foreach (string current in list3) { string fileName = Path.GetFileName(current); string output = Path.Combine(targetCrossCompiledASMFolder, fileName + ".s"); MonoCrossCompile.JobCompileAOT jobCompileAOT = new MonoCrossCompile.JobCompileAOT(buildTarget, crossCompilerPath, sourceAssembliesFolder, crossCompileOptions, fileName, output, additionalOptions); list.Add(jobCompileAOT); list2.Add(jobCompileAOT.m_doneEvent); ThreadPool.QueueUserWorkItem(new WaitCallback(jobCompileAOT.ThreadPoolCallback)); if (list2.Count >= Environment.ProcessorCount) { flag = MonoCrossCompile.WaitForBuildOfFile(list2, ref num4); MonoCrossCompile.DisplayAOTProgressBar(count, num3); num3++; if (!flag) { break; } } } while (list2.Count > 0) { flag = MonoCrossCompile.WaitForBuildOfFile(list2, ref num4); MonoCrossCompile.DisplayAOTProgressBar(count, num3); num3++; if (!flag) { break; } } foreach (MonoCrossCompile.JobCompileAOT current2 in list) { if (current2.m_Exception != null) { UnityEngine.Debug.LogErrorFormat("Cross compilation job {0} failed.\n{1}", new object[] { current2.m_input, current2.m_Exception }); flag = false; } } return flag; }
public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker, string stagingAreaDataManaged) { HashSet <UnityType> set; HashSet <string> set2; string str = Path.Combine(stagingAreaDataManaged, "ICallSummary.txt"); string exe = Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Tools/InternalCallRegistrationWriter/InternalCallRegistrationWriter.exe"); string args = $"-assembly=" { Path.Combine(stagingAreaDataManaged, "UnityEngine.dll") } " -summary=" { str } ""; Runner.RunManagedProgram(exe, args); CodeStrippingUtils.GenerateDependencies(Path.GetFullPath(stagingAreaDataManaged), str, usedClassRegistry, stripping, out set, out set2, null); using (TextWriter writer = new StreamWriter(file)) { string[] assemblyFileNames = checker.GetAssemblyFileNames(); AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions(); bool flag = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic; ArrayList list = BuildNativeMethodList(assemblyDefinitions); if (buildTarget == BuildTarget.iOS) { writer.WriteLine("#include \"RegisterMonoModules.h\""); writer.WriteLine("#include <stdio.h>"); } writer.WriteLine(""); writer.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR"); writer.WriteLine(" #define DECL_USER_FUNC(f) void f() __attribute__((weak_import))"); writer.WriteLine(@" #define REGISTER_USER_FUNC(f)\"); writer.WriteLine(@" do {\"); writer.WriteLine(@" if(f != NULL)\"); writer.WriteLine(@" mono_dl_register_symbol(#f, (void*)f);\"); writer.WriteLine(@" else\"); writer.WriteLine(" ::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\"); writer.WriteLine(" }while(0)"); writer.WriteLine("#else"); writer.WriteLine(" #define DECL_USER_FUNC(f) void f() "); writer.WriteLine(" #if !defined(__arm64__)"); writer.WriteLine(" #define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)"); writer.WriteLine(" #else"); writer.WriteLine(" #define REGISTER_USER_FUNC(f)"); writer.WriteLine(" #endif"); writer.WriteLine("#endif"); writer.WriteLine("extern \"C\"\n{"); writer.WriteLine(" typedef void* gpointer;"); writer.WriteLine(" typedef int gboolean;"); if (buildTarget == BuildTarget.iOS) { writer.WriteLine(" const char* UnityIPhoneRuntimeVersion = \"{0}\";", Application.unityVersion); writer.WriteLine(" void mono_dl_register_symbol (const char* name, void *addr);"); writer.WriteLine("#if !defined(__arm64__)"); writer.WriteLine(" extern int mono_ficall_flag;"); writer.WriteLine("#endif"); } writer.WriteLine(" void mono_aot_register_module(gpointer *aot_info);"); writer.WriteLine("#if __ORBIS__ || SN_TARGET_PSP2"); writer.WriteLine("#define DLL_EXPORT __declspec(dllexport)"); writer.WriteLine("#else"); writer.WriteLine("#define DLL_EXPORT"); writer.WriteLine("#endif"); writer.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)"); writer.WriteLine(" extern gboolean mono_aot_only;"); for (int i = 0; i < assemblyFileNames.Length; i++) { string str4 = assemblyFileNames[i]; string str5 = assemblyDefinitions[i].Name.Name.Replace(".", "_").Replace("-", "_").Replace(" ", "_"); writer.WriteLine(" extern gpointer* mono_aot_module_{0}_info; // {1}", str5, str4); } writer.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)"); IEnumerator enumerator = list.GetEnumerator(); try { while (enumerator.MoveNext()) { string current = (string)enumerator.Current; writer.WriteLine(" DECL_USER_FUNC({0});", current); } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } writer.WriteLine("}"); writer.WriteLine("DLL_EXPORT void RegisterMonoModules()"); writer.WriteLine("{"); writer.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)"); writer.WriteLine(" mono_aot_only = true;"); if (buildTarget == BuildTarget.iOS) { writer.WriteLine(" mono_ficall_flag = {0};", !flag ? "false" : "true"); } foreach (AssemblyDefinition definition in assemblyDefinitions) { string str7 = definition.Name.Name.Replace(".", "_").Replace("-", "_").Replace(" ", "_"); writer.WriteLine(" mono_aot_register_module(mono_aot_module_{0}_info);", str7); } writer.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)"); writer.WriteLine(""); if (buildTarget == BuildTarget.iOS) { IEnumerator enumerator2 = list.GetEnumerator(); try { while (enumerator2.MoveNext()) { string str8 = (string)enumerator2.Current; writer.WriteLine(" REGISTER_USER_FUNC({0});", str8); } } finally { IDisposable disposable2 = enumerator2 as IDisposable; if (disposable2 != null) { disposable2.Dispose(); } } } writer.WriteLine("}"); writer.WriteLine(""); AssemblyDefinition unityEngine = null; for (int j = 0; j < assemblyFileNames.Length; j++) { if (assemblyFileNames[j] == "UnityEngine.dll") { unityEngine = assemblyDefinitions[j]; } } if (buildTarget == BuildTarget.iOS) { AssemblyDefinition[] assemblies = new AssemblyDefinition[] { unityEngine }; GenerateRegisterInternalCalls(assemblies, writer); ResolveDefinedNativeClassesFromMono(assemblies, usedClassRegistry); ResolveReferencedUnityEngineClassesFromMono(assemblyDefinitions, unityEngine, usedClassRegistry); GenerateRegisterModules(set, set2, writer, stripping); if (stripping && (usedClassRegistry != null)) { GenerateRegisterClassesForStripping(set, writer); } else { GenerateRegisterClasses(set, writer); } } writer.Close(); } }
public static bool CrossCompileAOTDirectoryParallel(string crossCompilerPath, BuildTarget buildTarget, CrossCompileOptions crossCompileOptions, string sourceAssembliesFolder, string targetCrossCompiledASMFolder, string additionalOptions) { sourceAssembliesFolder = Path.Combine(Directory.GetCurrentDirectory(), sourceAssembliesFolder); targetCrossCompiledASMFolder = Path.Combine(Directory.GetCurrentDirectory(), targetCrossCompiledASMFolder); int num = 1; int num2 = 1; ThreadPool.GetMaxThreads(out num, out num2); List <MonoCrossCompile.JobCompileAOT> list = new List <MonoCrossCompile.JobCompileAOT>(); List <ManualResetEvent> list2 = new List <ManualResetEvent>(); bool flag = true; List <string> list3 = new List <string>( from path in Directory.GetFiles(sourceAssembliesFolder) where Path.GetExtension(path) == ".dll" select path); int count = list3.Count; int num3 = 0; MonoCrossCompile.DisplayAOTProgressBar(count, num3); long num4 = (long)Math.Min(1800000, (count + 3) * 1000 * 30); foreach (string current in list3) { string fileName = Path.GetFileName(current); string output = Path.Combine(targetCrossCompiledASMFolder, fileName + ".s"); MonoCrossCompile.JobCompileAOT jobCompileAOT = new MonoCrossCompile.JobCompileAOT(buildTarget, crossCompilerPath, sourceAssembliesFolder, crossCompileOptions, fileName, output, additionalOptions); list.Add(jobCompileAOT); list2.Add(jobCompileAOT.m_doneEvent); ThreadPool.QueueUserWorkItem(new WaitCallback(jobCompileAOT.ThreadPoolCallback)); if (list2.Count >= Environment.ProcessorCount) { flag = MonoCrossCompile.WaitForBuildOfFile(list2, ref num4); MonoCrossCompile.DisplayAOTProgressBar(count, num3); num3++; if (!flag) { break; } } } while (list2.Count > 0) { flag = MonoCrossCompile.WaitForBuildOfFile(list2, ref num4); MonoCrossCompile.DisplayAOTProgressBar(count, num3); num3++; if (!flag) { break; } } foreach (MonoCrossCompile.JobCompileAOT current2 in list) { if (current2.m_Exception != null) { UnityEngine.Debug.LogErrorFormat("Cross compilation job {0} failed.\n{1}", new object[] { current2.m_input, current2.m_Exception }); flag = false; } } return(flag); }
private static void CrossCompileAOT(BuildTarget target, string crossCompilerAbsolutePath, string assembliesAbsoluteDirectory, CrossCompileOptions crossCompileOptions, string input, string output, string additionalOptions) { string empty = string.Empty; if (!MonoCrossCompile.IsDebugableAssembly(input)) { crossCompileOptions &= ~CrossCompileOptions.Debugging; crossCompileOptions &= ~CrossCompileOptions.LoadSymbols; } bool flag1 = (crossCompileOptions & CrossCompileOptions.Debugging) != CrossCompileOptions.Dynamic; bool flag2 = (crossCompileOptions & CrossCompileOptions.LoadSymbols) != CrossCompileOptions.Dynamic; bool flag3 = flag1 || flag2; if (flag3) empty += "--debug "; if (flag1) empty += "--optimize=-linears "; string str1 = empty + "--aot=full,asmonly,"; if (flag3) str1 += "write-symbols,"; if ((crossCompileOptions & CrossCompileOptions.Debugging) != CrossCompileOptions.Dynamic) str1 += "soft-debug,"; else if (!flag3) str1 += "nodebug,"; if (target != BuildTarget.iOS) str1 += "print-skipped,"; if (additionalOptions != null & additionalOptions.Trim().Length > 0) str1 = str1 + additionalOptions.Trim() + ","; string fileName = Path.GetFileName(output); string str2 = Path.Combine(assembliesAbsoluteDirectory, fileName); if ((crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic) str1 += "ficall,"; if ((crossCompileOptions & CrossCompileOptions.Static) != CrossCompileOptions.Dynamic) str1 += "static,"; string str3 = str1 + "outfile=\"" + fileName + "\" \"" + input + "\" "; Process process = new Process(); process.StartInfo.FileName = crossCompilerAbsolutePath; process.StartInfo.Arguments = str3; process.StartInfo.EnvironmentVariables["MONO_PATH"] = assembliesAbsoluteDirectory; process.StartInfo.EnvironmentVariables["GAC_PATH"] = assembliesAbsoluteDirectory; process.StartInfo.EnvironmentVariables["GC_DONT_GC"] = "yes please"; if ((crossCompileOptions & CrossCompileOptions.ExplicitNullChecks) != CrossCompileOptions.Dynamic) process.StartInfo.EnvironmentVariables["MONO_DEBUG"] = "explicit-null-checks"; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; if (MonoCrossCompile.ArtifactsPath != null) { if (!Directory.Exists(MonoCrossCompile.ArtifactsPath)) Directory.CreateDirectory(MonoCrossCompile.ArtifactsPath); File.AppendAllText(MonoCrossCompile.ArtifactsPath + "output.txt", process.StartInfo.FileName + "\n"); File.AppendAllText(MonoCrossCompile.ArtifactsPath + "output.txt", process.StartInfo.Arguments + "\n"); File.AppendAllText(MonoCrossCompile.ArtifactsPath + "output.txt", assembliesAbsoluteDirectory + "\n"); File.AppendAllText(MonoCrossCompile.ArtifactsPath + "output.txt", str2 + "\n"); File.AppendAllText(MonoCrossCompile.ArtifactsPath + "output.txt", input + "\n"); File.AppendAllText(MonoCrossCompile.ArtifactsPath + "houtput.txt", fileName + "\n\n"); File.Copy(assembliesAbsoluteDirectory + "\\" + input, MonoCrossCompile.ArtifactsPath + "\\" + input, true); } process.StartInfo.WorkingDirectory = assembliesAbsoluteDirectory; MonoProcessUtility.RunMonoProcess(process, "AOT cross compiler", str2); File.Move(str2, output); if ((crossCompileOptions & CrossCompileOptions.Static) != CrossCompileOptions.Dynamic) return; string str4 = Path.Combine(assembliesAbsoluteDirectory, fileName + ".def"); if (!File.Exists(str4)) return; File.Move(str4, output + ".def"); }
public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker, string stagingAreaDataManaged, IIl2CppPlatformProvider platformProvider) { string text = Path.Combine(stagingAreaDataManaged, "ICallSummary.txt"); string exe = Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Tools/InternalCallRegistrationWriter/InternalCallRegistrationWriter.exe"); string args = string.Format("-assembly=\"{0}\" -summary=\"{1}\"", Path.Combine(stagingAreaDataManaged, "UnityEngine.dll"), text); Runner.RunManagedProgram(exe, args); HashSet <UnityType> hashSet; HashSet <string> nativeModules; CodeStrippingUtils.GenerateDependencies(Path.GetDirectoryName(stagingAreaDataManaged), text, usedClassRegistry, stripping, out hashSet, out nativeModules, platformProvider); using (TextWriter textWriter = new StreamWriter(file)) { string[] assemblyFileNames = checker.GetAssemblyFileNames(); AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions(); bool flag = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic; ArrayList arrayList = MonoAOTRegistration.BuildNativeMethodList(assemblyDefinitions); if (buildTarget == BuildTarget.iOS) { textWriter.WriteLine("#include \"RegisterMonoModules.h\""); textWriter.WriteLine("#include <stdio.h>"); } textWriter.WriteLine(""); textWriter.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR"); textWriter.WriteLine(" #define DECL_USER_FUNC(f) void f() __attribute__((weak_import))"); textWriter.WriteLine(" #define REGISTER_USER_FUNC(f)\\"); textWriter.WriteLine(" do {\\"); textWriter.WriteLine(" if(f != NULL)\\"); textWriter.WriteLine(" mono_dl_register_symbol(#f, (void*)f);\\"); textWriter.WriteLine(" else\\"); textWriter.WriteLine(" ::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\"); textWriter.WriteLine(" }while(0)"); textWriter.WriteLine("#else"); textWriter.WriteLine(" #define DECL_USER_FUNC(f) void f() "); textWriter.WriteLine(" #if !defined(__arm64__)"); textWriter.WriteLine(" #define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)"); textWriter.WriteLine(" #else"); textWriter.WriteLine(" #define REGISTER_USER_FUNC(f)"); textWriter.WriteLine(" #endif"); textWriter.WriteLine("#endif"); textWriter.WriteLine("extern \"C\"\n{"); textWriter.WriteLine(" typedef void* gpointer;"); textWriter.WriteLine(" typedef int gboolean;"); if (buildTarget == BuildTarget.iOS) { textWriter.WriteLine(" const char* UnityIPhoneRuntimeVersion = \"{0}\";", Application.unityVersion); textWriter.WriteLine(" void mono_dl_register_symbol (const char* name, void *addr);"); textWriter.WriteLine("#if !defined(__arm64__)"); textWriter.WriteLine(" extern int mono_ficall_flag;"); textWriter.WriteLine("#endif"); } textWriter.WriteLine(" void mono_aot_register_module(gpointer *aot_info);"); textWriter.WriteLine("#if __ORBIS__ || SN_TARGET_PSP2"); textWriter.WriteLine("#define DLL_EXPORT __declspec(dllexport)"); textWriter.WriteLine("#else"); textWriter.WriteLine("#define DLL_EXPORT"); textWriter.WriteLine("#endif"); textWriter.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)"); textWriter.WriteLine(" extern gboolean mono_aot_only;"); for (int i = 0; i < assemblyFileNames.Length; i++) { string arg = assemblyFileNames[i]; string text2 = assemblyDefinitions[i].Name.Name; text2 = text2.Replace(".", "_"); text2 = text2.Replace("-", "_"); text2 = text2.Replace(" ", "_"); textWriter.WriteLine(" extern gpointer* mono_aot_module_{0}_info; // {1}", text2, arg); } textWriter.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)"); IEnumerator enumerator = arrayList.GetEnumerator(); try { while (enumerator.MoveNext()) { string arg2 = (string)enumerator.Current; textWriter.WriteLine(" DECL_USER_FUNC({0});", arg2); } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } textWriter.WriteLine("}"); textWriter.WriteLine("DLL_EXPORT void RegisterMonoModules()"); textWriter.WriteLine("{"); textWriter.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)"); textWriter.WriteLine(" mono_aot_only = true;"); if (buildTarget == BuildTarget.iOS) { textWriter.WriteLine(" mono_ficall_flag = {0};", (!flag) ? "false" : "true"); } AssemblyDefinition[] array = assemblyDefinitions; for (int j = 0; j < array.Length; j++) { AssemblyDefinition assemblyDefinition = array[j]; string text3 = assemblyDefinition.Name.Name; text3 = text3.Replace(".", "_"); text3 = text3.Replace("-", "_"); text3 = text3.Replace(" ", "_"); textWriter.WriteLine(" mono_aot_register_module(mono_aot_module_{0}_info);", text3); } textWriter.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)"); textWriter.WriteLine(""); if (buildTarget == BuildTarget.iOS) { IEnumerator enumerator2 = arrayList.GetEnumerator(); try { while (enumerator2.MoveNext()) { string arg3 = (string)enumerator2.Current; textWriter.WriteLine(" REGISTER_USER_FUNC({0});", arg3); } } finally { IDisposable disposable2; if ((disposable2 = (enumerator2 as IDisposable)) != null) { disposable2.Dispose(); } } } textWriter.WriteLine("}"); textWriter.WriteLine(""); AssemblyDefinition assemblyDefinition2 = null; for (int k = 0; k < assemblyFileNames.Length; k++) { if (assemblyFileNames[k] == "UnityEngine.dll") { assemblyDefinition2 = assemblyDefinitions[k]; } } if (buildTarget == BuildTarget.iOS) { AssemblyDefinition[] assemblies = new AssemblyDefinition[] { assemblyDefinition2 }; MonoAOTRegistration.GenerateRegisterInternalCalls(assemblies, textWriter); MonoAOTRegistration.GenerateRegisterModules(hashSet, nativeModules, textWriter, stripping); if (stripping && usedClassRegistry != null) { MonoAOTRegistration.GenerateRegisterClassesForStripping(hashSet, textWriter); } else { MonoAOTRegistration.GenerateRegisterClasses(hashSet, textWriter); } } textWriter.Close(); } }
public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker, string stagingAreaDataManaged) { HashSet<UnityType> set; HashSet<string> set2; string str = Path.Combine(stagingAreaDataManaged, "ICallSummary.txt"); string exe = Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Tools/InternalCallRegistrationWriter/InternalCallRegistrationWriter.exe"); string args = string.Format("-assembly=\"{0}\" -summary=\"{1}\"", Path.Combine(stagingAreaDataManaged, "UnityEngine.dll"), str); Runner.RunManagedProgram(exe, args); CodeStrippingUtils.GenerateDependencies(Path.GetDirectoryName(stagingAreaDataManaged), str, usedClassRegistry, stripping, out set, out set2, null); using (TextWriter writer = new StreamWriter(file)) { string[] assemblyFileNames = checker.GetAssemblyFileNames(); AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions(); bool flag = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic; ArrayList list = BuildNativeMethodList(assemblyDefinitions); if (buildTarget == BuildTarget.iOS) { writer.WriteLine("#include \"RegisterMonoModules.h\""); writer.WriteLine("#include <stdio.h>"); } writer.WriteLine(""); writer.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR"); writer.WriteLine(" #define DECL_USER_FUNC(f) void f() __attribute__((weak_import))"); writer.WriteLine(@" #define REGISTER_USER_FUNC(f)\"); writer.WriteLine(@" do {\"); writer.WriteLine(@" if(f != NULL)\"); writer.WriteLine(@" mono_dl_register_symbol(#f, (void*)f);\"); writer.WriteLine(@" else\"); writer.WriteLine(" ::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\"); writer.WriteLine(" }while(0)"); writer.WriteLine("#else"); writer.WriteLine(" #define DECL_USER_FUNC(f) void f() "); writer.WriteLine(" #if !defined(__arm64__)"); writer.WriteLine(" #define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)"); writer.WriteLine(" #else"); writer.WriteLine(" #define REGISTER_USER_FUNC(f)"); writer.WriteLine(" #endif"); writer.WriteLine("#endif"); writer.WriteLine("extern \"C\"\n{"); writer.WriteLine(" typedef void* gpointer;"); writer.WriteLine(" typedef int gboolean;"); if (buildTarget == BuildTarget.iOS) { writer.WriteLine(" const char* UnityIPhoneRuntimeVersion = \"{0}\";", Application.unityVersion); writer.WriteLine(" void mono_dl_register_symbol (const char* name, void *addr);"); writer.WriteLine("#if !defined(__arm64__)"); writer.WriteLine(" extern int mono_ficall_flag;"); writer.WriteLine("#endif"); } writer.WriteLine(" void mono_aot_register_module(gpointer *aot_info);"); writer.WriteLine("#if __ORBIS__ || SN_TARGET_PSP2"); writer.WriteLine("#define DLL_EXPORT __declspec(dllexport)"); writer.WriteLine("#else"); writer.WriteLine("#define DLL_EXPORT"); writer.WriteLine("#endif"); writer.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)"); writer.WriteLine(" extern gboolean mono_aot_only;"); for (int i = 0; i < assemblyFileNames.Length; i++) { string str4 = assemblyFileNames[i]; string str5 = assemblyDefinitions[i].Name.Name.Replace(".", "_").Replace("-", "_").Replace(" ", "_"); writer.WriteLine(" extern gpointer* mono_aot_module_{0}_info; // {1}", str5, str4); } writer.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)"); IEnumerator enumerator = list.GetEnumerator(); try { while (enumerator.MoveNext()) { string current = (string) enumerator.Current; writer.WriteLine(" DECL_USER_FUNC({0});", current); } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } writer.WriteLine("}"); writer.WriteLine("DLL_EXPORT void RegisterMonoModules()"); writer.WriteLine("{"); writer.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)"); writer.WriteLine(" mono_aot_only = true;"); if (buildTarget == BuildTarget.iOS) { writer.WriteLine(" mono_ficall_flag = {0};", !flag ? "false" : "true"); } foreach (AssemblyDefinition definition in assemblyDefinitions) { string str7 = definition.Name.Name.Replace(".", "_").Replace("-", "_").Replace(" ", "_"); writer.WriteLine(" mono_aot_register_module(mono_aot_module_{0}_info);", str7); } writer.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)"); writer.WriteLine(""); if (buildTarget == BuildTarget.iOS) { IEnumerator enumerator2 = list.GetEnumerator(); try { while (enumerator2.MoveNext()) { string str8 = (string) enumerator2.Current; writer.WriteLine(" REGISTER_USER_FUNC({0});", str8); } } finally { IDisposable disposable2 = enumerator2 as IDisposable; if (disposable2 != null) { disposable2.Dispose(); } } } writer.WriteLine("}"); writer.WriteLine(""); AssemblyDefinition unityEngine = null; for (int j = 0; j < assemblyFileNames.Length; j++) { if (assemblyFileNames[j] == "UnityEngine.dll") { unityEngine = assemblyDefinitions[j]; } } if (buildTarget == BuildTarget.iOS) { AssemblyDefinition[] assemblies = new AssemblyDefinition[] { unityEngine }; GenerateRegisterInternalCalls(assemblies, writer); ResolveDefinedNativeClassesFromMono(assemblies, usedClassRegistry); ResolveReferencedUnityEngineClassesFromMono(assemblyDefinitions, unityEngine, usedClassRegistry); GenerateRegisterModules(set, set2, writer, stripping); if (stripping && (usedClassRegistry != null)) { GenerateRegisterClassesForStripping(set, writer); } else { GenerateRegisterClasses(set, writer); } } writer.Close(); } }
public static bool CrossCompileAOTDirectoryParallel(BuildTarget buildTarget, CrossCompileOptions crossCompileOptions, string sourceAssembliesFolder, string targetCrossCompiledASMFolder, string additionalOptions) { return MonoCrossCompile.CrossCompileAOTDirectoryParallel(buildTarget, crossCompileOptions, sourceAssembliesFolder, targetCrossCompiledASMFolder, string.Empty, additionalOptions); }
public static bool CrossCompileAOTDirectoryParallel(string crossCompilerPath, BuildTarget buildTarget, CrossCompileOptions crossCompileOptions, string sourceAssembliesFolder, string targetCrossCompiledASMFolder, string additionalOptions) { sourceAssembliesFolder = Path.Combine(Directory.GetCurrentDirectory(), sourceAssembliesFolder); targetCrossCompiledASMFolder = Path.Combine(Directory.GetCurrentDirectory(), targetCrossCompiledASMFolder); int workerThreads = 1; int completionPortThreads = 1; ThreadPool.GetMaxThreads(out workerThreads, out completionPortThreads); List <JobCompileAOT> list = new List <JobCompileAOT>(); List <ManualResetEvent> events = new List <ManualResetEvent>(); bool flag = true; if (< > f__am$cache0 == null) {
public static bool CrossCompileAOTDirectoryParallel(string crossCompilerPath, BuildTarget buildTarget, CrossCompileOptions crossCompileOptions, string sourceAssembliesFolder, string targetCrossCompiledASMFolder, string additionalOptions) { sourceAssembliesFolder = Path.Combine(Directory.GetCurrentDirectory(), sourceAssembliesFolder); targetCrossCompiledASMFolder = Path.Combine(Directory.GetCurrentDirectory(), targetCrossCompiledASMFolder); int workerThreads = 1; int completionPortThreads = 1; ThreadPool.GetMaxThreads(out workerThreads, out completionPortThreads); List<MonoCrossCompile.JobCompileAOT> jobCompileAotList = new List<MonoCrossCompile.JobCompileAOT>(); List<ManualResetEvent> events = new List<ManualResetEvent>(); bool flag = true; List<string> stringList = new List<string>(((IEnumerable<string>) Directory.GetFiles(sourceAssembliesFolder)).Where<string>((Func<string, bool>) (path => Path.GetExtension(path) == ".dll"))); int count = stringList.Count; int filesFinished = 0; MonoCrossCompile.DisplayAOTProgressBar(count, filesFinished); long timeout = (long) Math.Min(1800000, (count + 3) * 1000 * 30); using (List<string>.Enumerator enumerator = stringList.GetEnumerator()) { while (enumerator.MoveNext()) { string fileName = Path.GetFileName(enumerator.Current); string output = Path.Combine(targetCrossCompiledASMFolder, fileName + ".s"); MonoCrossCompile.JobCompileAOT jobCompileAot = new MonoCrossCompile.JobCompileAOT(buildTarget, crossCompilerPath, sourceAssembliesFolder, crossCompileOptions, fileName, output, additionalOptions); jobCompileAotList.Add(jobCompileAot); events.Add(jobCompileAot.m_doneEvent); ThreadPool.QueueUserWorkItem(new WaitCallback(jobCompileAot.ThreadPoolCallback)); if (events.Count >= Environment.ProcessorCount) { flag = MonoCrossCompile.WaitForBuildOfFile(events, ref timeout); MonoCrossCompile.DisplayAOTProgressBar(count, filesFinished); ++filesFinished; if (!flag) break; } } } while (events.Count > 0) { flag = MonoCrossCompile.WaitForBuildOfFile(events, ref timeout); MonoCrossCompile.DisplayAOTProgressBar(count, filesFinished); ++filesFinished; if (!flag) break; } using (List<MonoCrossCompile.JobCompileAOT>.Enumerator enumerator = jobCompileAotList.GetEnumerator()) { while (enumerator.MoveNext()) { MonoCrossCompile.JobCompileAOT current = enumerator.Current; if (current.m_Exception != null) { UnityEngine.Debug.LogErrorFormat("Cross compilation job {0} failed.\n{1}", new object[2] { (object) current.m_input, (object) current.m_Exception }); flag = false; } } } return flag; }
public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker) { using (TextWriter writer = new StreamWriter(file)) { string[] assemblyFileNames = checker.GetAssemblyFileNames(); AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions(); bool flag = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic; ArrayList list = BuildNativeMethodList(assemblyDefinitions); if (buildTarget == BuildTarget.iOS) { writer.WriteLine("#include \"RegisterMonoModules.h\""); writer.WriteLine("#include <stdio.h>"); } writer.WriteLine(string.Empty); writer.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR"); writer.WriteLine("\t#define DECL_USER_FUNC(f) void f() __attribute__((weak_import))"); writer.WriteLine("\t#define REGISTER_USER_FUNC(f)\\"); writer.WriteLine("\t\tdo {\\"); writer.WriteLine("\t\tif(f != NULL)\\"); writer.WriteLine("\t\t\tmono_dl_register_symbol(#f, (void*)f);\\"); writer.WriteLine("\t\telse\\"); writer.WriteLine("\t\t\t::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\"); writer.WriteLine("\t\t}while(0)"); writer.WriteLine("#else"); writer.WriteLine("\t#define DECL_USER_FUNC(f) void f() "); writer.WriteLine("\t#if !defined(__arm64__)"); writer.WriteLine("\t#define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)"); writer.WriteLine("\t#else"); writer.WriteLine("\t\t#define REGISTER_USER_FUNC(f)"); writer.WriteLine("\t#endif"); writer.WriteLine("#endif"); writer.WriteLine("extern \"C\"\n{"); writer.WriteLine("\ttypedef void* gpointer;"); writer.WriteLine("\ttypedef int gboolean;"); if (buildTarget == BuildTarget.iOS) { writer.WriteLine("\tconst char*\t\t\tUnityIPhoneRuntimeVersion = \"{0}\";", Application.unityVersion); writer.WriteLine("\tvoid\t\t\t\tmono_dl_register_symbol (const char* name, void *addr);"); writer.WriteLine("#if !defined(__arm64__)"); writer.WriteLine("\textern int\t\t\tmono_ficall_flag;"); writer.WriteLine("#endif"); } writer.WriteLine("\tvoid\t\t\t\tmono_aot_register_module(gpointer *aot_info);"); writer.WriteLine("#if !(__ORBIS__)"); writer.WriteLine("#define DLL_EXPORT"); writer.WriteLine("#else"); writer.WriteLine("#define DLL_EXPORT __declspec(dllexport)"); writer.WriteLine("#endif"); writer.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)"); writer.WriteLine("\textern gboolean\t\tmono_aot_only;"); for (int i = 0; i < assemblyFileNames.Length; i++) { string str = assemblyFileNames[i]; string str2 = assemblyDefinitions[i].Name.Name.Replace(".", "_").Replace("-", "_").Replace(" ", "_"); writer.WriteLine("\textern gpointer*\tmono_aot_module_{0}_info; // {1}", str2, str); } writer.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)"); IEnumerator enumerator = list.GetEnumerator(); try { while (enumerator.MoveNext()) { string current = (string)enumerator.Current; writer.WriteLine("\tDECL_USER_FUNC({0});", current); } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable == null) { } disposable.Dispose(); } writer.WriteLine("}"); writer.WriteLine("DLL_EXPORT void RegisterMonoModules()"); writer.WriteLine("{"); writer.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)"); writer.WriteLine("\tmono_aot_only = true;"); if (buildTarget == BuildTarget.iOS) { writer.WriteLine("\tmono_ficall_flag = {0};", !flag ? "false" : "true"); } foreach (AssemblyDefinition definition in assemblyDefinitions) { string str4 = definition.Name.Name.Replace(".", "_").Replace("-", "_").Replace(" ", "_"); writer.WriteLine("\tmono_aot_register_module(mono_aot_module_{0}_info);", str4); } writer.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)"); writer.WriteLine(string.Empty); if (buildTarget == BuildTarget.iOS) { IEnumerator enumerator2 = list.GetEnumerator(); try { while (enumerator2.MoveNext()) { string str5 = (string)enumerator2.Current; writer.WriteLine("\tREGISTER_USER_FUNC({0});", str5); } } finally { IDisposable disposable2 = enumerator2 as IDisposable; if (disposable2 == null) { } disposable2.Dispose(); } } writer.WriteLine("}"); writer.WriteLine(string.Empty); AssemblyDefinition unityEngine = null; for (int j = 0; j < assemblyFileNames.Length; j++) { if (assemblyFileNames[j] == "UnityEngine.dll") { unityEngine = assemblyDefinitions[j]; } } if (buildTarget == BuildTarget.iOS) { AssemblyDefinition[] assemblies = new AssemblyDefinition[] { unityEngine }; GenerateRegisterInternalCalls(assemblies, writer); ResolveDefinedNativeClassesFromMono(assemblies, usedClassRegistry); ResolveReferencedUnityEngineClassesFromMono(assemblyDefinitions, unityEngine, usedClassRegistry); GenerateRegisterModules(usedClassRegistry, writer, stripping); if (stripping && (usedClassRegistry != null)) { GenerateRegisterClassesForStripping(usedClassRegistry, writer); } else { GenerateRegisterClasses(usedClassRegistry, writer); } } writer.Close(); } }
static public bool CrossCompileAOTDirectoryParallel(string crossCompilerPath, BuildTarget buildTarget, CrossCompileOptions crossCompileOptions, string sourceAssembliesFolder, string targetCrossCompiledASMFolder, string additionalOptions) { sourceAssembliesFolder = Path.Combine(Directory.GetCurrentDirectory(), sourceAssembliesFolder); targetCrossCompiledASMFolder = Path.Combine(Directory.GetCurrentDirectory(), targetCrossCompiledASMFolder); // Generate AOT Files (using OSX cross-compiler) int workerThreads = 1; int completionPortThreads = 1; ThreadPool.GetMaxThreads(out workerThreads, out completionPortThreads); List <JobCompileAOT> jobList = new List <JobCompileAOT>(); List <ManualResetEvent> eventList = new List <ManualResetEvent>(); bool success = true; var dllList = new List <string>(Directory.GetFiles(sourceAssembliesFolder) .Where(path => Path.GetExtension(path) == ".dll")); int numFiles = dllList.Count; int numFinished = 0; DisplayAOTProgressBar(numFiles, numFinished); long timeout = System.Math.Min(30 * 1000 * 60, (numFiles + 3) * 1000 * 30); // 30 minute limit in case of FOOBARs, 30 seconds for each file foreach (string fileName in dllList) { // Cross AOT compile string inputPath = Path.GetFileName(fileName); string outputPath = Path.Combine(targetCrossCompiledASMFolder, inputPath + ".s"); JobCompileAOT job = new JobCompileAOT(buildTarget, crossCompilerPath, sourceAssembliesFolder, crossCompileOptions, inputPath, outputPath, additionalOptions); jobList.Add(job); eventList.Add(job.m_doneEvent); ThreadPool.QueueUserWorkItem(job.ThreadPoolCallback); if (eventList.Count >= Environment.ProcessorCount) { success = WaitForBuildOfFile(eventList, ref timeout); DisplayAOTProgressBar(numFiles, numFinished); numFinished += 1; if (!success) { break; } } } while (eventList.Count > 0) { success = WaitForBuildOfFile(eventList, ref timeout); DisplayAOTProgressBar(numFiles, numFinished); numFinished += 1; if (!success) { break; } } foreach (var job in jobList) { if (job.m_Exception != null) { Debug.LogErrorFormat("Cross compilation job {0} failed.\n{1}", job.m_input, job.m_Exception); success = false; } } return(success); }
public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker) { using (TextWriter output = (TextWriter) new StreamWriter(file)) { string[] assemblyFileNames = checker.GetAssemblyFileNames(); AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions(); bool flag = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic; ArrayList arrayList = MonoAOTRegistration.BuildNativeMethodList(assemblyDefinitions); if (buildTarget == BuildTarget.iOS) { output.WriteLine("#include \"RegisterMonoModules.h\""); output.WriteLine("#include <stdio.h>"); } output.WriteLine(string.Empty); output.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR"); output.WriteLine(" #define DECL_USER_FUNC(f) void f() __attribute__((weak_import))"); output.WriteLine(" #define REGISTER_USER_FUNC(f)\\"); output.WriteLine(" do {\\"); output.WriteLine(" if(f != NULL)\\"); output.WriteLine(" mono_dl_register_symbol(#f, (void*)f);\\"); output.WriteLine(" else\\"); output.WriteLine(" ::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\"); output.WriteLine(" }while(0)"); output.WriteLine("#else"); output.WriteLine(" #define DECL_USER_FUNC(f) void f() "); output.WriteLine(" #if !defined(__arm64__)"); output.WriteLine(" #define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)"); output.WriteLine(" #else"); output.WriteLine(" #define REGISTER_USER_FUNC(f)"); output.WriteLine(" #endif"); output.WriteLine("#endif"); output.WriteLine("extern \"C\"\n{"); output.WriteLine(" typedef void* gpointer;"); output.WriteLine(" typedef int gboolean;"); if (buildTarget == BuildTarget.iOS) { output.WriteLine(" const char* UnityIPhoneRuntimeVersion = \"{0}\";", (object)Application.unityVersion); output.WriteLine(" void mono_dl_register_symbol (const char* name, void *addr);"); output.WriteLine("#if !defined(__arm64__)"); output.WriteLine(" extern int mono_ficall_flag;"); output.WriteLine("#endif"); } output.WriteLine(" void mono_aot_register_module(gpointer *aot_info);"); output.WriteLine("#if __ORBIS__ || SN_TARGET_PSP2"); output.WriteLine("#define DLL_EXPORT __declspec(dllexport)"); output.WriteLine("#else"); output.WriteLine("#define DLL_EXPORT"); output.WriteLine("#endif"); output.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)"); output.WriteLine(" extern gboolean mono_aot_only;"); for (int index = 0; index < assemblyFileNames.Length; ++index) { string str1 = assemblyFileNames[index]; string str2 = ((AssemblyNameReference)assemblyDefinitions[index].get_Name()).get_Name().Replace(".", "_").Replace("-", "_").Replace(" ", "_"); output.WriteLine(" extern gpointer* mono_aot_module_{0}_info; // {1}", (object)str2, (object)str1); } output.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)"); foreach (string str in arrayList) { output.WriteLine(" DECL_USER_FUNC({0});", (object)str); } output.WriteLine("}"); output.WriteLine("DLL_EXPORT void RegisterMonoModules()"); output.WriteLine("{"); output.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)"); output.WriteLine(" mono_aot_only = true;"); if (buildTarget == BuildTarget.iOS) { output.WriteLine(" mono_ficall_flag = {0};", !flag ? (object)"false" : (object)"true"); } foreach (AssemblyDefinition assemblyDefinition in assemblyDefinitions) { string str = ((AssemblyNameReference)assemblyDefinition.get_Name()).get_Name().Replace(".", "_").Replace("-", "_").Replace(" ", "_"); output.WriteLine(" mono_aot_register_module(mono_aot_module_{0}_info);", (object)str); } output.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)"); output.WriteLine(string.Empty); if (buildTarget == BuildTarget.iOS) { foreach (string str in arrayList) { output.WriteLine(" REGISTER_USER_FUNC({0});", (object)str); } } output.WriteLine("}"); output.WriteLine(string.Empty); AssemblyDefinition unityEngine = (AssemblyDefinition)null; for (int index = 0; index < assemblyFileNames.Length; ++index) { if (assemblyFileNames[index] == "UnityEngine.dll") { unityEngine = assemblyDefinitions[index]; } } if (buildTarget == BuildTarget.iOS) { AssemblyDefinition[] assemblies = new AssemblyDefinition[1] { unityEngine }; MonoAOTRegistration.GenerateRegisterInternalCalls(assemblies, output); MonoAOTRegistration.ResolveDefinedNativeClassesFromMono(assemblies, usedClassRegistry); MonoAOTRegistration.ResolveReferencedUnityEngineClassesFromMono(assemblyDefinitions, unityEngine, usedClassRegistry); MonoAOTRegistration.GenerateRegisterModules(usedClassRegistry, output, stripping); if (stripping && usedClassRegistry != null) { MonoAOTRegistration.GenerateRegisterClassesForStripping(usedClassRegistry, output); } else { MonoAOTRegistration.GenerateRegisterClasses(usedClassRegistry, output); } } output.Close(); } }
private static void CompileAll(string inputDirectory, string outputDirectory) { Directory.CreateDirectory(outputDirectory); IEnumerable <string> files = Directory.EnumerateFiles(inputDirectory); var shaderSets = from path in files let vert = path.EndsWith("vert") let frag = path.EndsWith("frag") where vert || frag let name = Path.GetFileNameWithoutExtension(path) group(path, vert, frag) by name into g where g.Count() == 2 select new { Name = g.Key, Vertex = g.FirstOrDefault(x => x.vert).path, Fragment = g.FirstOrDefault(x => x.frag).path, }; foreach (var shaderSet in shaderSets) { string outputBase = Path.Combine(outputDirectory, shaderSet.Name); byte[] vs = File.ReadAllBytes(shaderSet.Vertex); byte[] fs = File.ReadAllBytes(shaderSet.Fragment); string vsSource = Encoding.UTF8.GetString(vs); string fsSource = Encoding.UTF8.GetString(fs); var debugCompileOptions = new GlslCompileOptions(debug: true); var vsSpvDebugOutput = SpirvCompilation.CompileGlslToSpirv( vsSource, string.Empty, ShaderStages.Vertex, debugCompileOptions); var fsSpvDebugOutput = SpirvCompilation.CompileGlslToSpirv( fsSource, string.Empty, ShaderStages.Fragment, debugCompileOptions); var releaseCompileOptions = new GlslCompileOptions(debug: false); var vsSpvReleaseOutput = SpirvCompilation.CompileGlslToSpirv( vsSource, string.Empty, ShaderStages.Vertex, releaseCompileOptions); var fsSpvReleaseOutput = SpirvCompilation.CompileGlslToSpirv( fsSource, string.Empty, ShaderStages.Fragment, releaseCompileOptions); File.WriteAllBytes(outputBase + "-vertex.450.glsl.spv", vsSpvReleaseOutput.SpirvBytes); File.WriteAllBytes(outputBase + "-fragment.450.glsl.spv", fsSpvDebugOutput.SpirvBytes); var glCompileOptions = new CrossCompileOptions(fixClipSpaceZ: true, invertVertexOutputY: false); var glslResult = SpirvCompilation.CompileVertexFragment( vsSpvDebugOutput.SpirvBytes, fsSpvDebugOutput.SpirvBytes, CrossCompileTarget.GLSL, glCompileOptions); File.WriteAllText(outputBase + "-vertex.330.glsl", glslResult.VertexShader); File.WriteAllText(outputBase + "-fragment.330.glsl", glslResult.FragmentShader); var esslResult = SpirvCompilation.CompileVertexFragment( vsSpvDebugOutput.SpirvBytes, fsSpvDebugOutput.SpirvBytes, CrossCompileTarget.ESSL, glCompileOptions); File.WriteAllText(outputBase + "-vertex.300.glsles", glslResult.VertexShader); File.WriteAllText(outputBase + "-fragment.300.glsles", glslResult.FragmentShader); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { var hlslDebugOutput = SpirvCompilation.CompileVertexFragment( vsSpvDebugOutput.SpirvBytes, fsSpvDebugOutput.SpirvBytes, CrossCompileTarget.HLSL); File.WriteAllText(outputBase + "-vertex.hlsl", hlslDebugOutput.VertexShader); File.WriteAllText(outputBase + "-fragment.hlsl", hlslDebugOutput.FragmentShader); var hlslReleaseOutput = SpirvCompilation.CompileVertexFragment( vsSpvReleaseOutput.SpirvBytes, fsSpvReleaseOutput.SpirvBytes, CrossCompileTarget.HLSL); byte[] vertBytes = Encoding.UTF8.GetBytes(hlslReleaseOutput.VertexShader); byte[] fragBytes = Encoding.UTF8.GetBytes(hlslReleaseOutput.FragmentShader); File.WriteAllBytes(outputBase + "-vertex.hlsl.bytes", CompileHlsl(ShaderStages.Vertex, vertBytes)); File.WriteAllBytes(outputBase + "-fragment.hlsl.bytes", CompileHlsl(ShaderStages.Fragment, fragBytes)); } } }