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

Unable to use SQLitePCLRaw.bundle_zetetic prerelease in Maui app #481

Closed sjlombardo closed 2 years ago

sjlombardo commented 2 years ago

We're in the process of testing SQLCipher integrations under Maui using the recent prerelease packages. Currently, installation of SQLitePCLRaw.bundle_zetetic 2.1.0-pre20220318192836 in a Maui application targeting iOS fails. It looks like the package has a declared dependency on SQLitePCLRaw.lib.sqlcipher which doesn't exist on nuget.org, thus causing the install to fail. That dependency appears to be new to the 2.1.0-pre* packages, and doesn't exist in 2.0.7 or 2.0.8 pre.

This may have occurred with commit b0598d47213f510c17551ae166beeb55059e7eb0, though to be honest I'm not clear on whether SQLitePCLRaw.lib.sqlcipher should actually exist (I tend to think it should not so that SQLitePCLRaw.provider.internal can be used). Thank you for your time!

ericsink commented 2 years ago

Looks like I made a mistake when I switched the way the bundle nuspec files are built. I'll get this fixed ASAP. Thanks for the report.

ericsink commented 2 years ago

And BTW, no, SQLitePCLRaw.lib.sqlcipher is not supposed to exist as a package. I build things with a placeholder library which is kind-of pretending to your package, but my placeholder is not supposed to become a nuget package or be referenced as one. Previously, I was generating explicit nuspec files, but I switched to allowing "dotnet pack" to build them from project references, and this problem slipped in.

ericsink commented 2 years ago

The attempted fix mentioned above is in 2.1.0-pre20220427180151, now on nuget.

sjlombardo commented 2 years ago

Hi @ericsink - thanks for publishing that. I've confirmed that the new preview package will now install.

Do you happen to know if the internal provider SQLitePCLRaw.provider.internal works with .net 6/Maui? With iOS, we have a binding assembly with an embedded static library (libsqlcipher.a), setup with all the requisite LinkWith attributes, like so:

[assembly: LinkWith("libsqlcipher.a", LinkTarget.Simulator | LinkTarget.Simulator64 | LinkTarget.ArmV7 | LinkTarget.ArmV7s | LinkTarget.Arm64, ForceLoad = true, Frameworks = "Security")]

This works perfectly for a Xamarin iOS app, but linking fails for a Maui app with undefined symbol errors for all of the _sqlite3* symbols,

2>Undefined symbols for architecture x86_64:
2>  "_sqlite3_aggregate_context", referenced from:
2>     -u command line option
2>  "_sqlite3_aggregate_count", referenced from:
2>     -u command line option
...

Just wondering, have you seen anything like that, or use the internal provider with it before?

ericsink commented 2 years ago

Hmmm. That's odd.

I'm pretty sure the internal provider is working fine for net6.0-ios for the other bundles. Something must be different in the interaction between bundle_zetetic and your lib package.

My first wild guess is to ask if you are building with net6.0-ios as the target framework? I can't even confidently claim that it's necessary, but I'm building that way, so if you are not, that would be a difference.

More tidbits:

Here in my repo, in src/SQLitePCLRaw.lib.e_sqlite3.ios is the iOS assembly for e_sqlite3. My bundle_zetetic assumes that your assembly will be equivalent except with different bits for the static lib.

When I build bundle_zetetic, I reference SQLitePCLRaw.lib.sqlcipher.ios.placeholder, which is pretending to be your package.

sjlombardo commented 2 years ago

Hi @ericsink - I've tracked this down to some problem with LinkWith using LinkTarget. Specifying LinkTarget causes the link step to fail for net6.0-ios, but the same assembly works fine for a standard Xamarin iOS app. I've been able to verify that everything is working with the LinkWith as follows:

[assembly: LinkWith("libsqlcipher.a", ForceLoad = true, Frameworks = "Security")]

I'm not really sure if this is a bug with the linker. Thanks for the pointer to the e_sqlite3.ios code, it was helpful for comparison, and for making this fix to bundle_zetetic!

ericsink commented 2 years ago

Looks like now that I have released 2.1.0, this issue can be closed.