From e7bff1cf7a0dd456d333ff399f6095c5898630b4 Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Tue, 7 Nov 2023 01:42:18 +0100 Subject: [PATCH] VSOptions: Prepare for setting the INCLUDE env var for importC Upstreaming from LDC, to pave the way for fixing Issue 24111. --- compiler/src/dmd/vsoptions.d | 36 ++++++++++++++++++++++++++++++++++++ compiler/src/dmd/vsoptions.h | 2 ++ 2 files changed, 38 insertions(+) diff --git a/compiler/src/dmd/vsoptions.d b/compiler/src/dmd/vsoptions.d index d735040c1b62..be8f735c6055 100644 --- a/compiler/src/dmd/vsoptions.d +++ b/compiler/src/dmd/vsoptions.d @@ -471,6 +471,18 @@ public: return FileName.exists(proposed) ? proposed : null; } + const(char)* getVCIncludeDir() const + { + const(char)* proposed; + + if (VCToolsInstallDir !is null) + proposed = FileName.combine(VCToolsInstallDir, "include"); + else if (VCInstallDir !is null) + proposed = FileName.combine(VCInstallDir, "include"); + + return FileName.exists(proposed) ? proposed : null; + } + /** * get the path to the universal CRT libraries * Params: @@ -528,6 +540,30 @@ public: return null; } + const(char)* getSDKIncludePath() const + { + if (WindowsSdkDir) + { + alias umExists = returnDirIfContainsFile!"um"; // subdir in this case + + const sdk = FileName.combine(WindowsSdkDir.toDString, "include"); + if (WindowsSdkVersion) + { + if (auto p = umExists(sdk, WindowsSdkVersion.toDString)) // SDK 10.0 + return p; + } + // purely speculative + if (auto p = umExists(sdk, "win8")) // SDK 8.0 + return p; + if (auto p = umExists(sdk, "winv6.3")) // SDK 8.1 + return p; + if (auto p = umExists(sdk)) // SDK 7.1 or earlier + return p; + } + + return null; + } + private: extern(D): diff --git a/compiler/src/dmd/vsoptions.h b/compiler/src/dmd/vsoptions.h index fc63e1c1b9b3..5c6a7c38257a 100644 --- a/compiler/src/dmd/vsoptions.h +++ b/compiler/src/dmd/vsoptions.h @@ -25,8 +25,10 @@ struct VSOptions void initialize(); const char *getVCBinDir(bool x64, const char *&addpath) const; const char *getVCLibDir(bool x64) const; + const char *getVCIncludeDir() const; const char *getUCRTLibPath(bool x64) const; const char *getSDKLibPath(bool x64) const; + const char *getSDKIncludePath() const; }; #endif // _WIN32