Live data from Hacker News

Show HN: Tiny 1k Rust binary on Windows

github.com

11–20 of 66 posts

Re: Show HN: Tiny 1k Rust binary on Windows

#11

On Windows the smallest exe can be achieved by writing in assembly and compiling as .com executable. These literally just contain the compiled assembly and are usually used on, for example, the 4k demoscene. 1k with rust is certainly a nice squeeze.

The size limited demos are use techniques like in the OP, scrapping the runtime, no std, filling the unused exe header sections with own data, quantizing floating point values, etc. And/or exe packers like Crinkler and kkrunchy. COM's are no longer used.

Re: Show HN: Tiny 1k Rust binary on Windows

#12

I have found this https://github.com/HugoPlatzer/tiny-rust-binaries . Can you test it and see how it behaves with msvc toolchain?

That contains a lot of platform-specific build instructions for Linux (and for the ELF file format used on Linux but not Windows), so it's never going to work with the msvc toolchain.

For some reason, I saw ELF as EXE! hahaha ^_^

My bad everyone, my bad!

Re: Show HN: Tiny 1k Rust binary on Windows

#16

I'm disappointed. In C I can get a 1k Hello Word binary simply be writing int main(void) { puts("Hello World!"); return 0; } The Rust version is a mess [0] [0] https://github.com/mcountryman/min-sized-rust-windows/blob/m...

You're comparing C+StdLib vs. Rust without StdLib. Disable stdlib for C version and use the following program:

#include

int _start() {

    const char str[] = "Hello world!\n";
    HANDLE stdout = GetStdHandle(STD_OUTPUT_HANDLE);
    DWORD written;

    WriteFile(stdout, str, sizeof(str), &written, NULL);
    ExitProcess(12);

    return 0;
}

https://stackoverflow.com/a/42536990

Which is similar to what the Rust program does. The result should be significantly less than 1k

Re: Show HN: Tiny 1k Rust binary on Windows

#17

I'm disappointed. In C I can get a 1k Hello Word binary simply be writing int main(void) { puts("Hello World!"); return 0; } The Rust version is a mess [0] [0] https://github.com/mcountryman/min-sized-rust-windows/blob/m...

Can you, though?

Compiling that source on Windows using visual studio produces a 98K executable.

Re: Show HN: Tiny 1k Rust binary on Windows

#19
post #14

I notice you moved from asm! to llvm_asm! [0]. Since the commit message doesn't explain why, would you be able to do so here? (Purely for my own curiosity) [0] https://github.com/mcountryman/min-sized-rust-windows/commit...

They are the same: asm! was replaced by llvm_asm! because it currently only supports llvm asm and the name might suggest otherwise [1]. A backend independant syntax for asm! was recently specified [2], but that will take some time to implement.

[1] https://github.com/rust-lang/rfcs/pull/2843

[2] https://github.com/rust-lang/rfcs/pull/2873

Re: Show HN: Tiny 1k Rust binary on Windows

#20

Earlier quoted context omitted.

That contains a lot of platform-specific build instructions for Linux (and for the ELF file format used on Linux but not Windows), so it's never going to work with the msvc toolchain.

For some reason, I saw ELF as EXE! hahaha ^_^ My bad everyone, my bad!

I linked these guys here https://github.com/pts/pts-tinype. They managed to do something similar with the PE headers, and I might have to try that next although I'm doubtful win64 exes are permitted to run if they are >1Kb
Post reply on HN