Remix.run Logo
koito17 5 days ago

> Most shells take less space than that!

Most shells dynamically link to a runtime your OS provides "for free". The 4.3 MiB binary in question is bundling the Rust runtime and its dependencies.

For reference, a statically-compiled C++ "Hello, World" is 2.2 MiB after stripping.

  % cat hello.nix
  {
    pkgs ? import <nixpkgs> { crossSystem = "aarch64-linux"; }
  }:
  
  pkgs.stdenv.mkDerivation {
    name = "hello-static";
    src = pkgs.writeText "hello.cpp" ''
      #include <iostream>
      int main() {
        std::cout << "Hello, World!" << std::endl;
        return 0;
      }
    '';
    dontUnpack = true;
    buildInputs = [ pkgs.glibc.static ];
    buildPhase = "$CXX -std=c++17 -static -o hello $src";
    installPhase = "mkdir -p $out/bin; cp hello $out/bin/";
  }
  
  % nix-build hello.nix
  ...
  
  % wc -c result/bin/hello
  2224640 result/bin/hello