-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Statically Linked version of PK CLI #84
Comments
Based on some research in:
Node ExecutableThe node executable that we use from https://github.com/yao-pkg/pkg like for example https://github.com/yao-pkg/pkg-fetch/releases/download/v3.5/node-v20.11.1-linux-x64 is a slimmed down node executable designed specifically to be used for embedding for pkg. It is however a fully featured node executable, if you were to launch it, it asks you for a path to a file to execute. Unlike the regular node executable, it does not launch a prompt on startup. Unlike the
Things like zlib, openssl... etc are already statically linked into the binary. If we want to do further static linking (for portability reasons, not necessarily performance reasons), you could try to statically link the C++ standard library dependencies first, but for the Glibc, you'd need to use musl or something that is intended for static linking. This will require bringing the compilation of the node binary into the fold of Matrix AI, and running our own CI to do this. We should aim to do this for security reasons anyway and supply chain security. To make the downloaded node executable work in NixOS you just need to add the interpreter path first as this solves the Glibc standard library, and then add a rpath to load the C++ standard library.
The role of
|
@brynblack @tegefaulkes this would be the high level issue over #102. |
The serialised JS should be optimised as much as possible too. With compression and elimination of unnecessary artifacts (tree shaking with esmodule support) too. |
There's actually one more thing that isn't addressed, and that's https://github.com/MatrixAI/js-workers. The migration to ESM MatrixAI/js-workers#12 has been stumped because of the underlying library isn't suited for it. The way multi-processing and web-workers work in node is relying on launching a copy of the interpreter process but executing some code that may exist on the filesystem. As per MatrixAI/TypeScript-Demo-Lib#32, I think multiprocessing/multithreading needs to be re-framed entirely... If we are trying to enable to the ability to share memory/library/objects between the threads and without a filesystem... then one has to consider how it decomposes down to using pthreads at all. |
Specification
Being inspired by Golang and other products like airplane.dev... etc. I can see that statically linked CLI executables is far easier to distribute. For example in https://github.com/airplanedev/cli/releases/tag/v0.3.201 you can just download the executable, and immediately run it on NixOS without problems:
One thing that would make it easier, is that we would be able to run
polykey
on NixOS and other Linux distributions far more easily.Right now when we produce the Linux release of the CLI executable, we have to use
steam-run
on NixOS to run it because it uses the precompiled nodejs from https://github.com/yao-pkg/pkg-fetch and https://github.com/yao-pkg/pkg, which is a dynamically linked nodejs that refers to the standard Linux FHS location for the link loader, which is not the same location as it is on NixOS.We also saw recently that due to the latest release of rocksdb, it didn't work on an older version of Ubuntu because it didn't have the latest C++ libraries.
We can sidestep all of this by statically building a binary. In fact pkg does support this. However it mentions this:
And our libraries that are native like
js-db
,js-quic
... etc are all loaded using the dynamic link loader which relies onrequire
orprocess.dlopen
.So we need to figure out how to produce statically linkable object files from
js-db
for example, and have that be consumed by Polykey-CLI to statically compile with the nodejs static. I'm not even sure if this is in fact possible, without also bringing in the compilation process of nodejs itself in PK-CLI somehow (right now we don't compile nodejs, it's just assumed to exist in binary form when we build the binary).I raised a question about this in yao-pkg/pkg#12.
Additional context
steam-run
package from NixOS simulates a FHS, but it's possible it's overkill, since you can actually simulate an FHS using nix-shellbuild --compile
and a native FFI, however that's a major overhaul, I'm not even sure if it does a full static build, no docs on this.deno compile
and use it in Nix. REPL starts instead of program. denoland/deno#19961 (comment) - Resolution of the mystery of how to patch deno compiled binariesTasks
pkg
- compiled nodejs from source, along with bringing in static binariesThe text was updated successfully, but these errors were encountered: