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

Add a new "ScanForModuleDependencies" flag. #1788

Merged
merged 5 commits into from
Feb 22, 2022

Conversation

LoneBoco
Copy link
Contributor

@LoneBoco LoneBoco commented Jan 4, 2022

What does this PR do?

This controls the Visual Studio "Scan Sources for Module Dependencies" option, which controls how it scans for C++20 modules. This new flag sets the option in the generated project files.

How does this PR change Premake's behavior?

This PR adds a new flag option that generates a new entry in the group for each configuration.

Anything else we should know?

Nope.

Did you check all the boxes?

  • Focus on a single fix or feature; remove any unrelated formatting or code changes
  • Add unit tests showing fix or feature works; all tests pass
  • Mention any related issues (put closes #XXXX in comment to auto-close issue when PR is merged)
  • Follow our coding conventions
  • Minimize the number of commits
  • Align documentation to your changes

You can now support Premake on our OpenCollective. Your contributions help us spend more time responding to requests like these!

This controls the Visual Studio "Scan Sources for Module Dependencies" option, which controls how it scans for C++20 modules.  This new flag sets the option in the generated project files.
@Jarod42
Copy link
Contributor

Jarod42 commented Jan 5, 2022

Is there a equivalent (command-line) flag for other IDEs which might use msvc as compiler?

@LoneBoco
Copy link
Contributor Author

LoneBoco commented Jan 5, 2022

Is there a equivalent (command-line) flag for other IDEs which might use msvc as compiler?

No. This isn't a command-line flag for the compiler. This controls how the Visual Studio IDE scans for module dependencies and how it determines which files to compile.

This is related to using the import command. By default, Visual Studio will only look at .ixx modules to build the dependency graph. If it encounters something like import <vector>;, it will build that file as a header unit (.ifc), including any other headers it might import.

But say your main.cpp file had import <iostream>; and no .ixx files in your project tried to import the iostream header. This would cause a build failure as iostream was never compiled into a header unit.

Error C7612 could not find header unit for 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\include\iostream' MyProject MyProject\src\main.cpp

By enabling the Scan Sources for Module Dependencies flag, Visual Studio would have also scanned .cpp files and saw that we are trying to import iostream, so it would have built iostream as a header unit. Then, when we compile, the build would be successful.

Other IDEs which use Visual Studio as a compiler would probably have their own way of determining which files to build. They might scan .cpp files on their own, or maybe have a setting where you list additional files to compile.

The solutions given by Microsoft are:

  1. Enable the Scan Sources for Module Dependencies option to scan every source file (increasing compile times).
  2. Build a static shared library that imports header files, giving anything that links to it access to them.
  3. Manually specifying that a .h file should be compiled as a header unit. See PR Initial C++20 module support for Visual Studio #1570 for supporting CompileAs options.
  4. Enable experimental STL modules and import them.

Copy link
Member

@samsinsane samsinsane left a comment

Choose a reason for hiding this comment

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

We don't add new flags, please create an API instead.

@LoneBoco
Copy link
Contributor Author

LoneBoco commented Jan 7, 2022

Okay. It has been converted to an API call now.

Copy link
Member

@samsinsane samsinsane left a comment

Choose a reason for hiding this comment

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

LGTM

@samsinsane samsinsane merged commit 7deba66 into premake:master Feb 22, 2022
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.

None yet

4 participants