Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt DMD's MSVC toolchain detection #3415

Merged
merged 6 commits into from
May 4, 2020
Merged

Conversation

kinke
Copy link
Member

@kinke kinke commented Apr 29, 2020

This reduces the overhead for auto-detecting and setting up an MSVC toolchain from a very rough 1 second to about 8 milliseconds on my box. Enabling the auto-detection by default (and so preferring MSVC over the 'internal' toolchain if there's a Visual C++ installation) is now possible, fixing issues like #3402.

The MSVC setup now consists of the bare minimum - prepending 3 directories to the LIB env var and 1-2 directories to PATH.

@kinke
Copy link
Member Author

kinke commented Apr 29, 2020

@rainers: Looks usable, thx for this. I still didn't expect almost 10 ms for this stuff; the COM stuff alone takes 5-6 ms on my box (and I have 2 installations to iterate over).

I changed it to use the latest version found via COM, not the first one (and check for an existing VC subdir). I also don't want to reintroduce any narrow WinAPI calls and will switch to the wide API (e.g., when getting the installation dir from the registry); is that an option for DMD too? Otherwise the diff might get pretty ugly.

@JohanEngelen
Copy link
Member

This reduces the overhead for auto-detecting and setting up an MSVC toolchain from a very rough 1 second to about 8 milliseconds on my box. Enabling the auto-detection by default (and so preferring MSVC over the 'internal' toolchain if there's a Visual C++ installation) is now possible, fixing issues like #3402.

Very nice.

@kinke kinke force-pushed the vsoptions branch 3 times, most recently from ed0629f to 99cf321 Compare April 29, 2020 23:47
@kinke
Copy link
Member Author

kinke commented Apr 30, 2020

For Azure (with unknown number of VS installations; the previous batch file took a few seconds):

MSVC setup took 137592 microseconds

2nd time a few seconds later:

MSVC setup took 10358 microseconds

@rainers
Copy link
Contributor

rainers commented Apr 30, 2020

I still didn't expect almost 10 ms for this stuff; the COM stuff alone takes 5-6 ms on my box (and I have 2 installations to iterate over).

I guess that's mostly loading DLLs as part of creating the COM object (I just stepped over it in the debugger, and it showed 6 ms, too - for 10 DLLs on a rather fast SSD).

I changed it to use the latest version found via COM, not the first one (and check for an existing VC subdir).

Should be fine. That probably also results in more predictable behvior.

I also don't want to reintroduce any narrow WinAPI calls and will switch to the wide API (e.g., when getting the installation dir from the registry); is that an option for DMD too?

Should be no problem as far as I can see.

Copy link
Contributor

@rainers rainers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of nits.

dmd/vsoptions.d Outdated
continue;
scope(exit) SysFreeString(thisInstallDir);

if (versionString && wcscmp(thisVersionString, versionString) <= 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is string comparison of the version good enough? Probably ok, as 3 digit versions are still some time in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've verified that 1.x < 10.x.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant 100.x is not less than 99.x.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh. ;)

dmd/vsoptions.d Outdated Show resolved Hide resolved
dmd/vsoptions.d Show resolved Hide resolved
dmd/vsoptions.d Outdated Show resolved Hide resolved
The MSVC toolchain setup is skipped if LDC is run inside a 'VS Native/Cross
Tools Command Prompt' (more precisely, if the VSINSTALLDIR environment variable
is set). You can set the LDC_VSDIR_FORCE environment variable (to some
non-empty value) to enforce setting up the MSVC toolchain.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't checked the C++ code whether it is actually doing this, but I think it should be the default behavior to adapt to the architecture even if the VS/VC installation path is given by the environment variable. It is pretty annoying if you have to call vcvarsall.bat or similar to adapt the LIB environment variable although you have the option -m32/64 to specify just that to LDC.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nobody except you has ever complained about that ;), and I still have no idea why that's needed for the DMD build setup.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I have a solution now, checking the VSCMD_ARG_TGT_ARCH env var (VS 2017+) for a mismatch and not skipping the MSVC setup in that case. The environment is still left untouched (thus avoiding potential issues) if the targets match up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me, thanks.

You can set the LDC_VSDIR environment variable to select a specific version,
e.g., 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community'.
The MSVC toolchain setup is skipped if LDC is run inside a 'VS Native/Cross
Tools Command Prompt' (more precisely, if the VSINSTALLDIR environment variable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the Build Tools set VSINSTALLDIR aswell? Shouldn't this check VCINSTALLDIR, too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been like this for years, I've tested it with Build Tools 2015 IIRC years ago, no complaints.

This reduces the overhead for auto-detecting and setting up an MSVC
toolchain from a very rough 1 second to about 8 milliseconds on my box.
Enabling the auto-detection by default (and so preferring MSVC over the
'internal' toolchain if there's a Visual C++ installation) is now
possible, fixing issues like ldc-developers#3402.

The MSVC setup now consists of the bare minimum - prepending 3
directories to the LIB env var and 1-2 directories to PATH.
kinke added 2 commits May 1, 2020 01:57
…n't match

This doesn't work for VS 2015, but 2017 and 2019. For VS 2015, I haven't
found a suitable env var, and I don't want to parse LIB and/or PATH to
guess the target architecture (LDC_VSDIR_FORCE can still be used).
@kinke kinke marked this pull request as ready for review May 1, 2020 01:06
@kinke kinke merged commit c6430a3 into ldc-developers:master May 4, 2020
@kinke kinke deleted the vsoptions branch May 4, 2020 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants