Skip to content

Commit

Permalink
Merge pull request #14 from billywhizz/main
Browse files Browse the repository at this point in the history
0.0.7-pre
  • Loading branch information
billywhizz authored Dec 2, 2023
2 parents 85d7f17 + c60fa73 commit 3190ce2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 10 additions & 6 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}`)],
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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',
Expand All @@ -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: {
Expand Down
20 changes: 7 additions & 13 deletions lib/duckdb/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
9 changes: 6 additions & 3 deletions lib/proc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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()
Expand All @@ -105,6 +107,7 @@ if (core.os === 'linux' || core.os === 'mac') {
status[0] = lo.errno
status[1] = pid
}
return status
}

}
Expand Down

0 comments on commit 3190ce2

Please sign in to comment.