From a42740e6f08ecc8f8a9c58dac2f3c4370b5aeb11 Mon Sep 17 00:00:00 2001 From: Andrew Johnston Date: Mon, 11 Dec 2023 09:48:10 +0000 Subject: [PATCH 1/5] build bindings in LO_HOME --- lib/build.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/build.js b/lib/build.js index 1ef3254..11d9378 100644 --- a/lib/build.js +++ b/lib/build.js @@ -78,8 +78,8 @@ async function create_lo_home (path) { // todo: change these methods to accept objects, not filenames async function compile_bindings (lib, verbose = false) { const cwd = getcwd() - const lib_dir = `lib/${lib}` - const binding_path = `${lib_dir}/api.js` + const lib_dir = join(LO_HOME, `lib/${lib}`) + const binding_path = join(LO_HOME, `${lib_dir}/api.js`) // todo: download the lib if we don't have it internally console.log(`${AM}compile binding${AD} ${lib} ${AY}in${AD} ${lib_dir}`) @@ -129,7 +129,7 @@ async function compile_bindings (lib, verbose = false) { console.log(`${AY}shared lib ${AD} ${def.name}.so ${AY}with${AG} ${CC}${AD}`) unlink(`${def.name}.so`) if (os === 'mac') { - exec2([...LINK.split(' '), '-bundle_loader', '../../lo', ...LARGS, OPT, '-bundle', ...WARN, '-o', + exec2([...LINK.split(' '), '-bundle_loader', LO_PATH, ...LARGS, OPT, '-bundle', ...WARN, '-o', `${def.name}.so`, `${def.name}.o`, ...(def.obj || []).filter(f => extName(f) === 'a'), ...(def.libs || []).map(l => `-l${l}`), @@ -300,6 +300,16 @@ const LARGS = (getenv('LARGS') || link_args).split(' ') const so_ext = (os === 'linux' ? 'so' : (os === 'mac' ? 'so' : 'dll')) config.os = os +let LO_PATH = '../../lo' +if (os === 'mac') { + const { mach } = lo.load('mach') + const max_path = new Uint32Array([1024]) + const path_name = lo.ptr(new Uint8Array(1024)) + assert(mach.get_executable_path(path_name.ptr, max_path) === 0) + LO_PATH = lo.latin1Decode(path_name.ptr, max_path[0]) + console.log(`found lo at ${LO_PATH}`) +} + const runtimes = { core: { bindings: [ From c85eaf7bc4029c39ccc87ab8eb48958ec5bef2cc Mon Sep 17 00:00:00 2001 From: Andrew Johnston Date: Mon, 11 Dec 2023 09:48:30 +0000 Subject: [PATCH 2/5] fix timer close on macos --- lib/timer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/timer.js b/lib/timer.js index ff5b272..e49c416 100644 --- a/lib/timer.js +++ b/lib/timer.js @@ -27,7 +27,7 @@ class MacTimer { } close () { - this.loop.remove(this.fd) + this.loop.remove(this.fd, kevents.EVFILT_TIMER) } } From 0b20714e64c0c3ee6f74223661417cac04452763 Mon Sep 17 00:00:00 2001 From: Andrew Johnston Date: Mon, 11 Dec 2023 09:48:51 +0000 Subject: [PATCH 3/5] add write_string libssl binding --- lib/libssl/api.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/libssl/api.js b/lib/libssl/api.js index 27e72a5..255321d 100644 --- a/lib/libssl/api.js +++ b/lib/libssl/api.js @@ -309,6 +309,12 @@ const api = { pointers: ['SSL*'], result: 'i32' }, + SSL_write_string: { + parameters: ['pointer', 'string', 'i32'], + pointers: ['SSL*'], + result: 'i32', + name: 'SSL_write' + }, SSL_get_version: { parameters: ['pointer'], pointers: ['const SSL*'], From e8ef754ff38b162a5aa690b820d77e23a090e0c9 Mon Sep 17 00:00:00 2001 From: Andrew Johnston Date: Mon, 11 Dec 2023 09:49:07 +0000 Subject: [PATCH 4/5] SOCKADDR_LEN in net binding --- lib/net/api.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/net/api.js b/lib/net/api.js index fb61dff..e132468 100644 --- a/lib/net/api.js +++ b/lib/net/api.js @@ -98,6 +98,7 @@ const api = { }, write_string: { parameters: ['i32', 'string', 'i32'], + // we can add an override which reference another parameter and sets the param to a field/property of it override: [, , { param: 1, fastfield: '->length', slowfield: '.length()' }], result: 'i32', name: 'write' @@ -142,7 +143,8 @@ const constants = { IPPROTO_RAW: 'i32', SIOCSIFFLAGS: 'i32', SIOCSIFADDR: 'i32', - SIOCSIFNETMASK: 'i32', + SIOCSIFNETMASK: 'i32', + SOCKADDR_LEN: 16 } const includes = [ @@ -164,7 +166,6 @@ if (globalThis.lo) { includes.push('sys/sendfile.h') includes.push('linux/if_tun.h') constants.SOCK_NONBLOCK = 'i32' - constants.SOCKADDR_LEN = 16 // todo constants.SOCK_CLOEXEC = 'i32' constants.PF_PACKET = 'i32' constants.ETH_P_ALL = 'i32' From 8f610cd5b95a51a32912b39e319f4c23b989350d Mon Sep 17 00:00:00 2001 From: Andrew Johnston Date: Mon, 11 Dec 2023 11:50:26 +0000 Subject: [PATCH 5/5] bump version --- Makefile | 2 +- lib/build.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e03b958..2102f7e 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.12-pre +VERSION=0.0.13-pre V8_VERSION=1.0.0 RUNTIME=lo LO_HOME=$(shell pwd) diff --git a/lib/build.js b/lib/build.js index 11d9378..2cf9d30 100644 --- a/lib/build.js +++ b/lib/build.js @@ -246,7 +246,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.12pre"' +const VERSION = getenv('VERSION') || '"0.0.13pre"' const RUNTIME = getenv('RUNTIME') || '"lo"' const TARGET = getenv('TARGET') || 'lo' const LINK_TYPE = (getenv('LINK_TYPE') || '-rdynamic').split(' ')