Compare commits

...

2 commits

Author SHA1 Message Date
Anton Nesterov 849dbff420
[feat] add shared lib build script 2024-08-29 22:39:27 +02:00
Anton Nesterov 9572a7e549
[feat] add shared lib build script 2024-08-29 22:35:08 +02:00
6 changed files with 8 additions and 14 deletions

View file

@ -23,11 +23,11 @@ static Napi::Object RowIterator(const Napi::CallbackInfo& args) {
free(next);
return val;
};
auto free_iter = [=](const Napi::CallbackInfo& a){
auto cleanup = [=](const Napi::CallbackInfo& a){
FreeIter(iter);
};
it.Set("next", Napi::Function::New(env, next_row));
it.Set("free", Napi::Function::New(env, free_iter));
it.Set("cleanup", Napi::Function::New(env, cleanup));
return it;
}

View file

@ -1,5 +0,0 @@
build-lib:
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -o ../lib/libdal-arm64.dylib -buildmode=c-shared ./dal.go
for arch in amd64 arm64; do\
CC=x86_64-unknown-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=$${arch} go build -o ../lib/libdal-$${arch}.so -buildmode=c-shared ./dal.go;\
done

View file

@ -2,7 +2,7 @@ import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
type RowIterator = {
next: () => Buffer;
free: () => void;
cleanup: () => void;
};
type SQLite = {
initSQLite: (pragmas: Buffer) => void;

View file

@ -3,7 +3,7 @@
*/
import { dlopen, FFIType, suffix, ptr, toBuffer } from "bun:ffi";
const libname = `lib/clib.${suffix}`;
const libname = `../clib/clib.${suffix}`;
const libpath = libname;
const {
@ -35,9 +35,8 @@ const {
},
});
function initSQLite(pragmas: string) {
const buf = Buffer.from(pragmas);
InitSQLite(ptr(buf));
function initSQLite(pragmas: Buffer) {
InitSQLite(ptr(pragmas));
}
function rowIterator(buf: Buffer) {

View file

@ -27,7 +27,7 @@ export default class CBuilder<
const response = iter.next();
const rows = decodeRows(response);
if (rows.length === 0) {
iter.free();
iter.cleanup();
break;
}
for (const row of rows) {

View file

@ -27,7 +27,7 @@
"fmt": "prettier --write .",
"build": "tsc",
"prepublish": "tsc",
"preinstall": "cd binding && go build -buildmode=c-archive -o dal.a ./dal.go",
"preinstall": "cd binding && go build -buildmode=c-archive -o dal.a ./dal.go && cd ../clib && go build -o ./clib.dylib -buildmode=c-shared ./main.go",
"postinstall": "node-gyp configure build"
}
}