aboutsummaryrefslogtreecommitdiffstats
path: root/build/conf/linkers/msvc_linker.conf
blob: 62a649d0361ee0d65346c43c2b0c719e086789d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
LINK_EXE_CMD=${_WINE_LINK_PREFIX} ${_MSVC_LINK_OLD}
LINK_LIB_CMD=${_WINE_LIB_PREFIX} ${_MSVC_LIB_OLD}

_MSVC_ARCH=
when ($ARCH_I386 == "yes" || $ARCH_I686 == "yes") {
    _MSVC_ARCH=x86
}
elsewhen ($ARCH_X86_64 == "yes") {
    _MSVC_ARCH=x64
}
elsewhen ($ARCH_ARM == "yes") {
    _MSVC_ARCH=arm
}

_FLAGS_MACHINE=/MACHINE:${toupper:_MSVC_ARCH}

_FLAGS_IGNORE=/IGNORE:4221

_FLAGS_COMMON_IDE_MSVS=
when ($IDE_MSVS == "yes") {
    _FLAGS_COMMON_IDE_MSVS=/INCREMENTAL
}
otherwise {
    _FLAGS_COMMON_IDE_MSVS=/INCREMENTAL:NO
}

# TODO(nslus): DEVTOOLS-1868 remove restriction.
_FLAGS_DEBUG_ONLY_DEBUG=
_FLAGS_RELEASE_ONLY_DEBUG=
_FLAGS_COMMON_DEBUG=
when (!$NO_DEBUGINFO || $NO_DEBUGINFO == "no" || $NO_DEBUGINFO == "0") {
    when ($IDE_MSVS == "yes") {
        when ($CLANG_CL == "yes") {
            _FLAGS_DEBUG_ONLY_DEBUG=/DEBUG
        }
        otherwise {
            _FLAGS_DEBUG_ONLY_DEBUG=/DEBUG:FASTLINK
        }
        _FLAGS_RELEASE_ONLY_DEBUG=/DEBUG
    }
    otherwise {
        _FLAGS_COMMON_DEBUG=/DEBUG
    }
}

_FLAGS_COMMON_LIBPATHS=
when ($IDE_MSVS != "yes") {
    _FLAGS_COMMON_LIBPATHS=\
        /LIBPATH:\"${quo:_MSVC_TC_KIT_LIBS}/um/$_MSVC_ARCH\" \
        /LIBPATH:\"${quo:_MSVC_TC_KIT_LIBS}/ucrt/$_MSVC_ARCH\" \
        /LIBPATH:\"${quo:_MSVC_TC_VC_ROOT}/lib/$_MSVC_ARCH\"
}

_FLAGS_COMMON =/NOLOGO /ERRORREPORT:PROMPT /SUBSYSTEM:CONSOLE /TLBID:1 $MSVC_DYNAMICBASE /NXCOMPAT
_FLAGS_COMMON+=$_FLAGS_IGNORE
_FLAGS_COMMON+=$_FLAGS_MACHINE
_FLAGS_COMMON+=$_FLAGS_COMMON_IDE_MSVS
_FLAGS_COMMON+=$_FLAGS_COMMON_DEBUG
_FLAGS_COMMON+=$_FLAGS_COMMON_LIBPATHS

_FLAGS_DEBUG_ONLY_CLANG_CL=
when ($CLANG_CL == "yes") {
    _FLAGS_DEBUG_ONLY_CLANG_CL=/STACK:4194304
}

_FLAGS_DEBUG_ONLY =$_FLAGS_DEBUG_ONLY_CLANG_CL
_FLAGS_DEBUG_ONLY+=$_FLAGS_DEBUG_ONLY_DEBUG
_FLAGS_RELEASE_ONLY =$_FLAGS_RELEASE_ONLY_DEBUG

LINK_EXE_FLAGS_DEBUG =$_FLAGS_COMMON
LINK_EXE_FLAGS_DEBUG+=$_FLAGS_DEBUG_ONLY

LINK_EXE_FLAGS_RELEASE =$_FLAGS_COMMON
LINK_EXE_FLAGS_RELEASE+=$_FLAGS_RELEASE_ONLY

LINK_LIB_FLAGS=$_FLAGS_IGNORE $_FLAGS_MACHINE

LINK_STDLIBS=\
    advapi32.lib \
    comdlg32.lib \
    crypt32.lib \
    dnsapi.lib \
    gdi32.lib \
    iphlpapi.lib \
    kernel32.lib \
    mswsock.lib \
    ole32.lib \
    oleaut32.lib \
    psapi.lib \
    rpcrt4.lib \
    secur32.lib \
    shell32.lib \
    shlwapi.lib \
    user32.lib \
    userenv.lib \
    uuid.lib \
    version.lib \
    winmm.lib \
    winspool.lib \
    ws2_32.lib

LDFLAGS_GLOBAL=
LDFLAGS=
OBJADDE=
OBJADDE_LIB=
OBJADDE_LIB_GLOBAL=

LINK_EXE_FLAGS=$LINK_EXE_FLAGS_PER_TYPE
LINK_EXE_VFS_FLAGS=
when ($_UNDER_WINE_LINK != "yes") {
    LINK_EXE_VFS_FLAGS=/vfsoverlay:${BINDIR}/vfsoverlay.yaml
}
LINK_EXE_FLAGS+=${LINK_EXE_VFS_FLAGS}

GENERATE_COMMON_LIB_VFS_CMD=\
    ${YMAKE_PYTHON3} ${input:"build/scripts/generate_win_vfs.py"} \
    ${BINDIR} \
    ${_FLAGS_COMMON_LIBPATHS}

GENERATE_COMMON_LIB_VFS=
when ($_UNDER_WINE_LINK != "yes") {
    GENERATE_COMMON_LIB_VFS=${GENERATE_COMMON_LIB_VFS_CMD}
}

LINK_IMPLIB=/IMPLIB:${output;noext;rootrel;pre=$MODULE_PREFIX:REALPRJNAME.lib}
_LINK_EXTRA_OUTPUT=
when (!$NO_DEBUGINFO || $NO_DEBUGINFO == "no" || $NO_DEBUGINFO == "0") {
    _LINK_EXTRA_OUTPUT=/PDB:${output;noext;rootrel;pre=$MODULE_PREFIX:REALPRJNAME.pdb}
}
LINK_EXTRA_OUTPUT=$_LINK_EXTRA_OUTPUT

LIB_WRAPPER=${FIX_MSVC_OUTPUT} lib
LINK_WRAPPER=${FIX_MSVC_OUTPUT} link
when ($_UNDER_WINE_LINK == "yes") {
    LINK_WRAPPER=
}
when ($_UNDER_WINE_LIB == "yes") {
    LIB_WRAPPER=
}

LINK_WRAPPER_DYNLIB=\
    ${YMAKE_PYTHON} ${input:"build/scripts/link_dyn_lib.py"} ${hide;input:"build/scripts/fix_py2_protobuf.py"} \
    --arch WINDOWS \
    --target $TARGET

EXPORTS_VALUE=
LINK_IMPLIB_VALUE=
when ($EXPORTS_FILE) {
    LINK_IMPLIB_VALUE=$LINK_IMPLIB
    EXPORTS_VALUE=/DEF:${input:EXPORTS_FILE}
}

GENERATE_MF_CMD=\
    $YMAKE_PYTHON ${input:"build/scripts/generate_mf.py"} ${input;hide:"build/scripts/process_command_files.py"} \
    --build-root $ARCADIA_BUILD_ROOT \
    --module-name $REALPRJNAME \
    -o ${output;rootrel;pre=$MODULE_PREFIX;suf=$MODULE_SUFFIX.mf:REALPRJNAME} \
    -t $MODULE_TYPE \
    --ya-start-command-file \
    -Ya,lics $LICENSE_NAMES \
    -Ya,peers ${rootrel:PEERS} \
    -Ya,credits ${input:CREDITS_TEXTS_FILE} $CREDITS_FLAGS \
    --ya-end-command-file

_EXTRA_OBJS=
_GENERATE_EXTRA_OBJS=

# we split srcs_global into two groups: libs and objs
# # each group can be in its own command file
# first group need /WHOLEARCHIVE: prefix which will be added in fix_msvc_output.py or run_msvc_wine.py
# the tail of link commands will be added in the third command file
_MSVC_SRCS_GLOBALS=\
--start-wa --ya-start-command-file ${qe;rootrel;ext=.lib:SRCS_GLOBAL} --ya-end-command-file --end-wa \
--ya-start-command-file ${qe;rootrel;ext=.obj:SRCS_GLOBAL} --ya-end-command-file

REAL_LINK_DYN_LIB_CMDLINE=\
    ${GENERATE_COMMON_LIB_VFS} && \
    ${TOOLCHAIN_ENV} \
    ${cwd:ARCADIA_BUILD_ROOT} \
    ${LINK_WRAPPER} \
    ${LINK_WRAPPER_DYNLIB} \
    ${LINK_EXE_CMD} \
    ${LINK_IMPLIB_VALUE} \
    /DLL \
    /OUT:${qe;rootrel:TARGET} \
    ${LINK_EXTRA_OUTPUT} \
    ${EXPORTS_VALUE} \
    ${pre=--whole-archive-peers :WHOLE_ARCHIVE_PEERS} \
    ${pre=--whole-archive-libs :_WHOLE_ARCHIVE_LIBS_VALUE_GLOBAL} \
    $_MSVC_SRCS_GLOBALS \
    --ya-start-command-file \
    ${VCS_C_OBJ_RR} \
    ${qe;rootrel:AUTO_INPUT} \
    ${qe;rootrel;ext=.lib:PEERS} ${qe;rootrel;ext=.dll;noext;suf=.lib:PEERS} \
    $LINK_EXE_FLAGS \
    $LINK_STDLIBS $LDFLAGS \
    $LDFLAGS_GLOBAL \
    $OBJADDE \
    --ya-end-command-file

REAL_LINK_DYN_LIB=$REAL_LINK_DYN_LIB_IMPL($_WHOLE_ARCHIVE_PEERS_VALUE)

SWIG_DLL_JAR_CMD=$GENERATE_MF && $GENERATE_VCS_C_INFO_NODEP && $REAL_SWIG_DLL_JAR_CMD

_MSVC_HEAD_LINK_LIB=${TOOLCHAIN_ENV} ${cwd:ARCADIA_BUILD_ROOT} ${LIB_WRAPPER} ${LINK_LIB_CMD}
_MSVC_TAIL_LINK_LIB=\
    --ya-start-command-file \
    ${qe;rootrel:AUTO_INPUT} \
    $LINK_LIB_FLAGS \
    --ya-end-command-file \
    ${hide;kv:"soe"} ${hide;kv:"p AR"} ${hide;kv:"pc light-red"}

LINK_LIB=${GENERATE_MF} && $_MSVC_HEAD_LINK_LIB /OUT:${qe;rootrel:TARGET} $_MSVC_TAIL_LINK_LIB
GLOBAL_LINK_LIB=$_MSVC_HEAD_LINK_LIB /OUT:${qe;rootrel:GLOBAL_TARGET} $_MSVC_TAIL_LINK_LIB

LINK_EXE_CMDLINE=\
    ${GENERATE_MF} && \
    ${_GENERATE_EXTRA_OBJS} && \
    $GENERATE_VCS_C_INFO_NODEP && \
    ${GENERATE_COMMON_LIB_VFS} && \
    ${TOOLCHAIN_ENV} \
    ${cwd:ARCADIA_BUILD_ROOT} \
    ${LINK_WRAPPER} \
    ${LINK_EXE_CMD} \
    /OUT:${qe;rootrel:TARGET} \
    ${pre=--whole-archive-peers :WHOLE_ARCHIVE_PEERS} \
    ${pre=--whole-archive-libs :_WHOLE_ARCHIVE_LIBS_VALUE_GLOBAL} \
    ${LINK_EXTRA_OUTPUT} \
    $_MSVC_SRCS_GLOBALS \
    --ya-start-command-file \
    ${VCS_C_OBJ_RR} \
    ${_EXTRA_OBJS} \
    ${qe;rootrel:AUTO_INPUT} \
    $LINK_EXE_FLAGS \
    $LINK_STDLIBS \
    $LDFLAGS \
    $LDFLAGS_GLOBAL \
    $OBJADDE \
    ${qe;rootrel;ext=.lib:PEERS} ${qe;rootrel;ext=.dll;noext;suf=.lib:PEERS} \
    --ya-end-command-file \
    ${hide;kv:"soe"} ${hide;kv:"p LD"} ${hide;kv:"pc blue"}

LINK_EXE=$LINK_EXE_IMPL($_WHOLE_ARCHIVE_PEERS_VALUE)

LINK_DYN_LIB=${GENERATE_MF} && $GENERATE_VCS_C_INFO_NODEP && $REAL_LINK_DYN_LIB ${hide;kv:"soe"} ${hide;kv:"p LD"} ${hide;kv:"pc blue"}

LINK_EXEC_DYN_LIB_CMDLINE=\
    ${GENERATE_MF} && \
    $GENERATE_VCS_C_INFO_NODEP && \
    ${GENERATE_COMMON_LIB_VFS} && \
    ${TOOLCHAIN_ENV} \
    ${cwd:ARCADIA_BUILD_ROOT} \
    ${LINK_WRAPPER} \
    ${LINK_WRAPPER_DYNLIB} \
    ${LINK_EXE_CMD} \
    /OUT:${qe;rootrel:TARGET} \
    ${LINK_EXTRA_OUTPUT} \
    ${EXPORTS_VALUE} \
    ${pre=--whole-archive-peers :WHOLE_ARCHIVE_PEERS} \
    ${pre=--whole-archive-libs :_WHOLE_ARCHIVE_LIBS_VALUE_GLOBAL} \
    $_MSVC_SRCS_GLOBALS \
    '--ya-start-command-file \
    ${VCS_C_OBJ_RR} \
    ${qe;rootrel:AUTO_INPUT} \
    ${qe;rootrel;ext=.lib:PEERS} ${qe;rootrel;ext=.dll;noext;suf=.lib:PEERS} \
    $LINK_EXE_FLAGS \
    $LINK_STDLIBS \
    $LDFLAGS $LDFLAGS_GLOBAL \
    $OBJADDE \
    --ya-end-command-file \
    ${hide;kv:"soe"} ${hide;kv:"p LD"} ${hide;kv:"pc blue"}

LINK_EXEC_DYN_LIB=$LINK_EXEC_DYN_LIB_IMPL($_WHOLE_ARCHIVE_PEERS_VALUE)

macro PACK_GLOBALS_IN_LIBRARY() {
    ENABLE(UNUSED_MACRO)
}

LINK_GLOBAL_FAT_OBJECT=\
    ${TOOLCHAIN_ENV} \
    ${cwd:ARCADIA_BUILD_ROOT} \
    ${LIB_WRAPPER} \
    ${LINK_LIB_CMD} \
    /OUT:${output;qe;rootrel:REALPRJNAME.global.lib} \
    --ya-start-command-file \
    ${qe;rootrel;ext=.lib:SRCS_GLOBAL} \
    ${qe;rootrel;ext=.obj:SRCS_GLOBAL} \
    ${qe;rootrel:AUTO_INPUT} \
    $LINK_LIB_FLAGS \
    --ya-end-command-file

LINK_PEERS_FAT_OBJECT=\
    ${TOOLCHAIN_ENV} \
    ${cwd:ARCADIA_BUILD_ROOT} \
    ${LIB_WRAPPER} \
    ${LINK_LIB_CMD} \
    /OUT:${qe;rootrel;output:TARGET} \
    --ya-start-command-file \
    ${qe;rootrel:PEERS} \
    $LINK_LIB_FLAGS \
    --ya-end-command-file

LINK_FAT_OBJECT=\
    ${GENERATE_MF} && \
    $GENERATE_VCS_C_INFO_NODEP && \
    $LINK_GLOBAL_FAT_OBJECT && \
    $LINK_PEERS_FAT_OBJECT \
    ${hide;kv:"p LD"} ${hide;kv:"pc light-blue"} ${hide;kv:"show_out"}