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