Skip to content

Commit fb7e312

Browse files
authored
Merge pull request #17 from powersync-ja/fix/maui-extension-loading
fix: MAUI Extension loading
2 parents 0550f53 + 0745974 commit fb7e312

File tree

11 files changed

+85
-37
lines changed

11 files changed

+85
-37
lines changed

.github/workflows/dev-packages.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@ on: workflow_dispatch
77
jobs:
88
dev-release:
99
name: Publish Dev Packages
10-
runs-on: windows-latest
10+
runs-on: macos-latest
1111

1212
steps:
1313
- name: Checkout Repository
1414
uses: actions/checkout@v4
15+
with:
16+
ref: ${{ github.ref }}
1517

1618
- name: Setup .NET SDK
1719
uses: actions/setup-dotnet@v4
1820
with:
19-
dotnet-version: '8.0'
21+
dotnet-version: '8.0'
22+
23+
- name: Install MAUI Workloads
24+
run: dotnet workload restore
2025

2126
- name: Download PowerSync extension
2227
run: dotnet run --project Tools/Setup
@@ -37,7 +42,7 @@ jobs:
3742

3843
- name: Run Push For Common
3944
continue-on-error: true
40-
run: dotnet nuget push ${{ github.workspace }}\output\PowerSync.Common*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
45+
run: dotnet nuget push ${{ github.workspace }}/output/PowerSync.Common*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
4146

4247
- name: Extract MAUI Package Version from CHANGELOG.md
4348
id: extract_maui_version
@@ -46,10 +51,13 @@ jobs:
4651
MAUI_VERSION=$(awk '/^## [0-9]+\.[0-9]+\.[0-9]+-dev(\.[0-9]+)?$/ {print $2; exit}' PowerSync/PowerSync.Maui/CHANGELOG.md)
4752
echo "Detected Version: $MAUI_VERSION"
4853
echo "VERSION=$MAUI_VERSION" >> $GITHUB_ENV
49-
54+
55+
- name: Build MAUI Project
56+
run: dotnet build PowerSync/PowerSync.Maui -c Release
57+
5058
- name: Run Pack For MAUI
5159
run: dotnet pack PowerSync/PowerSync.Maui -c Release -o ${{ github.workspace }}/output
5260

5361
- name: Run Push For MAUI
5462
continue-on-error: true
55-
run: dotnet nuget push ${{ github.workspace }}\output\PowerSync.Maui*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
63+
run: dotnet nuget push ${{ github.workspace }}/output/PowerSync.Maui*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}

.github/workflows/release.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,22 @@ on: workflow_dispatch
66
jobs:
77
release:
88
name: Release
9-
runs-on: windows-latest
9+
runs-on: macos-latest
1010
if: github.ref == 'refs/heads/main'
1111

1212
steps:
1313
- name: Checkout Repository
1414
uses: actions/checkout@v4
15+
with:
16+
ref: ${{ github.ref }}
1517

1618
- name: Setup .NET SDK
1719
uses: actions/setup-dotnet@v4
1820
with:
19-
dotnet-version: '8.0'
21+
dotnet-version: '8.0'
22+
23+
- name: Install MAUI Workloads
24+
run: dotnet workload restore
2025

2126
- name: Download PowerSync extension
2227
run: dotnet run --project Tools/Setup
@@ -37,7 +42,7 @@ jobs:
3742

3843
- name: Run Push for Common
3944
continue-on-error: true
40-
run: dotnet nuget push ${{ github.workspace }}\output\PowerSync.Common*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
45+
run: dotnet nuget push ${{ github.workspace }}/output/PowerSync.Common*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
4146

4247
- name: Extract MAUI Package Version from CHANGELOG.md
4348
id: extract_maui_version
@@ -46,10 +51,13 @@ jobs:
4651
MAUI_VERSION=$(awk '/^## [0-9]+\.[0-9]+\.[0-9]+/ {print $2; exit}' PowerSync/PowerSync.Maui/CHANGELOG.md)
4752
echo "Detected Version: $MAUI_VERSION"
4853
echo "VERSION=$MAUI_VERSION" >> $GITHUB_ENV
54+
55+
- name: Build MAUI Project
56+
run: dotnet build PowerSync/PowerSync.Maui -c Release
4957

5058
- name: Run Pack For MAUI
5159
run: dotnet pack PowerSync/PowerSync.Maui -c Release -o ${{ github.workspace }}/output
5260

5361
- name: Run Push For MAUI
5462
continue-on-error: true
55-
run: dotnet nuget push ${{ github.workspace }}\output\PowerSync.Maui*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
63+
run: dotnet nuget push ${{ github.workspace }}/output/PowerSync.Maui*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}

PowerSync/PowerSync.Common/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# PowerSync.Common Changelog
22

3+
## 0.0.4-alpha.1
4+
- Fixed MAUI issues related to extension loading when installing package outside of the monorepo.
5+
36
## 0.0.3-alpha.1
47
- Minor changes to accommodate PowerSync.MAUI package extension.
58

PowerSync/PowerSync.Common/PowerSync.Common.csproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,22 @@
3030
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
3131
<PackageReference Include="System.Threading.Channels" Version="8.0.0" />
3232
</ItemGroup>
33+
34+
<ItemGroup>
35+
<None Include="PowerSync.Common.targets" Pack="true" PackagePath="build\" />
36+
<None Include="PowerSync.Common.targets" Pack="true" PackagePath="buildTransitive\" />
37+
</ItemGroup>
3338

3439
<!-- Check allows us to skip for all MAUI targets-->
3540
<!-- For monorepo-->
36-
<ItemGroup Condition="!$(TargetFramework.Contains('-'))">
41+
<ItemGroup Condition="!$(TargetFramework.EndsWith('-android')) AND !$(TargetFramework.EndsWith('-ios'))">
3742
<Content Include="runtimes\**\*.*">
3843
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3944
</Content>
4045
</ItemGroup>
4146

4247
<!-- For releasing runtimes -->
43-
<ItemGroup Condition="!$(TargetFramework.Contains('-'))">
48+
<ItemGroup Condition="!$(TargetFramework.EndsWith('-android')) AND !$(TargetFramework.EndsWith('-ios'))">
4449
<None Include="runtimes\**\*.*" Pack="true" PackagePath="runtimes\" />
4550
</ItemGroup>
4651

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project>
2+
<Target Name="RemovePowerSyncNativeForAndroid" AfterTargets="ResolvePackageAssets" Condition="$(TargetFramework.Contains('android'))">
3+
<ItemGroup>
4+
<NativeCopyLocalItems Remove="@(NativeCopyLocalItems)" Condition="'%(NuGetPackageId)' == 'PowerSync.Common'" />
5+
</ItemGroup>
6+
</Target>
7+
</Project>

PowerSync/PowerSync.Maui/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# PowerSync.Maui Changelog
22

3+
## 0.0.2-alpha.1
4+
- Fixed issues related to extension loading when installing package outside of the monorepo.
5+
36
## 0.0.1-alpha.1
47

58
- Introduce package. Support for iOS/Android use cases.

PowerSync/PowerSync.Maui/PowerSync.Maui.csproj

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
<PackageIcon>icon.png</PackageIcon>
2020
<NoWarn>NU5100</NoWarn>
2121
<PackageReadmeFile>README.md</PackageReadmeFile>
22+
<IsBindingProject>true</IsBindingProject>
23+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
24+
<IncludeBuildOutput>true</IncludeBuildOutput>
2225
</PropertyGroup>
2326

2427
<ItemGroup>
@@ -32,26 +35,14 @@
3235
<SubType>Designer</SubType>
3336
</None>
3437
</ItemGroup>
35-
36-
<!-- For monorepo-->
37-
<ItemGroup Condition="$(TargetFramework.Contains('-android'))">
38-
<Content Include="Platforms\Android\**\*.*">
39-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
40-
</Content>
41-
</ItemGroup>
4238

43-
<ItemGroup Condition="$(TargetFramework.Contains('-ios'))">
44-
<Content Include="Platforms\iOS\NativeLibs\powersync-sqlite-core.xcframework\**\*.*">
45-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
46-
</Content>
47-
</ItemGroup>
48-
49-
<!-- For releasing runtimes -->
50-
<ItemGroup Condition="$(TargetFramework.Contains('-android'))">
51-
<None Include="Platforms\Android\**\*.*" Pack="true" PackagePath="Platforms\Android" />
52-
</ItemGroup>
5339

5440
<ItemGroup Condition="$(TargetFramework.Contains('-ios'))">
55-
<None Include="Platforms\iOS\NativeLibs\powersync-sqlite-core.xcframework\**\*.*" Pack="true" PackagePath="Platforms\iOS" />
41+
<ObjcBindingApiDefinition Include="build\ApiDefinition.cs" />
42+
43+
<NativeReference Include="platforms\iOS\NativeLibs\powersync-sqlite-core.xcframework">
44+
<Kind>Framework</Kind>
45+
<SmartLink>False</SmartLink>
46+
</NativeReference>
5647
</ItemGroup>
5748
</Project>

PowerSync/PowerSync.Maui/SQLite/MAUISQLiteAdapter.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ protected override void LoadExtension(SqliteConnection db)
1919
db.EnableExtensions(true);
2020

2121
#if IOS
22-
LoadExtensionIOS(db);
22+
LoadExtensionIOS(db);
2323
#elif ANDROID
2424
db.LoadExtension("libpowersync");
2525
#else
@@ -29,16 +29,21 @@ protected override void LoadExtension(SqliteConnection db)
2929

3030
private void LoadExtensionIOS(SqliteConnection db)
3131
{
32-
#if IOS
33-
var bundlePath = Foundation.NSBundle.MainBundle.BundlePath;
32+
#if IOS
33+
var bundlePath = Foundation.NSBundle.FromIdentifier("co.powersync.sqlitecore")?.BundlePath;
34+
if (bundlePath == null)
35+
{
36+
throw new Exception("Could not find PowerSync SQLite extension bundle path");
37+
}
38+
3439
var filePath =
35-
Path.Combine(bundlePath, "Frameworks", "powersync-sqlite-core.framework", "powersync-sqlite-core");
36-
40+
Path.Combine(bundlePath, "powersync-sqlite-core");
41+
3742
using var loadExtension = db.CreateCommand();
3843
loadExtension.CommandText = "SELECT load_extension(@path, @entryPoint)";
3944
loadExtension.Parameters.AddWithValue("@path", filePath);
4045
loadExtension.Parameters.AddWithValue("@entryPoint", "sqlite3_powersync_init");
4146
loadExtension.ExecuteNonQuery();
42-
#endif
47+
#endif
4348
}
4449
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace PowerSync.Maui.build
2+
{
3+
// Empty API definition - allows xcframework to be included without managed bindings
4+
}

demos/MAUITodo/MAUITodo.csproj

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
<PropertyGroup>
44
<ApplicationId>com.companyname.todo</ApplicationId>
55

6-
<TargetFrameworks>net8.0-android;net8.0-ios</TargetFrameworks>
6+
<TargetFrameworks>net8.0-android</TargetFrameworks>
77
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
8-
8+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('osx'))">$(TargetFrameworks);net8.0-ios</TargetFrameworks>
99

1010
<OutputType>Exe</OutputType>
1111
<RootNamespace>MAUITodo</RootNamespace>
@@ -34,6 +34,13 @@
3434
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.19041.0</SupportedOSPlatformVersion>
3535
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.19041.0</TargetPlatformMinVersion>
3636
</PropertyGroup>
37+
38+
<!-- Potentially only needed for net8.0-ios: https://github.com/microsoft/appcenter-sdk-dotnet/issues/1755#issuecomment-2373256340 -->
39+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-ios|AnyCPU'">
40+
<RuntimeIdentifier>iossimulator-x64</RuntimeIdentifier>
41+
<ForceSimulatorX64ArchitectureInIDE>true</ForceSimulatorX64ArchitectureInIDE>
42+
</PropertyGroup>
43+
3744
<ItemGroup>
3845
<!-- App Icon -->
3946
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

0 commit comments

Comments
 (0)