From b6fa585040815e46e823cc559b864497a33a1205 Mon Sep 17 00:00:00 2001 From: awakecoding <295841+awakecoding@users.noreply.github.com> Date: Tue, 8 Sep 2026 17:26:18 -0400 Subject: [PATCH] bindings/dotnet: validate packaged consumers Exercise the completed replica API through packed NativeAOT, Android, and iOS consumers so package layout, native asset resolution, trimming, and sync exports are checked before NuGet publication. Keep the published turso_sdk_kit filenames and package version unchanged while allowing samples to select locally packed package versions. Tests: dotnet format whitespace; local NuGet pack inspection; win-x64 NativeAOT packaged consumer run --- .github/workflows/dotnet-publish.yml | 214 +++++++++++++++++- bindings/dotnet/Directory.Build.props | 1 + .../Android/AndroidManifest.xml | 5 + .../Android/AndroidPackageConsumer.csproj | 25 ++ .../Android/MainActivity.cs | 20 ++ .../samples/MobilePackageConsumer/README.md | 9 + .../MobilePackageConsumer/iOS/AppDelegate.cs | 19 ++ .../MobilePackageConsumer/iOS/Info.plist | 21 ++ .../iOS/IosPackageConsumer.csproj | 22 ++ .../samples/MobilePackageConsumer/iOS/Main.cs | 4 + .../samples/NativeAot/NativeAotSample.csproj | 11 +- bindings/dotnet/samples/NativeAot/Program.cs | 24 +- bindings/dotnet/samples/NativeAot/README.md | 4 +- .../dotnet/samples/ReplicaPackageSmoke.cs | 48 ++++ 14 files changed, 410 insertions(+), 17 deletions(-) create mode 100644 bindings/dotnet/samples/MobilePackageConsumer/Android/AndroidManifest.xml create mode 100644 bindings/dotnet/samples/MobilePackageConsumer/Android/AndroidPackageConsumer.csproj create mode 100644 bindings/dotnet/samples/MobilePackageConsumer/Android/MainActivity.cs create mode 100644 bindings/dotnet/samples/MobilePackageConsumer/README.md create mode 100644 bindings/dotnet/samples/MobilePackageConsumer/iOS/AppDelegate.cs create mode 100644 bindings/dotnet/samples/MobilePackageConsumer/iOS/Info.plist create mode 100644 bindings/dotnet/samples/MobilePackageConsumer/iOS/IosPackageConsumer.csproj create mode 100644 bindings/dotnet/samples/MobilePackageConsumer/iOS/Main.cs create mode 100644 bindings/dotnet/samples/ReplicaPackageSmoke.cs diff --git a/.github/workflows/dotnet-publish.yml b/.github/workflows/dotnet-publish.yml index 39c234925..86672b2c9 100644 --- a/.github/workflows/dotnet-publish.yml +++ b/.github/workflows/dotnet-publish.yml @@ -435,6 +435,16 @@ jobs: exit 1 fi + while IFS= read -r package; do + package_entries=$(mktemp) + unzip -Z1 "$package" > "$package_entries" + if grep -Fq "turso_sync_sdk_kit" "$package_entries"; then + echo "Internal Rust crate name leaked into $package" + exit 1 + fi + rm "$package_entries" + done < <(find src -path '*/bin/Release/*.nupkg' -type f) + static_packages=( "win-x64:turso_sdk_kit.lib" "win-arm64:turso_sdk_kit.lib" @@ -625,9 +635,211 @@ jobs: if ($output -notcontains "Rows: 3") { throw "Unexpected NativeAOT sample output: $output" } + if (-not ($output -match "^Stats revision:")) { + throw "NativeAOT sample did not read sync statistics: $output" + } + foreach ($expectedLine in @("Checkpoint: complete", "Disposed: complete")) { + if ($output -notcontains $expectedLine) { + throw "NativeAOT sample did not exercise the sync lifecycle ($expectedLine): $output" + } + } + + validate-android-package: + needs: publish + runs-on: ubuntu-latest + timeout-minutes: 30 + permissions: + contents: read + + defaults: + run: + working-directory: ${{ env.working-directory }} + + steps: + - name: Checkout code + uses: actions/checkout@v6 + + - name: Install dotnet SDK + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 10.0.x + + - name: Set up Android SDK + uses: android-actions/setup-android@v4 + + - name: Install Android workload and NDK + shell: bash + run: | + set -euo pipefail + dotnet workload install android + sdkmanager --install "ndk;27.2.12479018" + echo "ANDROID_NDK_HOME=$ANDROID_HOME/ndk/27.2.12479018" >> "$GITHUB_ENV" + echo "ANDROID_NDK_ROOT=$ANDROID_HOME/ndk/27.2.12479018" >> "$GITHUB_ENV" + + - name: Download NuGet packages + uses: actions/download-artifact@v7 + with: + name: nuget-packages + path: ${{ env.working-directory }}/artifacts/nuget-packages + + - name: Build Android package consumer + shell: bash + run: | + set -euo pipefail + package_source=$(realpath artifacts/nuget-packages) + nuget_config=samples/MobilePackageConsumer/NuGet.config + cat > "$nuget_config" < + + + + + + + + + + + + + + + + + EOF + + project=samples/MobilePackageConsumer/Android/AndroidPackageConsumer.csproj + dotnet restore "$project" -r android-arm64 --configfile "$nuget_config" + dotnet build "$project" -c Release -f net10.0-android -r android-arm64 \ + --no-restore -t:SignAndroidPackage -p:AndroidPackageFormats=apk + + - name: Verify Android native asset and sync exports + shell: bash + run: | + set -euo pipefail + apk=$(find samples/MobilePackageConsumer/Android/bin/Release -name '*-Signed.apk' -print -quit) + if [ -z "$apk" ]; then + echo "Android package consumer did not produce a signed APK" + exit 1 + fi + + native_entry=lib/arm64-v8a/libturso_sdk_kit.so + if ! unzip -Z1 "$apk" | grep -Fxq "$native_entry"; then + echo "$apk does not contain $native_entry" + exit 1 + fi + + mkdir -p artifacts/mobile-android + unzip -p "$apk" "$native_entry" > artifacts/mobile-android/libturso_sdk_kit.so + readelf="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-readelf" + for symbol in \ + turso_sync_database_new \ + turso_sync_database_create \ + turso_sync_database_open \ + turso_sync_database_connect \ + turso_sync_database_stats \ + turso_sync_database_checkpoint \ + turso_sync_database_deinit + do + if ! "$readelf" --dyn-syms --wide artifacts/mobile-android/libturso_sdk_kit.so | grep -Eq "[[:space:]]${symbol}$"; then + echo "Android package asset does not export $symbol" + exit 1 + fi + done + + validate-ios-package: + needs: publish + runs-on: macos-26 + timeout-minutes: 30 + permissions: + contents: read + + defaults: + run: + working-directory: ${{ env.working-directory }} + + steps: + - name: Checkout code + uses: actions/checkout@v6 + + - name: Install dotnet SDK + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 10.0.x + + - name: Install iOS workload + run: dotnet workload install ios + + - name: Download NuGet packages + uses: actions/download-artifact@v7 + with: + name: nuget-packages + path: ${{ env.working-directory }}/artifacts/nuget-packages + + - name: Build iOS package consumer + shell: bash + run: | + set -euo pipefail + package_source=$(realpath artifacts/nuget-packages) + nuget_config=samples/MobilePackageConsumer/NuGet.config + cat > "$nuget_config" < + + + + + + + + + + + + + + + + + EOF + + project=samples/MobilePackageConsumer/iOS/IosPackageConsumer.csproj + dotnet restore "$project" -r iossimulator-arm64 --configfile "$nuget_config" + dotnet build "$project" -c Release -f net10.0-ios -r iossimulator-arm64 --no-restore \ + -p:CodesignKey= -p:CodesignProvision= + + - name: Verify iOS native asset and sync exports + shell: bash + run: | + set -euo pipefail + app=$(find samples/MobilePackageConsumer/iOS/bin/Release -name '*.app' -type d -print -quit) + if [ -z "$app" ]; then + echo "iOS package consumer did not produce an app bundle" + exit 1 + fi + + framework="$app/Frameworks/libturso_sdk_kit.framework/libturso_sdk_kit" + if [ ! -f "$framework" ]; then + echo "$app does not contain the legacy-named libturso_sdk_kit framework" + exit 1 + fi + + for symbol in \ + turso_sync_database_new \ + turso_sync_database_create \ + turso_sync_database_open \ + turso_sync_database_connect \ + turso_sync_database_stats \ + turso_sync_database_checkpoint \ + turso_sync_database_deinit + do + if ! nm -gU "$framework" | grep -Eq "[[:space:]]_${symbol}$"; then + echo "iOS package asset does not export $symbol" + exit 1 + fi + done publish-to-nuget: - needs: validate-nativeaot-static-package + needs: [validate-nativeaot-static-package, validate-android-package, validate-ios-package] if: ${{ github.event_name == 'workflow_dispatch' && !inputs.skip-publish && !inputs.dry-run }} runs-on: ubuntu-latest timeout-minutes: 10 diff --git a/bindings/dotnet/Directory.Build.props b/bindings/dotnet/Directory.Build.props index 84d2deb8e..1dbbbfcdb 100644 --- a/bindings/dotnet/Directory.Build.props +++ b/bindings/dotnet/Directory.Build.props @@ -1,6 +1,7 @@ 0.8.0-pre.9 + $(Version) net8.0;net9.0;net10.0 Turso Turso diff --git a/bindings/dotnet/samples/MobilePackageConsumer/Android/AndroidManifest.xml b/bindings/dotnet/samples/MobilePackageConsumer/Android/AndroidManifest.xml new file mode 100644 index 000000000..152ff68b4 --- /dev/null +++ b/bindings/dotnet/samples/MobilePackageConsumer/Android/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/bindings/dotnet/samples/MobilePackageConsumer/Android/AndroidPackageConsumer.csproj b/bindings/dotnet/samples/MobilePackageConsumer/Android/AndroidPackageConsumer.csproj new file mode 100644 index 000000000..489b500c7 --- /dev/null +++ b/bindings/dotnet/samples/MobilePackageConsumer/Android/AndroidPackageConsumer.csproj @@ -0,0 +1,25 @@ + + + net10.0-android + 31 + Exe + enable + enable + com.turso.packageconsumer + 1 + 1.0 + full + + + + + + + + + + + + + + diff --git a/bindings/dotnet/samples/MobilePackageConsumer/Android/MainActivity.cs b/bindings/dotnet/samples/MobilePackageConsumer/Android/MainActivity.cs new file mode 100644 index 000000000..526606554 --- /dev/null +++ b/bindings/dotnet/samples/MobilePackageConsumer/Android/MainActivity.cs @@ -0,0 +1,20 @@ +using Android.App; +using Android.OS; +using Turso.Samples; + +namespace Turso.PackageConsumer.Android; + +[Activity(Label = "Turso package consumer", MainLauncher = true)] +public sealed class MainActivity : Activity +{ + protected override void OnCreate(Bundle? savedInstanceState) + { + base.OnCreate(savedInstanceState); + + var directory = FilesDir?.AbsolutePath + ?? throw new InvalidOperationException("Android did not provide an application files directory."); + var result = ReplicaPackageSmoke.Run(Path.Combine(directory, "replica.db")); + if (result.Rows != 3) + throw new InvalidOperationException($"Expected 3 rows, got {result.Rows}."); + } +} diff --git a/bindings/dotnet/samples/MobilePackageConsumer/README.md b/bindings/dotnet/samples/MobilePackageConsumer/README.md new file mode 100644 index 000000000..b628a7929 --- /dev/null +++ b/bindings/dotnet/samples/MobilePackageConsumer/README.md @@ -0,0 +1,9 @@ +# Mobile package-consumer validation + +These minimal Android and iOS apps consume `Turso.Data.Sqlite.Provider` through its normal NuGet package layering. Their reachable startup path creates an offline embedded replica when needed, opens it, uses the sync connection and statistics APIs, checkpoints, and disposes the native handles. + +The `dotnet-publish` workflow builds the Android ARM64 APK and iOS ARM64 simulator app from the packages produced by the same run. It verifies that each application contains the legacy-named `libturso_sdk_kit` native asset and that the asset exports the sync entry points used by the managed code. + +CI does not launch either app. Android emulator and iOS simulator execution are intentionally outside this package build/link check. + +For a local compile against the current source tree rather than packed artifacts, pass `-p:TursoUseProjectReferences=true`. CI leaves this property unset so it always tests the package dependency chain. diff --git a/bindings/dotnet/samples/MobilePackageConsumer/iOS/AppDelegate.cs b/bindings/dotnet/samples/MobilePackageConsumer/iOS/AppDelegate.cs new file mode 100644 index 000000000..54e12b644 --- /dev/null +++ b/bindings/dotnet/samples/MobilePackageConsumer/iOS/AppDelegate.cs @@ -0,0 +1,19 @@ +using Foundation; +using Turso.Samples; +using UIKit; + +namespace Turso.PackageConsumer.iOS; + +[Register("AppDelegate")] +public sealed class AppDelegate : UIApplicationDelegate +{ + public override bool FinishedLaunching(UIApplication application, NSDictionary? launchOptions) + { + var directory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + var result = ReplicaPackageSmoke.Run(Path.Combine(directory, "replica.db")); + if (result.Rows != 3) + throw new InvalidOperationException($"Expected 3 rows, got {result.Rows}."); + + return true; + } +} diff --git a/bindings/dotnet/samples/MobilePackageConsumer/iOS/Info.plist b/bindings/dotnet/samples/MobilePackageConsumer/iOS/Info.plist new file mode 100644 index 000000000..e533fe0d9 --- /dev/null +++ b/bindings/dotnet/samples/MobilePackageConsumer/iOS/Info.plist @@ -0,0 +1,21 @@ + + + + + CFBundleDisplayName + Turso package consumer + CFBundleIdentifier + com.turso.packageconsumer + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIDeviceFamily + + 1 + 2 + + + diff --git a/bindings/dotnet/samples/MobilePackageConsumer/iOS/IosPackageConsumer.csproj b/bindings/dotnet/samples/MobilePackageConsumer/iOS/IosPackageConsumer.csproj new file mode 100644 index 000000000..620809b11 --- /dev/null +++ b/bindings/dotnet/samples/MobilePackageConsumer/iOS/IosPackageConsumer.csproj @@ -0,0 +1,22 @@ + + + net10.0-ios + 13.0 + Exe + enable + enable + full + + + + + + + + + + + + + + diff --git a/bindings/dotnet/samples/MobilePackageConsumer/iOS/Main.cs b/bindings/dotnet/samples/MobilePackageConsumer/iOS/Main.cs new file mode 100644 index 000000000..61fe1e392 --- /dev/null +++ b/bindings/dotnet/samples/MobilePackageConsumer/iOS/Main.cs @@ -0,0 +1,4 @@ +using Turso.PackageConsumer.iOS; +using UIKit; + +UIApplication.Main(args, null, typeof(AppDelegate)); diff --git a/bindings/dotnet/samples/NativeAot/NativeAotSample.csproj b/bindings/dotnet/samples/NativeAot/NativeAotSample.csproj index ab3f43049..85bd39fe1 100644 --- a/bindings/dotnet/samples/NativeAot/NativeAotSample.csproj +++ b/bindings/dotnet/samples/NativeAot/NativeAotSample.csproj @@ -10,10 +10,17 @@ - + + + + + + + + diff --git a/bindings/dotnet/samples/NativeAot/Program.cs b/bindings/dotnet/samples/NativeAot/Program.cs index 4cfd0afcb..8f4315966 100644 --- a/bindings/dotnet/samples/NativeAot/Program.cs +++ b/bindings/dotnet/samples/NativeAot/Program.cs @@ -1,19 +1,17 @@ -using Turso.Data.Sqlite; +using Turso.Samples; -using var connection = new SqliteConnection("Data Source=:memory:"); -connection.Open(); +var directory = Path.Combine(Path.GetTempPath(), $"turso-nativeaot-{Guid.NewGuid():N}"); +Directory.CreateDirectory(directory); -using (var command = connection.CreateCommand()) +try { - command.CommandText = """ - CREATE TABLE items (value TEXT NOT NULL); - INSERT INTO items VALUES ('native'), ('aot'), ('turso'); - """; - command.ExecuteNonQuery(); + var result = ReplicaPackageSmoke.Run(Path.Combine(directory, "replica.db")); + Console.WriteLine($"Rows: {result.Rows}"); + Console.WriteLine($"Stats revision: {result.Revision}"); + Console.WriteLine("Checkpoint: complete"); + Console.WriteLine("Disposed: complete"); } - -using (var command = connection.CreateCommand()) +finally { - command.CommandText = "SELECT COUNT(*) FROM items"; - Console.WriteLine($"Rows: {command.ExecuteScalar()}"); + Directory.Delete(directory, recursive: true); } diff --git a/bindings/dotnet/samples/NativeAot/README.md b/bindings/dotnet/samples/NativeAot/README.md index 7c72eabaa..748d43240 100644 --- a/bindings/dotnet/samples/NativeAot/README.md +++ b/bindings/dotnet/samples/NativeAot/README.md @@ -1,6 +1,6 @@ # Turso NativeAOT sample -This sample publishes a NativeAOT executable that statically links `turso_sdk_kit` from the RID-specific `Turso.Data.NativeAot.*` package: +This sample publishes a NativeAOT executable that statically links the legacy-named `turso_sdk_kit` library from the RID-specific `Turso.Data.NativeAot.*` package: ```bash dotnet publish -c Release -r win-x64 @@ -8,6 +8,8 @@ dotnet publish -c Release -r win-x64 Set `true` with `true` and reference the matching `Turso.Data.NativeAot.` package to enable static native assets. Supported runtime identifiers are `win-x64`, `win-arm64`, `linux-x64`, `linux-arm64`, `osx-x64`, and `osx-arm64`. +The executable creates an offline embedded replica when needed, opens it, connects, writes and reads local data, reads sync statistics, checkpoints, and disposes both the connection and database. This makes NativeAOT publish validate the sync exports rather than only the local database exports. + When using an unreleased local package, add the package output folder as a restore source, for example: ```bash diff --git a/bindings/dotnet/samples/ReplicaPackageSmoke.cs b/bindings/dotnet/samples/ReplicaPackageSmoke.cs new file mode 100644 index 000000000..a6f51f86d --- /dev/null +++ b/bindings/dotnet/samples/ReplicaPackageSmoke.cs @@ -0,0 +1,48 @@ +using System.Net; +using Turso; + +namespace Turso.Samples; + +internal readonly record struct ReplicaPackageSmokeResult(long Rows, string Revision); + +internal static class ReplicaPackageSmoke +{ + internal static ReplicaPackageSmokeResult Run(string path) + { + using var httpClient = new HttpClient(new UnexpectedHttpHandler()); + var options = new TursoSyncDatabaseOptions(path, new Uri("https://example.invalid")) + { + BootstrapIfEmpty = false, + HttpClient = httpClient, + }; + + if (!File.Exists(path)) + { + using var created = TursoSyncDatabase.Create(options); + } + + using var database = TursoSyncDatabase.Open(options); + long rows; + using (var connection = database.Connect()) + { + connection.ExecuteNonQuery("CREATE TABLE IF NOT EXISTS items (value TEXT NOT NULL)"); + connection.ExecuteNonQuery("DELETE FROM items"); + connection.ExecuteNonQuery("INSERT INTO items VALUES ('native'), ('sync'), ('turso')"); + using var command = new TursoCommand(connection, "SELECT COUNT(*) FROM items"); + rows = Convert.ToInt64(command.ExecuteScalar()); + } + + var stats = database.GetStats(); + database.Checkpoint(); + return new ReplicaPackageSmokeResult(rows, stats.Revision); + } + + private sealed class UnexpectedHttpHandler : HttpMessageHandler + { + protected override Task SendAsync( + HttpRequestMessage request, + CancellationToken cancellationToken) + => throw new InvalidOperationException( + $"BootstrapIfEmpty=false must not make an HTTP request ({request.Method} {request.RequestUri})."); + } +}