Skip to content

Statically Linked version of PK CLI #84

Open
@CMCDragonkai

Description

@CMCDragonkai

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:

»» ~/Projects/airplane
 ♖ file airplane
airplane: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=Y7wWH3mifiqz5aem5Cxt/7sovkpNEjt7IJRP97P-1/CWBYjxSmrDYD9oEeD2kS/4L0HFVWRnfaSbHYuxre4, stripped

»» ~/Projects/airplane
 ♖ ldd ./airplane
	not a dynamic executable

»» ~/Projects/airplane
 ♜ ./airplane
Airplane CLI

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:

Note that fully static Node binaries are not capable of loading native bindings, so you may not use Node bindings with linuxstatic.

And our libraries that are native like js-db, js-quic... etc are all loaded using the dynamic link loader which relies on require or process.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

Tasks

  1. Investigate static compilation using pkg - compiled nodejs from source, along with bringing in static binaries
  2. Make sure the virtual filesystem that pkg needs to use still works
  3. Incorporate it into the nix process, the ci process, and distribution process
  4. Test that it works, and make sure we try to squeeze it down
  5. Test what "static" compilation means in the case of MacOS and Windows

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions