-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Support for SelfContainedDeployment [SCD] for executable projects #29
Comments
Darn it, this was itching my brain too much for what/where the key MSBuild/CLR function to abuse/learn from is since I've had to deal with it before, and is basically the starting point for "you have a assembly from ILASM, now you want an executable, be it self-contained, R2R, or framework dependant, here is where it is weaved into a template". So I dug that back up to be roughly here: https://github.com/dotnet/runtime/blob/main/src/installer/managed/Microsoft.NET.HostModel/AppHost/HostWriter.cs#L36 That (in theory) if you can find the Apphost Template for self-contained runtime, you should be able to weave/find-replace the magic string with the desired raw assembly binary content, re-copy all the resources, set execute bits etc as that function call does and in theory there you go. In theory. Is it a goal to not require a CLR/Dotnet SDK installed? Or can we depend on a valid (modern aka net-core 6+) SDK on the developers machine/CI/build agents etc? If we can depend on existing dotnet SDK, whipping up/abusing deep calls into either the HostModel tools or preferably custom MSBuild target(s) to then do the final weaving may not be too hard? And would give advantage of all the ready-2-run AoT etc tooling (even though quite silly for Rust!) |
The project currently expects there to be at least some parts of the .NET SDK( SCD could be done by the projects "linker". Besides joining intermediate files, it is also responsible for assembling the final executable using AOT could be beneficial. Currently, the project emits only pure-IL assemblies. This could be changed in the far future, but until then, enabling AOT could yield some serious performance improvements. AOT could also improve testing: due to the lazy nature of the JIT (methods are compiled as needed), a method with invalid CIL can slip through all the tests, if it is not invoked ( |
On requiring the DotNet SDK: that is fair and makes sense, though wouldn't that mean a user could compile but then not run the code? Hrm, that would be more akin to cross-compilation/wasm/etc so maybe that is fair. Was just mostly thinking that relying on the SDK could mean far less custom code on your side especially with linking/packaging/weaving/etc the final assembly. Those while not easy to do outside MSBuild targets, are certainly doable. On SCD: My thought was to consider always doing so (for executable crates/targets), and having the Though a challenge with any of these paths is either auto-installing/extracting the few specific SDK tools (all the AppHost bundles to weave into, CrossGen2 and AoT tools, etc) or just has to require a compatible SDK be installed. On AoT/R2R: oh that is a thought and trick, using that to force the CLR to fully parse every single thing of your CIL and (kinda) validate it, at least far more than |
Why do you think AOT is nearly impossible without MSbuild tasks? Currently it is mostly gathering required dependencies and passing it to ILC which do the magic. If you ever want, you can call it yourself. If you take a look at AOT targets in SDK there no task for ILc itself, only for finding runtime packages, but that’s anyway required for all packaging options. my point is that AOT approximately same complexity as other targets if codegen is appropriate |
AOT: Not impossible, just exceedingly annoying since in theory you will also likely want to pass it to R2R first, to build out all the arguments/parameters as required. My understanding is that the arguments are not stable SDK version to SDK version for either, and the only officially-unofficially not-supported but recommended-if-you-have-to method is building the arguments lists via MSBuild tasks+targets. |
The arguments are stable. We have been using R2R and NativeAOT on godbolt (compiler explorer) to generate binary for disasm, it never breaks since the day one we introduced it (since .NET 6). And we are passing arguments to the compiler directly without using MSBuild. |
As part of back and forth on a recent reddit thread where you got cargo integration (sort of) working by wrapping a shell script to
dotnet run %foo%.exe
the real assembly, I had pondered about a future state where if the rust project is a executable you by-default run the Self Contained Deployment MSBuild tasks/target(s) to weave the final assembly into an actual ELF or PE.I am not entirely sure where/what step this would take place at, nor off-hand the exact magical incantations desired to re-weave an existing CLR assembly to say ELF via MSBuild (or other dotnet API), but this would solve a few of the integration issues of this project into normal
cargo
flows. Note thatlib
anddylib
etc projects could remain plain CLR assemblies, this would just be a thing for anything executable (or testable, etc).I intended to poke-with-a-stick this idea in a few months, but also thought at least writing this down in case you or someone else gets inspired to try it out. I may be able to provide guidance here-and-there, I am far more familiar with the CLR/MSBuild side of the tooling world than rustc/cargo.
The text was updated successfully, but these errors were encountered: