From 94e3d151d72f75f6911425fecfd288a7ee912826 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Sat, 17 Jul 2021 19:49:13 +0200 Subject: [PATCH 1/4] Create dotnet.yml --- .github/workflows/dotnet.yml | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/dotnet.yml diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml new file mode 100644 index 00000000..8f50d17e --- /dev/null +++ b/.github/workflows/dotnet.yml @@ -0,0 +1,42 @@ +name: .NET + +on: + push: + branches: [ emclient ] + pull_request: + branches: [ emclient ] + +jobs: + build: + + runs-on: windows-latest + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + path: "SQLitePCL.raw" + - uses: actions/checkout@v2 + with: + repository: ericsink/cb + path: "cb" + - name: Setup .NET 5 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 5.0.x + - name: Setup .NET 3.1 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 3.1.x + - name: Setup .NET 2.1 + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 2.1.x + - name: Add msbuild to PATH + uses: microsoft/setup-msbuild@v1.0.2 + - name: Install T4 + run: dotnet tool install --global dotnet-t4 + - name: Build + run: | + cd SQLitePCL.raw/build + dotnet run From 7cb092ce60e1b94e3a90a16ad7f381adf06c2e55 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Sat, 17 Jul 2021 20:23:18 +0200 Subject: [PATCH 2/4] Skip testing APIs that are not available on older winsqlite.dll --- src/common/tests_xunit.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/common/tests_xunit.cs b/src/common/tests_xunit.cs index 078a756e..95ab296c 100644 --- a/src/common/tests_xunit.cs +++ b/src/common/tests_xunit.cs @@ -676,6 +676,10 @@ public void test_last_insert_rowid() [Fact] public void test_keywords() { + var version = raw.sqlite3_libversion_number(); + + if (version < 3024000) return; // Added in 3.24.0: https://sqlite.org/releaselog/3_24_0.html + var n = SQLitePCL.raw.sqlite3_keyword_count(); Assert.True(n > 0); for (var i=0; i Date: Sat, 17 Jul 2021 23:47:30 +0200 Subject: [PATCH 3/4] Add and fix macOS builds --- .github/workflows/dotnet.yml | 7 +++++- build/Program.fs | 28 ++++++++++++++---------- src/common/tests_xunit.cs | 42 ++++++++++++++++++++++++++++-------- 3 files changed, 56 insertions(+), 21 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 8f50d17e..83c2f01d 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -9,7 +9,11 @@ on: jobs: build: - runs-on: windows-latest + strategy: + matrix: + os: [windows-latest, macos-latest] + + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 @@ -33,6 +37,7 @@ jobs: with: dotnet-version: 2.1.x - name: Add msbuild to PATH + if: startsWith(matrix.os, 'windows') uses: microsoft/setup-msbuild@v1.0.2 - name: Install T4 run: dotnet tool install --global dotnet-t4 diff --git a/build/Program.fs b/build/Program.fs index 1686ba94..78869d49 100644 --- a/build/Program.fs +++ b/build/Program.fs @@ -2,6 +2,7 @@ open System open System.Diagnostics open System.IO +open System.Runtime.InteropServices open System.Xml.Linq open System.Linq @@ -165,25 +166,30 @@ let main argv = //exec "dotnet" (sprintf "run --framework=%s" "net5.0") (Path.Combine(top, "test_nupkgs", "cil", "fake_xunit")) - exec "dotnet" "test" (Path.Combine(top, "test_nupkgs", "e_sqlite3", "real_xunit")) - exec "dotnet" "test" (Path.Combine(top, "test_nupkgs", "winsqlite3", "real_xunit")) - exec "dotnet" "test" (Path.Combine(top, "test_nupkgs", "e_sqlcipher", "real_xunit")) - // TODO do bundle_sqlite3 real_xunit here? + let real_xunit_dirs = [ + yield "e_sqlite3" + yield "e_sqlcipher" + // TODO do bundle_sqlite3 real_xunit here? + if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then yield "winsqlite3" + ] let fake_xunit_tfms = [ - "netcoreapp2.1" - "netcoreapp3.1" - //"net461" + yield "netcoreapp2.1" + yield "netcoreapp3.1" + if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then yield "net461" ] let fake_xunit_dirs = [ - "e_sqlite3" - "e_sqlcipher" - "winsqlite3" - "sqlite3" + yield "e_sqlite3" + yield "e_sqlcipher" + if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then yield "winsqlite3" + yield "sqlite3" ] for tfm in fake_xunit_tfms do + for dir in real_xunit_dirs do + let args = sprintf "test --framework=%s" tfm + exec "dotnet" args (Path.Combine(top, "test_nupkgs", dir, "real_xunit")) for dir in fake_xunit_dirs do let args = sprintf "run --framework=%s" tfm exec "dotnet" args (Path.Combine(top, "test_nupkgs", dir, "fake_xunit")) diff --git a/src/common/tests_xunit.cs b/src/common/tests_xunit.cs index 95ab296c..eda7e811 100644 --- a/src/common/tests_xunit.cs +++ b/src/common/tests_xunit.cs @@ -18,6 +18,7 @@ limitations under the License. using System.Collections.Generic; using System.Linq; using System.IO; +using System.Runtime.InteropServices; using System.Text; using SQLitePCL; using SQLitePCL.Ugly; @@ -67,10 +68,13 @@ public void test_GetZeroTerminatedUTF8Bytes() [Fact] public void test_call_sqlite3_enable_load_extension() { - using (sqlite3 db = ugly.open(":memory:")) + if (0 == raw.sqlite3_compileoption_used("SQLITE_OMIT_LOAD_EXTENSION")) { - var rc = raw.sqlite3_enable_load_extension(db, 0); - Assert.Equal(raw.SQLITE_OK, rc); + using (sqlite3 db = ugly.open(":memory:")) + { + var rc = raw.sqlite3_enable_load_extension(db, 0); + Assert.Equal(raw.SQLITE_OK, rc); + } } } @@ -781,10 +785,17 @@ public void test_threadsafe() public void test_enable_shared_cache() { int result = raw.sqlite3_enable_shared_cache(1); - Assert.Equal(raw.SQLITE_OK, result); + // https://www.sqlite.org/c3ref/enable_shared_cache.html + // Note: This method is disabled on MacOS X 10.7 and iOS version 5.0 and will always + // return SQLITE_MISUSE. On those systems, shared cache mode should be enabled + // per-database connection via sqlite3_open_v2() with SQLITE_OPEN_SHAREDCACHE. + if (result != raw.SQLITE_MISUSE) + { + Assert.Equal(raw.SQLITE_OK, result); - result = raw.sqlite3_enable_shared_cache(0); - Assert.Equal(raw.SQLITE_OK, result); + result = raw.sqlite3_enable_shared_cache(0); + Assert.Equal(raw.SQLITE_OK, result); + } } [Fact] @@ -815,12 +826,15 @@ public void test_sqlite3_soft_heap_limit64() } [Fact] - public void sqlite3_hard_heap_limit64() + public void test_sqlite3_hard_heap_limit64() { var version = raw.sqlite3_libversion_number(); - if (version < 3031001) return; // Added in 3.31.1: https://sqlite.org/releaselog/3_31_1.html + // Skip failing test on macOS system provided libsqlite3.dylib + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && raw.GetNativeLibraryName() == "sqlite3") + return; + var query = raw.sqlite3_hard_heap_limit64(-1); Assert.True(query >= 0); @@ -835,11 +849,17 @@ public void sqlite3_hard_heap_limit64() [Fact] public void test_sqlite3_status() { + // Skip failing test on macOS system provided libsqlite3.dylib + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && raw.GetNativeLibraryName() == "sqlite3") + return; + using (sqlite3 db = ugly.open(":memory:")) { int current; int highwater; - ugly.sqlite3_status(raw.SQLITE_STATUS_MEMORY_USED, out current, out highwater, 0); + + var rc = raw.sqlite3_status(raw.SQLITE_STATUS_MEMORY_USED, out current, out highwater, 0); + Assert.Equal(raw.SQLITE_OK, rc); Assert.True(current > 0); Assert.True(highwater > 0); @@ -2825,6 +2845,10 @@ public class class_test_sqlite3_config [Order(0)] public void test_log() { + // Skip failing test on macOS system provided libsqlite3.dylib + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && raw.GetNativeLibraryName() == "sqlite3") + return; + var msgs = new List(); var rc = raw.sqlite3_config_log( (v, errcode, msg) => msgs.Add(msg), From 24e3a2a1b3da18847cb93fd5bbff7c4c734dded6 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Sun, 18 Jul 2021 21:51:49 +0200 Subject: [PATCH 4/4] Include osx-arm64 binaries for e_sqlite3 --- gen_nuspecs/gen_nuspecs.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/gen_nuspecs/gen_nuspecs.cs b/gen_nuspecs/gen_nuspecs.cs index 16b2876e..b0244ef5 100644 --- a/gen_nuspecs/gen_nuspecs.cs +++ b/gen_nuspecs/gen_nuspecs.cs @@ -318,12 +318,13 @@ string cpu } static string make_cb_path_mac( - WhichLib lib + WhichLib lib, + string cpu ) { var dir_name = lib.AsString_basename_in_cb(); var lib_name = lib.AsString_libname_in_cb(LibSuffix.DYLIB); - return Path.Combine("$cb_bin_path$", dir_name, "mac", lib_name); + return Path.Combine("$cb_bin_path$", dir_name, "mac", cpu, lib_name); } static void write_nuspec_file_entry_native_linux( @@ -344,13 +345,15 @@ XmlWriter f static void write_nuspec_file_entry_native_mac( WhichLib lib, + string cpu_in_cb, + string rid, XmlWriter f ) { var filename = lib.AsString_libname_in_nupkg(LibSuffix.DYLIB); write_nuspec_file_entry_native( - make_cb_path_mac(lib), - "osx-x64", + make_cb_path_mac(lib, cpu_in_cb), + rid, filename, f ); @@ -408,7 +411,8 @@ XmlWriter f write_nuspec_file_entry_native_uwp(lib, win_toolset, "appcontainer", "x64", "win10-x64", f); write_nuspec_file_entry_native_uwp(lib, win_toolset, "appcontainer", "x86", "win10-x86", f); - write_nuspec_file_entry_native_mac(lib, f); + write_nuspec_file_entry_native_mac(lib, "x86_64", "osx-x64", f); + write_nuspec_file_entry_native_mac(lib, "arm64", "osx-arm64", f); write_nuspec_file_entry_native_linux(lib, "x64", "linux-x64", f); write_nuspec_file_entry_native_linux(lib, "x86", "linux-x86", f);