Environment
- OS: Windows 11, non-admin user
- Build: dmd debug build, phobos
make BUILD=debug
Steps to reproduce
- Clone dmd and phobos
- Build dmd:
rdmd build.d BUILD=debug (from compiler/src/)
- Build phobos:
make -j4 BUILD=debug (from phobos/)
Error
src\core\stdc\errno.c: fatal error C1083: Cannot open compiler generated file: '\sla8.': Permission denied
Error: C preprocess command ...cl.exe failed for file src\core\stdc\errno.c, exit status 2
Root cause
runPreprocessor() in compiler/src/dmd/link.d:965 calls tmpnam(null) to generate
a temp file name for cl.exe's /Fi output flag. On Windows, MSVC CRT's tmpnam()
always returns paths in the format \sXXXXXX. (at the drive root — e.g. C:\sla8.),
regardless of the TMP/TEMP environment variables. Non-admin users cannot write
to the drive root, so cl.exe fails.
Fix
Replace tmpnam(null) with GetTempPathA + GetTempFileNameA, which correctly
use the user's temp directory:
import core.sys.windows.winbase : GetTempFileNameA, GetTempPathA;
char[260] tempDir = void;
char[260] tempFile = void;
GetTempPathA(260, tempDir.ptr);
GetTempFileNameA(tempDir.ptr, "dmd", 0, tempFile.ptr);
const(char)[] ifilename = tempFile[0 .. strlen(tempFile.ptr) + 1];