This is an archive of the discontinued LLVM Phabricator instance.

Detect Visual Studio in Windows packaging script
ClosedPublic

Authored by pbo-linaro on Oct 4 2022, 9:07 AM.

Details

Summary

Instead of hardcoding a specific VS install, try sequentially:

  • %VSINSTALLDIR% (already set from a vs prompt)
  • 2019/Enterprise
  • 2019/Professional
  • 2019/Community
  • 2019/BuildTools

It stops when one is found and set vsdevcmd env var.

Diff Detail

Event Timeline

pbo-linaro created this revision.Oct 4 2022, 9:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 4 2022, 9:07 AM
pbo-linaro requested review of this revision.Oct 4 2022, 9:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 4 2022, 9:07 AM
hans accepted this revision.Oct 5 2022, 12:50 AM

lgtm

This revision is now accepted and ready to land.Oct 5 2022, 12:50 AM

@hans Would that be possible for you to merge it again please?

If that's annoying for you, I can request commit access (have at least 2 more patches coming for this script).
Thanks.

Phabricator supports stacks. Up right you will find Edit Related Revisions... You could upload your whole list of patches,

@tschuett Thanks, I'll try that :)

thieta added a subscriber: thieta.Oct 5 2022, 4:29 AM
thieta added inline comments.
llvm/utils/release/build_llvm_release.bat
56

I wonder if we should allow 2022 here as well. At least with a switch or something. LLVM should work with it and I don't see any reason for users to install 2019 just for this?

pbo-linaro added inline comments.Oct 5 2022, 4:32 AM
llvm/utils/release/build_llvm_release.bat
56

I'm 100% ok to select VS2022 by default (and fallback to 2019 if needed).
Do you know if everything is building fine under that newer version?

thieta added inline comments.Oct 5 2022, 4:36 AM
llvm/utils/release/build_llvm_release.bat
56

Yeah we build with 2022 and haven't seen any problems. Maybe after your patch with switches we could introduce a switch to force a VS version if more than one is installed?

pbo-linaro added inline comments.Oct 6 2022, 12:19 AM
llvm/utils/release/build_llvm_release.bat
56

Great. Is that ok for you to introduce this after that patch? Or I can edit, and add 2022 selection in this one.

pbo-linaro marked 2 inline comments as done and an inline comment as not done.
thieta accepted this revision.Oct 6 2022, 12:38 AM
thieta added inline comments.
llvm/utils/release/build_llvm_release.bat
56

I think it's fine doing it like this now and then adding a new commit that adds vs2022 support.

hans added inline comments.Oct 6 2022, 1:16 AM
llvm/utils/release/build_llvm_release.bat
56

Okay, i will go ahead and commit this now then.

This revision was landed with ongoing or failed builds.Oct 6 2022, 1:19 AM
This revision was automatically updated to reflect the committed changes.
compnerd added inline comments.
llvm/utils/release/build_llvm_release.bat
339

I think that this is better done through vswhere which is packaged up in the Visual Studio installation as of 2019 and newer.

SET vswhere=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe
FOR /F "delims=" %%r IN ('^""%vswhere%" -nologo -latest -products "*" -all -prerelease -property installationPath^"') DO set VsDevCmd=%%r\Common7\Tools\VsDevCmd.bat

Will give you the path to the latest vsdevcmd available in VsDevCmd. It will also implicitly scan different editions, and avoids the need to scan for it manually.

pbo-linaro marked an inline comment as done.Oct 6 2022, 10:59 AM
pbo-linaro added inline comments.
llvm/utils/release/build_llvm_release.bat
339

As VS2019 was hardcoded before, I thought their was a strong requirement to use this, so I didn't go the vswhere way.
As we discussed about adding a VS2022 flag, I can switch to that if others prefer it.

After trying, on my machine, it says:
$ "%vswhere%" -nologo -latest -products "*" -all -prerelease -property installationPath
C:\Program Files\Microsoft Visual Studio\2022\Preview

Alas, I definitely don't want to use a preview to compile this, but maybe there is a switch or something to have only stable.
I'd like to leave an override possibilty (detecting a VS prompt), so people can do as they want.

@hans @thieta Do you prefer that one?

Vswhere has a million options so I bet we can get it to find whatever we want. What I like about that approach is that it is not relying on hardcoded paths and it will work on any setup.

I think if possible we should do this:

  1. if we are in a dev shell - use that
  2. if the user pass --vs2022 - try to find latest vs22 installed (exclude preview if possible)
  3. find latest non-preview version installed.
  4. no vswhere or no VS installed - error out.
pbo-linaro marked an inline comment as done.Oct 6 2022, 11:21 AM

Sounds good. Could we drop the idea for --vs2022 option?
A user can still open a VS prompt if he needs to overwrite thing (and that simplifies the script).

Sounds good. Could we drop the idea for --vs2022 option?
A user can still open a VS prompt if he needs to overwrite thing (and that simplifies the script).

Yes that's fine!

I'll make another patch for this change then.