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

blazor wasm and efcorepreview 7 SQLitePCLRaw.bundle_e_sqlite3 ver 2.1.0 and 2.1.1 preview fails in runtime #511

Closed sajjadarashhh closed 1 year ago

sajjadarashhh commented 1 year ago

at this issue I've been created in dotnet repo i described sqlitepcl.raw is not working on blazor wasm .net 7 and in https://github.com/dotnet/runtime/issues/74988#issuecomment-1235658677 stevesandersonMS is talking about somethings there show we this issue maybe throws from this package and this package can works on .net 6 only, through in .net 7 we have some problems with this. your can help we to don't have same problems in newer version of .net in future and coming releases?

ericsink commented 1 year ago

@bricelam I'm looking into this, but I'm wondering about your take as well. Any thoughts on why the Wasm stuff wouldn't work on .NET 7?

ericsink commented 1 year ago

Starting with .NET 6, I created a new project

dotnet new blazorwasm

and added SQLitePCLRaw:

dotnet add package sqlitepclraw.bundle_e_sqlite3

In Program.cs, I added:

SQLitePCL.Batteries.Init();

And in Pages/Index.razor I added:

<p>SQLite version: @ver</p>

@code {
    private int ver = SQLitePCL.raw.sqlite3_libversion_number();
}

And all this works.

Then I installed .NET 7 preview 7. When I tried to build, I got this warning:

C:\Program Files\dotnet\sdk-manifests\7.0.100\microsoft.net.workload.mono.toolchain\WorkloadManifest.targets(133,7): warning : @(NativeFileReference) is not empty, but the native references won't be linked in, because neither $(WasmBuildNative), nor $(RunAOTCompilation) are 'true'. NativeFileReference=C:\Users\eric\.nuget\packages\sqlitepclraw.lib.e_sqlite3\2.1.1\buildTransitive\net6.0\..\..\runtimes\browser-wasm\nativeassets\net6.0\e_sqlite3.a [C:\Users\eric\dev\issue511\issue511.csproj]

Which I speculate is related to the problem. Perhaps .NET 7 has changed and now the NativeFileReference needs something more than before.

bricelam commented 1 year ago

@lewing @radical Do we just need a new static library compiled with a new version (3.1.12) of emscripten? Or were there bigger changes in this area?

/cc @danroth27 @JeremyLikness @ajcvickers

radical commented 1 year ago

no, it might be a build issue. I'll take a look.

radical commented 1 year ago

You need the wasm-tools workload installed. If you set WasmBuildNative=true, then you get:

/usr/local/share/dotnet/sdk/7.0.100-rc.1.22405.9/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): 
    error NETSDK1147: To build this project, the following workloads must be installed: wasm-tools [/private/tmp/esq/esq.csproj]
/usr/local/share/dotnet/sdk/7.0.100-rc.1.22405.9/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): 
    error NETSDK1147: To install these workloads, run the following command: dotnet workload restore [/private/tmp/esq/esq.csproj]
radical commented 1 year ago

@lewing @radical Do we just need a new static library compiled with a new version (3.1.12) of emscripten? Or were there bigger changes in this area?

It should be built against emscripten 3.1.12.

ericsink commented 1 year ago

I installed the wasm-tools workload and set WasmBuildNative to true. After that, the attached sample, using .NET 7 and SQLitePCLRaw.bundle_e_sqlite3 2.1.1 works fine.

i511.zip

ericsink commented 1 year ago

The same sample with bundle_e_sqlcipher works too.

TBF, this same doesn't really do anything except call sqlite3_libversion_number().

bricelam commented 1 year ago

@ericsink I'll prepare some PRs to add assets for browser-wasm on net7.0.

sajjadarashhh commented 1 year ago

@ericsink I've use this version of sqlite in EFCore! and there's have Problems in newer version to work with together you can see sample repo in thats mentioned issue in top

ericsink commented 1 year ago

@bricelam I can wait for your PRs to see what's inside them, but I'm curious.

What change are you planning to make? If we've confirmed what the problem is here, then I missed it.

bricelam commented 1 year ago

The Emscripten ABI isn't stable, so static libraries compiled with one version aren't guaranteed to work on newer versions. The current strategy for dealing with this in .NET is to pick one version of Emscripten to use with each version of .NET.

.NET Emscripten
6.0 2.0.23
7.0 3.1.12

We should compile and ship a new version of the static library using that version of Emscripten. The lib packages will look like this:

ericsink commented 1 year ago

I published 2.1.2-pre20220913165057 on nuget, containing the new builds @bricelam did.

@sajjadarashhh I would be interested to know if this resolves the problem this issue started with.

sajjadarashhh commented 1 year ago

@ericsink thank you to resolve this. yeah thats works fine for me. ♥