4.26 and Include What You Use (IWYU)

With 4.26, and at least for VSCode, this is more difficult. 4.26 includes a preinclude that includes a header with 600+ headers. This gets rid of all the usual IWYU errors. It’s going to be difficult spotting some of them.

I’m guessing we should still try do IWYU for 4.26 even if nothing errors?

That seems to be orthogonal to IWYU.
Whenever you use a type, you need to include the header for it. Examples of using

  • Inheriting from that type
  • Accessing members off of that type
  • Casting to that type (needs to know inheritance hierarchy due to compile time checks)
  • Needing it its size to be able to store it on the stack (rather rare with Unreal)

Forward declarations for members work due to pointers being the same regardless to what they point to, they all take up the same space on the stack.

The preinclude file is called SharedPCH.Engine.ShadowErrors.h. If you rebuild a project the SharedPCH.Engine.ShadowErrors.cpp file is compiled. The cpp file is just a single line that includes the header. It also creates a >1 GB pch file. It also produces on object file.

Your source files have response files that are used when they are compiled. These are in the Build folder and not for Intellisense. In this response file the SharedPCH.Engine.ShadowErrors.h header file is forced included and the pch file is used. For example in the BuildingEscape Build folder there is a OpenDoor.cpp.obj.response file that has this.

So I think you actually don’t need to do IWYU in 4.26? Because that huge file of 600 headers is being included. Not just in Intellisense but compiled with your source files?

Maybe you can shed some light because this is over my head!

That is a precompiled header. Consider it an optimisation that you shouldn’t need to think about that Unreal adds to improve build times and doesn’t change the principles of IWYU.

1 Like

You should be able to disable pch if you really don’t like faster build times.

Find the means to disable from these links.

Here’s more info:
https://stackoverflow.com/questions/41614024/precompiled-headers-and-normal-includes
http://kantandev.com/articles/ue4-includes-precompiled-headers-and-iwyu-include-what-you-use

  1. 4.26 makes it harder to spot IWYU but you should still use it
  2. (not tested yet) To spot IWYU errors easier, you can disable SharedPCH/Unity builds in your BuildConfiguration.xml file with this:
<bUsePCHFiles>false</bUsePCHFiles>
<bUseSharedPCHs>false</bUseSharedPCHs>
<bUseUnityBuild>false</bUseUnityBuild>
  1. Remember to remove these when done for faster build times.

Here’s a link on where to put the BuildConfiguration.xml file:
https://docs.unrealengine.com/en-US/ProductionPipelines/BuildTools/UnrealBuildTool/BuildConfiguration/index.html

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.