News for hackers. Stuff that matters.
Re:Show HN: Tiny 1k Rust binary on Windows by slezyr on Tuesday December 01, 2020 @08:13AM (#25264798)
You're comparing C+StdLib vs. Rust without StdLib. Disable stdlib for C version and use the following program:

#include <windows.h>

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 by ChrisSD on Tuesday December 01, 2020 @11:18AM (#25266511)
I tried your program with MSVC using the following command:

    cl small2.c /MD /link /entry:_start /subsystem:CONSOLE kernel32.lib
It's 5kb.
Re:Show HN: Tiny 1k Rust binary on Windows by slezyr on Tuesday December 01, 2020 @02:45PM (#25269021)
If I remember correctly you need a /nodefaultlib flag to disable stdlibs

https://docs.microsoft.com/en-us/cpp/build/reference/nodefau...

Re:Show HN: Tiny 1k Rust binary on Windows by ChrisSD on Tuesday December 01, 2020 @03:31PM (#25269504)
Ok, I've just tried that but I also needed to add `/force` otherwise it complained about missing symbols. So the full compile line is:

    cl small2.c /link /force /nodefaultlib /entry:_start /subsystem:CONSOLE kernel32.lib
This gets it down to 3kb.
Re:Show HN: Tiny 1k Rust binary on Windows by zamadatix on Tuesday December 01, 2020 @10:09AM (#25265805)
I think the thing being measured by GP is "easiest way to get to the 1kb mentioned in the title" not "most complicated way to get as small as possible".