xref: /aosp_15_r20/external/angle/build/config/win/BUILD.gn (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1# Copyright 2013 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/config/c++/c++.gni")
6import("//build/config/chrome_build.gni")
7import("//build/config/clang/clang.gni")
8import("//build/config/compiler/compiler.gni")
9import("//build/config/rust.gni")
10import("//build/config/sanitizers/sanitizers.gni")
11import("//build/config/win/control_flow_guard.gni")
12import("//build/config/win/visual_studio_version.gni")
13import("//build/timestamp.gni")
14import("//build/toolchain/rbe.gni")
15import("//build/toolchain/toolchain.gni")
16
17assert(is_win)
18
19declare_args() {
20  # Turn this on to have the linker output extra timing information.
21  win_linker_timing = false
22
23  # possible values for target_winuwp_version:
24  #   "10" - Windows UWP 10
25  #   "8.1" - Windows RT 8.1
26  #   "8.0" - Windows RT 8.0
27  target_winuwp_version = "10"
28
29  # possible values:
30  #   "app" - Windows Store Applications
31  #   "phone" - Windows Phone Applications
32  #   "system" - Windows Drivers and Tools
33  #   "server" - Windows Server Applications
34  #   "desktop" - Windows Desktop Applications
35  target_winuwp_family = "app"
36
37  # Set this to use clang-style diagnostics format instead of MSVC-style, which
38  # is useful in e.g. Emacs compilation mode.
39  # E.g.:
40  #  Without this, clang emits a diagnostic message like this:
41  #    foo/bar.cc(12,34): error: something went wrong
42  #  and with this switch, clang emits it like this:
43  #    foo/bar.cc:12:34: error: something went wrong
44  use_clang_diagnostics_format = false
45}
46
47# This is included by reference in the //build/config/compiler config that
48# is applied to all targets. It is here to separate out the logic that is
49# Windows-only.
50config("compiler") {
51  if (current_cpu == "x86") {
52    asmflags = [
53      # When /safeseh is specified, the linker will only produce an image if it
54      # can also produce a table of the image's safe exception handlers. This
55      # table specifies for the operating system which exception handlers are
56      # valid for the image. Note that /SAFESEH isn't accepted on the command
57      # line, only /safeseh. This is only accepted by ml.exe, not ml64.exe.
58      "/safeseh",
59    ]
60  }
61
62  cflags = [
63    "/Gy",  # Enable function-level linking.
64    "/FS",  # Preserve previous PDB behavior.
65    "/bigobj",  # Some of our files are bigger than the regular limits.
66    "/utf-8",  # Assume UTF-8 by default to avoid code page dependencies.
67  ]
68
69  if (is_clang) {
70    cflags += [
71      "/Zc:twoPhase",
72
73      # Consistently use backslash as the path separator when expanding the
74      # __FILE__ macro when targeting Windows regardless of the build
75      # environment.
76      "-ffile-reproducible",
77    ]
78  }
79
80  # Force C/C++ mode for the given GN detected file type. This is necessary
81  # for precompiled headers where the same source file is compiled in both
82  # modes.
83  cflags_c = [ "/TC" ]
84  cflags_cc = [ "/TP" ]
85
86  cflags += [
87    # Work around crbug.com/526851, bug in VS 2015 RTM compiler.
88    "/Zc:sizedDealloc-",
89  ]
90
91  if (is_clang) {
92    # Required to make the 19041 SDK compatible with clang-cl.
93    # See https://crbug.com/1089996 issue #2 for details.
94    cflags += [ "/D__WRL_ENABLE_FUNCTION_STATICS__" ]
95
96    # Tell clang which version of MSVC to emulate.
97    cflags += [ "-fmsc-version=1934" ]
98
99    if (is_component_build) {
100      cflags += [
101        # Do not export inline member functions. This makes component builds
102        # faster. This is similar to -fvisibility-inlines-hidden.
103        "/Zc:dllexportInlines-",
104      ]
105    }
106
107    if (current_cpu == "x86") {
108      if (host_cpu == "x86" || host_cpu == "x64") {
109        cflags += [ "-m32" ]
110      } else {
111        cflags += [ "--target=i386-windows" ]
112      }
113    } else if (current_cpu == "x64") {
114      if (host_cpu == "x86" || host_cpu == "x64") {
115        cflags += [ "-m64" ]
116      } else {
117        cflags += [ "--target=x86_64-windows" ]
118      }
119    } else if (current_cpu == "arm64") {
120      cflags += [ "--target=aarch64-pc-windows" ]
121    } else {
122      assert(false, "unknown current_cpu " + current_cpu)
123    }
124
125    # Chrome currently requires SSE3. Clang supports targeting any Intel
126    # microarchitecture. MSVC only supports a subset of architectures, and the
127    # next step after SSE2 will be AVX.
128    if (current_cpu == "x86" || current_cpu == "x64") {
129      cflags += [ "-msse3" ]
130    }
131
132    # Enable ANSI escape codes if something emulating them is around (cmd.exe
133    # doesn't understand ANSI escape codes by default). Make sure to not enable
134    # this if remoteexec is in use, because this will lower cache hits.
135    if (!use_remoteexec &&
136        exec_script("//build/win/use_ansi_codes.py", [], "trim string") ==
137        "True") {
138      cflags += [ "-fansi-escape-codes" ]
139    }
140
141    if (use_clang_diagnostics_format) {
142      cflags += [ "/clang:-fdiagnostics-format=clang" ]
143    }
144  }
145
146  if (use_lld && !use_thin_lto) {
147    # /Brepro lets the compiler not write the mtime field in the .obj output.
148    # link.exe /incremental relies on this field to work correctly, but lld
149    # never looks at this timestamp, so it's safe to pass this flag with
150    # lld and get more deterministic compiler output in return.
151    # In LTO builds, the compiler doesn't write .obj files containing mtimes,
152    # so /Brepro is ignored there.
153    cflags += [ "/Brepro" ]
154  }
155
156  ldflags = []
157
158  if (use_lld) {
159    # lld defaults to writing the current time in the pe/coff header.
160    # For build reproducibility, pass an explicit timestamp. See
161    # build/compute_build_timestamp.py for how the timestamp is chosen.
162    # (link.exe also writes the current time, but it doesn't have a flag to
163    # override that behavior.)
164    ldflags += [ "/TIMESTAMP:" + build_timestamp ]
165
166    # Don't look for libpaths in %LIB%, similar to /X in cflags above.
167    ldflags += [ "/lldignoreenv" ]
168  }
169
170  # Some binaries create PDBs larger than 4 GiB. Increasing the PDB page size
171  # to 8 KiB allows 8 GiB PDBs. The larger page size also allows larger block maps
172  # which is a PDB limit that was hit in https://crbug.com/1406510. The page size
173  # can easily be increased in the future to allow even larger PDBs or larger
174  # block maps.
175  # This flag requires lld-link.exe or link.exe from VS 2022 or later to create
176  # the PDBs, and tools from circa 22H2 or later to consume the PDBs.
177  # Debug component builds can generate PDBs that exceed 8 GiB, so use an
178  # even larger page size, allowing up to 16 GiB PDBs.
179  if (is_debug && !is_component_build) {
180    ldflags += [ "/pdbpagesize:16384" ]
181  } else {
182    ldflags += [ "/pdbpagesize:8192" ]
183  }
184
185  if (!is_debug && !is_component_build) {
186    # Enable standard linker optimizations like GC (/OPT:REF) and ICF in static
187    # release builds.
188    # Release builds always want these optimizations, so enable them explicitly.
189    ldflags += [
190      "/OPT:REF",
191      "/OPT:ICF",
192      "/INCREMENTAL:NO",
193      "/FIXED:NO",
194    ]
195
196    if (use_lld) {
197      # String tail merging leads to smaller binaries, but they don't compress
198      # as well, leading to increased mini_installer size (crbug.com/838449).
199      ldflags += [ "/OPT:NOLLDTAILMERGE" ]
200    }
201
202    # TODO(siggi): Is this of any use anymore?
203    # /PROFILE ensures that the PDB file contains FIXUP information (growing the
204    # PDB file by about 5%) but does not otherwise alter the output binary. It
205    # is enabled opportunistically for builds where it is not prohibited (not
206    # supported when incrementally linking, or using /debug:fastlink).
207    ldflags += [ "/PROFILE" ]
208  }
209
210  # arflags apply only to static_libraries. The normal linker configs are only
211  # set for executable and shared library targets so arflags must be set
212  # elsewhere. Since this is relatively contained, we just apply them in this
213  # more general config and they will only have an effect on static libraries.
214  arflags = [
215    # "No public symbols found; archive member will be inaccessible." This
216    # means that one or more object files in the library can never be
217    # pulled in to targets that link to this library. It's just a warning that
218    # the source file is a no-op.
219    "/ignore:4221",
220  ]
221}
222
223# This is included by reference in the //build/config/compiler:runtime_library
224# config that is applied to all targets. It is here to separate out the logic
225# that is Windows-only. Please see that target for advice on what should go in
226# :runtime_library vs. :compiler.
227config("runtime_library") {
228  cflags = []
229  cflags_cc = []
230
231  # Defines that set up the CRT.
232  defines = [
233    "__STD_C",
234    "_CRT_RAND_S",
235    "_CRT_SECURE_NO_DEPRECATE",
236    "_SCL_SECURE_NO_DEPRECATE",
237  ]
238
239  # Defines that set up the Windows SDK.
240  defines += [
241    "_ATL_NO_OPENGL",
242    "_WINDOWS",
243    "CERT_CHAIN_PARA_HAS_EXTRA_FIELDS",
244    "PSAPI_VERSION=2",
245    "WIN32",
246    "_SECURE_ATL",
247  ]
248
249  if (current_os == "winuwp") {
250    # When targeting Windows Runtime, certain compiler/linker flags are
251    # necessary.
252    defines += [
253      "WINUWP",
254      "__WRL_NO_DEFAULT_LIB__",
255    ]
256    if (target_winuwp_family == "app") {
257      defines += [ "WINAPI_FAMILY=WINAPI_FAMILY_PC_APP" ]
258    } else if (target_winuwp_family == "phone") {
259      defines += [ "WINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP" ]
260    } else if (target_winuwp_family == "system") {
261      defines += [ "WINAPI_FAMILY=WINAPI_FAMILY_SYSTEM" ]
262    } else if (target_winuwp_family == "server") {
263      defines += [ "WINAPI_FAMILY=WINAPI_FAMILY_SERVER" ]
264    } else {
265      defines += [ "WINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP" ]
266    }
267    cflags_cc += [ "/EHsc" ]
268
269    # This warning is given because the linker cannot tell the difference
270    # between consuming WinRT APIs versus authoring WinRT within static
271    # libraries as such this warning is always given by the linker. Since
272    # consuming WinRT APIs within a library is legitimate but authoring
273    # WinRT APis is not allowed, this warning is disabled to ignore the
274    # legitimate consumption of WinRT APIs within static library builds.
275    arflags = [ "/IGNORE:4264" ]
276
277    if (target_winuwp_version == "10") {
278      defines += [ "WIN10=_WIN32_WINNT_WIN10" ]
279    } else if (target_winuwp_version == "8.1") {
280      defines += [ "WIN8_1=_WIN32_WINNT_WINBLUE" ]
281    } else if (target_winuwp_version == "8.0") {
282      defines += [ "WIN8=_WIN32_WINNT_WIN8" ]
283    }
284  } else {
285    # When not targeting Windows Runtime, make sure the WINAPI family is set
286    # to desktop.
287    defines += [ "WINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP" ]
288  }
289}
290
291# Chromium only supports Windowes 10+.
292# Some third-party libraries assume that these defines set what version of
293# Windows is available at runtime. Targets using these libraries need to
294# manually override this config for their compiles.
295config("winver") {
296  defines = [
297    "NTDDI_VERSION=NTDDI_WIN10_NI",
298
299    # We can't say `=_WIN32_WINNT_WIN10` here because some files do
300    # `#if WINVER < 0x0600` without including windows.h before,
301    # and then _WIN32_WINNT_WIN10 isn't yet known to be 0x0A00.
302    "_WIN32_WINNT=0x0A00",
303    "WINVER=0x0A00",
304  ]
305}
306
307# Linker flags for Windows SDK setup, this is applied only to EXEs and DLLs.
308config("sdk_link") {
309  if (current_cpu == "x86") {
310    ldflags = [
311      "/SAFESEH",  # Not compatible with x64 so use only for x86.
312      "/largeaddressaware",
313    ]
314  }
315}
316
317# This default linker setup is provided separately from the SDK setup so
318# targets who want different library configurations can remove this and specify
319# their own.
320config("common_linker_setup") {
321  ldflags = [
322    "/FIXED:NO",
323    "/ignore:4199",
324    "/ignore:4221",
325    "/NXCOMPAT",
326    "/DYNAMICBASE",
327  ]
328
329  if (win_linker_timing) {
330    ldflags += [
331      "/time",
332      "/verbose:incr",
333    ]
334  }
335}
336
337config("default_cfg_compiler") {
338  # Emit table of address-taken functions for Control-Flow Guard (CFG).
339  # This is needed to allow functions to be called by code that is built
340  # with CFG enabled, such as system libraries.
341  # The CFG guards are only emitted if |win_enable_cfg_guards| is enabled.
342  if (win_enable_cfg_guards) {
343    if (is_clang) {
344      cflags = [ "/guard:cf" ]
345    }
346    rustflags = [ "-Ccontrol-flow-guard" ]
347  } else {
348    if (is_clang) {
349      cflags = [ "/guard:cf,nochecks" ]
350    }
351    rustflags = [ "-Ccontrol-flow-guard=nochecks" ]
352  }
353}
354
355# To disable CFG guards for a target, remove the "default_cfg_compiler"
356# config, and add "disable_guards_cfg_compiler" config.
357config("disable_guards_cfg_compiler") {
358  # Emit table of address-taken functions for Control-Flow Guard (CFG).
359  # This is needed to allow functions to be called by code that is built
360  # with CFG enabled, such as system libraries.
361  if (is_clang) {
362    cflags = [ "/guard:cf,nochecks" ]
363  }
364  rustflags = [ "-Ccontrol-flow-guard=nochecks" ]
365}
366
367config("cfi_linker") {
368  # Control Flow Guard (CFG)
369  # https://msdn.microsoft.com/en-us/library/windows/desktop/mt637065.aspx
370  # /DYNAMICBASE (ASLR) is turned off in debug builds, therefore CFG cannot be
371  # turned on either.
372  # ASan and CFG leads to slow process startup. Chromium's test runner uses
373  # lots of child processes, so this means things are really slow. Disable CFG
374  # for now. https://crbug.com/846966
375  if (!is_debug && !is_asan) {
376    # Turn on CFG bitmap generation and CFG load config.
377    ldflags = [ "/guard:cf" ]
378  }
379}
380
381# This is a superset of all the delayloads needed for chrome.exe, chrome.dll,
382# and chrome_elf.dll. The linker will automatically ignore anything which is not
383# linked to the binary at all (it is harmless to have an unmatched /delayload).
384#
385# We delayload most libraries as the dlls are simply not required at startup (or
386# at all, depending on the process type). In unsandboxed process they will load
387# when first needed.
388#
389# Some dlls open handles when they are loaded, and we may not want them to be
390# loaded in renderers or other sandboxed processes. Conversely, some dlls must
391# be loaded before sandbox lockdown.
392#
393# Some dlls themselves load others - in particular, to avoid unconditionally
394# loading user32.dll - we require that the following dlls are all delayloaded:
395# user32, gdi32, comctl32, comdlg32, cryptui, d3d9, dwmapi, imm32, msi, ole32,
396# oleacc, rstrtmgr, shell32, shlwapi, and uxtheme.
397#
398# Advapi32.dll is unconditionally loaded at process startup on Windows 10, but
399# on Windows 11 it is not, which makes it worthwhile to delay load it.
400# Additionally, advapi32.dll exports several functions that are forwarded to
401# other DLLs such as cryptbase.dll. If calls to those functions are present but
402# there are some processes where the functions are never called then delay
403# loading of advapi32.dll avoids pulling in those DLLs (such as cryptbase.dll)
404# unnecessarily, even if advapi32.dll itself is loaded.
405#
406# This config applies to chrome.exe, chrome.dll, chrome_elf.dll (& others).
407#
408# This config should also be used for any test binary whose goal is to run
409# tests with the full browser.
410config("delayloads") {
411  ldflags = [
412    "/DELAYLOAD:api-ms-win-core-synch-l1-2-0.dll",
413    "/DELAYLOAD:api-ms-win-core-winrt-error-l1-1-0.dll",
414    "/DELAYLOAD:api-ms-win-core-winrt-l1-1-0.dll",
415    "/DELAYLOAD:api-ms-win-core-winrt-string-l1-1-0.dll",
416    "/DELAYLOAD:advapi32.dll",
417    "/DELAYLOAD:bcryptprimitives.dll",
418    "/DELAYLOAD:comctl32.dll",
419    "/DELAYLOAD:comdlg32.dll",
420    "/DELAYLOAD:credui.dll",
421    "/DELAYLOAD:cryptui.dll",
422    "/DELAYLOAD:d3d11.dll",
423    "/DELAYLOAD:d3d12.dll",
424    "/DELAYLOAD:d3d9.dll",
425    "/DELAYLOAD:dcomp.dll",
426    "/DELAYLOAD:dwmapi.dll",
427    "/DELAYLOAD:dxgi.dll",
428    "/DELAYLOAD:dxva2.dll",
429    "/DELAYLOAD:esent.dll",
430    "/DELAYLOAD:fontsub.dll",
431    "/DELAYLOAD:gdi32.dll",
432    "/DELAYLOAD:hid.dll",
433    "/DELAYLOAD:imagehlp.dll",
434    "/DELAYLOAD:imm32.dll",
435    "/DELAYLOAD:msi.dll",
436    "/DELAYLOAD:netapi32.dll",
437    "/DELAYLOAD:ncrypt.dll",
438    "/DELAYLOAD:ole32.dll",
439    "/DELAYLOAD:oleacc.dll",
440    "/DELAYLOAD:pdh.dll",
441    "/DELAYLOAD:propsys.dll",
442    "/DELAYLOAD:psapi.dll",
443    "/DELAYLOAD:rpcrt4.dll",
444    "/DELAYLOAD:rstrtmgr.dll",
445    "/DELAYLOAD:setupapi.dll",
446    "/DELAYLOAD:shell32.dll",
447    "/DELAYLOAD:shlwapi.dll",
448    "/DELAYLOAD:uiautomationcore.dll",
449    "/DELAYLOAD:urlmon.dll",
450    "/DELAYLOAD:user32.dll",
451    "/DELAYLOAD:usp10.dll",
452    "/DELAYLOAD:uxtheme.dll",
453    "/DELAYLOAD:wer.dll",
454    "/DELAYLOAD:wevtapi.dll",
455    "/DELAYLOAD:wininet.dll",
456    "/DELAYLOAD:winusb.dll",
457    "/DELAYLOAD:wsock32.dll",
458    "/DELAYLOAD:wtsapi32.dll",
459  ]
460}
461
462# This config (along with `:delayloads`) applies to chrome.exe & chrome_elf.dll.
463# Entries should not appear in both configs.
464config("delayloads_not_for_child_dll") {
465  ldflags = [
466    "/DELAYLOAD:crypt32.dll",
467    "/DELAYLOAD:dbghelp.dll",
468    "/DELAYLOAD:dhcpcsvc.dll",
469    "/DELAYLOAD:dwrite.dll",
470    "/DELAYLOAD:iphlpapi.dll",
471    "/DELAYLOAD:oleaut32.dll",
472    "/DELAYLOAD:secur32.dll",
473    "/DELAYLOAD:userenv.dll",
474    "/DELAYLOAD:winhttp.dll",
475    "/DELAYLOAD:winmm.dll",
476    "/DELAYLOAD:winspool.drv",
477    "/DELAYLOAD:wintrust.dll",
478    "/DELAYLOAD:ws2_32.dll",
479  ]
480}
481
482# CRT --------------------------------------------------------------------------
483
484# Configures how the runtime library (CRT) is going to be used.
485# See https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx for a reference of
486# what each value does.
487config("default_crt") {
488  if (is_component_build) {
489    # Component mode: dynamic CRT. Since the library is shared, it requires
490    # exceptions or will give errors about things not matching, so keep
491    # exceptions on.
492    configs = [ ":dynamic_crt" ]
493  } else {
494    if (current_os == "winuwp") {
495      # https://blogs.msdn.microsoft.com/vcblog/2014/06/10/the-great-c-runtime-crt-refactoring/
496      # contains a details explanation of what is happening with the Windows
497      # CRT in Visual Studio releases related to Windows store applications.
498      configs = [ ":dynamic_crt" ]
499    } else {
500      # Desktop Windows: static CRT.
501      configs = [ ":static_crt" ]
502    }
503  }
504}
505
506# Use this to force use of the release CRT when building perf-critical build
507# tools that need to be fully optimized even in debug builds, for those times
508# when the debug CRT is part of the bottleneck. This also avoids *implicitly*
509# defining _DEBUG.
510config("release_crt") {
511  if (is_component_build) {
512    cflags = [ "/MD" ]
513
514    # /MD specifies msvcrt.lib as the CRT library, which is the dynamic+release
515    # version. Rust needs to agree, and its default mode is dynamic+release, so
516    # we do nothing here. See https://github.com/rust-lang/rust/issues/39016.
517
518    if (use_custom_libcxx) {
519      # On Windows, including libcpmt[d]/msvcprt[d] explicitly links the C++
520      # standard library, which libc++ needs for exception_ptr internals.
521      ldflags = [ "/DEFAULTLIB:msvcprt.lib" ]
522    }
523  } else {
524    cflags = [ "/MT" ]
525
526    # /MT specifies libcmt.lib as the CRT library, which is the static+release
527    # version. Rust needs to agree, so we tell it to use the static+release CRT
528    # as well. See https://github.com/rust-lang/rust/issues/39016.
529    rustflags = [ "-Ctarget-feature=+crt-static" ]
530
531    if (use_custom_libcxx) {
532      ldflags = [ "/DEFAULTLIB:libcpmt.lib" ]
533    }
534  }
535}
536
537config("dynamic_crt") {
538  if (is_debug) {
539    # This pulls in the DLL debug CRT and defines _DEBUG
540    cflags = [ "/MDd" ]
541
542    # /MDd specifies msvcrtd.lib as the CRT library. Rust needs to agree, so we
543    # specify it explicitly. Rust defaults to the dynamic+release library, which
544    # we remove here, and then replace. See
545    # https://github.com/rust-lang/rust/issues/39016.
546    rustflags = [
547      "-Clink-arg=/nodefaultlib:msvcrt.lib",
548      "-Clink-arg=msvcrtd.lib",
549    ]
550
551    if (use_custom_libcxx) {
552      ldflags = [ "/DEFAULTLIB:msvcprtd.lib" ]
553    }
554  } else {
555    cflags = [ "/MD" ]
556
557    # /MD specifies msvcrt.lib as the CRT library, which is the dynamic+release
558    # version. Rust needs to agree, and its default mode is dynamic+release, so
559    # we do nothing here. See https://github.com/rust-lang/rust/issues/39016.
560
561    if (use_custom_libcxx) {
562      ldflags = [ "/DEFAULTLIB:msvcprt.lib" ]
563    }
564  }
565}
566
567config("static_crt") {
568  if (is_debug) {
569    # This pulls in the static debug CRT and defines _DEBUG
570    cflags = [ "/MTd" ]
571
572    # /MTd specifies libcmtd.lib as the CRT library. Rust needs to agree, so we
573    # specify it explicitly. We tell Rust that we're using the static CRT but
574    # remove the release library that it chooses, and replace with the debug
575    # library. See https://github.com/rust-lang/rust/issues/39016.
576    rustflags = [
577      "-Ctarget-feature=+crt-static",
578      "-Clink-arg=/nodefaultlib:libcmt.lib",
579      "-Clink-arg=libcmtd.lib",
580    ]
581
582    if (use_custom_libcxx) {
583      ldflags = [ "/DEFAULTLIB:libcpmtd.lib" ]
584    }
585  } else {
586    cflags = [ "/MT" ]
587
588    # /MT specifies libcmt.lib as the CRT library, which is the static+release
589    # version. Rust needs to agree, so we tell it to use the static+release CRT
590    # as well. See https://github.com/rust-lang/rust/issues/39016.
591    rustflags = [ "-Ctarget-feature=+crt-static" ]
592
593    if (use_custom_libcxx) {
594      ldflags = [ "/DEFAULTLIB:libcpmt.lib" ]
595    }
596  }
597}
598
599# Subsystem --------------------------------------------------------------------
600
601# This is appended to the subsystem to specify a minimum version.
602# The number after the comma is the minimum required OS version.
603# Set to 10.0 since we only support >= Win10 since M110.
604subsystem_version_suffix = ",10.0"
605
606config("console") {
607  ldflags = [ "/SUBSYSTEM:CONSOLE$subsystem_version_suffix" ]
608}
609config("windowed") {
610  ldflags = [ "/SUBSYSTEM:WINDOWS$subsystem_version_suffix" ]
611}
612
613# Incremental linking ----------------------------------------------------------
614
615# Applies incremental linking or not depending on the current configuration.
616config("default_incremental_linking") {
617  # Enable incremental linking for debug builds and all component builds - any
618  # builds where performance is not job one.
619  # TODO(thakis): Always turn this on with lld, no reason not to.
620  if (is_debug || is_component_build) {
621    ldflags = [ "/INCREMENTAL" ]
622    if (use_lld) {
623      # lld doesn't use ilk files and doesn't really have an incremental link
624      # mode; the only effect of the flag is that the .lib file timestamp isn't
625      # updated if the .lib doesn't change.
626      # TODO(thakis): Why pass /OPT:NOREF for lld, but not otherwise?
627      # TODO(thakis): /INCREMENTAL is on by default in link.exe, but not in
628      # lld.
629      ldflags += [ "/OPT:NOREF" ]
630
631      # TODO(crbug.com/40267564): Mixing incrememntal and icf produces an error
632      # in lld-link.
633      ldflags += [ "/OPT:NOICF" ]
634    }
635  } else {
636    ldflags = [ "/INCREMENTAL:NO" ]
637  }
638}
639
640# Character set ----------------------------------------------------------------
641
642# Not including this config means "ansi" (8-bit system codepage).
643config("unicode") {
644  defines = [
645    "_UNICODE",
646    "UNICODE",
647  ]
648}
649
650# Lean and mean ----------------------------------------------------------------
651
652# Some third party code might not compile with WIN32_LEAN_AND_MEAN so we have
653# to have a separate config for it. Remove this config from your target to
654# get the "bloaty and accommodating" version of windows.h.
655config("lean_and_mean") {
656  defines = [ "WIN32_LEAN_AND_MEAN" ]
657}
658
659# Nominmax --------------------------------------------------------------------
660
661# Some third party code defines NOMINMAX before including windows.h, which
662# then causes warnings when it's been previously defined on the command line.
663# For such targets, this config can be removed.
664
665config("nominmax") {
666  defines = [ "NOMINMAX" ]
667}
668