Skip to content

Remove the compiler binary's hard dependency on node_modules/node.js in general. #15

@miviwi

Description

@miviwi

The issue

As of right now - and correct me if I'm wrong, as I'm writing this up only based on what I know about node.js in general - attempting to do this:

$ git clone https://github.com/lys-lang/lys-compiler.git && cd lys-compiler
$ npm i     # <-pretty sure this isn't strictly necessary?
$ make build
$ # assuming the directly `~/.local/bin` exists and is included in PATH
$ install node_module/.bin/lys ~/.local/bin
$ lys

...results in a "bad" binary in the sense that it throws an error1 (and I don't mean the one about a missing input file).

On my system it looks very similar to this (I've replaced the path to my home directory with ${HOME}):

node:internal/modules/cjs/loader:1412
  throw err;
  ^

Error: Cannot find module './index-bin'
Require stack:
- ${HOME}/.local/bin/lys
    at Function._resolveFilename (node:internal/modules/cjs/loader:1409:15)
    at defaultResolveImpl (node:internal/modules/cjs/loader:1060:19)
    at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1065:22)
    at Function._load (node:internal/modules/cjs/loader:1214:37)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:234:24)
    at Module.require (node:internal/modules/cjs/loader:1495:12)
    at require (node:internal/modules/helpers:135:16)
    at Object.<anonymous> (${HOME}/.local/bin/lys:4:21)
    at Module._compile (node:internal/modules/cjs/loader:1739:14) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '${HOME}/.local/bin/lys' ]
}

Node.js v23.6.0

My problem is that lys should be a standalone binary at best... but to be real with ourselves an/some extra *.sos/*.dlls will likely be required. Currently it's very far from that, as I believe to have demonstrated (all this isn't even mentioning the fact it's non-obvious — without looking through node_modules/doing a findwhere index-bin.js is even located)

Obviously I'm aware of the fact that an x86/ARM can't execute WASM by itself (😉) which is the crux of the matter here.

My proposition:

  1. in the long term completely discard node as our runtime in lieu of a native one
    • ex. wasmtime is super simple — less than 50 lines of code in Python for ex. is able to spit out a native, AOT compiled ELF/Mach-O binary
  2. for the time being - introduce some kind of a "bundling" step, so that one can just do something to the effect of install node_modules/**/lys [...] and have it work
    • doesn't necessarily have to be 1 file... just not the ~44 .js files which currently make up the lys/dist directory (not counting the .lys files in stdlib/ as having separate source files is unavoidable in this case); pack them into some archive during make build, then extract into a temp directory at runtime — that sort of thing

Note:

I may have/have likely made many (many) false assumptions here and am aware of such a possibility. Please do correct any errors in my understanding. Having said that though, none of them take away from my broader point I believe.

Footnotes

  1. as does the compilation command make build/make lys-build itself (make lys-test is... unaffected somehow?), likely due to incompatibilites with node v23. doesn't seem to matter much though as executing ./node_modules/.bin/lys is fine...?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions