Skip to content

Commit 2d7aec7

Browse files
Deprecate NoRuntimeChecks, add dedicated API (#2583)
1 parent 161be46 commit 2d7aec7

File tree

10 files changed

+211
-15
lines changed

10 files changed

+211
-15
lines changed

modules/vstudio/_preload.lua

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@
727727
p.api.addAllowed("vectorextensions", { "NEON", "MXU" })
728728
p.api.addAllowed("exceptionhandling", {"UnwindTables"})
729729
p.api.addAllowed("kind", p.PACKAGING)
730-
p.api.addAllowed("flags", { "NoImplicitLink", "NoCopyLocal" })
730+
p.api.addAllowed("flags", { "NoImplicitLink", "NoCopyLocal", "NoRuntimeChecks" })
731731

732732
p.api.register {
733733
name = "implicitlink",
@@ -766,6 +766,27 @@
766766
allowcopylocal("Default")
767767
end)
768768

769+
p.api.register {
770+
name = "runtimechecks",
771+
scope = "config",
772+
kind = "string",
773+
allowed = {
774+
"Default",
775+
"Off",
776+
"StackFrames",
777+
"UninitializedVariables",
778+
"FastChecks",
779+
}
780+
}
781+
782+
p.api.deprecateValue("flags", "NoRuntimeChecks", "Use `runtimechecks` instead.",
783+
function(value)
784+
runtimechecks("Off")
785+
end,
786+
function(value)
787+
runtimechecks("Default")
788+
end)
789+
769790
--
770791
-- Decide when the full module should be loaded.
771792
--

modules/vstudio/tests/vc200x/test_compiler_block.lua

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,11 +601,79 @@
601601
<Tool
602602
Name="VCCLCompilerTool"
603603
Optimization="0"
604+
BasicRuntimeChecks="0"
604605
RuntimeLibrary="2"
605606
]]
606607
end
607608

608609

610+
--
611+
-- Check handling of the runtimechecks API with "Off" value.
612+
--
613+
614+
function suite.onRuntimeChecks_Off()
615+
runtimechecks "Off"
616+
prepare()
617+
test.capture [[
618+
<Tool
619+
Name="VCCLCompilerTool"
620+
Optimization="0"
621+
BasicRuntimeChecks="0"
622+
RuntimeLibrary="2"
623+
]]
624+
end
625+
626+
627+
--
628+
-- Check handling of the runtimechecks API with "StackFrames" value.
629+
--
630+
631+
function suite.onRuntimeChecks_StackFrames()
632+
runtimechecks "StackFrames"
633+
prepare()
634+
test.capture [[
635+
<Tool
636+
Name="VCCLCompilerTool"
637+
Optimization="0"
638+
BasicRuntimeChecks="1"
639+
RuntimeLibrary="2"
640+
]]
641+
end
642+
643+
644+
--
645+
-- Check handling of the runtimechecks API with "UninitializedVariables" value.
646+
--
647+
648+
function suite.onRuntimeChecks_UninitializedVariables()
649+
runtimechecks "UninitializedVariables"
650+
prepare()
651+
test.capture [[
652+
<Tool
653+
Name="VCCLCompilerTool"
654+
Optimization="0"
655+
BasicRuntimeChecks="2"
656+
RuntimeLibrary="2"
657+
]]
658+
end
659+
660+
661+
--
662+
-- Check handling of the runtimechecks API with "FastChecks" value.
663+
--
664+
665+
function suite.onRuntimeChecks_FastChecks()
666+
runtimechecks "FastChecks"
667+
prepare()
668+
test.capture [[
669+
<Tool
670+
Name="VCCLCompilerTool"
671+
Optimization="0"
672+
BasicRuntimeChecks="3"
673+
RuntimeLibrary="2"
674+
]]
675+
end
676+
609677

610678
--
611679
-- Check handling of the EnableMultiProcessorCompile flag.

modules/vstudio/tests/vc2010/test_compile_settings.lua

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,54 @@
894894
end
895895

896896

897+
--
898+
-- Check handling of the runtimechecks API with "Off" value.
899+
--
900+
901+
function suite.onRuntimeChecks_Off()
902+
runtimechecks "Off"
903+
prepare()
904+
test.capture [[
905+
<ClCompile>
906+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
907+
<WarningLevel>Level3</WarningLevel>
908+
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
909+
]]
910+
end
911+
912+
913+
--
914+
-- Check handling of the runtimechecks API with "FastChecks" value.
915+
--
916+
917+
function suite.onRuntimeChecks_FastChecks()
918+
runtimechecks "FastChecks"
919+
prepare()
920+
test.capture [[
921+
<ClCompile>
922+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
923+
<WarningLevel>Level3</WarningLevel>
924+
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
925+
]]
926+
end
927+
928+
929+
--
930+
-- Check handling of the runtimechecks API with "Default" value.
931+
--
932+
933+
function suite.onRuntimeChecks_Default()
934+
runtimechecks "Default"
935+
prepare()
936+
test.capture [[
937+
<ClCompile>
938+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
939+
<WarningLevel>Level3</WarningLevel>
940+
<Optimization>Disabled</Optimization>
941+
]]
942+
end
943+
944+
897945
--
898946
-- Check handling of the EnableMultiProcessorCompile flag.
899947
--

modules/vstudio/vs200x_vcproj.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,9 +870,17 @@
870870
if not filecfg
871871
and not config.isOptimizedBuild(cfg)
872872
and cfg.clr == p.OFF
873-
and not cfg.flags.NoRuntimeChecks
874873
then
875-
p.w('BasicRuntimeChecks="3"')
874+
local runtimechecks = cfg.runtimechecks or "Default"
875+
local map = {
876+
Off = 0,
877+
StackFrames = 1,
878+
UninitializedVariables = 2,
879+
FastChecks = 3,
880+
Default = 3
881+
}
882+
883+
p.w('BasicRuntimeChecks="%s"', map[runtimechecks])
876884
end
877885
end
878886

modules/vstudio/vs2010_vcxproj.lua

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,15 +2218,23 @@
22182218

22192219
function m.basicRuntimeChecks(cfg, condition)
22202220
local prjcfg, filecfg = p.config.normalize(cfg)
2221-
local runtime = config.getruntime(prjcfg) or iif(config.isDebugBuild(cfg), "Debug", "Release")
2222-
if filecfg then
2223-
if filecfg.flags.NoRuntimeChecks or (config.isOptimizedBuild(filecfg) and runtime:endswith("Debug")) then
2224-
m.element("BasicRuntimeChecks", condition, "Default")
2225-
end
2226-
else
2227-
if prjcfg.flags.NoRuntimeChecks or (config.isOptimizedBuild(prjcfg) and runtime:endswith("Debug")) then
2228-
m.element("BasicRuntimeChecks", nil, "Default")
2229-
end
2221+
2222+
local function getruntimecheck(c)
2223+
local checks = {
2224+
Off = "Default", -- Per MSVC SDK docs, "Default" means no runtime checks
2225+
StackFrames = "StackFrameRuntimeCheck",
2226+
UninitializedVariables = "UninitializedLocalUsageCheck",
2227+
FastChecks = "EnableFastChecks",
2228+
}
2229+
2230+
local runtimecheck = c.runtimechecks
2231+
return checks[runtimecheck]
2232+
2233+
end
2234+
2235+
local check = getruntimecheck(filecfg or prjcfg)
2236+
if check then
2237+
m.element("BasicRuntimeChecks", condition, check)
22302238
end
22312239
end
22322240

src/_premake_init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@
346346
"NoManifest",
347347
"NoMinimalRebuild",
348348
"NoPCH",
349-
"NoRuntimeChecks",
350349
"NoBufferSecurityCheck",
351350
"OmitDefaultLibrary",
352351
"RelativeLinks",

website/docs/flags.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ flags { "flag_list" }
2727
| NoManifest | Prevent the generation of a manifest for Windows executables and shared libraries. Deprecated in Premake 5.0.0-beta8. Use `manifest` API instead. |
2828
| NoMinimalRebuild | Disable Visual Studio's [minimal rebuild feature][1]. Deprecated in Premake 5.0.0-beta8. Use `minimalrebuild` API instead. | Visual Studio has deprecated this feature as of vs2015.|
2929
| NoPCH | Disable precompiled header support. If not specified, the toolset default behavior will be used. Deprecated in Premake 5.0.0-beta8. Use `enablepch` API instead. |
30-
| NoRuntimeChecks | Disable Visual Studio's [default stack frame and uninitialized variable checks][2] on debug builds. |
30+
| NoRuntimeChecks | Disable Visual Studio's [default stack frame and uninitialized variable checks][2] on debug builds. Deprecated in Premake 5.0.0-beta8. Use `runtimechecks` API instead. |
3131
| OmitDefaultLibrary | Omit the specification of a runtime library in object files. Deprecated in Premake 5.0.0-beta8. Use `nodefaultlib` API instead. |
3232
| RelativeLinks | Forces the linker to use relative paths to libraries instead of absolute paths. Deprecated in Premake 5.0.0-beta8. Use `userelativelinks` API instead. |
3333
| ShadowedVariables | Warn when a variable, type declaration, or function is shadowed. Deprecated in Premake 5.0.0-beta8. Use `buildoptions` API instead to add compile warnings. |

website/docs/runtimechecks.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Controls whether runtime error checking is enabled for Visual Studio C/C++ projects.
2+
3+
```lua
4+
runtimechecks ("value")
5+
```
6+
7+
If no value is set for a configuration, the toolset's default behavior will be used. By default, runtime checks are enabled for debug builds.
8+
9+
### Parameters ###
10+
11+
`value` specifies the desired behavior:
12+
13+
| Value | Description |
14+
|------------------------|------------------------------------------------------|
15+
| Off | Turns off runtime error checking |
16+
| Default | Use the toolset default behavior (Default value) |
17+
| StackFrames | Enables runtime checks for stack frames |
18+
| UninitializedVariables | Enables runtime checks for uninitialized variables |
19+
| FastChecks | Enables all fast runtime checks |
20+
21+
### Applies To ###
22+
23+
Project configurations.
24+
25+
### Availability ###
26+
27+
Premake 5.0.0-beta8 or later in Visual Studio only.
28+
29+
### Examples ###
30+
31+
Disable runtime checks:
32+
33+
```lua
34+
runtimechecks "Off"
35+
```
36+
37+
Enable runtime checks even in optimized builds:
38+
39+
```lua
40+
filter { "configurations:Release" }
41+
optimize "On"
42+
runtimechecks "FastChecks"
43+
```

website/docs/userelativelinks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Project configurations.
2222

2323
### Availability ###
2424

25-
Premake 5.0.0-beta8 or later. Replaces the deprecated `RelativeLinks` flag.
25+
Premake 5.0.0-beta8 or later.
2626

2727
### Examples ###
2828

website/sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ module.exports = {
247247
'runcodeanalysis',
248248
'runpathdirs',
249249
'runtime',
250+
'runtimechecks',
250251
'sanitize',
251252
'scanformoduledependencies',
252253
'shaderassembler',

0 commit comments

Comments
 (0)