dotnet / dotnet/sdk

IncludeNativeLibrariesForSelfExtract not working with newer libsodium binaries for osx/linux-musl

Open
#45,903 7 comments 3 reactions 0 assignees View on GitHub
area-Single-File untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Describe the bug
As discussed [here](https://github.com/jedisct1/libsodium/issues/1437), publishing a single-file application for `osx-x64`/`osx-arm64` with `-p:IncludeNativeLibrariesForSelfExtract=true` doesn't embed `libsodium.dylib` in the executable as of v1.0.19.1+ of the [libsodium NuGet package](https://www.nuget.org/packages/libsodium/). The same issue occurs with `libsodium.a` for `linux-musl-x64`/`linux-musl-arm64`. This wasn't a problem with v1.0.19. `win-x64`, `win-x86`, `win-arm64`, `linux-x64`, `linux-arm64`, and `linux-arm` don't seem to be affected.

As it's unclear why this is happening, I'm opening an issue here to try and get some help from .NET maintainers.

### To reproduce
1. Download the latest [.NET 8 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) installer.
2. Create a folder to house the project and navigate to it in the terminal.
3. Create a [new console project](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-new) with `dotnet new console --framework net8.0`.
4. [Install](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-add-package) the [libsodium NuGet package](https://www.nuget.org/packages/libsodium) with `dotnet add package libsodium --version 1.0.19.1`.
5. Do a self-contained, single-file [publish](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish) for macOS with `dotnet publish -c Release -r osx-x64 -p:PublishSingleFile=true -p:PublishTrimmed=true -p:PublishReadyToRun=true -p:IncludeNativeLibrariesForSelfExtract=true --self-contained true`. The extra options are just what I normally use.
6. Navigate to the printed path (`bin\Release\net8.0\osx-x64\publish\`), and you'll see there's a `libsodium.dylib` file.
7. Delete the files in this folder and return to the original project directory.
8. Change the libsodium package version with `dotnet add package libsodium --version 1.0.19`.
9. Use `dotnet publish` again as before.
10. Navigate to the printed path again, and you'll see there's no `libsodium.dylib` file. This is what you want.

### Further technical details
Tried on a Windows machine with the latest .NET 8/9 SDKs and on a macOS machine with the latest .NET 8 SDK.

```
.NET SDK:
Version: 9.0.101
Commit: eedb237549
Workload version: 9.0.100-manifests.3068a692
MSBuild version: 17.12.12+1cce77968

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.101\

.NET workloads installed:
There are no installed workloads to display.
Configured to use loose manifests when installing new manifests.

Host:
Version: 9.0.0
Architecture: x64
Commit: 9d5a6a9aa4

.NET SDKs installed:
8.0.404 [C:\Program Files\dotnet\sdk]
9.0.101 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
None

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.