FYI I've just repeated a similar test with:

  * Nim devel 1.9.1
  * Nim stable 1.6.12
  * Rust nightly (1.70.0-nightly)



Shared conditions:

  * ubuntu 22.04
  * print "Hello, World!"
  * static link
  * lto
  * panics
  * opt size
  * musl
  * strip
  * no binary compression
  * no hacks on source code (subjective, I've been following 
<https://hookrace.net/blog/nim-binary-size/> and 
<https://github.com/johnthagen/min-sized-rust> up to a point)



hello.nim
    
    
    echo "Hello, World!"
    
    
    Run

Nim compile conf
    
    
    nim \
      --gcc.exe:/usr//bin/musl-gcc \
      --gcc.linkerexe:/usr/bin/musl-gcc \
      --passC:"-flto" \
      --passL:"-flto" \
      --passL:"-static" \
      --panics:on \
      --gc:arc \
      -d:release \
      --opt:size \
      c hello \
      && strip -s hello
    
    
    Run

hello.rs
    
    
    fn main() {
        println!("Hello, world!");
    }
    
    
    Run

Cargo.toml
    
    
    [package]
    name = "min-sized-rust"
    version = "0.1.0"
    edition = "2021"
    
    [profile.release]
    strip = true  # Automatically strip symbols from the binary.
    opt-level = "z"  # Optimize for size.
    lto = true
    codegen-units = 1
    panic = "abort"
    
    
    Run

Rust compile conf
    
    
    cargo +nightly build \
      -Z build-std=std,panic_abort \
      -Z build-std-features=panic_immediate_abort \
      --target="x86_64-unknown-linux-musl" \
      --release
    
    
    Run

Results (bytes):

  * Rust: 51296
  * Nim stable: 26296
  * Nim devel: 26368


Reply via email to