Skip to content

add "Fast" option to LinkTimeOptimization API which enables LTCG:incremental for vs2010, and behaves as "On" for other toolsets#2549

Merged
samsinsane merged 1 commit intopremake:masterfrom
withmorten:fix-lto-default-msvc
Dec 15, 2025
Merged

add "Fast" option to LinkTimeOptimization API which enables LTCG:incremental for vs2010, and behaves as "On" for other toolsets#2549
samsinsane merged 1 commit intopremake:masterfrom
withmorten:fix-lto-default-msvc

Conversation

@withmorten
Copy link
Contributor

@withmorten withmorten commented Dec 1, 2025

add "Fast" option to LinkTimeOptimization API which enables LTCG:incremental for vs2010, and behaves as "On" for other toolsets

What does this PR do?

^ see commit description

How does this PR change Premake's behavior?

This adds a "Fast" option to the LinkTimeOptimiation for vs2010 projects.

Anything else we should know?

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!

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.

Default is supposed to do nothing so that you get the default of the tool you're using. The linked PR didn't change that behaviour, so I'm inclined to reject this PR.

@nickclark2016
Copy link
Member

When Premake specifies a "default" value, we are using the toolset default (i.e. if you used cl.exe, what is the behavior), not the default generated project from VS. I agree with @samsinsane and would agree that the behavior as implemented is the correct behavior.

@withmorten
Copy link
Contributor Author

I see - the cl.exe default is WholeProgramOptimization being off.

Would it be acceptable to create another PR that adds an "incremental" or "fast" option? The API changed the setting from incremental/fast to "full" when enabling it.

@nickclark2016
Copy link
Member

Would this be a new API for Link Time Code Generation? (Fast, Full, etc)

@withmorten
Copy link
Contributor Author

I think? I'm not well versed in the internal terms of premake :)

Currently you can do

linktimeoptimization "on"
linktimeoptimization "off"
linktimeoptimization "default"

I would add either

linktimeoptimization "full"

or

linktimeoptimization "fast"

and keep the other as "on".

The previous premake behaviour with

flags { "LinkTimeOptimization" }

was essentially "fast", with WholeProgramOptimization set to TRUE and LinkTimeCodeGeneration for the linker options unset - which Visual Studio defaults to as /LTCG:INCREMENTAL.

The behaviour now with "on" is LinkTimeCodeGeneration set to UseLinkTimeCodeGeneration, which would be "full".

So my question is - should "on" revert the behaviour back to the previous flags behaviour and add the new behaviour as "full", or should it add the old flags behaviour as "fast" and keep the new behaviour as "on" ?

@nickclark2016
Copy link
Member

nickclark2016 commented Dec 11, 2025

I would argue that we should have:

linktimeoptimization "On" -> `/LTCG`
linktimeoptimization "Fast" -> `/LTCG:INCREMENTAL`

In GCC and Clang, "On" should stay mapped to -flto
On GCC, "Fast" should be -flto=auto
On Clang, "Fast" should be -flto=thin

@samsinsane
Copy link
Member

should "on" revert the behaviour back to the previous flags behaviour

The API didn't introduce new behaviour for "on", it's exactly as it was with the flags. So I agree with @nickclark2016 adding "Fast" as an option makes the most sense.

@withmorten
Copy link
Contributor Author

Ah I see. The version I have been using was so old, it didn't have this change yet:

490686c

This is what changed the default on behaviour to full from fast by adding the missing xml element.

Ok, I will add a new "fast" option then. I will rename and force push this PR, so don't close it yet :)

@withmorten withmorten changed the title fix visual studio LinkTimeOptimization default not setting WholeProgramOptimization to true add "Fast" option to LinkTimeOptimization API which enables LTCG:incremental for vs2010, and behaves as "On" for other toolsets Dec 13, 2025
@withmorten
Copy link
Contributor Author

I've force pushed and renamed the PR. I just searched for "linktimeoptimization" and hopefully fixed up all the required places, and added tests.

Copy link
Member

@nickclark2016 nickclark2016 left a comment

Choose a reason for hiding this comment

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

See prior comments. Hit approve on accident.

@withmorten withmorten force-pushed the fix-lto-default-msvc branch 2 times, most recently from 417dcac to 4fd78b8 Compare December 14, 2025 14:50
Copy link
Member

@nickclark2016 nickclark2016 left a comment

Choose a reason for hiding this comment

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

Minor changes, but overall happy with the code. Suggest merging in master, since there's a decent amount of changes that landed in the last 48 hours.

test.isequal("windres", clang.gettoolname(cfg, "rc"))
end

function suite.tools_onLinkTimeOptimizationViaFlag()
Copy link
Member

Choose a reason for hiding this comment

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

The LTO flag was actually removed. The "via flag" test is no longer required. (Same comment on Clang, GCC, and MSC).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah - I see. it would have been nice to keep that as deprecated option so I don't need to use different versions of premake for git bisecting old project files, but oh well :D

Copy link
Member

Choose a reason for hiding this comment

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

All flags are being deprecated and removed ahead of the 5.0 full release. We'll be rolling out a new release soon with them all deprecated in favor of a dedicated API for each.

Premake 5.0-beta4 and later No newline at end of file
Premake 5.0-beta4 and later

Fast is available from Premake 5.0-beta8 or later. Applies to Visual Studio 2010 and clang, will behave as On for other toolsets. No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

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

Given it's slightly more complex than just "Exists starting here", leave the "Premake 5.0-beta4 and later", then add a column to the table called Notes (see flags.md)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done - or get rid of the "available from Premake 5.0-beta8 or later" ?

…emental for vs2010, ftlo=thin for clang and behaves as "On" for other toolsets

add missing clang toolset tests for LinkTimeOptimization
@withmorten
Copy link
Contributor Author

withmorten commented Dec 14, 2025

Minor changes, but overall happy with the code. Suggest merging in master, since there's a decent amount of changes that landed in the last 48 hours.

Done.

I think I just accidentally started a rewiew and deleted the pending comment, oh well. What a mess this interface is.

@samsinsane samsinsane merged commit 47cd240 into premake:master Dec 15, 2025
51 checks passed
@withmorten
Copy link
Contributor Author

Thanks!

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.

4 participants