Fix Bugzilla issue 24111 - [ImportC] fatal error C1034: stdio.h: no include path set (#16248)

* Fix Bugzilla issue 24111 - [ImportC] fatal error C1034: stdio.h: no include path set
This commit is contained in:
SHOO 2024-03-03 13:35:04 +09:00 committed by GitHub
parent 2e2c799be6
commit 0186032fa9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 67 additions and 0 deletions

View file

@ -1172,6 +1172,57 @@ public int runPreprocessor(ref const Loc loc, const(char)[] cpp, const(char)[] f
// Convert command to wchar
wchar[1024] scratch = void;
auto smbuf = SmallBuffer!wchar(scratch.length, scratch[]);
// INCLUDE
static VSOptions vsopt; // cache, as this can be expensive
static Strings includePaths;
if (includePaths.length == 0)
{
if (!vsopt.VSInstallDir)
vsopt.initialize();
if (auto vcincludedir = vsopt.getVCIncludeDir()) {
includePaths.push(vcincludedir);
} else {
return DArray!ubyte();
}
if (auto sdkincludedir = vsopt.getSDKIncludePath()) {
includePaths.push(FileName.combine(sdkincludedir, "ucrt"));
includePaths.push(FileName.combine(sdkincludedir, "shared"));
includePaths.push(FileName.combine(sdkincludedir, "um"));
includePaths.push(FileName.combine(sdkincludedir, "winrt"));
includePaths.push(FileName.combine(sdkincludedir, "cppwinrt"));
} else {
includePaths = Strings.init;
return DArray!ubyte();
}
}
// Get current environment variable and rollback
auto oldIncludePathLen = GetEnvironmentVariableW("INCLUDE"w.ptr, null, 0);
wchar* oldIncludePaths = cast(wchar*)mem.xmalloc(oldIncludePathLen * wchar.sizeof);
oldIncludePathLen = GetEnvironmentVariableW("INCLUDE"w.ptr, oldIncludePaths, oldIncludePathLen);
scope (exit)
{
SetEnvironmentVariableW("INCLUDE"w.ptr, oldIncludePaths);
mem.xfree(oldIncludePaths);
}
// Make new environment variable
OutBuffer envbuf;
foreach (inc; includePaths[])
{
if (FileName.exists(inc) == 2)
{
envbuf.write(cast(const ubyte[])toWStringz(inc[0..strlen(inc)], smbuf));
envbuf.writewchar(';');
}
}
envbuf.write(cast(const ubyte[])oldIncludePaths[0..oldIncludePathLen]);
envbuf.writewchar('\0');
// Temporarily set INCLUDE environment variable
SetEnvironmentVariableW("INCLUDE"w.ptr, cast(LPCWSTR)envbuf.buf);
auto szCommand = toWStringz(buf.peekChars()[0 .. buf.length], smbuf);
int exitCode = runProcessCollectStdout(szCommand.ptr, buffer[], &sink);

View file

@ -0,0 +1 @@
#include <stdio.h>

View file

@ -0,0 +1,15 @@
import dshell;
int main()
{
version (Windows)
{
auto cmd = "$DMD -m$MODEL -c $EXTRA_FILES" ~ SEP ~ "issue24111.c";
run(cmd);
import std.process: environment;
environment.remove("INCLUDE");
run(cmd);
}
return 0;
}