xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.44k stars 507 forks source link

Build failure after adding PackageReference with native dependency due to picking wrong file #20934

Closed AArnott closed 1 month ago

AArnott commented 1 month ago

Steps to Reproduce

  1. Create a new Maui app.
  2. Add a reference to the Nerdbank.Zcash nuget package (0.3.1-beta).
  3. Select an iOS simulator as the debug target (I used "iPhone 15 iOS 17.5").
  4. Hit F5

Expected Behavior

Build succeeds.

Actual Behavior

Build fails.

1>MauiApp1 -> c:\temp\MauiApp1\MauiApp1\bin\Debug\net8.0-ios\iossimulator-arm64\MauiApp1.dll
1>Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
1>Tool xcrun execution finished (exit code = 1).
1>ld: building for iOS Simulator, but linking in dylib built for macOS, file 'obj/Debug/net8.0-ios/iossimulator-arm64/nativelibraries/libnerdbank_zcash_rust.dylib'
1>clang: error: linker command failed with exit code 1 (use -v to see invocation)
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\17.2.8078\targets\Xamarin.Shared.Sdk.targets(1564,3): error : clang++ exited with code 1:
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\17.2.8078\targets\Xamarin.Shared.Sdk.targets(1564,3): error : ld: building for iOS Simulator, but linking in dylib built for macOS, file 'obj/Debug/net8.0-ios/iossimulator-arm64/nativelibraries/libnerdbank_zcash_rust.dylib'
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\17.2.8078\targets\Xamarin.Shared.Sdk.targets(1564,3): error : clang: error: linker command failed with exit code 1 (use -v to see invocation)
1>Done building project "MauiApp1.csproj" -- FAILED.

Environment

Version information Microsoft Visual Studio Enterprise 2022 Version 17.10.1 VisualStudio.17.Release/17.10.1+34928.147 Microsoft .NET Framework Version 4.8.09032 Installed Version: Enterprise Visual C++ 2022 00476-80000-00000-AA738 Microsoft Visual C++ 2022 ASP.NET and Web Tools 17.10.338.1105 ASP.NET and Web Tools AvaloniaPackage Extension 1.0 AvaloniaPackage Visual Studio Extension Detailed Info Azure App Service Tools v3.0.0 17.10.338.1105 Azure App Service Tools v3.0.0 Azure Functions and Web Jobs Tools 17.10.338.1105 Azure Functions and Web Jobs Tools C# Tools 4.10.0-3.24270.2+e8f775c1d8a73dee7ad02408712d714251e708ea C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools. Extensibility Message Bus 1.4.39 (main@e8108eb) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration. GitHub Copilot 0.2.889.30432 GitHub Copilot is an AI pair programmer that helps you write code faster and with less work. Microsoft Azure Tools for Visual Studio 2.9 Support for Azure Cloud Services projects Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines Mono Debugging for Visual Studio 17.10.8 (a565b86) Support for debugging Mono processes with Visual Studio. NuGet Package Manager 6.10.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/ Project System Tools 1.0 Tools for working with C#, VisualBasic, and F# projects. Razor (ASP.NET Core) 17.10.3.2427201+4f57d1de251e654812adde201c0265a8ca7ca31d Provides languages services for ASP.NET Core Razor. ResX Resource Manager ResXManager Manage localization of all ResX-based resources in one place. Shows all resources of a solution and lets you edit the strings and their localizations in a well-arranged data grid. SQL Server Data Tools 17.10.171.4 Microsoft SQL Server Data Tools Test Adapter for Boost.Test 1.0 Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory. Test Adapter for Google Test 1.0 Enables Visual Studio's testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory. TypeScript Tools 17.0.30327.2001 TypeScript Tools for Microsoft Visual Studio Visual Basic Tools 4.10.0-3.24270.2+e8f775c1d8a73dee7ad02408712d714251e708ea Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Visual F# Tools 17.10.0-beta.24228.1+dd749058c91585e9b5dae62b0f8df892429ee28f Microsoft Visual F# Tools Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio. VisualStudio.DeviceLog 1.0 Information about my package VisualStudio.Mac 1.0 Mac Extension for Visual Studio Xamarin 17.10.0.110 (main@cf2e960) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android. Xamarin Designer 17.10.3.10 (remotes/origin/d17-10@3beef58f89) Visual Studio extension to enable Xamarin Designer tools in Visual Studio. Xamarin.Android SDK 13.2.2.0 (d17-5/45b0e14) Xamarin.Android Reference Assemblies and MSBuild support. Mono: d9a6e87 Java.Interop: xamarin/java.interop/d17-5@149d70fe SQLite: xamarin/sqlite/3.40.1@68c69d8 Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d

Build Logs

MauiApp1_Debug_AnyCPU_net8.0-ios_Build_2024-07-23T08_22_10.8891218-06_00.zip

Example Project (If Possible)

MauiApp1.zip

AArnott commented 1 month ago

Consider the crux of the error message:

building for iOS Simulator, but linking in dylib built for macOS

This suggests that the wrong native .dylib was picked up by the build. The Nerdbank.Zcash package contains a runtimes folder with the following options:

android-arm64
android-x64
ios-arm64
linux-arm64
linux-x64
osx-arm64
osx-x64
win-arm64
win-x64

Given we're building for the iOS simulator, ios-arm64 would be the appropriate choice. This in particular because my mac mini uses Apple silicone, so it is in fact running an arm64 simulator (not an x64 one). But based on the error message, it appears that the build chose one of the osx-* options.

AArnott commented 1 month ago

Hang on... there might actually be a packing bug in nerdbank.zcash. Tracking that down.