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 support for unity builds #2011

Merged
merged 13 commits into from
Apr 14, 2023
Merged

Add support for unity builds #2011

merged 13 commits into from
Apr 14, 2023

Conversation

Sharlock93
Copy link
Contributor

What does this PR do?

Adds Support for Unity builds in visual studio 2019+. Adds one new flag "enableUnityBuild" with options On and Off.

How does this PR change Premake's behavior?

Adds Unity Build/Jumbo Build support.

Anything else we should know?

Unity builds really speed up compile time, being able to set them per config and project is a nice feature and something I personally needed.

Did you check all the boxes?
Honestly I did this in a hurry and was a neat feature that I wanted myself, if there is anything in particular I should be adding then feedback is welcome.

@Jarod42
Copy link
Contributor

Jarod42 commented Dec 14, 2022

Documentation and unit test are missing.

Wonder if it should be integrated to https://github.com/dcourtois/premake-compilationunit (listed in https://premake.github.io/community/modules/#tool-modules) which does Single compilation unit support.

src/_premake_init.lua Outdated Show resolved Hide resolved
src/_premake_init.lua Outdated Show resolved Hide resolved
@Sharlock93
Copy link
Contributor Author

Sharlock93 commented Dec 15, 2022

Documentation and unit test are missing.

If you could point me to where I should be adding those it would be great.

Wonder if it should be integrated to https://github.com/dcourtois/premake-compilationunit (listed in https://premake.github.io/community/modules/#tool-modules) which does Single compilation unit support.

The difference here being that Visual Studio itself does that kind of "Unity/Single Compilation Unit" automatically. For example if you enable it in a project it will generate a file called "unity_<random_suffix>.cpp" that basically does what that module is doing.

I haven't added more flags (honestly because I didn't need them myself) but a more complete set of flags exist for Unity/Jumbo builds that specify how many files should be packed up in one Unity file etc.

image

That module is more useful in a context where native support for Unity builds doesn't exist.

@Jarod42
Copy link
Contributor

Jarod42 commented Dec 15, 2022

Documentation and unit test are missing.

If you could point me to where I should be adding those it would be great.

I would say

  • UTs should go somewhere in premake-core\modules\vstudio\tests\vc2010
  • Doc should be in premake-core\website\docs (premake5 docs-check should pass)

Wonder if it should be integrated to https://github.com/dcourtois/premake-compilationunit (listed in https://premake.github.io/community/modules/#tool-modules) which does Single compilation unit support.

The difference here being that Visual Studio itself does that kind of "Unity/Single Compilation Unit" automatically. For example if you enable it in a project it will generate a file called "unity_<random_suffix>.cpp" that basically does what that module is doing.

That module is more useful in a context where native support for Unity builds doesn't exist.

I meant: use special flag for msvc which can do it natively, but keep the module as is for other actions.

@Sharlock93
Copy link
Contributor Author

I meant: use special flag for msvc which can do it natively, but keep the module as is for other actions.

I mean you could do that but this feature really should be part of visual studio as this is a native feature on visual studio itself so in essence premake is missing it.

@nickclark2016
Copy link
Member

Can you add the documentation so the CI can pass that step?

enableUnityBuilds "value"
```

If no toolset is specified for a configuration, the system or IDE default will be used.
Copy link
Contributor

Choose a reason for hiding this comment

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

"toolset"? Seems to be a copy paste...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah 100%, I wanted to keep the same structure and easiest was to copy paste something, been so busy lately that this ended up being a rushed job.

modules/vstudio/vs2010_vcxproj.lua Outdated Show resolved Hide resolved
Co-authored-by: Joris Dauphin <Jarod42@users.noreply.github.com>
@nickclark2016
Copy link
Member

Missing one more step in the documentation (and maybe this is something we should better document in the contributing doc), but you need to add it to the sidebar.js since it's a new API.

@Sharlock93
Copy link
Contributor Author

Missing one more step in the documentation (and maybe this is something we should better document in the contributing doc), but you need to add it to the sidebar.js since it's a new API.

yeah sorry about that, been super busy with work and it could be that its written somewhere but I didn't see it.

website/docs/Project-API.md Outdated Show resolved Hide resolved
@@ -275,6 +275,7 @@ module.exports = {
'toolsversion',
'transition',
'undefines',
'unitybuilds',
Copy link
Member

Choose a reason for hiding this comment

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

enableunitybuild

Copy link
Contributor Author

Choose a reason for hiding this comment

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

one of these days...

@samsinsane samsinsane requested a review from KyrietS April 13, 2023 13:29
@samsinsane samsinsane merged commit f4e88bb into premake:master Apr 14, 2023
@sparkskapil
Copy link

When I try to use this option I get this error.
attempt to call a nil value (global 'enableunitybuild')

Am I missing something here?

@nickclark2016
Copy link
Member

What version of premake are you using?

@sparkskapil
Copy link

sparkskapil commented Mar 2, 2024

What version of premake are you using?

Premake 5.0.0-beta2

Currently I managed it by creating my own hook.

@nickclark2016
Copy link
Member

Try one of the CI builds. They should have it.

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.

6 participants