Skip to content

Commit

Permalink
Merge pull request #15 from billywhizz/main
Browse files Browse the repository at this point in the history
Fixes for linux arm64 bindings
  • Loading branch information
billywhizz authored Dec 2, 2023
2 parents 3190ce2 + da50a39 commit 0ed1840
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 47 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.7-pre
VERSION=0.0.8-pre
V8_VERSION=1.0.0
RUNTIME=lo
LO_HOME=$(shell pwd)
Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 15 additions & 15 deletions builtins.S
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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:
30 changes: 15 additions & 15 deletions builtins_linux.S
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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:
2 changes: 1 addition & 1 deletion lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 3 additions & 1 deletion lib/pico/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
4 changes: 3 additions & 1 deletion lib/tcc/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion lib/wireguard/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions main_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 0ed1840

Please sign in to comment.