SQLitePCL.raw icon indicating copy to clipboard operation
SQLitePCL.raw copied to clipboard

`clang` error when building with `-r iossimulator-arm64`

Open rdavisau opened this issue 2 years ago • 8 comments

When trying to use sqlite on an apple silicon, attempting to build for iossimulator-arm64 fails with

ld: in <path_to>/linker_cache/e_sqlite3.a(sqlite3.o), building for iOS Simulator, 
but linking in object file built for iOS, file '<path_to>/linker_cache/e_sqlite3.a'

To reproduce:

dotnet new ios -o test-ios-sql
dotnet add test-ios-sql package SQLitePCLRaw.bundle_e_sqlite3
dotnet build test-ios-sql -r iossimulator-arm64

Full output:

MSBuild version 17.4.1+9a89d02ff for .NET
  Determining projects to restore...
  Restored /Users/rdavis/Source/testios/test-ios-sql/test-ios-sql.csproj (in 110 ms).
/usr/local/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(1142,5): warning NETSDK1179: One of '--self-contained' or '--no-self-contained' options are required when '--runtime' is used. [/Users/rdavis/Source/testios/test-ios-sql/test-ios-sql.csproj]
  Detected signing identity:
          
    Bundle Id: com.companyname.test_ios_sql
    App Id: com.companyname.test_ios_sql
  test-ios-sql -> /Users/rdavis/Source/testios/test-ios-sql/bin/Debug/net7.0-ios/iossimulator-arm64/test-ios-sql.dll
  Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
  Optimizing assemblies for size. This process might take a while.
  Tool xcrun execution finished (exit code = 1).
          
  ld: in /Users/rdavis/Source/testios/test-ios-sql/obj/Debug/net7.0-ios/iossimulator-arm64/linker-cache/e_sqlite3.a(sqlite3.o), building for iOS Simulator, but linking in object file built for iOS, file '/Users/rdavis/Source/testios/test-ios-sql/obj/Debug/net7.0-ios/iossimulator-arm64/linker-cache/e_sqlite3.a'
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  
/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/16.2.1007/targets/Xamarin.Shared.Sdk.targets(1225,3): error : clang++ exited with code 1: [/Users/rdavis/Source/testios/test-ios-sql/test-ios-sql.csproj]
/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/16.2.1007/targets/Xamarin.Shared.Sdk.targets(1225,3): error : ld: in /Users/rdavis/Source/testios/test-ios-sql/obj/Debug/net7.0-ios/iossimulator-arm64/linker-cache/e_sqllite3.a(sqlite3.o), building for iOS Simulator, but linking in object file built for iOS, file '/Users/rdavis/Source/testios/test-ios-sql/obj/Debug/net7.0-ios/iossimulator-arm64/linker-cache/e_sqllite3.a' [/Users/rdavis/Source/testios/test-ios-sql/test-ios-sql.csproj]
/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/16.2.1007/targets/Xamarin.Shared.Sdk.targets(1225,3): error : clang: error: linker command failed with exit code 1 (use -v to see invocation) [/Users/rdavis/Source/testios/test-ios-sql/test-ios-sql.csproj]

Build FAILED.

dotnet build test-ios-sql -r iossimulator-x64 works ok.

dotnet --version 7.0.102

(Verified that it affects sqlite3 (not just sqlcipher) and updated the issue.)

rdavisau avatar Feb 21 '23 04:02 rdavisau

Totally out of my depth but I suppose that here we need to at least add arm64 to the simulator architectures. There might also need to be some extra shenanigans - I saw this commentary about not mixing platforms; I am not smart enough to work out whether we are already doing what needs to be done here, or if things have just been ok up till now due to no overlapping architectures.

rdavisau avatar Feb 22 '23 03:02 rdavisau

The absence of arm64 in that simulator arch list does look wrong. I'll take a look at fixing this.

ericsink avatar Feb 23 '23 15:02 ericsink

Progress on this has been made by @filipnavara in ericsink/cb#14

ericsink avatar May 16 '23 00:05 ericsink

@filipnavara The new pre-release (2.1.5-pre20230516213315) should contain the iOS arm64 simulator changes. Does it work for you?

ericsink avatar May 17 '23 00:05 ericsink

I'm not Filip, but the updated repro

dotnet new ios -o test-ios-sql
dotnet add test-ios-sql package SQLitePCLRaw.bundle_e_sqlite3 -v 2.1.5-pre20230516213315
dotnet build test-ios-sql -r iossimulator-arm64

works for me.

I can also now build arm64 simulator in another established project that's using bundle_e_sqlcipher with the latest preview of that. Great stuff both!

rdavisau avatar May 17 '23 03:05 rdavisau

I tested 2.1.5-pre20230516213315 on our MAUI project and it works just fine with iossimulator-x64 and iossimulator-arm64.

filipnavara avatar May 19 '23 15:05 filipnavara

thankyou thankyou everyone. Please consider making 2.1.5 the minimum version for sqlite-net-cipher as well.

smacpherson-ces avatar Oct 11 '23 06:10 smacpherson-ces

FYI, it appears the green bundle still has this issue in 2.1.7. I switched to SQLitePCLRaw.bundle_e_sqlite3 and was able to compile and deploy to an iOS sim on an M1.

In a Maui app.

bmacombe avatar Dec 28 '23 14:12 bmacombe