diff --git a/Makefile b/Makefile index ff540c1..081ac82 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ CCARGS=-std=c++17 -c -fno-omit-frame-pointer -fno-rtti -fno-exceptions CARGS=-c -fno-omit-frame-pointer WARN=-Werror -Wpedantic -Wall -Wextra -Wno-unused-parameter OPT=-O3 -VERSION=0.0.6-pre +VERSION=0.0.7-pre V8_VERSION=1.0.0 RUNTIME=lo LO_HOME=$(shell pwd) diff --git a/TODO.md b/TODO.md index eec80b5..aff9369 100644 --- a/TODO.md +++ b/TODO.md @@ -56,6 +56,8 @@ - [ ] **todo**: rename lo.library and lo.libraries to lo.binding and lo.bindings - [ ] **todo**: proc.js - mem() doesn't work on macos (no proc fs) - [ ] **bug**: if i run ```lo main.js``` it goes into a loop as it tries to recursively load the builtin main.js +- [ ] **bug**: for static libraries, we need to compile without -fPIC: https://stackoverflow.com/questions/28187163/how-do-you-link-a-static-library-to-a-shared-library +- [ ] **todo**: change inflate builder to download the depencies rather than having them embedded in the runtime ## features diff --git a/lib/build.js b/lib/build.js index 6d2a734..d008cda 100644 --- a/lib/build.js +++ b/lib/build.js @@ -104,11 +104,13 @@ async function compile_bindings (lib, verbose = false) { } console.log(`${AY}compile${AD} ${def.name}.cc ${AY}with${AG} ${CC}${AD}`) + unlink(`${def.name}.o`) exec2([...CC.split(' '), ...CFLAGS, OPT, `-I${LO_HOME}`, `-I${LO_HOME}/v8`, ...include_paths.map(p => `-I${p}`), '-I.', `-I${LO_HOME}/v8/include`, `-I${lib_dir}`, ...WARN, '-o', `${def.name}.o`, `${def.name}.cc`], verbose) console.log(`${AY}static lib ${AD} ${def.name}.a`) + unlink(`${def.name}.a`) if (def.obj && def.obj.length) { exec2(['ar', 'crsT', `${def.name}.a`, `${def.name}.o`, ...def.obj.filter(f => extName(f) === 'o')], verbose) } else { @@ -118,13 +120,15 @@ async function compile_bindings (lib, verbose = false) { // todo: fix this for mac // https://copyprogramming.com/howto/what-are-the-differences-between-so-and-dylib-on-macos console.log(`${AY}shared lib ${AD} ${def.name}.so ${AY}with${AG} ${CC}${AD}`) + unlink(`${def.name}.so`) if (os === 'mac') { exec2([...LINK.split(' '), ...LARGS, OPT, '-bundle', ...WARN, '-o', - `${def.name}.so`, `${def.name}.a`, ...(def.obj || []).filter(f => extName(f) === 'a'), + `${def.name}.so`, `${def.name}.o`, ...(def.obj || []).filter(f => extName(f) === 'a'), ...(def.libs || []).map(l => `-l${l}`)], verbose) } else if (os === 'linux') { // todo: why do we not include .o obj files here? + // confused by this. why does linking against the .a file not work? exec2([...LINK.split(' '), ...LARGS, OPT, '-shared', ...WARN, '-o', `${def.name}.so`, `${def.name}.o`, ...(def.obj || []).filter(f => extName(f) === 'a'), ...(def.libs || []).map(l => `-l${l}`)], @@ -228,7 +232,7 @@ const encoder = new TextEncoder() const status = new Int32Array(2) // todo: clean up api so we can pass a config in and run builds through api -const VERSION = getenv('VERSION') || '"0.0.6pre"' +const VERSION = getenv('VERSION') || '"0.0.7pre"' const RUNTIME = getenv('RUNTIME') || '"lo"' const TARGET = getenv('TARGET') || 'lo' const C = getenv('C') || 'gcc' @@ -278,15 +282,14 @@ const runtimes = { 'lo.h', 'lib/core/api.js', 'lib/curl/api.js', - 'lib/duckdb/api.js', 'lib/encode/api.js', 'lib/epoll/api.js', 'lib/inflate/api.js', - 'lib/inflate/em_inflate.c', - 'lib/inflate/em_inflate.h', 'lib/libffi/api.js', 'lib/libssl/api.js', 'lib/lz4/api.js', + 'lib/inflate/em_inflate.c', + 'lib/inflate/em_inflate.h', 'lib/mbedtls/api.js', 'lib/net/api.js', 'lib/pico/api.js', @@ -296,7 +299,8 @@ const runtimes = { 'lib/system/api.js', 'lib/tcc/api.js', 'lib/wireguard/api.js', - 'lib/zlib/api.js' + 'lib/zlib/api.js', + 'lib/duckdb/api.js', ] }, mbedtls: { diff --git a/lib/duckdb/api.js b/lib/duckdb/api.js index 118e049..7f1bac2 100644 --- a/lib/duckdb/api.js +++ b/lib/duckdb/api.js @@ -146,36 +146,30 @@ int set_config (duckdb_config* config, const char* key, const char* value) { } ` -import { fetch } from 'lib/curl.js' -import { inflate } from 'lib/inflate.js' -import { untar } from 'lib/untar.js' import { isDir, isFile } from 'lib/fs.js' import { exec } from 'lib/proc.js' async function build (C = 'gcc', CC = 'g++') { const { assert } = lo - const { chdir, mkdir, S_IRWXU, S_IRWXG, S_IROTH, S_IXOTH, readFile } = lo.core + const { chdir, mkdir, S_IRWXU, S_IRWXG, S_IROTH, S_IXOTH } = lo.core + const status = new Int32Array(2) + if (!isDir('deps/duckdb')) { mkdir('deps', S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) assert(chdir('deps') === 0) - if (!isFile('v0.9.2.tar.gz')) { - console.log('fetching release') - fetch('https://github.com/duckdb/duckdb/archive/refs/tags/v0.9.2.tar.gz', 'v0.9.2.tar.gz') - } - const bytes = readFile('v0.9.2.tar.gz') - const dir_name = untar(inflate(bytes)) - const cwd = lo.getcwd() - assert(lo.core.rename(`${cwd}/${dir_name}`, `${cwd}/duckdb`) === 0) + exec('git', ['clone', '--depth', '1', '--single-branch', '-b', 'v0.9.2', 'https://github.com/duckdb/duckdb.git'], status) + assert(status[0] === 0) assert(chdir('../') === 0) } + if (obj.some(o => !isFile(o))) { assert(chdir('deps/duckdb') === 0) - const status = new Int32Array(2) exec('python3', ['scripts/amalgamation.py'], status) exec(CC.split(' ')[0], [...CC.split(' ').slice(1), '-fPIC', '-c', '-O3', '-o', 'duckdb.o', '-Isrc/amalgamation', 'src/amalgamation/duckdb.cpp'], status) assert(status[0] === 0) assert(chdir('../../') === 0) } + } export { name, api, constants, structs, obj, build, include_paths, includes, preamble } diff --git a/lib/proc.js b/lib/proc.js index 6efceb4..25714c0 100644 --- a/lib/proc.js +++ b/lib/proc.js @@ -58,7 +58,7 @@ if (core.os === 'linux' || core.os === 'mac') { } } - exec = (name, vargs, status) => { + exec = (name, vargs, status = new Int32Array(2)) => { const { args } = makeArgs([name, ...vargs]) const pid = fork() if (pid === 0) { @@ -71,9 +71,10 @@ if (core.os === 'linux' || core.os === 'mac') { status[0] = lo.errno status[1] = pid } + return status } - exec_env = (name, vargs, env, status) => { + exec_env = (name, vargs, env, status = new Int32Array(2)) => { const { args } = makeArgs([name, ...vargs]) const pid = fork() if (pid === 0) { @@ -89,9 +90,10 @@ if (core.os === 'linux' || core.os === 'mac') { status[0] = lo.errno status[1] = pid } + return status } - exec_path_env = (name, vargs, env, status) => { + exec_path_env = (name, vargs, env, status = new Int32Array(2)) => { const { args } = makeArgs([name, ...vargs]) const env_args = makeArgs(env).args const pid = fork() @@ -105,6 +107,7 @@ if (core.os === 'linux' || core.os === 'mac') { status[0] = lo.errno status[1] = pid } + return status } }