Skip to content

Commit

Permalink
Add packages for SQLite3 Multiple Ciphers
Browse files Browse the repository at this point in the history
  • Loading branch information
bricelam committed Nov 9, 2023
1 parent 6f4b3ec commit a777b17
Show file tree
Hide file tree
Showing 20 changed files with 326 additions and 0 deletions.
9 changes: 9 additions & 0 deletions build/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ let main argv =
let nuspec_dirs = [
"lib.e_sqlite3"
"lib.e_sqlcipher"
"lib.sqlite3mc"
]

for s in nuspec_dirs do
Expand All @@ -48,18 +49,23 @@ let main argv =
"provider.winsqlite3"
"provider.e_sqlite3"
"provider.e_sqlcipher"
"provider.sqlite3mc"
"provider.sqlite3"
"provider.sqlcipher"
"lib.e_sqlite3.android"
"lib.e_sqlite3.ios"
"lib.e_sqlite3.tvos"
"lib.e_sqlcipher.android"
"lib.e_sqlcipher.ios"
"lib.sqlite3mc.android"
"lib.sqlite3mc.ios"
"lib.e_sqlite3"
"lib.e_sqlcipher"
"lib.sqlite3mc"
"bundle_green"
"bundle_e_sqlite3"
"bundle_e_sqlcipher"
"bundle_sqlite3mc"
"bundle_zetetic"
"bundle_winsqlite3"
"bundle_sqlite3"
Expand All @@ -86,6 +92,7 @@ let main argv =
let real_xunit_dirs = [
yield "e_sqlite3"
yield "e_sqlcipher"
yield "sqlite3mc"
// TODO do bundle_sqlite3 real_xunit here?
if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then yield "winsqlite3"
]
Expand All @@ -99,6 +106,7 @@ let main argv =
let fake_xunit_dirs = [
yield "e_sqlite3"
yield "e_sqlcipher"
yield "sqlite3mc"
if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then yield "winsqlite3"
yield "sqlite3"
]
Expand All @@ -116,6 +124,7 @@ let main argv =
let args = "run -f net6.0-windows -r win-x86 --no-self-contained"
exec "dotnet" args (Path.Combine(top, "test_nupkgs", "e_sqlite3", "fake_xunit"))
exec "dotnet" args (Path.Combine(top, "test_nupkgs", "e_sqlcipher", "fake_xunit"))
exec "dotnet" args (Path.Combine(top, "test_nupkgs", "sqlite3mc", "fake_xunit"))
#endif

printfn "generating push.bat"
Expand Down
61 changes: 61 additions & 0 deletions gen_lib_nuspecs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ static string AsString_basename_in_cb(this WhichLib e)
{
case WhichLib.E_SQLITE3: return "e_sqlite3";
case WhichLib.E_SQLCIPHER: return "e_sqlcipher"; // TODO no e_ prefix in cb yet
case WhichLib.SQLITE3MC: return "sqlite3mc";
default:
throw new NotImplementedException(string.Format("WhichLib.AsString for {0}", e));
}
Expand All @@ -175,6 +176,7 @@ static string AsString_basename_in_nupkg(this WhichLib e)
{
case WhichLib.E_SQLITE3: return "e_sqlite3";
case WhichLib.E_SQLCIPHER: return "e_sqlcipher";
case WhichLib.SQLITE3MC: return "sqlite3mc";
default:
throw new NotImplementedException(string.Format("WhichLib.AsString for {0}", e));
}
Expand Down Expand Up @@ -600,11 +602,69 @@ private static void gen_nuspec_lib_e_sqlcipher(string dir_src)
}
}

private static void gen_nuspec_lib_sqlite3mc(string dir_src)
{
string id = string.Format("{0}.lib.sqlite3mc", common.ROOT_NAME);

var settings = common.XmlWriterSettings_default();
settings.OmitXmlDeclaration = false;

var dir_proj = Path.Combine(dir_src, id);
Directory.CreateDirectory(dir_proj);
common.gen_dummy_csproj(dir_proj, id);

using (XmlWriter f = XmlWriter.Create(Path.Combine(dir_proj, string.Format("{0}.nuspec", id)), settings))
{
f.WriteStartDocument();
f.WriteComment("Automatically generated");

f.WriteStartElement("package", "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd");

f.WriteStartElement("metadata");
common.write_nuspec_common_metadata(id, f);
f.WriteElementString("description", "This package contains platform-specific native code builds of SQLite3 Multiple Ciphers (see utelle/SQLite3MultipleCiphers on GitHub) for use with SQLitePCLRaw. To use this package, you need SQLitePCLRaw.core as well as one of the SQLitePCLRaw.provider.* packages. Convenience packages are named SQLitePCLRaw.bundle_*.");

f.WriteEndElement(); // metadata

f.WriteStartElement("files");

write_nuspec_file_entries_from_cb(WhichLib.SQLITE3MC, "v142", f);

{
var tname = string.Format("{0}.targets", id);
Directory.CreateDirectory(Path.Combine(dir_proj, "net461"));
var path_targets = Path.Combine(dir_proj, "net461", tname);
var relpath_targets = nuget_path_combine(".", "net461", tname);
gen_nuget_targets(path_targets, WhichLib.SQLITE3MC);
common.write_nuspec_file_entry(
relpath_targets,
string.Format("buildTransitive\\{0}", TFM.NET461.AsString()),
f
);
}

write_nuspec_wasm_targets_file_entry(dir_src, id, WhichLib.SQLITE3MC, TFM.NET60, f);
write_nuspec_wasm_targets_file_entry(dir_src, id, WhichLib.SQLITE3MC, TFM.NET70, f);
write_nuspec_wasm_targets_file_entry(dir_src, id, WhichLib.SQLITE3MC, TFM.NET80, f);

// TODO need a comment here to explain these
common.write_empty(f, TFM.NET461);
common.write_empty(f, TFM.NETSTANDARD20);

f.WriteEndElement(); // files

f.WriteEndElement(); // package

f.WriteEndDocument();
}
}

enum WhichLib
{
NONE,
E_SQLITE3,
E_SQLCIPHER,
SQLITE3MC,
}

static LibSuffix get_lib_suffix_from_rid(string rid)
Expand Down Expand Up @@ -879,6 +939,7 @@ public static void Main(string[] args)

gen_nuspec_lib_e_sqlite3(dir_src);
gen_nuspec_lib_e_sqlcipher(dir_src);
gen_nuspec_lib_sqlite3mc(dir_src);
}
}

5 changes: 5 additions & 0 deletions gen_providers/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,10 @@ let main argv =
gen_provider s s (Some subname_funcptrs_win) "Cdecl" "dllimport" "FEATURE_WIN32DIR/true" "FEATURE_FUNCPTRS/callingconv" "FEATURE_KEY/true" "FEATURE_LOADEXTENSION/true"
gen_provider s s (Some subname_funcptrs_notwin) "Cdecl" "dllimport" "FEATURE_WIN32DIR/false" "FEATURE_FUNCPTRS/plain" "FEATURE_KEY/true" "FEATURE_LOADEXTENSION/true"

gen_provider "sqlite3mc" "sqlite3mc" (Some subname_prenet5_win) "Cdecl" "dllimport" "FEATURE_WIN32DIR/true" "FEATURE_FUNCPTRS/false" "FEATURE_KEY/true" "FEATURE_LOADEXTENSION/false"
gen_provider "sqlite3mc" "sqlite3mc" (Some subname_prenet5_notwin) "Cdecl" "dllimport" "FEATURE_WIN32DIR/false" "FEATURE_FUNCPTRS/false" "FEATURE_KEY/true" "FEATURE_LOADEXTENSION/false"
gen_provider "sqlite3mc" "sqlite3mc" (Some subname_funcptrs_win) "Cdecl" "dllimport" "FEATURE_WIN32DIR/true" "FEATURE_FUNCPTRS/callingconv" "FEATURE_KEY/true" "FEATURE_LOADEXTENSION/true"
gen_provider "sqlite3mc" "sqlite3mc" (Some subname_funcptrs_notwin) "Cdecl" "dllimport" "FEATURE_WIN32DIR/false" "FEATURE_FUNCPTRS/plain" "FEATURE_KEY/true" "FEATURE_LOADEXTENSION/true"

0 // return an integer exit code

Binary file added sn/SQLitePCLRaw.lib.sqlite3mc.snk
Binary file not shown.
Binary file added sn/SQLitePCLRaw.provider.sqlite3mc.snk
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Xamarin.Legacy.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;$(tfm_net6_ios);$(tfm_net6_maccatalyst);$(tfm_net6_android);$(tfm_classic_ios);$(tfm_classic_android);net461</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<PackageId>SQLitePCLRaw.bundle_sqlite3mc</PackageId>
<AssemblyName>SQLitePCLRaw.batteries_v2</AssemblyName>
<AssemblyOriginatorKeyFile>..\..\sn\SQLitePCLRaw.batteries_v2.snk</AssemblyOriginatorKeyFile>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<PackageDescription>This 'batteries-included' bundle brings in SQLitePCLRaw.core and the necessary stuff for certain common use cases. Call SQLitePCL.Batteries.Init(). Policy of this bundle: sqlite3mc included</PackageDescription>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\..\src\common\batteries_v2.cs" />
</ItemGroup>

<Import Condition=" '$(TargetFramework)' == 'netstandard2.0' " Project="..\msbuild_bundle_fragments\sqlite3mc_dllimport.xml" />
<Import Condition=" '$(TargetFramework)' == '$(tfm_net6_ios)' " Project="..\msbuild_bundle_fragments\sqlite3mc_ios.xml" />
<Import Condition=" '$(TargetFramework)' == '$(tfm_net6_maccatalyst)' " Project="..\msbuild_bundle_fragments\sqlite3mc_dllimport.xml" />
<Import Condition=" '$(TargetFramework)' == '$(tfm_net6_android)' " Project="..\msbuild_bundle_fragments\sqlite3mc_android.xml" />
<Import Condition=" '$(TargetFramework)' == '$(tfm_classic_ios)' " Project="..\msbuild_bundle_fragments\sqlite3mc_ios.xml" />
<Import Condition=" '$(TargetFramework)' == '$(tfm_classic_android)' " Project="..\msbuild_bundle_fragments\sqlite3mc_android.xml" />
<Import Condition=" '$(TargetFramework)' == 'net461' " Project="..\msbuild_bundle_fragments\sqlite3mc_dynamic.xml" />

</Project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project Sdk="Xamarin.Legacy.Sdk">
<PropertyGroup>
<TargetFrameworks>$(tfm_net6_android);$(tfm_classic_android)</TargetFrameworks>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\sn\SQLitePCLRaw.lib.sqlite3mc.snk</AssemblyOriginatorKeyFile>
<PackageDescription>This package contains platform-specific native code builds of SQLite3 Multiple Ciphers (see utelle/SQLite3MultipleCiphers on GitHub) for use with SQLitePCLRaw. To use this package, you need SQLitePCLRaw.core as well as one of the SQLitePCLRaw.provider.* packages. Convenience packages are named SQLitePCLRaw.bundle_*.</PackageDescription>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\..\src\common\embedded_init.cs" />
</ItemGroup>

<PropertyGroup Label="Android DesignTimeBuild error workaround">
<DesignTimeBuild>false</DesignTimeBuild>
</PropertyGroup>

<ItemGroup>
<EmbeddedNativeLibrary Include="$([System.IO.Path]::Combine($(cb_bin_path), 'sqlite3mc', 'android', 'x86', 'libsqlite3mc.so'))">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>x86\libsqlite3mc.so</Link>
</EmbeddedNativeLibrary>
<EmbeddedNativeLibrary Include="$([System.IO.Path]::Combine($(cb_bin_path), 'sqlite3mc', 'android', 'x86_64', 'libsqlite3mc.so'))">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>x86_64\libsqlite3mc.so</Link>
</EmbeddedNativeLibrary>
<EmbeddedNativeLibrary Include="$([System.IO.Path]::Combine($(cb_bin_path), 'sqlite3mc', 'android', 'arm64-v8a', 'libsqlite3mc.so'))">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>arm64-v8a\libsqlite3mc.so</Link>
</EmbeddedNativeLibrary>
<EmbeddedNativeLibrary Include="$([System.IO.Path]::Combine($(cb_bin_path), 'sqlite3mc', 'android', 'armeabi-v7a', 'libsqlite3mc.so'))">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>armeabi-v7a\libsqlite3mc.so</Link>
</EmbeddedNativeLibrary>
</ItemGroup>

</Project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Xamarin.Legacy.Sdk">
<PropertyGroup>
<TargetFrameworks>$(tfm_net6_ios);$(tfm_classic_ios)</TargetFrameworks>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\sn\SQLitePCLRaw.lib.sqlite3mc.snk</AssemblyOriginatorKeyFile>
<PackageDescription>This package contains platform-specific native code builds of SQLite3 Multiple Ciphers (see utelle/SQLite3MultipleCiphers on GitHub) for use with SQLitePCLRaw. To use this package, you need SQLitePCLRaw.core as well as one of the SQLitePCLRaw.provider.* packages. Convenience packages are named SQLitePCLRaw.bundle_*.</PackageDescription>
</PropertyGroup>

<ItemGroup>
<None Include="$(cb_bin_path)\sqlite3mc\ios\device\sqlite3mc.a" Pack="true" PackagePath="static\device" />
<None Include="$(cb_bin_path)\sqlite3mc\ios\simulator\sqlite3mc.a" Pack="true" PackagePath="static\simulator" />
<None Include="SQLitePCLRaw.lib.sqlite3mc.ios.targets" Pack="true" PackagePath="build" />
<None Include="SQLitePCLRaw.lib.sqlite3mc.ios.targets" Pack="true" PackagePath="buildTransitive" />
</ItemGroup>
</Project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Condition="'$(RuntimeIdentifier)'=='ios-arm64' or '$(ComputedPlatform)'=='iPhone'">
<NativeReference Include="$(MSBuildThisFileDirectory)..\static\device\sqlite3mc.a">
<Kind>Static</Kind>
<SmartLink>False</SmartLink>
<ForceLoad>true</ForceLoad>
</NativeReference>
</ItemGroup>
<ItemGroup Condition="'$(RuntimeIdentifier)'=='iossimulator-arm64' or '$(RuntimeIdentifier)'=='iossimulator-x64' or '$(ComputedPlatform)'=='iPhoneSimulator'">
<NativeReference Include="$(MSBuildThisFileDirectory)..\static\simulator\sqlite3mc.a">
<Kind>Static</Kind>
<SmartLink>False</SmartLink>
<ForceLoad>true</ForceLoad>
</NativeReference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0;net6.0-windows</TargetFrameworks>
<LangVersion>$(ProviderLangVersion)</LangVersion>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\sn\SQLitePCLRaw.provider.sqlite3mc.snk</AssemblyOriginatorKeyFile>
<PackageDescription>SQLitePCLRaw is a Portable Class Library (PCL) for low-level (raw) access to SQLite. Packages named 'SQLitePCLRaw.provider.*' (like this one) are 'plugins' that allow SQLitePCLRaw.core to access the native SQLite library. This provider does DllImport of 'sqlite3mc', the SQLite3 Multiple Ciphers builds provided with SQLitePCLRaw.</PackageDescription>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\SQLitePCLRaw.core\SQLitePCLRaw.core.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<Compile Include="Generated\provider_sqlite3mc_prenet5_win.cs" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<Compile Include="Generated\provider_sqlite3mc_funcptrs_notwin.cs" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0-windows' ">
<Compile Include="Generated\provider_sqlite3mc_funcptrs_win.cs" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions src/common/batteries_v2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public static void Init()
SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_e_sqlite3());
#elif PROVIDER_e_sqlcipher
SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_e_sqlcipher());
#elif PROVIDER_sqlite3mc
SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3mc());
#elif PROVIDER_sqlcipher
SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlcipher());
#elif PROVIDER_winsqlite3
Expand All @@ -105,6 +107,8 @@ public static void Init()
DoDynamic_cdecl("e_sqlite3", NativeLibrary.WHERE_RUNTIME_RID | NativeLibrary.WHERE_ADJACENT | NativeLibrary.WHERE_CODEBASE);
#elif PROVIDER_NAME_e_sqlcipher
DoDynamic_cdecl("e_sqlcipher", NativeLibrary.WHERE_RUNTIME_RID | NativeLibrary.WHERE_ADJACENT);
#elif PROVIDER_NAME_sqlite3mc
DoDynamic_cdecl("sqlite3mc", NativeLibrary.WHERE_RUNTIME_RID | NativeLibrary.WHERE_ADJACENT);
#elif PROVIDER_NAME_sqlcipher
DoDynamic_cdecl("sqlcipher", NativeLibrary.WHERE_ARCH); // TODO coordinate with zetetic
#elif PROVIDER_NAME_winsqlite3
Expand Down
5 changes: 5 additions & 0 deletions src/global.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"sdk":
{
"version": "6.0.100",
"rollForward": "latestFeature"
},
"msbuild-sdks":
{
"MSBuild.Sdk.Extras": "3.0.44",
Expand Down
13 changes: 13 additions & 0 deletions src/msbuild_bundle_fragments/sqlite3mc_android.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

<Project>

<PropertyGroup>
<DefineConstants>$(DefineConstants);PROVIDER_sqlite3mc</DefineConstants>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\SQLitePCLRaw.lib.sqlite3mc.android\SQLitePCLRaw.lib.sqlite3mc.android.csproj" />
<ProjectReference Include="..\SQLitePCLRaw.provider.sqlite3mc\SQLitePCLRaw.provider.sqlite3mc.csproj" />
</ItemGroup>

</Project>
13 changes: 13 additions & 0 deletions src/msbuild_bundle_fragments/sqlite3mc_dllimport.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project>

<PropertyGroup>
<DefineConstants>$(DefineConstants);PROVIDER_sqlite3mc</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SQLitePCLRaw.lib.sqlite3mc" Version="$(version)" />
<ProjectReference Include="..\SQLitePCLRaw.provider.sqlite3mc\SQLitePCLRaw.provider.sqlite3mc.csproj" />
</ItemGroup>

</Project>

18 changes: 18 additions & 0 deletions src/msbuild_bundle_fragments/sqlite3mc_dynamic.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project>

<PropertyGroup>
<DefineConstants>$(DefineConstants);PROVIDER_dynamic;PROVIDER_dynamic_cdecl;PROVIDER_NAME_sqlite3mc</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SQLitePCLRaw.lib.sqlite3mc" Version="$(version)" />
<ProjectReference Include="..\SQLitePCLRaw.provider.dynamic_cdecl\SQLitePCLRaw.provider.dynamic_cdecl.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\src\common\nativelibrary_defines.cs" />
<Compile Include="..\..\src\common\nativelibrary_for_netstandard2.cs" />
</ItemGroup>

</Project>

13 changes: 13 additions & 0 deletions src/msbuild_bundle_fragments/sqlite3mc_ios.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

<Project>

<PropertyGroup>
<DefineConstants>$(DefineConstants);PROVIDER_internal</DefineConstants>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\SQLitePCLRaw.lib.sqlite3mc.ios\SQLitePCLRaw.lib.sqlite3mc.ios.csproj" />
<ProjectReference Include="..\SQLitePCLRaw.provider.internal\SQLitePCLRaw.provider.internal.csproj" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions test_nupkgs/sqlite3mc/fake_xunit/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

using System;

public static class foo
{
public static int Main()
{
SQLitePCL.Batteries_V2.Init();
return Xunit.Run.AllTestsInCurrentAssembly();
}
}

Loading

0 comments on commit a777b17

Please sign in to comment.