NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.44k stars 13.65k forks source link

[BUG] buildDotnetModule fails to publish with `-p:PublishAot=true` #280923

Open anpin opened 8 months ago

anpin commented 8 months ago

Describe the bug

If a dotnet project contains <PublishAot>true</PublishAot> dotnetInstallHook fails with

  jitinterface_x64.so: cannot open shared object file: No such file or directory
  libjitinterface_x64.so: cannot open shared object file: No such file or directory
  jitinterface_x64: cannot open shared object file: No such file or directory
  libjitinterface_x64: cannot open shared object file: No such file or directory

Steps To Reproduce

nix build github:anpin/dotnet-aot-on-nix#noFix

Expected behavior

Build succeeds

Additional context

The libraries required for publishing are distributed via microsoft.netcore.app.crossgen2.linux-x64 and runtime.linux-x64.microsoft.dotnet.ilcompiler (at least for the x86_64-linux), so adding these paths to LD_LIBRARY_PATH resolves the issue. You can run nix build github:anpin/dotnet-aot-on-nix which would include following snippet. However the build would fail anyway due to the upstream issue which can be reproduced on other linux distributions https://github.com/dotnet/sdk/issues/37995

  postConfigure = ''
    TOOLS="$HOME/.nuget/packages/microsoft.netcore.app.crossgen2.linux-x64/8.0.0/tools/"
    TOOLS="$TOOLS:$HOME/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/tools/"
    export LD_LIBRARY_PATH="$LDLIBRARY_PATH:$TOOLS"
  '';

Notify maintainers

@NixOS/dotnet

Metadata

 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.8, NixOS, 24.05 (Uakari), 24.05.20231227.d97b439`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - channels(a): `"nixpkgs"`
 - channels(root): `"nixos"`
 - nixpkgs: `/home/a/.nix-defexpr/channels/nixpkgs`

Add a :+1: reaction to issues you find important.

mdarocha commented 8 months ago

I think thats fixed in https://github.com/NixOS/nixpkgs/pull/267743 - see https://github.com/NixOS/nixpkgs/pull/267743/commits/ed64607e51e9bb8291eae8aae8f8e24981e3dca0

anpin commented 8 months ago

it is indeed fixed by your PR. thank you!

adamcstephens commented 7 months ago

This issue still exists, as #267743 was never merged.

fsharpplay> /build/tmp.6VlXKrGn82/.nuget/packages/fsharp.core/8.0.101/lib/netstandard2.1/FSharp.Core.dll : warning IL3053: Assembly 'FSharp.Core' produced AOT analysis warnings. [/build/j24rjwk5qbi969kxj17707zx0gjjvnvj-source/fsharpaot.fsproj]
fsharpplay> /build/tmp.6VlXKrGn82/.nuget/packages/fsharp.core/8.0.101/lib/netstandard2.1/FSharp.Core.dll : warning IL2104: Assembly 'FSharp.Core' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries [/build/j24rjwk5qbi969kxj17707zx0gjjvnvj-source/fsharpaot.fsproj]
fsharpplay> EXEC : error : Unable to load shared library 'jitinterface_x64' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable: [/build/j24rjwk5qbi969kxj17707zx0gjjvnvj-source/fsharpaot.fsproj]
fsharpplay>   jitinterface_x64.so: cannot open shared object file: No such file or directory
fsharpplay>   libjitinterface_x64.so: cannot open shared object file: No such file or directory
fsharpplay>   jitinterface_x64: cannot open shared object file: No such file or directory
fsharpplay>   libjitinterface_x64: cannot open shared object file: No such file or directory
fsharpplay>   System.DllNotFoundException: Unable to load shared library 'jitinterface_x64' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable:
anpin commented 7 months ago

I'm pretty sure it works for me. Can you try to generate nugetDeps files using something like this:

dotnet restore some.fsproj --packages packages -p:PublishNativeAot=True -r:linux-x64
nuget-to-nix packages > deps.nix
adamcstephens commented 7 months ago

That's a different restore than I was using, but it doesn't make a difference. Unless I use #267743 the build fails. Here's my reproducer repo: https://codeberg.org/adamcstephens/fsharpplay

anpin commented 7 months ago

I might be using the PR then. Would have to check later.  On Tue, Feb 13, 2024 at 2:20 PM, Adam C. Stephens @.***> wrote:
That's a different restore than I was using, but it doesn't make a difference. Unless I use #267743 the build fails. Here's my reproducer repo: https://codeberg.org/adamcstephens/fsharpplay

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

adamcstephens commented 4 months ago

I opened https://github.com/NixOS/nixpkgs/pull/306161 standalone to see if we can move this forward without the tests.

corngood commented 2 months ago

309409 is my proposed fix for this. If anyone wants to try it out, that would be appreciated.

If anyone has an example of a package in nixpkgs that could benefit from AOT, that would be useful too.