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

Implemented VS API for toggling of C++20 modules and STL module build #2130

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions modules/vstudio/_preload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,26 @@
}
}

p.api.register {
name = "enablemodules",
scope = { "config" },
kind = "string",
allowed = {
"On",
"Off"
}
Comment on lines +201 to +205
Copy link
Member

Choose a reason for hiding this comment

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

Using the boolean type would probably be better.

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about using those, but there are also plenty of spots in the code where "Off" and "On" are used in place of a boolean value. Should we start just using boolean instead? If so, that's an easy fix.

Copy link
Member

Choose a reason for hiding this comment

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

The inputs for boolean are more flexible:

local mapping = {
["false"] = false,
["no"] = false,
["off"] = false,
["on"] = true,
["true"] = true,
["yes"] = true,
}
if type(value) == "string" then
value = mapping[value:lower()]
if value == nil then
error { msg="expected boolean; got " .. value }
end
return value
end
if type(value) == "boolean" then
return value
end
if type(value) == "number" then
return (value ~= 0)
end
return (value ~= nil)

From memory there are issues when using this with look up tables, which is how the toolsets work. So, it's up to you whether you think it's a good idea or not.

}

p.api.register {
name = "buildstlmodules",
scope = { "config" },
kind = "string",
allowed = {
"On",
"Off"
}
Comment on lines +211 to +215
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

}

--
-- Decide when the full module should be loaded.
--
Expand Down
26 changes: 26 additions & 0 deletions modules/vstudio/tests/vc2019/test_compile_settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,29 @@
<UseStandardPreprocessor>false</UseStandardPreprocessor>
]]
end

function suite.enableModulesOff()
enablemodules 'Off'
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
<EnableModules>false</EnableModules>
]]
end

function suite.enableModulesOn()
enablemodules 'On'
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
<EnableModules>true</EnableModules>
]]
end
26 changes: 26 additions & 0 deletions modules/vstudio/tests/vc2022/test_compile_settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,29 @@ function suite.TreatAngleIncludeAsExternalOffFile()
<TreatAngleIncludeAsExternal>false</TreatAngleIncludeAsExternal>
]]
end

function suite.BuildStlModulesOff()
buildstlmodules 'Off'
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
<BuildStlModules>false</BuildStlModules>
]]
end

function suite.BuildStlModulesOn()
buildstlmodules 'On'
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
<BuildStlModules>true</BuildStlModules>
]]
end
20 changes: 20 additions & 0 deletions modules/vstudio/vs2010_vcxproj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@
m.externalAngleBrackets,
m.scanSourceForModuleDependencies,
m.useStandardPreprocessor,
m.enableModules,
m.buildStlModules,
}

if cfg.kind == p.STATICLIB then
Expand Down Expand Up @@ -3024,6 +3026,24 @@
end


function m.enableModules(cfg)
if _ACTION >= "vs2019" then
if cfg.enablemodules then
m.element("EnableModules", nil, iif(cfg.enablemodules == "On", "true", "false"))
end
end
end


function m.buildStlModules(cfg)
if _ACTION >= "vs2022" then
if cfg.buildstlmodules then
Copy link
Contributor

@Jarod42 Jarod42 Aug 30, 2023

Choose a reason for hiding this comment

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

Would it make sense to have this one activated, and not the other? (to emit warning for strange config).

Copy link
Member Author

Choose a reason for hiding this comment

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

In my opinion, it makes no sense to have this activated wtihout the other, but I don't believe we do this kind of sanity checking elsewhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

m.element("BuildStlModules", nil, iif(cfg.buildstlmodules == "On", "true", "false"))
end
end
end


function m.externalAngleBrackets(cfg, condition)
if _ACTION >= "vs2019" then
if cfg.externalanglebrackets == p.OFF then
Expand Down
24 changes: 24 additions & 0 deletions website/docs/buildstlmodules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Sets whether or not the compiler should build STL modules.

```lua
buildstlmodules("value")
```

### Parameters ###

`value` is one of:

- `On`
- `Off`

### Applies To ###

The `config` scope.

### Availability ###

Premake 5.0.0 beta 3 or later for Visual Studio 2022 and later.

### See Also ###

* [enablemodules](enablemodules.md)
20 changes: 20 additions & 0 deletions website/docs/enablemodules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Sets whether or not the compiler should enable C++20 modules.

```lua
enablemodules("value")
```

### Parameters ###

`value` is one of:

- `On`
- `Off`

### Applies To ###

The `config` scope.

### Availability ###

Premake 5.0.0 beta 3 or later for Visual Studio 2019 and later.
nickclark2016 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ module.exports = {
'buildoptions',
'buildoutputs',
'buildrule',
'buildstlmodules',
'callingconvention',
'cdialect',
'characterset',
Expand Down Expand Up @@ -139,6 +140,7 @@ module.exports = {
'embed',
'embedandsign',
'enabledefaultcompileitems',
'enablemodules',
'enableunitybuild',
'enablewarnings',
'endian',
Expand Down