-
-
Notifications
You must be signed in to change notification settings - Fork 512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AOT Support #1332
Comments
FYI I used the following to get this project to work with AOT: Create some file (e.g. MyRoots.xml) with the following content (substitute MyAssembly with your assembly name): <linker>
<assembly fullname="MyAssembly" />
<assembly fullname="Spectre.Console.Cli">
<type fullname="Spectre.Console.Cli.ExplainCommand" />
<type fullname="Spectre.Console.Cli.XmlDocCommand" />
<type fullname="Spectre.Console.Cli.VersionCommand" />
</assembly>
</linker> This makes sure that all the reflected commands needed don't get trimmed out. Then make use of it in your csproj: <ItemGroup>
<TrimmerRootDescriptor Include="MyRoots.xml" />
</ItemGroup> |
Hmm.... things seemed to be working for me. I was just interested in cleaning up the warnings, but your answer now makes me wonder if some things are broken that i didn't catch. I'll have to take another look |
The project I am working on is here on GitHub so if you are interested in seeing if you see what I see then I can push what I discovered up into the repo (https://github.com/borrrden/Spectre.Net). Coincidentally the project started as a port of a separate unrelated project also called Spectre and then I remembered that this repo existed and thought it was poetic. |
There are still a few more issues I am having with AOT:
|
An alternative to the xml file mentioned by @borrrden that worked for me is to use the [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(DiffCommand))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(DiffCommandSettings))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, "Spectre.Console.Cli.ExplainCommand", "Spectre.Console.Cli")]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, "Spectre.Console.Cli.VersionCommand", "Spectre.Console.Cli")]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, "Spectre.Console.Cli.XmlDocCommand", "Spectre.Console.Cli")]
private static int Main(string[] args)
{
} |
@andwi Would you happen to know anything about my enum situation? 😄 |
Sorry no, my application has not used any enum values so I have not encountered that |
build using `dotnet publish -r linux-amd64 -c Release` test with `bin/Release/net8.0/linux-x64/fsharp-spectre-console-template greet -n John` based on spectreconsole/spectre.console#1332 (comment)
I use CommandApp and AppSettings in my application.
and it seems to work just fine, however, I get the following warnings.
|
Anyone else get the error
not only do i get trim warnings but the app commands dont want to run because this explain command (which im assuming is the builtin command that polls your custom commands) wont work. Ps. works fine without AOT. so im assuming something is going wrong with the assemblies loaded |
FYI in the base |
Yup. Just waiting for someone who wants it enough to send a PR 🙂 |
Hopefully someone with some AOT library knowledge can hop on this quickly! |
@patriksvensson I can take this issue, I've done something similar in the past. |
You're a legend mate, good luck. Ill be watching closely |
@patriksvensson For most of the updates we would need to use tooling added in .net7. It also will likely require #if NET7_0_OR_GREATER etc in order to maintain support for AOT for .NET 7,8,9 while also supporting netstandard and net6. Would this work for you? For example
|
No, things like that would be a pain to maintain. NET7 support could be removed though since it's end of life. |
@BlazeFace You could make more targeted changes: public static List<string> GetMarkupNames(Decoration decoration)
{
var result = new List<string>();
var decorationValues =
#if NET5_0_OR_GREATER
Enum.GetValues<Decoration>();
#else
Enum.GetValues(typeof(Decoration)).Cast<Decoration>();
#endif
decorationValues
.Where(flag => (decoration & flag) != 0)
.ForEach(flag =>
{
if (flag != Decoration.None && _reverseLookup.TryGetValue(flag, out var name))
{
result.Add(name);
}
});
return result;
} |
@phil-scott-78 Thanks, that helps a lot! |
I ran into a brick wall of responsibilities that was a large part of the reason that PR languished, but the reality is I think to do this in a manner that would be acceptable to users and maintainers is gonna involve a major rewrite after the 1.0 release with some breaking changes along with a source generator to tie the the user code together. I think it's a very worthy undertaking, but here be dragons |
@phil-scott-78 Agreed, after looking over the thread I see exactly what you are mentioning. Very happy to help! Would we be ok with just the console project AOT compatible while Spectre CLI support coming later? |
I think the main focus right now should be the Console support just so we can make TUI Apps for consoles in a minimal way with AOT, the cli would be handy too but for now users can just make their own parser for command line arguments so Cli doesnt necessarily have to work on aot yet. |
Is your feature request related to a problem? Please describe.
This library actually works in the context of native code generation (AOT), but it produces a compiler warning (which makes me suspect there are some features in this library that would not work from an AOT perspective.
Describe the solution you'd like
Would love to see this library run cleanly in an AOT build (AOT seems like a primary candidate for a library like this to create multi-platform commandline tools that do not rely on the dotnet framework being installed.
Describe alternatives you've considered
None
Additional context
Please upvote 👍 this issue if you are interested in it.
The text was updated successfully, but these errors were encountered: