checks/check-static-exts-cross: init, move checks to separate dir
This commit is contained in:
@@ -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)
|
||||
''
|
||||
@@ -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)
|
||||
''
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <sqlite3ext.h>
|
||||
|
||||
SQLITE_EXTENSION_INIT1
|
||||
|
||||
static void add_func(
|
||||
sqlite3_context *ctx,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
) {
|
||||
if (argc != 2) {
|
||||
sqlite3_result_null(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
int a = sqlite3_value_int(argv[0]);
|
||||
int b = sqlite3_value_int(argv[1]);
|
||||
|
||||
sqlite3_result_int(ctx, a + b);
|
||||
}
|
||||
|
||||
int sqlite3_addext_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
) {
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
|
||||
return sqlite3_create_function(
|
||||
db,
|
||||
"myadd",
|
||||
2,
|
||||
SQLITE_UTF8 | SQLITE_DETERMINISTIC,
|
||||
0,
|
||||
add_func,
|
||||
0,
|
||||
0
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <sqlite3ext.h>
|
||||
|
||||
SQLITE_EXTENSION_INIT1
|
||||
|
||||
static void mult_func(
|
||||
sqlite3_context *ctx,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
) {
|
||||
if (argc != 2) {
|
||||
sqlite3_result_null(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
int a = sqlite3_value_int(argv[0]);
|
||||
int b = sqlite3_value_int(argv[1]);
|
||||
|
||||
sqlite3_result_int(ctx, a * b);
|
||||
}
|
||||
|
||||
int sqlite3_multext_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
) {
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
|
||||
return sqlite3_create_function(
|
||||
db,
|
||||
"mymult",
|
||||
2,
|
||||
SQLITE_UTF8 | SQLITE_DETERMINISTIC,
|
||||
0,
|
||||
mult_func,
|
||||
0,
|
||||
0
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <sqlite3ext.h>
|
||||
|
||||
SQLITE_EXTENSION_INIT1
|
||||
|
||||
static void sub_func(
|
||||
sqlite3_context *ctx,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
) {
|
||||
if (argc != 2) {
|
||||
sqlite3_result_null(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
int a = sqlite3_value_int(argv[0]);
|
||||
int b = sqlite3_value_int(argv[1]);
|
||||
|
||||
sqlite3_result_int(ctx, a - b);
|
||||
}
|
||||
|
||||
int sqlite3_subext_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
) {
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
|
||||
return sqlite3_create_function(
|
||||
db,
|
||||
"mysub",
|
||||
2,
|
||||
SQLITE_UTF8 | SQLITE_DETERMINISTIC,
|
||||
0,
|
||||
sub_func,
|
||||
0,
|
||||
0
|
||||
);
|
||||
}
|
||||
@@ -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
|
||||
'';
|
||||
}
|
||||
Reference in New Issue
Block a user