_some prog with dynamic linking perhaps
Some checks failed
Build Android / Game (Android, Release ARM64) (push) Has been cancelled
Build iOS / Game (iOS, Release ARM64) (push) Has been cancelled
Build Linux / Editor (Linux, Development x64) (push) Has been cancelled
Build Linux / Game (Linux, Release x64) (push) Has been cancelled
Build macOS / Editor (Mac, Development ARM64) (push) Has been cancelled
Build macOS / Game (Mac, Release ARM64) (push) Has been cancelled
Build Windows / Editor (Windows, Development x64) (push) Has been cancelled
Build Windows / Game (Windows, Release x64) (push) Has been cancelled
Cooker / Cook (Mac) (push) Has been cancelled
Tests / Tests (Linux) (push) Has been cancelled
Tests / Tests (Windows) (push) Has been cancelled

This commit is contained in:
2026-03-15 22:45:36 +02:00
parent 1ff4ac0402
commit 8cf6979f90
6 changed files with 121 additions and 13 deletions

View File

@@ -2,6 +2,7 @@
using Mono.Cecil;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -420,7 +421,18 @@ namespace Flax.Build
rmdir /S /Q %command%
"""
);
/*Utilities.WriteFileIfChanged(Path.Combine(Path.GetDirectoryName(inputFiles[0]), "rm.bat"),
"""
@echo off
setlocal enabledelayedexpansion
set command=%*
set command=!command:~3!
del /F /Q /S %command%
rmdir /S /Q %command%
"""
);*/
ConcurrentBag<string> outputStaticLibraryFiles = new ();
var compileAssembly = (string assemblyPath) =>
{
//if (!assemblyPath.Contains("Newtonsoft"))
@@ -493,8 +505,9 @@ namespace Flax.Build
// Copy AOT build products
foreach (var outputFile in options.OutputFiles)
{
outputStaticLibraryFiles.Add(outputFile);
// Skip if deployed file is already valid
var deployedFilePath = Path.Combine(dotnetOutputPath, Path.GetFileName(outputFile));
/*var deployedFilePath = Path.Combine(dotnetOutputPath, Path.GetFileName(outputFile));
if (!File.Exists(deployedFilePath) || File.GetLastWriteTime(outputFile) > File.GetLastWriteTime(deployedFilePath))
{
// Copy to the destination folder
@@ -502,7 +515,7 @@ namespace Flax.Build
if (useDebug && File.Exists(outputFile + ".pdb"))
Utilities.FileCopy(outputFile + ".pdb", Path.Combine(dotnetOutputPath, Path.GetFileName(outputFile + ".pdb")));
validCache = false;
}
}*/
}
}
else
@@ -554,6 +567,65 @@ namespace Flax.Build
throw new Exception("Mono AOT failed to link static libraries into a shared module");
}
}
else if (Configuration.AOTMode == DotNetAOTModes.MonoAOTDynamic)
{
var linkAssembly = (string outputFile) =>
{
Log.Info("");
Log.Warning(" " + Path.GetFileNameWithoutExtension(outputFile));
Log.Info("");
// Get output file path for this assembly (platform can use custom extension)
var options = new Toolchain.CSharpOptions
{
Action = Toolchain.CSharpOptions.ActionTypes.MonoLink,
InputFiles = [Path.Combine(Path.GetDirectoryName(outputFile), Path.GetFileNameWithoutExtension(outputFile))],
OutputFiles = [outputFile],
AssembliesPath = aotAssembliesPath,
//ClassLibraryPath = dotnetLibPath,
PlatformToolsPath = Path.GetDirectoryName(outputFile),
//EnableDebugSymbols = useDebug,
//EnableToolDebug = dotnetAotDebug,
};
if (!File.Exists(outputFile) && buildToolchain.CompileCSharp(ref options))
{
Log.Error("Failed to run linker on assembly " + outputFile);
failed = true;
return;
}
// Skip if deployed file is already valid
var deployedFilePath = Path.Combine(dotnetOutputPath, Path.GetFileName(outputFile));
if (!File.Exists(deployedFilePath) || File.GetLastWriteTime(outputFile) > File.GetLastWriteTime(deployedFilePath))
{
// Copy to the destination folder
Utilities.FileCopy(outputFile, deployedFilePath);
if (/*useDebug &&*/ File.Exists(outputFile + ".pdb"))
Utilities.FileCopy(outputFile + ".pdb", Path.Combine(dotnetOutputPath, Path.GetFileName(outputFile + ".pdb")));
validCache = false;
}
};
// Run final linking with single-threaded as this is very memory intensive process
if (Configuration.MaxConcurrency > 1 && Configuration.ConcurrencyProcessorScale > 0.0f && !dotnetAotDebug)
{
// Multi-threaded
var outputFiles = outputStaticLibraryFiles.OrderBy(x => x.Contains("System.Private.CoreLib") || x.Contains("System.Linq") || x.Contains("System.Private.Xml") ? 0 : 1).ToArray(); // Process the file which takes longest time first
System.Threading.Tasks.Parallel.ForEach(outputFiles/*, new System.Threading.Tasks.ParallelOptions() { MaxDegreeOfParallelism = Math.Min(8, Configuration.MaxConcurrency) }*/, linkAssembly);
}
else
{
foreach (var outputFile in outputStaticLibraryFiles)
{
linkAssembly(outputFile);
if (failed)
break;
}
}
if (failed)
throw new Exception($"Failed to run AOT. See log ({Configuration.LogFile}).");
}
}
else
{