Building from source on Windows

forkit forkit at gmail.com
Mon Jan 31 06:34:32 UTC 2022


On Friday, 28 January 2022 at 22:55:17 UTC, MoonlightSentinel 
wrote:
>
> Software:
> - Any VS version (already used 17 and 22 but others should work 
> as well)
> - DM make
>
> Setup for Druntime / Phobos*:
> - Change the VS-related variables in `win64.mak` based on your 
> specific VS installation (because they change with each version)
>   * `VCDIR`
>   * `SDKDIR`
>   * `BINDIR`
>
> Building should then be as simple as running `make -f 
> win64.mak` in each directory (for dmd it simply forwards to 
> `src/build.d`).
>
> ---
>
> Currently using VS 2022 which required the following changes:
>

So I've come up with the following code that will extract those 
values for me ;-)

// ----

module test;

import std.stdio : writeln;
import std.process : environment;

/+
When building from source on Windows, both "druntime\win64.mak"
and "phobos\win64.mak" require two variables (VCDIR and SDKDIR)
to be set according to the version of Visual Studio you are using.

This code below will provide you with the values for those two 
variables.

However, for this code to get those variables, you need to run 
this within
a VS Developer Command Prompt not a normal Command Prompt.
+/

int main()
{
     auto VCDIR = environment.get("VCToolsInstallDir");
     if (VCDIR is null) { return 1;}
     writeln("VCDIR=", VCDIR[0..$-1]); // also removes the 
trailing backslash

     auto SDKVersion = environment.get("WindowsSDKVersion");
     if (SDKVersion is null) { return 1;}

     auto SDKDIR = environment.get("WindowsSdkDir");
     if (SDKDIR is null) { return 1;}
     writeln("SDKDIR=", SDKDIR ~ "Include\\" ~ 
SDKVersion[0..$-1]); // also removes the trailing backslash

     return 0;
}

// -----


More information about the Digitalmars-d mailing list