Skip to content

Commit b7cc9bf

Browse files
authored
Use hybrid CRT linkage instead of full static (microsoft#5913)
See https://aka.ms/hybridcrt for additional details. When building ReleaseStatic, use the hybrid linkage model. This produces a binary that is closer in size to the dynamic linkage than the full static, relying on the UCRT binary that ships in Windows to provide the core CRT functionality. As an example, the WindowsPackageManager.dll is ~90 KB larger as hybrid than dynamic, but is another ~160 KB larger as static than hybrid.
1 parent 9a65ba4 commit b7cc9bf

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

.github/actions/spelling/expect.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ DCPPREST
124124
debian
125125
decompressor
126126
dedupe
127+
defaultlib
127128
DEFT
128129
deigh
129130
deleteifnotneeded
@@ -228,6 +229,7 @@ Howto
228229
hre
229230
hresults
230231
hwnd
232+
hybridcrt
231233
Hyperlink
232234
IARP
233235
IAttachment
@@ -568,6 +570,7 @@ UCase
568570
ucasemap
569571
UChars
570572
ucnv
573+
ucrt
571574
udwgp
572575
uec
573576
ULONGLONG

src/Directory.Build.props

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@
2828
<MultiProcessorCompilation>true</MultiProcessorCompilation>
2929
</ClCompile>
3030
</ItemDefinitionGroup>
31+
<ItemDefinitionGroup Condition="'$(Configuration)'=='ReleaseStatic'">
32+
<Link>
33+
<!-- Link statically against the runtime and STL, but link dynamically against the CRT by ignoring the static CRT
34+
lib and instead linking against the Universal CRT DLL import library. This "hybrid" linking mechanism is
35+
supported according to the CRT maintainer. Dynamic linking against the CRT makes the binaries a bit smaller
36+
than they would otherwise be if the CRT, runtime, and STL were all statically linked in.
37+
See https://aka.ms/hybridcrt for more details. -->
38+
<IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries);libucrt.lib</IgnoreSpecificDefaultLibraries>
39+
<AdditionalOptions>%(AdditionalOptions) /defaultlib:ucrt.lib</AdditionalOptions>
40+
</Link>
41+
</ItemDefinitionGroup>
3142

3243
<!-- For C# -->
3344
<PropertyGroup Condition="'$(WinGetMacros)' != ''">

0 commit comments

Comments
 (0)