From 8c9155a45573f36d4643d313ed90945a73e4e1c2 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sun, 31 May 2026 17:52:55 +0900 Subject: [PATCH] checks/check-static-exts-cross: init, move checks to separate dir --- checks/check-static-exts-cross.nix | 37 ++++++++++ checks/check-static-exts.nix | 35 ++++++++++ .../sqlite-example-exts}/addext.c | 0 .../sqlite-example-exts}/multext.c | 0 .../sqlite-example-exts}/subext.c | 0 checks/util/sqlite-example-exts-static.nix | 35 ++++++++++ flake.nix | 67 +------------------ 7 files changed, 110 insertions(+), 64 deletions(-) create mode 100644 checks/check-static-exts-cross.nix create mode 100644 checks/check-static-exts.nix rename {sqlite-example-exts => checks/sqlite-example-exts}/addext.c (100%) rename {sqlite-example-exts => checks/sqlite-example-exts}/multext.c (100%) rename {sqlite-example-exts => checks/sqlite-example-exts}/subext.c (100%) create mode 100644 checks/util/sqlite-example-exts-static.nix diff --git a/checks/check-static-exts-cross.nix b/checks/check-static-exts-cross.nix new file mode 100644 index 0000000..c8e9850 --- /dev/null +++ b/checks/check-static-exts-cross.nix @@ -0,0 +1,37 @@ +{ self, pkgs }: +let + pkgs' = pkgs.pkgsCross.aarch64-multiplatform; + + sqlite-example-exts-static = pkgs'.callPackage ./util/sqlite-example-exts-static.nix { }; + + sqlite-with-static-exts = self.mkSqlite { + pkgs = pkgs'; + + extensions = [ + { + library = "${sqlite-example-exts-static}/lib/libaddext.a"; + init = "sqlite3_addext_init"; + } + { + library = "${sqlite-example-exts-static}/lib/libsubext.a"; + init = "sqlite3_subext_init"; + } + { + library = "${sqlite-example-exts-static}/lib/libmultext.a"; + init = "sqlite3_multext_init"; + } + ]; + }; +in +pkgs'.runCommand "test-sqlite-with-static-exts-aarch64" { + nativeBuildInputs = [ sqlite-with-static-exts.sqlite-cli ]; + + passthru = { + inherit sqlite-example-exts-static; + inherit sqlite-with-static-exts; + }; +} '' + mkdir -p "$out" + sqlite3 :memory: <<<"SELECT myadd(1, 2), mysub(5, 3), mymult(4, 6);" | tee "$out/test.log" + grep -q -F "3|2|24" "$out/test.log" || (echo "Unexpected output from sqlite3 with static extensions" && exit 1) + '' diff --git a/checks/check-static-exts.nix b/checks/check-static-exts.nix new file mode 100644 index 0000000..10820b9 --- /dev/null +++ b/checks/check-static-exts.nix @@ -0,0 +1,35 @@ +{ self, pkgs }: +let + sqlite-example-exts-static = pkgs.callPackage ./util/sqlite-example-exts-static.nix { }; + + sqlite-with-static-exts = self.mkSqlite { + inherit pkgs; + + extensions = [ + { + library = "${sqlite-example-exts-static}/lib/libaddext.a"; + init = "sqlite3_addext_init"; + } + { + library = "${sqlite-example-exts-static}/lib/libsubext.a"; + init = "sqlite3_subext_init"; + } + { + library = "${sqlite-example-exts-static}/lib/libmultext.a"; + init = "sqlite3_multext_init"; + } + ]; + }; +in +pkgs.runCommand "test-sqlite-with-static-exts" { + nativeBuildInputs = [ sqlite-with-static-exts.sqlite-cli ]; + + passthru = { + inherit sqlite-example-exts-static; + inherit sqlite-with-static-exts; + }; +} '' + mkdir -p "$out" + sqlite3 :memory: <<<"SELECT myadd(1, 2), mysub(5, 3), mymult(4, 6);" | tee "$out/test.log" + grep -q -F "3|2|24" "$out/test.log" || (echo "Unexpected output from sqlite3 with static extensions" && exit 1) + '' diff --git a/sqlite-example-exts/addext.c b/checks/sqlite-example-exts/addext.c similarity index 100% rename from sqlite-example-exts/addext.c rename to checks/sqlite-example-exts/addext.c diff --git a/sqlite-example-exts/multext.c b/checks/sqlite-example-exts/multext.c similarity index 100% rename from sqlite-example-exts/multext.c rename to checks/sqlite-example-exts/multext.c diff --git a/sqlite-example-exts/subext.c b/checks/sqlite-example-exts/subext.c similarity index 100% rename from sqlite-example-exts/subext.c rename to checks/sqlite-example-exts/subext.c diff --git a/checks/util/sqlite-example-exts-static.nix b/checks/util/sqlite-example-exts-static.nix new file mode 100644 index 0000000..262dbc7 --- /dev/null +++ b/checks/util/sqlite-example-exts-static.nix @@ -0,0 +1,35 @@ +{ + sqlite, + stdenv, +}: +stdenv.mkDerivation { + name = "sqlite-example-exts-static"; + src = ../sqlite-example-exts; + + env.NIX_CFLAGS_COMPILE = "-DSQLITE_CORE"; + + buildInputs = [ sqlite.dev ]; + buildPhase = '' + runHook preBuild + + "$CC" -c addext.c + "$AR" rcs libaddext.a addext.o + + "$CC" -c subext.c + "$AR" rcs libsubext.a subext.o + + "$CC" -c multext.c + "$AR" rcs libmultext.a multext.o + + runHook postBuild + ''; + + + installPhase = '' + runHook preInstall + + install -Dm444 *.a -t "$out/lib" + + runHook postInstall + ''; +} diff --git a/flake.nix b/flake.nix index 548093e..abd59ec 100644 --- a/flake.nix +++ b/flake.nix @@ -41,70 +41,9 @@ "sqlite-static${result._suffix}" = result.sqlite-static; }) productVars)); - checks = forAllSystems (system: pkgs: let - sqlite-example-exts-static = pkgs.stdenv.mkDerivation { - name = "sqlite-example-exts-static"; - src = ./sqlite-example-exts; - - env.NIX_CFLAGS_COMPILE = "-DSQLITE_CORE"; - - buildInputs = with pkgs; [ sqlite.dev ]; - buildPhase = '' - runHook preBuild - - "$CC" -c addext.c - "$AR" rcs libaddext.a addext.o - - "$CC" -c subext.c - "$AR" rcs libsubext.a subext.o - - "$CC" -c multext.c - "$AR" rcs libmultext.a multext.o - - runHook postBuild - ''; - - - installPhase = '' - runHook preInstall - - install -Dm444 *.a -t "$out/lib" - - runHook postInstall - ''; - }; - - sqlite-with-static-exts = self.mkSqlite { - inherit pkgs; - - extensions = [ - { - library = "${sqlite-example-exts-static}/lib/libaddext.a"; - init = "sqlite3_addext_init"; - } - { - library = "${sqlite-example-exts-static}/lib/libsubext.a"; - init = "sqlite3_subext_init"; - } - { - library = "${sqlite-example-exts-static}/lib/libmultext.a"; - init = "sqlite3_multext_init"; - } - ]; - }; - in { - checkExts = pkgs.runCommand "test-sqlite-with-static-exts" { - nativeBuildInputs = [ sqlite-with-static-exts.sqlite-cli ]; - - passthru = { - inherit sqlite-example-exts-static; - inherit sqlite-with-static-exts; - }; - } '' - mkdir -p "$out" - sqlite3 :memory: <<<"SELECT myadd(1, 2), mysub(5, 3), mymult(4, 6);" | tee "$out/test.log" - grep -q -F "3|2|24" "$out/test.log" || (echo "Unexpected output from sqlite3 with static extensions" && exit 1) - ''; + checks = forAllSystems (system: pkgs: { + checkStaticExts = import ./checks/check-static-exts.nix { inherit self pkgs; }; + checkStaticExtsCross = import ./checks/check-static-exts-cross.nix { inherit self pkgs; }; }); }; }