xref: /aosp_15_r20/external/cronet/build/config/win/BUILD.gn (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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  # Disabled with cc_wrapper because of https://github.com/mozilla/sccache/issues/264
147  if (use_lld && !use_thin_lto && cc_wrapper == "") {
148    # /Brepro lets the compiler not write the mtime field in the .obj output.
149    # link.exe /incremental relies on this field to work correctly, but lld
150    # never looks at this timestamp, so it's safe to pass this flag with
151    # lld and get more deterministic compiler output in return.
152    # In LTO builds, the compiler doesn't write .obj files containing mtimes,
153    # so /Brepro is ignored there.
154    cflags += [ "/Brepro" ]
155  }
156
157  ldflags = []
158
159  if (use_lld) {
160    # lld defaults to writing the current time in the pe/coff header.
161    # For build reproducibility, pass an explicit timestamp. See
162    # build/compute_build_timestamp.py for how the timestamp is chosen.
163    # (link.exe also writes the current time, but it doesn't have a flag to
164    # override that behavior.)
165    ldflags += [ "/TIMESTAMP:" + build_timestamp ]
166
167    # Don't look for libpaths in %LIB%, similar to /X in cflags above.
168    ldflags += [ "/lldignoreenv" ]
169  }
170
171  # Some binaries create PDBs larger than 4 GiB. Increasing the PDB page size
172  # to 8 KiB allows 8 GiB PDBs. The larger page size also allows larger block maps
173  # which is a PDB limit that was hit in https://crbug.com/1406510. The page size
174  # can easily be increased in the future to allow even larger PDBs or larger
175  # block maps.
176  # This flag requires lld-link.exe or link.exe from VS 2022 or later to create
177  # the PDBs, and tools from circa 22H2 or later to consume the PDBs.
178  # Debug component builds can generate PDBs that exceed 8 GiB, so use an
179  # even larger page size, allowing up to 16 GiB PDBs.
180  if (is_debug && !is_component_build) {
181    ldflags += [ "/pdbpagesize:16384" ]
182  } else {
183    ldflags += [ "/pdbpagesize:8192" ]
184  }
185
186  if (!is_debug && !is_component_build) {
187    # Enable standard linker optimizations like GC (/OPT:REF) and ICF in static
188    # release builds.
189    # Release builds always want these optimizations, so enable them explicitly.
190    ldflags += [
191      "/OPT:REF",
192      "/OPT:ICF",
193      "/INCREMENTAL:NO",
194      "/FIXED:NO",
195    ]
196
197    if (use_lld) {
198      # String tail merging leads to smaller binaries, but they don't compress
199      # as well, leading to increased mini_installer size (crbug.com/838449).
200      ldflags += [ "/OPT:NOLLDTAILMERGE" ]
201    }
202
203    # TODO(siggi): Is this of any use anymore?
204    # /PROFILE ensures that the PDB file contains FIXUP information (growing the
205    # PDB file by about 5%) but does not otherwise alter the output binary. It
206    # is enabled opportunistically for builds where it is not prohibited (not
207    # supported when incrementally linking, or using /debug:fastlink).
208    ldflags += [ "/PROFILE" ]
209  }
210
211  # arflags apply only to static_libraries. The normal linker configs are only
212  # set for executable and shared library targets so arflags must be set
213  # elsewhere. Since this is relatively contained, we just apply them in this
214  # more general config and they will only have an effect on static libraries.
215  arflags = [
216    # "No public symbols found; archive member will be inaccessible." This
217    # means that one or more object files in the library can never be
218    # pulled in to targets that link to this library. It's just a warning that
219    # the source file is a no-op.
220    "/ignore:4221",
221  ]
222}
223
224# This is included by reference in the //build/config/compiler:runtime_library
225# config that is applied to all targets. It is here to separate out the logic
226# that is Windows-only. Please see that target for advice on what should go in
227# :runtime_library vs. :compiler.
228config("runtime_library") {
229  cflags = []
230  cflags_cc = []
231
232  # Defines that set up the CRT.
233  defines = [
234    "__STD_C",
235    "_CRT_RAND_S",
236    "_CRT_SECURE_NO_DEPRECATE",
237    "_SCL_SECURE_NO_DEPRECATE",
238  ]
239
240  # Defines that set up the Windows SDK.
241  defines += [
242    "_ATL_NO_OPENGL",
243    "_WINDOWS",
244    "CERT_CHAIN_PARA_HAS_EXTRA_FIELDS",
245    "PSAPI_VERSION=2",
246    "WIN32",
247    "_SECURE_ATL",
248  ]
249
250  if (current_os == "winuwp") {
251    # When targeting Windows Runtime, certain compiler/linker flags are
252    # necessary.
253    defines += [
254      "WINUWP",
255      "__WRL_NO_DEFAULT_LIB__",
256    ]
257    if (target_winuwp_family == "app") {
258      defines += [ "WINAPI_FAMILY=WINAPI_FAMILY_PC_APP" ]
259    } else if (target_winuwp_family == "phone") {
260      defines += [ "WINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP" ]
261    } else if (target_winuwp_family == "system") {
262      defines += [ "WINAPI_FAMILY=WINAPI_FAMILY_SYSTEM" ]
263    } else if (target_winuwp_family == "server") {
264      defines += [ "WINAPI_FAMILY=WINAPI_FAMILY_SERVER" ]
265    } else {
266      defines += [ "WINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP" ]
267    }
268    cflags_cc += [ "/EHsc" ]
269
270    # This warning is given because the linker cannot tell the difference
271    # between consuming WinRT APIs versus authoring WinRT within static
272    # libraries as such this warning is always given by the linker. Since
273    # consuming WinRT APIs within a library is legitimate but authoring
274    # WinRT APis is not allowed, this warning is disabled to ignore the
275    # legitimate consumption of WinRT APIs within static library builds.
276    arflags = [ "/IGNORE:4264" ]
277
278    if (target_winuwp_version == "10") {
279      defines += [ "WIN10=_WIN32_WINNT_WIN10" ]
280    } else if (target_winuwp_version == "8.1") {
281      defines += [ "WIN8_1=_WIN32_WINNT_WINBLUE" ]
282    } else if (target_winuwp_version == "8.0") {
283      defines += [ "WIN8=_WIN32_WINNT_WIN8" ]
284    }
285  } else {
286    # When not targeting Windows Runtime, make sure the WINAPI family is set
287    # to desktop.
288    defines += [ "WINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP" ]
289  }
290}
291
292# Chromium only supports Windowes 10+.
293# Some third-party libraries assume that these defines set what version of
294# Windows is available at runtime. Targets using these libraries need to
295# manually override this config for their compiles.
296config("winver") {
297  defines = [
298    "NTDDI_VERSION=NTDDI_WIN10_NI",
299
300    # We can't say `=_WIN32_WINNT_WIN10` here because some files do
301    # `#if WINVER < 0x0600` without including windows.h before,
302    # and then _WIN32_WINNT_WIN10 isn't yet known to be 0x0A00.
303    "_WIN32_WINNT=0x0A00",
304    "WINVER=0x0A00",
305  ]
306}
307
308# Linker flags for Windows SDK setup, this is applied only to EXEs and DLLs.
309config("sdk_link") {
310  if (current_cpu == "x86") {
311    ldflags = [
312      "/SAFESEH",  # Not compatible with x64 so use only for x86.
313      "/largeaddressaware",
314    ]
315  }
316}
317
318# This default linker setup is provided separately from the SDK setup so
319# targets who want different library configurations can remove this and specify
320# their own.
321config("common_linker_setup") {
322  ldflags = [
323    "/FIXED:NO",
324    "/ignore:4199",
325    "/ignore:4221",
326    "/NXCOMPAT",
327    "/DYNAMICBASE",
328  ]
329
330  if (win_linker_timing) {
331    ldflags += [
332      "/time",
333      "/verbose:incr",
334    ]
335  }
336}
337
338config("default_cfg_compiler") {
339  # Emit table of address-taken functions for Control-Flow Guard (CFG).
340  # This is needed to allow functions to be called by code that is built
341  # with CFG enabled, such as system libraries.
342  # The CFG guards are only emitted if |win_enable_cfg_guards| is enabled.
343  if (win_enable_cfg_guards) {
344    if (is_clang) {
345      cflags = [ "/guard:cf" ]
346    }
347    rustflags = [ "-Ccontrol-flow-guard" ]
348  } else {
349    if (is_clang) {
350      cflags = [ "/guard:cf,nochecks" ]
351    }
352    rustflags = [ "-Ccontrol-flow-guard=nochecks" ]
353  }
354}
355
356# To disable CFG guards for a target, remove the "default_cfg_compiler"
357# config, and add "disable_guards_cfg_compiler" config.
358config("disable_guards_cfg_compiler") {
359  # Emit table of address-taken functions for Control-Flow Guard (CFG).
360  # This is needed to allow functions to be called by code that is built
361  # with CFG enabled, such as system libraries.
362  if (is_clang) {
363    cflags = [ "/guard:cf,nochecks" ]
364  }
365  rustflags = [ "-Ccontrol-flow-guard=nochecks" ]
366}
367
368config("cfi_linker") {
369  # Control Flow Guard (CFG)
370  # https://msdn.microsoft.com/en-us/library/windows/desktop/mt637065.aspx
371  # /DYNAMICBASE (ASLR) is turned off in debug builds, therefore CFG cannot be
372  # turned on either.
373  # ASan and CFG leads to slow process startup. Chromium's test runner uses
374  # lots of child processes, so this means things are really slow. Disable CFG
375  # for now. https://crbug.com/846966
376  if (!is_debug && !is_asan) {
377    # Turn on CFG bitmap generation and CFG load config.
378    ldflags = [ "/guard:cf" ]
379  }
380}
381
382# This is a superset of all the delayloads needed for chrome.exe, chrome.dll,
383# and chrome_elf.dll. The linker will automatically ignore anything which is not
384# linked to the binary at all (it is harmless to have an unmatched /delayload).
385#
386# We delayload most libraries as the dlls are simply not required at startup (or
387# at all, depending on the process type). In unsandboxed process they will load
388# when first needed.
389#
390# Some dlls open handles when they are loaded, and we may not want them to be
391# loaded in renderers or other sandboxed processes. Conversely, some dlls must
392# be loaded before sandbox lockdown.
393#
394# Some dlls themselves load others - in particular, to avoid unconditionally
395# loading user32.dll - we require that the following dlls are all delayloaded:
396# user32, gdi32, comctl32, comdlg32, cryptui, d3d9, dwmapi, imm32, msi, ole32,
397# oleacc, rstrtmgr, shell32, shlwapi, and uxtheme.
398#
399# Advapi32.dll is unconditionally loaded at process startup on Windows 10, but
400# on Windows 11 it is not, which makes it worthwhile to delay load it.
401# Additionally, advapi32.dll exports several functions that are forwarded to
402# other DLLs such as cryptbase.dll. If calls to those functions are present but
403# there are some processes where the functions are never called then delay
404# loading of advapi32.dll avoids pulling in those DLLs (such as cryptbase.dll)
405# unnecessarily, even if advapi32.dll itself is loaded.
406#
407# This config applies to chrome.exe, chrome.dll, chrome_elf.dll (& others).
408#
409# This config should also be used for any test binary whose goal is to run
410# tests with the full browser.
411config("delayloads") {
412  ldflags = [
413    "/DELAYLOAD:api-ms-win-core-synch-l1-2-0.dll",
414    "/DELAYLOAD:api-ms-win-core-winrt-error-l1-1-0.dll",
415    "/DELAYLOAD:api-ms-win-core-winrt-l1-1-0.dll",
416    "/DELAYLOAD:api-ms-win-core-winrt-string-l1-1-0.dll",
417    "/DELAYLOAD:advapi32.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:dwmapi.dll",
426    "/DELAYLOAD:dxgi.dll",
427    "/DELAYLOAD:dxva2.dll",
428    "/DELAYLOAD:esent.dll",
429    "/DELAYLOAD:fontsub.dll",
430    "/DELAYLOAD:gdi32.dll",
431    "/DELAYLOAD:hid.dll",
432    "/DELAYLOAD:imagehlp.dll",
433    "/DELAYLOAD:imm32.dll",
434    "/DELAYLOAD:msi.dll",
435    "/DELAYLOAD:netapi32.dll",
436    "/DELAYLOAD:ncrypt.dll",
437    "/DELAYLOAD:ole32.dll",
438    "/DELAYLOAD:oleacc.dll",
439    "/DELAYLOAD:pdh.dll",
440    "/DELAYLOAD:propsys.dll",
441    "/DELAYLOAD:psapi.dll",
442    "/DELAYLOAD:rpcrt4.dll",
443    "/DELAYLOAD:rstrtmgr.dll",
444    "/DELAYLOAD:setupapi.dll",
445    "/DELAYLOAD:shell32.dll",
446    "/DELAYLOAD:shlwapi.dll",
447    "/DELAYLOAD:uiautomationcore.dll",
448    "/DELAYLOAD:urlmon.dll",
449    "/DELAYLOAD:user32.dll",
450    "/DELAYLOAD:usp10.dll",
451    "/DELAYLOAD:uxtheme.dll",
452    "/DELAYLOAD:wer.dll",
453    "/DELAYLOAD:wevtapi.dll",
454    "/DELAYLOAD:wininet.dll",
455    "/DELAYLOAD:winusb.dll",
456    "/DELAYLOAD:wsock32.dll",
457    "/DELAYLOAD:wtsapi32.dll",
458  ]
459}
460
461# This config (along with `:delayloads`) applies to chrome.exe & chrome_elf.dll.
462# Entries should not appear in both configs.
463config("delayloads_not_for_child_dll") {
464  ldflags = [
465    "/DELAYLOAD:crypt32.dll",
466    "/DELAYLOAD:dbghelp.dll",
467    "/DELAYLOAD:dhcpcsvc.dll",
468    "/DELAYLOAD:dwrite.dll",
469    "/DELAYLOAD:iphlpapi.dll",
470    "/DELAYLOAD:oleaut32.dll",
471    "/DELAYLOAD:secur32.dll",
472    "/DELAYLOAD:userenv.dll",
473    "/DELAYLOAD:winhttp.dll",
474    "/DELAYLOAD:winmm.dll",
475    "/DELAYLOAD:winspool.drv",
476    "/DELAYLOAD:wintrust.dll",
477    "/DELAYLOAD:ws2_32.dll",
478  ]
479}
480
481# CRT --------------------------------------------------------------------------
482
483# Configures how the runtime library (CRT) is going to be used.
484# See https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx for a reference of
485# what each value does.
486config("default_crt") {
487  if (is_component_build) {
488    # Component mode: dynamic CRT. Since the library is shared, it requires
489    # exceptions or will give errors about things not matching, so keep
490    # exceptions on.
491    configs = [ ":dynamic_crt" ]
492  } else {
493    if (current_os == "winuwp") {
494      # https://blogs.msdn.microsoft.com/vcblog/2014/06/10/the-great-c-runtime-crt-refactoring/
495      # contains a details explanation of what is happening with the Windows
496      # CRT in Visual Studio releases related to Windows store applications.
497      configs = [ ":dynamic_crt" ]
498    } else {
499      # Desktop Windows: static CRT.
500      configs = [ ":static_crt" ]
501    }
502  }
503}
504
505# Use this to force use of the release CRT when building perf-critical build
506# tools that need to be fully optimized even in debug builds, for those times
507# when the debug CRT is part of the bottleneck. This also avoids *implicitly*
508# defining _DEBUG.
509config("release_crt") {
510  if (is_component_build) {
511    cflags = [ "/MD" ]
512
513    if (rust_prebuilt_stdlib) {
514      rustflags = [ "-Ctarget-feature=-crt-static" ]
515    } else {
516      # /MD specifies msvcrt.lib as the CRT library. Rust needs to agree, so
517      # we specify it explicitly. Once
518      # https://github.com/rust-lang/rust/issues/39016 is resolved we should
519      # instead tell rustc which CRT to use (static/dynamic + release/debug).
520      rustflags = [ "-Clink-arg=msvcrt.lib" ]
521    }
522
523    if (use_custom_libcxx) {
524      # On Windows, including libcpmt[d]/msvcprt[d] explicitly links the C++
525      # standard library, which libc++ needs for exception_ptr internals.
526      ldflags = [ "/DEFAULTLIB:msvcprt.lib" ]
527    }
528  } else {
529    cflags = [ "/MT" ]
530
531    if (rust_prebuilt_stdlib) {
532      rustflags = [ "-Ctarget-feature=+crt-static" ]
533    } else {
534      # /MT specifies libcmt.lib as the CRT library. Rust needs to agree, so
535      # we specify it explicitly. Once
536      # https://github.com/rust-lang/rust/issues/39016 is resolved we should
537      # instead tell rustc which CRT to use (static/dynamic + release/debug).
538      rustflags = [ "-Clink-arg=libcmt.lib" ]
539    }
540
541    if (use_custom_libcxx) {
542      ldflags = [ "/DEFAULTLIB:libcpmt.lib" ]
543    }
544  }
545}
546
547config("dynamic_crt") {
548  if (is_debug) {
549    # This pulls in the DLL debug CRT and defines _DEBUG
550    cflags = [ "/MDd" ]
551
552    # /MDd specifies msvcrtd.lib as the CRT library. Rust needs to agree, so
553    # we specify it explicitly.
554    # Once https://github.com/rust-lang/rust/issues/39016 is resolved we should
555    # instead tell rustc which CRT to use (static/dynamic + release/debug). We
556    # can't support prebuilt stdlib in this path until then.
557    rustflags = [ "-Clink-arg=msvcrtd.lib" ]
558
559    if (use_custom_libcxx) {
560      ldflags = [ "/DEFAULTLIB:msvcprtd.lib" ]
561    }
562  } else {
563    cflags = [ "/MD" ]
564
565    if (rust_prebuilt_stdlib) {
566      rustflags = [ "-Ctarget-feature=-crt-static" ]
567    } else {
568      # /MD specifies msvcrt.lib as the CRT library. Rust needs to agree, so
569      # we specify it explicitly.
570      # Once https://github.com/rust-lang/rust/issues/39016 is resolved we
571      # should instead tell rustc which CRT to use (static/dynamic +
572      # release/debug).
573      rustflags = [ "-Clink-arg=msvcrt.lib" ]
574    }
575
576    if (use_custom_libcxx) {
577      ldflags = [ "/DEFAULTLIB:msvcprt.lib" ]
578    }
579  }
580}
581
582config("static_crt") {
583  if (is_debug) {
584    # This pulls in the static debug CRT and defines _DEBUG
585    cflags = [ "/MTd" ]
586
587    # /MTd specifies libcmtd.lib as the CRT library. Rust needs to agree, so
588    # we specify it explicitly.
589    # Once https://github.com/rust-lang/rust/issues/39016 is resolved we should
590    # instead tell rustc which CRT to use (static/dynamic + release/debug). We
591    # can't support prebuilt stdlib in this path until then.
592    rustflags = [ "-Clink-arg=libcmtd.lib" ]
593
594    if (use_custom_libcxx) {
595      ldflags = [ "/DEFAULTLIB:libcpmtd.lib" ]
596    }
597  } else {
598    cflags = [ "/MT" ]
599
600    if (rust_prebuilt_stdlib) {
601      rustflags = [ "-Ctarget-feature=+crt-static" ]
602    } else {
603      # /MT specifies libcmt.lib as the CRT library. Rust needs to agree, so
604      # we specify it explicitly.
605      # Once https://github.com/rust-lang/rust/issues/39016 is resolved we
606      # should instead tell rustc which CRT to use (static/dynamic +
607      # release/debug).
608      rustflags = [ "-Clink-arg=libcmt.lib" ]
609    }
610
611    if (use_custom_libcxx) {
612      ldflags = [ "/DEFAULTLIB:libcpmt.lib" ]
613    }
614  }
615}
616
617# Subsystem --------------------------------------------------------------------
618
619# This is appended to the subsystem to specify a minimum version.
620# The number after the comma is the minimum required OS version.
621# Set to 10.0 since we only support >= Win10 since M110.
622subsystem_version_suffix = ",10.0"
623
624config("console") {
625  ldflags = [ "/SUBSYSTEM:CONSOLE$subsystem_version_suffix" ]
626}
627config("windowed") {
628  ldflags = [ "/SUBSYSTEM:WINDOWS$subsystem_version_suffix" ]
629}
630
631# Incremental linking ----------------------------------------------------------
632
633# Applies incremental linking or not depending on the current configuration.
634config("default_incremental_linking") {
635  # Enable incremental linking for debug builds and all component builds - any
636  # builds where performance is not job one.
637  # TODO(thakis): Always turn this on with lld, no reason not to.
638  if (is_debug || is_component_build) {
639    ldflags = [ "/INCREMENTAL" ]
640    if (use_lld) {
641      # lld doesn't use ilk files and doesn't really have an incremental link
642      # mode; the only effect of the flag is that the .lib file timestamp isn't
643      # updated if the .lib doesn't change.
644      # TODO(thakis): Why pass /OPT:NOREF for lld, but not otherwise?
645      # TODO(thakis): /INCREMENTAL is on by default in link.exe, but not in
646      # lld.
647      ldflags += [ "/OPT:NOREF" ]
648
649      # TODO(crbug.com/1444129): Mixing incrememntal and icf produces an error
650      # in lld-link.
651      ldflags += [ "/OPT:NOICF" ]
652    }
653  } else {
654    ldflags = [ "/INCREMENTAL:NO" ]
655  }
656}
657
658# Character set ----------------------------------------------------------------
659
660# Not including this config means "ansi" (8-bit system codepage).
661config("unicode") {
662  defines = [
663    "_UNICODE",
664    "UNICODE",
665  ]
666}
667
668# Lean and mean ----------------------------------------------------------------
669
670# Some third party code might not compile with WIN32_LEAN_AND_MEAN so we have
671# to have a separate config for it. Remove this config from your target to
672# get the "bloaty and accommodating" version of windows.h.
673config("lean_and_mean") {
674  defines = [ "WIN32_LEAN_AND_MEAN" ]
675}
676
677# Nominmax --------------------------------------------------------------------
678
679# Some third party code defines NOMINMAX before including windows.h, which
680# then causes warnings when it's been previously defined on the command line.
681# For such targets, this config can be removed.
682
683config("nominmax") {
684  defines = [ "NOMINMAX" ]
685}
686