diff --git a/Makefile b/Makefile index 081ac82..24c4679 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.7-pre +VERSION=0.0.8-pre V8_VERSION=1.0.0 RUNTIME=lo LO_HOME=$(shell pwd) diff --git a/TODO.md b/TODO.md index aff9369..97b1bad 100644 --- a/TODO.md +++ b/TODO.md @@ -58,6 +58,7 @@ - [ ] **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 +- [ ] **todo**: we need an SSE4 alternative (NEON?) for arm64 for picohttpparser ## features diff --git a/builtins.S b/builtins.S index 2f7c56c..e9b1f89 100644 --- a/builtins.S +++ b/builtins.S @@ -73,11 +73,6 @@ __binary_lib_curl_api_js_start: .incbin "lib/curl/api.js" .global __binary_lib_curl_api_js_end __binary_lib_curl_api_js_end: -.global __binary_lib_duckdb_api_js_start -__binary_lib_duckdb_api_js_start: - .incbin "lib/duckdb/api.js" - .global __binary_lib_duckdb_api_js_end -__binary_lib_duckdb_api_js_end: .global __binary_lib_encode_api_js_start __binary_lib_encode_api_js_start: .incbin "lib/encode/api.js" @@ -93,16 +88,6 @@ __binary_lib_inflate_api_js_start: .incbin "lib/inflate/api.js" .global __binary_lib_inflate_api_js_end __binary_lib_inflate_api_js_end: -.global __binary_lib_inflate_em_inflate_c_start -__binary_lib_inflate_em_inflate_c_start: - .incbin "lib/inflate/em_inflate.c" - .global __binary_lib_inflate_em_inflate_c_end -__binary_lib_inflate_em_inflate_c_end: -.global __binary_lib_inflate_em_inflate_h_start -__binary_lib_inflate_em_inflate_h_start: - .incbin "lib/inflate/em_inflate.h" - .global __binary_lib_inflate_em_inflate_h_end -__binary_lib_inflate_em_inflate_h_end: .global __binary_lib_libffi_api_js_start __binary_lib_libffi_api_js_start: .incbin "lib/libffi/api.js" @@ -118,6 +103,16 @@ __binary_lib_lz4_api_js_start: .incbin "lib/lz4/api.js" .global __binary_lib_lz4_api_js_end __binary_lib_lz4_api_js_end: +.global __binary_lib_inflate_em_inflate_c_start +__binary_lib_inflate_em_inflate_c_start: + .incbin "lib/inflate/em_inflate.c" + .global __binary_lib_inflate_em_inflate_c_end +__binary_lib_inflate_em_inflate_c_end: +.global __binary_lib_inflate_em_inflate_h_start +__binary_lib_inflate_em_inflate_h_start: + .incbin "lib/inflate/em_inflate.h" + .global __binary_lib_inflate_em_inflate_h_end +__binary_lib_inflate_em_inflate_h_end: .global __binary_lib_mbedtls_api_js_start __binary_lib_mbedtls_api_js_start: .incbin "lib/mbedtls/api.js" @@ -168,3 +163,8 @@ __binary_lib_zlib_api_js_start: .incbin "lib/zlib/api.js" .global __binary_lib_zlib_api_js_end __binary_lib_zlib_api_js_end: +.global __binary_lib_duckdb_api_js_start +__binary_lib_duckdb_api_js_start: + .incbin "lib/duckdb/api.js" + .global __binary_lib_duckdb_api_js_end +__binary_lib_duckdb_api_js_end: diff --git a/builtins_linux.S b/builtins_linux.S index 98fc073..f7922f1 100644 --- a/builtins_linux.S +++ b/builtins_linux.S @@ -73,11 +73,6 @@ _binary_lib_curl_api_js_start: .incbin "lib/curl/api.js" .global _binary_lib_curl_api_js_end _binary_lib_curl_api_js_end: -.global _binary_lib_duckdb_api_js_start -_binary_lib_duckdb_api_js_start: - .incbin "lib/duckdb/api.js" - .global _binary_lib_duckdb_api_js_end -_binary_lib_duckdb_api_js_end: .global _binary_lib_encode_api_js_start _binary_lib_encode_api_js_start: .incbin "lib/encode/api.js" @@ -93,16 +88,6 @@ _binary_lib_inflate_api_js_start: .incbin "lib/inflate/api.js" .global _binary_lib_inflate_api_js_end _binary_lib_inflate_api_js_end: -.global _binary_lib_inflate_em_inflate_c_start -_binary_lib_inflate_em_inflate_c_start: - .incbin "lib/inflate/em_inflate.c" - .global _binary_lib_inflate_em_inflate_c_end -_binary_lib_inflate_em_inflate_c_end: -.global _binary_lib_inflate_em_inflate_h_start -_binary_lib_inflate_em_inflate_h_start: - .incbin "lib/inflate/em_inflate.h" - .global _binary_lib_inflate_em_inflate_h_end -_binary_lib_inflate_em_inflate_h_end: .global _binary_lib_libffi_api_js_start _binary_lib_libffi_api_js_start: .incbin "lib/libffi/api.js" @@ -118,6 +103,16 @@ _binary_lib_lz4_api_js_start: .incbin "lib/lz4/api.js" .global _binary_lib_lz4_api_js_end _binary_lib_lz4_api_js_end: +.global _binary_lib_inflate_em_inflate_c_start +_binary_lib_inflate_em_inflate_c_start: + .incbin "lib/inflate/em_inflate.c" + .global _binary_lib_inflate_em_inflate_c_end +_binary_lib_inflate_em_inflate_c_end: +.global _binary_lib_inflate_em_inflate_h_start +_binary_lib_inflate_em_inflate_h_start: + .incbin "lib/inflate/em_inflate.h" + .global _binary_lib_inflate_em_inflate_h_end +_binary_lib_inflate_em_inflate_h_end: .global _binary_lib_mbedtls_api_js_start _binary_lib_mbedtls_api_js_start: .incbin "lib/mbedtls/api.js" @@ -168,3 +163,8 @@ _binary_lib_zlib_api_js_start: .incbin "lib/zlib/api.js" .global _binary_lib_zlib_api_js_end _binary_lib_zlib_api_js_end: +.global _binary_lib_duckdb_api_js_start +_binary_lib_duckdb_api_js_start: + .incbin "lib/duckdb/api.js" + .global _binary_lib_duckdb_api_js_end +_binary_lib_duckdb_api_js_end: diff --git a/lib/build.js b/lib/build.js index d008cda..fbdb244 100644 --- a/lib/build.js +++ b/lib/build.js @@ -232,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.7pre"' +const VERSION = getenv('VERSION') || '"0.0.8pre"' const RUNTIME = getenv('RUNTIME') || '"lo"' const TARGET = getenv('TARGET') || 'lo' const C = getenv('C') || 'gcc' diff --git a/lib/pico/api.js b/lib/pico/api.js index 6c1e5dc..70982b6 100644 --- a/lib/pico/api.js +++ b/lib/pico/api.js @@ -121,7 +121,9 @@ async function build (C = 'gcc', CC = 'g++') { fetch('https://raw.githubusercontent.com/h2o/picohttpparser/master/picohttpparser.c', 'picohttpparser.c') const status = new Int32Array(2) const CARGS = C.split(' ') - exec(CARGS[0], [...CARGS.slice(1), '-c', '-I.', '-fPIC', '-O3', '-Wall', '-Wextra', '-msse4', '-std=c11', '-o', 'picohttpparser.o', 'picohttpparser.c'], status) + const ARCH_ARGS = ['-fPIC', '-O3', '-Wall', '-Wextra', '-std=c11'] + if (lo.core.arch === 'x64') ARCH_ARGS.push('-msse4') + exec(CARGS[0], [...CARGS.slice(1), '-c', '-I.', ...ARCH_ARGS, '-o', 'picohttpparser.o', 'picohttpparser.c'], status) } export { name, api, includes, obj, preamble, build } diff --git a/lib/tcc/api.js b/lib/tcc/api.js index 24975a8..ca76d6f 100644 --- a/lib/tcc/api.js +++ b/lib/tcc/api.js @@ -92,7 +92,9 @@ async function build (C = 'gcc', CC = 'g++') { if (obj.some(o => !isFile(o))) { assert(chdir('deps/libtcc') === 0) const status = new Int32Array(2) - exec('./configure', ['--extra-cflags=-mstackrealign -fPIC'], status) + let EXTRA_FLAGS = '-fPIC' + if (lo.core.arch === 'x64') EXTRA_FLAGS += ' -mstackrealign' + exec('./configure', [`--extra-cflags=${EXTRA_FLAGS}`], status) assert(status[0] === 0) exec('make', [`CC=${C}`, 'clean', 'libtcc.a'], status) assert(status[0] === 0) diff --git a/lib/wireguard/api.js b/lib/wireguard/api.js index 8432780..60660e5 100644 --- a/lib/wireguard/api.js +++ b/lib/wireguard/api.js @@ -95,7 +95,9 @@ async function build (C = 'gcc', CC = 'g++') { chdir('../') const status = new Int32Array(2) const CARGS = C.split(' ') - exec(CARGS[0], [...CARGS.slice(1), '-c', '-I.', '-mstackrealign', '-fPIC', '-O3', '-Ideps/wireguard-tools-master/contrib/embeddable-wg-library', '-o', 'wg.o', 'deps/wireguard-tools-master/contrib/embeddable-wg-library/wireguard.c'], status) + const ARCH_ARGS = ['-fPIC', '-O3'] + if (lo.core.arch === 'x64') ARCH_ARGS.push('-mstackrealign') + exec(CARGS[0], [...CARGS.slice(1), '-c', '-I.', ...ARCH_ARGS, '-Ideps/wireguard-tools-master/contrib/embeddable-wg-library', '-o', 'wg.o', 'deps/wireguard-tools-master/contrib/embeddable-wg-library/wireguard.c'], status) assert(status[0] === 0) const header = readFile('deps/wireguard-tools-master/contrib/embeddable-wg-library/wireguard.h') writeFile('wireguard.h', header) diff --git a/main.h b/main.h index 09eff51..bb42901 100644 --- a/main.h +++ b/main.h @@ -35,24 +35,22 @@ extern char _binary_lib_core_api_js_start[]; extern char _binary_lib_core_api_js_end[]; extern char _binary_lib_curl_api_js_start[]; extern char _binary_lib_curl_api_js_end[]; -extern char _binary_lib_duckdb_api_js_start[]; -extern char _binary_lib_duckdb_api_js_end[]; extern char _binary_lib_encode_api_js_start[]; extern char _binary_lib_encode_api_js_end[]; extern char _binary_lib_epoll_api_js_start[]; extern char _binary_lib_epoll_api_js_end[]; extern char _binary_lib_inflate_api_js_start[]; extern char _binary_lib_inflate_api_js_end[]; -extern char _binary_lib_inflate_em_inflate_c_start[]; -extern char _binary_lib_inflate_em_inflate_c_end[]; -extern char _binary_lib_inflate_em_inflate_h_start[]; -extern char _binary_lib_inflate_em_inflate_h_end[]; extern char _binary_lib_libffi_api_js_start[]; extern char _binary_lib_libffi_api_js_end[]; extern char _binary_lib_libssl_api_js_start[]; extern char _binary_lib_libssl_api_js_end[]; extern char _binary_lib_lz4_api_js_start[]; extern char _binary_lib_lz4_api_js_end[]; +extern char _binary_lib_inflate_em_inflate_c_start[]; +extern char _binary_lib_inflate_em_inflate_c_end[]; +extern char _binary_lib_inflate_em_inflate_h_start[]; +extern char _binary_lib_inflate_em_inflate_h_end[]; extern char _binary_lib_mbedtls_api_js_start[]; extern char _binary_lib_mbedtls_api_js_end[]; extern char _binary_lib_net_api_js_start[]; @@ -73,6 +71,8 @@ extern char _binary_lib_wireguard_api_js_start[]; extern char _binary_lib_wireguard_api_js_end[]; extern char _binary_lib_zlib_api_js_start[]; extern char _binary_lib_zlib_api_js_end[]; +extern char _binary_lib_duckdb_api_js_start[]; +extern char _binary_lib_duckdb_api_js_end[]; extern "C" { extern void* _register_core(); @@ -96,15 +96,14 @@ void register_builtins() { lo::builtins_add("lo.h", _binary_lo_h_start, _binary_lo_h_end - _binary_lo_h_start); lo::builtins_add("lib/core/api.js", _binary_lib_core_api_js_start, _binary_lib_core_api_js_end - _binary_lib_core_api_js_start); lo::builtins_add("lib/curl/api.js", _binary_lib_curl_api_js_start, _binary_lib_curl_api_js_end - _binary_lib_curl_api_js_start); - lo::builtins_add("lib/duckdb/api.js", _binary_lib_duckdb_api_js_start, _binary_lib_duckdb_api_js_end - _binary_lib_duckdb_api_js_start); lo::builtins_add("lib/encode/api.js", _binary_lib_encode_api_js_start, _binary_lib_encode_api_js_end - _binary_lib_encode_api_js_start); lo::builtins_add("lib/epoll/api.js", _binary_lib_epoll_api_js_start, _binary_lib_epoll_api_js_end - _binary_lib_epoll_api_js_start); lo::builtins_add("lib/inflate/api.js", _binary_lib_inflate_api_js_start, _binary_lib_inflate_api_js_end - _binary_lib_inflate_api_js_start); - lo::builtins_add("lib/inflate/em_inflate.c", _binary_lib_inflate_em_inflate_c_start, _binary_lib_inflate_em_inflate_c_end - _binary_lib_inflate_em_inflate_c_start); - lo::builtins_add("lib/inflate/em_inflate.h", _binary_lib_inflate_em_inflate_h_start, _binary_lib_inflate_em_inflate_h_end - _binary_lib_inflate_em_inflate_h_start); lo::builtins_add("lib/libffi/api.js", _binary_lib_libffi_api_js_start, _binary_lib_libffi_api_js_end - _binary_lib_libffi_api_js_start); lo::builtins_add("lib/libssl/api.js", _binary_lib_libssl_api_js_start, _binary_lib_libssl_api_js_end - _binary_lib_libssl_api_js_start); lo::builtins_add("lib/lz4/api.js", _binary_lib_lz4_api_js_start, _binary_lib_lz4_api_js_end - _binary_lib_lz4_api_js_start); + lo::builtins_add("lib/inflate/em_inflate.c", _binary_lib_inflate_em_inflate_c_start, _binary_lib_inflate_em_inflate_c_end - _binary_lib_inflate_em_inflate_c_start); + lo::builtins_add("lib/inflate/em_inflate.h", _binary_lib_inflate_em_inflate_h_start, _binary_lib_inflate_em_inflate_h_end - _binary_lib_inflate_em_inflate_h_start); lo::builtins_add("lib/mbedtls/api.js", _binary_lib_mbedtls_api_js_start, _binary_lib_mbedtls_api_js_end - _binary_lib_mbedtls_api_js_start); lo::builtins_add("lib/net/api.js", _binary_lib_net_api_js_start, _binary_lib_net_api_js_end - _binary_lib_net_api_js_start); lo::builtins_add("lib/pico/api.js", _binary_lib_pico_api_js_start, _binary_lib_pico_api_js_end - _binary_lib_pico_api_js_start); @@ -115,6 +114,7 @@ void register_builtins() { lo::builtins_add("lib/tcc/api.js", _binary_lib_tcc_api_js_start, _binary_lib_tcc_api_js_end - _binary_lib_tcc_api_js_start); lo::builtins_add("lib/wireguard/api.js", _binary_lib_wireguard_api_js_start, _binary_lib_wireguard_api_js_end - _binary_lib_wireguard_api_js_start); lo::builtins_add("lib/zlib/api.js", _binary_lib_zlib_api_js_start, _binary_lib_zlib_api_js_end - _binary_lib_zlib_api_js_start); + lo::builtins_add("lib/duckdb/api.js", _binary_lib_duckdb_api_js_start, _binary_lib_duckdb_api_js_end - _binary_lib_duckdb_api_js_start); lo::modules_add("core", &_register_core); lo::modules_add("inflate", &_register_inflate); lo::modules_add("curl", &_register_curl); diff --git a/main_win.h b/main_win.h index d0f070b..90abb66 100644 --- a/main_win.h +++ b/main_win.h @@ -29,15 +29,14 @@ void register_builtins() { lo::builtins_add("lo.h", _binary_lo_h_start, _binary_lo_h_len); lo::builtins_add("lib/core/api.js", _binary_lib_core_api_js_start, _binary_lib_core_api_js_len); lo::builtins_add("lib/curl/api.js", _binary_lib_curl_api_js_start, _binary_lib_curl_api_js_len); - lo::builtins_add("lib/duckdb/api.js", _binary_lib_duckdb_api_js_start, _binary_lib_duckdb_api_js_len); lo::builtins_add("lib/encode/api.js", _binary_lib_encode_api_js_start, _binary_lib_encode_api_js_len); lo::builtins_add("lib/epoll/api.js", _binary_lib_epoll_api_js_start, _binary_lib_epoll_api_js_len); lo::builtins_add("lib/inflate/api.js", _binary_lib_inflate_api_js_start, _binary_lib_inflate_api_js_len); - lo::builtins_add("lib/inflate/em_inflate.c", _binary_lib_inflate_em_inflate_c_start, _binary_lib_inflate_em_inflate_c_len); - lo::builtins_add("lib/inflate/em_inflate.h", _binary_lib_inflate_em_inflate_h_start, _binary_lib_inflate_em_inflate_h_len); lo::builtins_add("lib/libffi/api.js", _binary_lib_libffi_api_js_start, _binary_lib_libffi_api_js_len); lo::builtins_add("lib/libssl/api.js", _binary_lib_libssl_api_js_start, _binary_lib_libssl_api_js_len); lo::builtins_add("lib/lz4/api.js", _binary_lib_lz4_api_js_start, _binary_lib_lz4_api_js_len); + lo::builtins_add("lib/inflate/em_inflate.c", _binary_lib_inflate_em_inflate_c_start, _binary_lib_inflate_em_inflate_c_len); + lo::builtins_add("lib/inflate/em_inflate.h", _binary_lib_inflate_em_inflate_h_start, _binary_lib_inflate_em_inflate_h_len); lo::builtins_add("lib/mbedtls/api.js", _binary_lib_mbedtls_api_js_start, _binary_lib_mbedtls_api_js_len); lo::builtins_add("lib/net/api.js", _binary_lib_net_api_js_start, _binary_lib_net_api_js_len); lo::builtins_add("lib/pico/api.js", _binary_lib_pico_api_js_start, _binary_lib_pico_api_js_len); @@ -48,6 +47,7 @@ void register_builtins() { lo::builtins_add("lib/tcc/api.js", _binary_lib_tcc_api_js_start, _binary_lib_tcc_api_js_len); lo::builtins_add("lib/wireguard/api.js", _binary_lib_wireguard_api_js_start, _binary_lib_wireguard_api_js_len); lo::builtins_add("lib/zlib/api.js", _binary_lib_zlib_api_js_start, _binary_lib_zlib_api_js_len); + lo::builtins_add("lib/duckdb/api.js", _binary_lib_duckdb_api_js_start, _binary_lib_duckdb_api_js_len); lo::modules_add("core", &_register_core); lo::modules_add("inflate", &_register_inflate); lo::modules_add("curl", &_register_curl);