Skip to content

Provide static libraries for Native AOT deployment #657

@0xced

Description

@0xced

Currently, the SourceGear.sqlite3 package provides native dynamic libraries for Linux (libe_sqlite3.so), macOS (libe_sqlite3.dylib) and Windows (e_sqlite3.dll).

In Multiplatform AOT with SQLite: How to get it working!, Scott Galloway explains how to build for AOT and get SQLite working. Unfortunately, it still involves deploying the main application binary plus the native dynamic library for the chosen platform.

For Native AOT deployment, having a native static library would enable producing a single file application. I have experimented with this at https://github.com/0xced/mdsqlite-aot.

What you need to do is actually pretty simple, as documented on Native code interop with Native AOT - Linking:

<ItemGroup>
  <DirectPInvoke Include="e_sqlite3" />
  <NativeLibrary Include="$(SqliteNativeLibrary)" />
</ItemGroup>

Define the SqliteNativeLibrary property to point to the native static library for the platform you are building and you'll get a single file executable and SQLite working.

Ideally, if libe_sqlite3.a (Linux + macOS) and e_sqlite3.lib (Windows) would be provided by the SourceGear.sqlite3 NuGet package, then Native AOT deployment could work out of the box. I think some more MSBuild trickery would be needed to not copy the dynamic libraries when native AOT deployment is used. The SqliteNativeLibrary property could be defined by in the SourceGear.sqlite3.props file, probably based on the RuntimeIdentifier property.

I'd be happy to help on this but it seems that the cb repository is not used anymore to build the SourceGear.sqlite3 package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions