ericsink / SQLitePCL.raw

A Portable Class Library (PCL) for low-level (raw) access to SQLite
Apache License 2.0
512 stars 106 forks source link

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

Open rdavisau opened 1 year ago

rdavisau commented 1 year ago

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 commented 1 year ago

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.

ericsink commented 1 year ago

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

ericsink commented 1 year ago

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

ericsink commented 1 year ago

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

rdavisau commented 1 year ago

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!

filipnavara commented 1 year ago

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

smacpherson-ces commented 8 months ago

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

bmacombe commented 6 months ago

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.