Fallenwood.PublishAotCross
0.1.1
dotnet add package Fallenwood.PublishAotCross --version 0.1.1
NuGet\Install-Package Fallenwood.PublishAotCross -Version 0.1.1
<PackageReference Include="Fallenwood.PublishAotCross" Version="0.1.1" />
paket add Fallenwood.PublishAotCross --version 0.1.1
#r "nuget: Fallenwood.PublishAotCross, 0.1.1"
// Install Fallenwood.PublishAotCross as a Cake Addin #addin nuget:?package=Fallenwood.PublishAotCross&version=0.1.1 // Install Fallenwood.PublishAotCross as a Cake Tool #tool nuget:?package=Fallenwood.PublishAotCross&version=0.1.1
PublishAotCross
Forked from MichalStrehovsky/PublishAotCross
This is a NuGet package with an MSBuild target to aid in crosscompilation with PublishAot. It helps resolving following error:
$ dotnet publish -r linux-x64
Microsoft.NETCore.Native.Publish.targets(59,5): error : Cross-OS native compilation is not supported.
This nuget package allows using Zig as the linker/sysroot to allow crosscompiling to linux-x64/linux-arm64/linux-musl-x64/linux-musl-arm64 from a Windows/Linux machine.
Usage
Typical Cross build
By default it relies on Zig provided by the unofficial Vezel.Zig.Toolsets NuGet package. You can specify version of this package using the ZigVersion
property. Instructions for using your own Zig binaries are near the end of this document.
If you don't want to use Zig from the Vezel.Zig.Toolsets NuGet package, you can specify /p:UseExternalZig=true
. This will use whatever Zig is on your PATH. Download an archive with Zig for your host machine, extract it and place it on your PATH.
Optional: download LLVM. We only need llvm-objcopy executable so if you care about size, you can delete the rest. The executable needs to be on PATH - you could copy it next to the Zig executable. This step is optional and is required only to strip symbols (make the produced executables smaller). If you don't care about stripping symbols, you can skip it.
To your project that is already using Native AOT, add a reference to this NuGet package.
Publish for one of the newly available RIDs:
dotnet publish -r linux-x64
dotnet publish -r linux-arm64
dotnet publish -r linux-musl-x64
dotnet publish -r linux-musl-arm64
dotnet publish -r linux-musl-arm
(Only works for net >= 9.0)
If you skipped the second optional step to download llvm-objcopy, you must also pass
/p:StripSymbols=false
to the publish command, or you'll see an error instructing you to do that.
Even though Zig allows crosscompiling for Windows as well, it's not possible to crosscompile PublishAot like this due to ABI differences (MSVC vs. MingW ABI).
Use Zig as c compiler on same host
This package auto detects if host and target platforms are different to determine if Zig is used or not. Even though on the same platform, Zig can also be used as the dropped in C Compiler with
dotnet publish -r linux-x64 /p:PublishAot=true /p:AotPreferZig=true
Tested Variants
(Host)Windows x64 | Linux GNU x64 | Linux GNU arm64 | Linux MUSL x64 | Linux MUSL arm64 | |
---|---|---|---|---|---|
(target)Windows x64 | X | X | X | X | X |
Linux GNU x64 | O | O | O | N/A | N/A |
Linux GNU arm64 | O | O | O | N/A | N/A |
Linux MUSL x64 | O | O | O | N/A | N/A |
Linux MUSL arm64 | O | O | O | N/A | N/A |
Linux MUSL arm | N/A | O | N/A | N/A | N/A |
Notes: N/A
means it's might work but not tested.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.