Control: forwarded -1 https://github.com/dlang/dmd/pull/22464
Control: tags -1 + patch

On 1/27/26 21:16, Chris Lamb wrote:
Package: gdc-15
Version: 15.2.0-12
User: [email protected]
Usertags: toolchain timezone
Severity: normal

Dear Maintainer,

GDC handles SOURCE_DATE_EPOCH differently from GCC with respect
to timezones:

   $ cat test.c
   #include <stdio.h>
   void main() { printf(__DATE__ " " __TIME__ "\n"); }

   $ cat test.d
   import std.stdio;
   void main() { writeln(__DATE__ ~ " " ~ __TIME__); }

   $ SOURCE_DATE_EPOCH=1 gcc test.c -o test-c
   $ SOURCE_DATE_EPOCH=1 gdc test.d -o test-d

   $ ./test-c
   Jan  1 1970 00:00:01
   $ ./test-d
   Dec 31 1969 16:00:01

That final line should also be "Jan  1 1970 00:00:01", as gdc
should in effect ignore my machine's timezone (-0800) as
SOURCE_DATE_EPOCH is specified at compile time.

This affects the reproducibility of D packages that use
__TIME__ or __DATE__, such as dub:

   https://tests.reproducible-builds.org/debian/rb-pkg/unstable/amd64/dub.html

§

The cause of this is in gcc/d/dmd/globals.d:

         time_t ct;
         // https://issues.dlang.org/show_bug.cgi?id=20444
         if (auto p = getenv("SOURCE_DATE_EPOCH"))
         {
             if (!ct.parseDigits(p[0 .. strlen(p)]))
                 errorSink.error(Loc.initial, "value of environment variable 
`SOURCE_DATE_EPOCH` should be a valid UNIX timestamp, not: `%s`", p);
         }
         else
             core.stdc.time.time(&ct);
         const p = ctime(&ct);
         assert(p);

This call to ctime should be basically asctime(gmtime(&ct)), but only in
the case that SOURCE_DATE_EPOCH is set... so something like:

         time_t ct;
         char* p;
         // https://issues.dlang.org/show_bug.cgi?id=20444
         if (auto p2 = getenv("SOURCE_DATE_EPOCH"))
         {
             if (!ct.parseDigits(p2[0 .. strlen(p2)]))
                 errorSink.error(Loc.initial, "value of environment variable 
`SOURCE_DATE_EPOCH` should be a valid UNIX timestamp, not: `%s`", p2);
             p = asctime(gmtime(&ct));
         }
         else {
             core.stdc.time.time(&ct);
             p = ctime(&ct);
         }
         assert(p);

… although I am not a D programmer so this is not very idiomatic.


Regards,


Reply via email to