mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 21:21:48 +03:00
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:
parent
2e2c799be6
commit
0186032fa9
3 changed files with 67 additions and 0 deletions
|
@ -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);
|
||||
|
|
1
compiler/test/dshell/extra-files/issue24111.c
Normal file
1
compiler/test/dshell/extra-files/issue24111.c
Normal file
|
@ -0,0 +1 @@
|
|||
#include <stdio.h>
|
15
compiler/test/dshell/issue24111.d
Normal file
15
compiler/test/dshell/issue24111.d
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue