C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Random numbers in identical builds

From: Jeremy Rifkin <rifkin.jer_at_[hidden]>
Date: Sat, 8 Mar 2025 09:15:05 -0600
You can fairly easily do this with -D and std::source_location.

Cheers,
Jeremy

On Sat, Mar 8, 2025 at 08:54 Frederick Virchanza Gotham via Std-Proposals <
std-proposals_at_[hidden]> wrote:

>
> There's another thread running alongside this one about constexpr clocks,
> but I'm changing topic to focus on having UUID's at compile time, allowing
> for repeatable builds that produce an identical binary.
>
> You start by generating a UUID, so let's say:
>
> 11223344556677881122334455667788
>
> You feed this into the compiler something like:
>
> g++ -c myfile.cpp -o myfile.o
> -uuid_seed=11223344556677881122334455667788
>
> And so then when the compiler encounters the preprocessor macro 'UUID',
> here's what it does:
>
> It takes the name of the file, the line number and the character number,
> so a string something like "myfile.cpp 5 25", and it feeds it into MD5 to
> produce a hash digest.
> It takes the hash digest and XOR's with the UUID we gave it at the command
> line.
>
> This will give us unique 128-bit numbers at compile time, and if we hit
> Rebuild, we'll get an identical binary. It will also work fine for parallel
> builds.
>
> If we ever want to change the random numbers, just change the UUID we give
> it at the command line.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2025-03-08 15:15:17