-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy path001-add-mingw-toolchain.patch
1301 lines (1218 loc) · 42.4 KB
/
001-add-mingw-toolchain.patch
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/config/BUILD.gn b/config/BUILD.gn
index 35c9a6275..7cf9f574d 100644
--- a/config/BUILD.gn
+++ b/config/BUILD.gn
@@ -115,13 +115,13 @@ config("debug") {
defines += [ "DYNAMIC_ANNOTATIONS_PREFIX=NACL_" ]
}
- if (is_win) {
+ if (is_msvs) {
if (!enable_iterator_debugging && !use_custom_libcxx) {
# Iterator debugging is enabled by default by the compiler on debug
# builds, and we have to tell it to turn it off.
defines += [ "_HAS_ITERATOR_DEBUGGING=0" ]
}
- } else if ((is_linux || is_chromeos) && current_cpu == "x64" &&
+ } else if ((is_linux || is_chromeos || is_mingw) && current_cpu == "x64" &&
enable_iterator_debugging) {
# Enable libstdc++ debugging facilities to help catch problems early, see
# http://crbug.com/65151 .
@@ -161,25 +161,25 @@ config("default_libs") {
# instead the targets that use the less common ones (e.g. wininet or
# winspool) should include those explicitly.
libs = [
- "advapi32.lib",
- "comdlg32.lib",
- "dbghelp.lib",
- "dnsapi.lib",
- "gdi32.lib",
- "msimg32.lib",
- "odbc32.lib",
- "odbccp32.lib",
- "oleaut32.lib",
- "shell32.lib",
- "shlwapi.lib",
- "user32.lib",
- "usp10.lib",
- "uuid.lib",
- "version.lib",
- "wininet.lib",
- "winmm.lib",
- "winspool.lib",
- "ws2_32.lib",
+ "advapi32",
+ "comdlg32",
+ "dbghelp",
+ "dnsapi",
+ "gdi32",
+ "msimg32",
+ "odbc32",
+ "odbccp32",
+ "oleaut32",
+ "shell32",
+ "shlwapi",
+ "user32",
+ "usp10",
+ "uuid",
+ "version",
+ "wininet",
+ "winmm",
+ "winspool",
+ "ws2_32",
# Please don't add more stuff here. We should actually be making this
# list smaller, since all common things should be covered. If you need
@@ -195,9 +195,9 @@ config("default_libs") {
} else {
# These libraries are not compatible with Windows UWP (i.e. store apps.)
libs += [
- "delayimp.lib",
- "kernel32.lib",
- "ole32.lib",
+ "delayimp",
+ "kernel32",
+ "ole32",
]
}
} else if (is_android) {
@@ -291,9 +291,13 @@ group("shared_library_deps") {
# Windows linker setup for EXEs and DLLs.
if (is_win) {
_windows_linker_configs = [
- "//build/config/win:sdk_link",
"//build/config/win:common_linker_setup",
]
+ if (is_msvs) {
+ _windows_linker_configs += [
+ "//build/config/win:sdk_link",
+ ]
+ }
}
# This config defines the configs applied to all executables.
@@ -367,7 +371,7 @@ config("shared_library_config") {
# Recommend precompiled headers for targets with more than 50 .cc files.
config("precompiled_headers") {
if (enable_precompiled_headers) {
- if (is_win) {
+ if (is_msvs) {
# This is a string rather than a file GN knows about. It has to match
# exactly what's in the /FI flag below, and what might appear in the
# source code in quotes for an #include directive.
@@ -380,7 +384,7 @@ config("precompiled_headers") {
# Force include the header.
cflags = [ "/FI$precompiled_header" ]
- } else if (is_mac || is_linux) {
+ } else if (is_mac || is_linux || is_mingw) {
precompiled_source = "//build/precompile.h"
}
}
diff --git a/config/BUILDCONFIG.gn b/config/BUILDCONFIG.gn
index 1fa42b1b1..bab13adae 100644
--- a/config/BUILDCONFIG.gn
+++ b/config/BUILDCONFIG.gn
@@ -135,6 +135,9 @@ declare_args() {
# set "is_official_build" to true for any build intended to ship to end-users.
is_official_build = false
+ # Set to true when compiling with the MinGW GCC compiler on the MSYS2 environment.
+ is_mingw = current_os == "win" && (getenv("CXX") == "g++" || getenv("CXX") == "clang++")
+
# Set to true when compiling with the Clang compiler.
is_clang = current_os != "linux" ||
(current_cpu != "s390x" && current_cpu != "s390" &&
@@ -211,15 +214,23 @@ if (host_toolchain == "") {
# configurations we support this will always work and it saves build steps.
# Windows ARM64 targets require an x64 host for cross build.
if (target_cpu == "x86" || target_cpu == "x64") {
- if (is_clang) {
+ if (is_clang && !is_mingw) {
host_toolchain = "//build/toolchain/win:win_clang_$target_cpu"
} else {
- host_toolchain = "//build/toolchain/win:$target_cpu"
+ if (is_mingw) {
+ host_toolchain = "//build/toolchain/win:mingw_$target_cpu"
+ } else {
+ host_toolchain = "//build/toolchain/win:$target_cpu"
+ }
}
- } else if (is_clang) {
+ } else if (is_clang && !is_mingw) {
host_toolchain = "//build/toolchain/win:win_clang_$host_cpu"
} else {
- host_toolchain = "//build/toolchain/win:$host_cpu"
+ if (is_mingw) {
+ host_toolchain = "//build/toolchain/win:mingw_$host_cpu"
+ } else {
+ host_toolchain = "//build/toolchain/win:$host_cpu"
+ }
}
} else if (host_os == "aix") {
host_toolchain = "//build/toolchain/aix:$host_cpu"
@@ -253,8 +264,10 @@ if (target_os == "android") {
} else if (target_os == "win") {
# On Windows, we use the same toolchain for host and target by default.
# Beware, win cross builds have some caveats, see docs/win_cross.md
- if (is_clang) {
+ if (is_clang && !is_mingw) {
_default_toolchain = "//build/toolchain/win:win_clang_$target_cpu"
+ } else if (is_mingw) {
+ _default_toolchain = "//build/toolchain/win:mingw_$target_cpu"
} else {
_default_toolchain = "//build/toolchain/win:$target_cpu"
}
@@ -309,6 +322,7 @@ is_win = current_os == "win" || current_os == "winuwp"
is_apple = is_ios || is_mac
is_posix = !is_win && !is_fuchsia
+is_msvs = is_win && !is_mingw
# =============================================================================
# TARGET DEFAULTS
@@ -413,7 +427,7 @@ set_defaults("rust_library") {
# Compute the set of configs common to all linked targets (shared libraries,
# loadable modules, executables) to avoid duplication below.
-if (is_win) {
+if (is_msvs) {
# Many targets remove these configs, so they are not contained within
# //build/config:executable_config for easy removal.
_linker_configs = [
@@ -435,7 +449,7 @@ default_executable_configs = default_compiler_configs + [
"//build/config:executable_config",
] + _linker_configs
-if (is_win) {
+if (is_msvs) {
# Turn on linker CFI for executables, and position it so it can be removed
# if needed.
default_executable_configs += [ "//build/config/win:cfi_linker" ]
@@ -451,7 +465,7 @@ default_shared_library_configs = default_compiler_configs + [
"//build/config:default_libs",
"//build/config:shared_library_config",
] + _linker_configs
-if (is_win) {
+if (is_msvs) {
# Turn on linker CFI for DLLs, and position it so it can be removed if needed.
default_shared_library_configs += [ "//build/config/win:cfi_linker" ]
}
diff --git a/config/clang/BUILD.gn b/config/clang/BUILD.gn
index 8fd6760f3..0dae22f48 100644
--- a/config/clang/BUILD.gn
+++ b/config/clang/BUILD.gn
@@ -4,6 +4,10 @@
import("clang.gni")
+if (is_mingw) {
+ clang_use_chrome_plugins = false
+}
+
config("find_bad_constructs") {
if (clang_use_chrome_plugins) {
cflags = []
diff --git a/config/compiler/BUILD.gn b/config/compiler/BUILD.gn
index 4e6708bdd..ac5a3c120 100644
--- a/config/compiler/BUILD.gn
+++ b/config/compiler/BUILD.gn
@@ -317,13 +317,13 @@ config("compiler") {
# In general, Windows is totally different, but all the other builds share
# some common compiler and linker configuration.
- if (!is_win) {
+ if (!is_msvs) {
# Common POSIX compiler flags setup.
# --------------------------------
cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204
# Stack protection.
- if (is_apple) {
+ if (is_apple || is_mingw) {
# The strong variant of the stack protector significantly increases
# binary size, so only enable it in debug mode.
if (is_debug) {
@@ -377,7 +377,7 @@ config("compiler") {
# Non-Apple Posix and Fuchsia compiler flags setup.
# -----------------------------------
- if ((is_posix && !is_apple) || is_fuchsia) {
+ if ((is_posix && !is_apple) || is_fuchsia || is_mingw) {
if (enable_profiling) {
if (!is_debug) {
cflags += [ "-g" ]
@@ -527,11 +527,11 @@ config("compiler") {
# TODO(thakis): Make the driver pass --color-diagnostics to the linker
# if -fcolor-diagnostics is passed to it, and pass -fcolor-diagnostics
# in ldflags instead.
- if (is_win) {
+ if (is_msvs) {
# On Windows, we call the linker directly, instead of calling it through
# the driver.
ldflags += [ "--color-diagnostics" ]
- } else {
+ } else if (!is_clang) {
ldflags += [ "-Wl,--color-diagnostics" ]
}
}
@@ -558,7 +558,7 @@ config("compiler") {
"-instcombine-lower-dbg-declare=0",
]
if (!is_debug && use_thin_lto && is_a_target_toolchain) {
- if (is_win) {
+ if (is_msvs) {
ldflags += [ "-mllvm:-instcombine-lower-dbg-declare=0" ]
} else {
ldflags += [ "-Wl,-mllvm,-instcombine-lower-dbg-declare=0" ]
@@ -566,7 +566,7 @@ config("compiler") {
}
# TODO(crbug.com/1235145): Investigate why/if this should be needed.
- if (is_win) {
+ if (is_msvs) {
cflags += [ "/clang:-ffp-contract=off" ]
} else {
cflags += [ "-ffp-contract=off" ]
@@ -580,7 +580,7 @@ config("compiler") {
# C11/C++11 compiler flags setup.
# ---------------------------
- if (is_linux || is_chromeos || is_android || (is_nacl && is_clang) ||
+ if (is_linux || is_mingw || is_chromeos || is_android || (is_nacl && is_clang) ||
current_os == "aix") {
if (is_clang) {
standard_prefix = "c"
@@ -624,7 +624,7 @@ config("compiler") {
# support "c++20"/"gnu++20".
cflags_cc += [ "-std=${standard_prefix}++2a" ]
}
- } else if (is_win) {
+ } else if (is_msvs) {
cflags_c += [ "/std:c11" ]
if (use_cxx17 || (!is_clang && defined(msvc_use_cxx17) && msvc_use_cxx17)) {
cflags_cc += [ "/std:c++17" ]
@@ -683,7 +683,7 @@ config("compiler") {
# should be able to better manage binary size increases on its own.
import_instr_limit = 30
- if (is_win) {
+ if (is_msvs) {
ldflags += [
"/opt:lldltojobs=all",
"-mllvm:-import-instr-limit=$import_instr_limit",
@@ -758,7 +758,7 @@ config("compiler") {
if (compiler_timing) {
if (is_clang && !is_nacl) {
cflags += [ "-ftime-trace" ]
- } else if (is_win) {
+ } else if (is_msvs) {
cflags += [
# "Documented" here:
# http://aras-p.info/blog/2017/10/23/Best-unknown-MSVC-flag-d2cgsummary/
@@ -787,7 +787,7 @@ config("compiler") {
# present. On Android this increases binary size due to more thinks for long
# jumps. Turn it off by default and enable selectively for targets where it's
# beneficial.
- if (use_lld && !enable_call_graph_profile_sort) {
+ if (use_lld && !enable_call_graph_profile_sort && !is_mingw) {
if (is_win) {
ldflags += [ "/call-graph-profile-sort:no" ]
} else {
@@ -796,7 +796,7 @@ config("compiler") {
}
if (is_clang && !is_nacl && show_includes) {
- if (is_win) {
+ if (is_msvs) {
# TODO(crbug.com/1223741): Goma mixes the -H and /showIncludes output.
assert(!use_goma, "show_includes on Windows is not reliable with goma")
cflags += [
@@ -932,7 +932,7 @@ config("thinlto_optimize_default") {
if (!is_debug && use_thin_lto && is_a_target_toolchain) {
lto_opt_level = 0
- if (is_win) {
+ if (is_msvs) {
ldflags = [ "/opt:lldlto=" + lto_opt_level ]
} else {
ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
@@ -958,7 +958,7 @@ config("thinlto_optimize_max") {
lto_opt_level = 0
}
- if (is_win) {
+ if (is_msvs) {
ldflags = [ "/opt:lldlto=" + lto_opt_level ]
} else {
ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
@@ -989,7 +989,7 @@ config("compiler_cpu_abi") {
ldflags += [ "-fno-global-isel" ]
}
- if ((is_posix && !is_apple) || is_fuchsia) {
+ if ((is_posix && !is_apple) || is_fuchsia || is_mingw) {
# CPU architecture. We may or may not be doing a cross compile now, so for
# simplicity we always explicitly set the architecture.
if (current_cpu == "x64") {
@@ -1024,7 +1024,7 @@ config("compiler_cpu_abi") {
}
} else if (current_cpu == "arm64") {
if (is_clang && !is_android && !is_nacl && !is_fuchsia &&
- !(is_chromeos_lacros && is_chromeos_device)) {
+ !(is_chromeos_lacros && is_chromeos_device) && !is_win) {
cflags += [ "--target=aarch64-linux-gnu" ]
ldflags += [ "--target=aarch64-linux-gnu" ]
}
@@ -1334,7 +1334,7 @@ config("compiler_deterministic") {
# Eliminate build metadata (__DATE__, __TIME__ and __TIMESTAMP__) for
# deterministic build. See https://crbug.com/314403
if (!is_official_build) {
- if (is_win && !is_clang) {
+ if (is_msvs && !is_clang) {
cflags += [
"/wd4117", # Trying to define or undefine a predefined macro.
"/D__DATE__=",
@@ -1377,7 +1377,7 @@ config("compiler_deterministic") {
asmflags = [ "-Wa,-fdebug-compilation-dir,." ]
}
- if (is_win && use_lld) {
+ if (is_msvs && use_lld) {
if (symbol_level == 2 || (is_clang && using_sanitizer)) {
# Absolutize source file paths for PDB. Pass the real build directory
# if the pdb contains source-level debug information and if linker
@@ -1410,7 +1410,7 @@ config("compiler_deterministic") {
}
config("clang_revision") {
- if (is_clang && clang_base_path == default_clang_base_path) {
+ if (is_msvs && is_clang && clang_base_path == default_clang_base_path) {
update_args = [
"--print-revision",
"--verify-version=$clang_version",
@@ -1528,7 +1528,7 @@ config("default_warnings") {
cflags_cc = []
ldflags = []
- if (is_win) {
+ if (is_msvs) {
if (treat_warnings_as_errors) {
cflags += [ "/WX" ]
}
@@ -1603,10 +1603,33 @@ config("default_warnings") {
# files.
cflags += [ "-Wno-packed-not-aligned" ]
}
+
+ if (is_mingw) {
+ cflags += [
+ "-Wno-attributes", # "__decspec(dllimport) inline"
+ "-Wno-format", # PRIu64 llu support on MinGW
+ "-Wno-parentheses",
+ "-Wno-unknown-pragmas",
+ ]
+ if (!is_clang) {
+ cflags += [
+ "-Wno-array-bounds",
+ "-Wno-dangling-pointer",
+ "-Wno-shift-count-overflow",
+ "-Wno-sign-compare",
+ "-Wno-stringop-overflow", # False positive overflow error on gcc 10
+ "-Wno-stringop-truncation",
+ "-Wno-unused-but-set-variable",
+ ]
+ cflags_cc += [
+ "-Wno-conversion-null",
+ ]
+ }
+ }
}
# Common Clang and GCC warning setup.
- if (!is_win || is_clang) {
+ if (!is_msvs || is_clang) {
cflags += [
# Disables.
"-Wno-missing-field-initializers", # "struct foo f = {0};"
@@ -1711,7 +1734,7 @@ config("prevent_unsafe_narrowing") {
# part of Chromium.
config("chromium_code") {
- if (is_win) {
+ if (is_msvs) {
if (is_clang) {
cflags = [ "/W4" ] # Warning level 4.
@@ -1798,7 +1821,7 @@ config("no_chromium_code") {
cflags_cc = []
defines = []
- if (is_win) {
+ if (is_msvs) {
if (is_clang) {
cflags += [ "/W3" ] # Warning level 3.
}
@@ -1865,7 +1888,7 @@ config("noshadowing") {
# Allows turning Run-Time Type Identification on or off.
config("rtti") {
- if (is_win) {
+ if (is_msvs) {
cflags_cc = [ "/GR" ]
} else {
cflags_cc = [ "-frtti" ]
@@ -1875,7 +1898,7 @@ config("rtti") {
config("no_rtti") {
# Some sanitizer configs may require RTTI to be left enabled globally
if (!use_rtti) {
- if (is_win) {
+ if (is_msvs) {
cflags_cc = [ "/GR-" ]
} else {
cflags_cc = [ "-fno-rtti" ]
@@ -1919,7 +1942,7 @@ config("thin_archive") {
# confuses lldb.
if ((is_posix && !is_nacl && !is_apple) || is_fuchsia) {
arflags = [ "-T" ]
- } else if (is_win && use_lld) {
+ } else if (is_msvs && use_lld) {
arflags = [ "/llvmlibthin" ]
}
}
@@ -1930,7 +1953,7 @@ config("thin_archive") {
# Note: exceptions are disallowed in Google code.
config("exceptions") {
- if (is_win) {
+ if (is_msvs) {
# Enables exceptions in the STL.
if (!use_custom_libcxx) {
defines = [ "_HAS_EXCEPTIONS=1" ]
@@ -1943,7 +1966,7 @@ config("exceptions") {
}
config("no_exceptions") {
- if (is_win) {
+ if (is_msvs) {
# Disables exceptions in the STL.
# libc++ uses the __has_feature macro to control whether to use exceptions,
# so defining this macro is unnecessary. Defining _HAS_EXCEPTIONS to 0 also
@@ -2009,7 +2032,7 @@ config("no_incompatible_pointer_warnings") {
# Shared settings for both "optimize" and "optimize_max" configs.
# IMPORTANT: On Windows "/O1" and "/O2" must go before the common flags.
-if (is_win) {
+if (is_msvs) {
common_optimize_on_cflags = [
"/Ob2", # Both explicit and auto inlining.
"/Oy-", # Disable omitting frame pointers, must be after /O2.
@@ -2088,7 +2111,7 @@ if (is_win) {
}
config("default_stack_frames") {
- if (!is_win) {
+ if (!is_msvs) {
if (enable_frame_pointers) {
cflags = [ "-fno-omit-frame-pointer" ]
@@ -2115,7 +2138,7 @@ config("default_stack_frames") {
# Default "optimization on" config.
config("optimize") {
- if (is_win) {
+ if (is_msvs) {
if (chrome_pgo_phase != 2) {
# Favor size over speed, /O1 must be before the common flags.
# /O1 implies /Os and /GF.
@@ -2174,7 +2197,7 @@ config("optimize") {
# Turn off optimizations.
config("no_optimize") {
- if (is_win) {
+ if (is_msvs) {
cflags = [
"/Od", # Disable optimization.
"/Ob0", # Disable all inlining (on by default).
@@ -2226,7 +2249,7 @@ config("optimize_max") {
configs = [ "//build/config/nacl:irt_optimize" ]
} else {
ldflags = common_optimize_on_ldflags
- if (is_win) {
+ if (is_msvs) {
# Favor speed over size, /O2 must be before the common flags.
# /O2 implies /Ot, /Oi, and /GF.
cflags = [ "/O2" ] + common_optimize_on_cflags
@@ -2259,7 +2282,7 @@ config("optimize_speed") {
configs = [ "//build/config/nacl:irt_optimize" ]
} else {
ldflags = common_optimize_on_ldflags
- if (is_win) {
+ if (is_msvs) {
# Favor speed over size, /O2 must be before the common flags.
# /O2 implies /Ot, /Oi, and /GF.
cflags = [ "/O2" ] + common_optimize_on_cflags
@@ -2396,7 +2419,7 @@ config("win_pdbaltpath") {
# Full symbols.
config("symbols") {
- if (is_win) {
+ if (is_msvs) {
if (is_clang) {
cflags = [
# Debug information in the .obj files.
@@ -2485,7 +2508,7 @@ config("symbols") {
# DWARF info may be corrupt; offsets in a range list entry are in different
# sections" there. Maybe just a bug in nacl_switch_32.S.
_enable_gdb_index =
- symbol_level == 2 && !is_apple && !is_nacl && current_cpu != "x86" &&
+ symbol_level == 2 && !is_apple && !is_mingw && !is_nacl && current_cpu != "x86" &&
current_os != "zos" && (use_gold || use_lld) &&
# Disable on non-fission 32-bit Android because it pushes
# libcomponents_unittests over the 4gb size limit.
@@ -2536,7 +2559,7 @@ config("symbols") {
# This config guarantees to hold symbol for stack trace which are shown to user
# when crash happens in unittests running on buildbot.
config("minimal_symbols") {
- if (is_win) {
+ if (is_msvs) {
# Functions, files, and line tables only.
cflags = []
@@ -2610,7 +2633,7 @@ config("minimal_symbols") {
# told to not generate debug information and the linker then just puts function
# names in the final debug information.
config("no_symbols") {
- if (is_win) {
+ if (is_msvs) {
ldflags = [ "/DEBUG" ]
# All configs using /DEBUG should include this:
@@ -2710,6 +2733,11 @@ buildflag_header("compiler_buildflags") {
config("cet_shadow_stack") {
if (enable_cet_shadow_stack && is_win) {
assert(target_cpu == "x64")
- ldflags = [ "/CETCOMPAT" ]
+ if (is_mingw) {
+ ldflags = [ "-fcf-protection=full" ]
+ cflags = [ "-fcf-protection=full" ]
+ } else {
+ ldflags = [ "/CETCOMPAT" ]
+ }
}
}
diff --git a/config/linux/pkg-config.py b/config/linux/pkg-config.py
index 2e38c7ffb..0802bf760 100755
--- a/config/linux/pkg-config.py
+++ b/config/linux/pkg-config.py
@@ -40,6 +40,11 @@ from optparse import OptionParser
# Additionally, you can specify the option --atleast-version. This will skip
# the normal outputting of a dictionary and instead print true or false,
# depending on the return value of pkg-config for the given package.
+#
+# --pkg_config_libdir=<path> allows direct override
+# of the PKG_CONFIG_LIBDIR environment library.
+#
+# --full-path-libs causes lib names to include their full path.
def SetConfigPath(options):
@@ -103,12 +108,29 @@ def RewritePath(path, strip_prefix, sysroot):
else:
return path
+flag_regex = re.compile("(-.)(.+)")
+
+def FlagReplace(matchobj):
+ if matchobj.group(1) == '-I':
+ return matchobj.group(1) + subprocess.check_output([u'cygpath',u'-w',matchobj.group(2)]).strip().decode("utf-8")
+ if matchobj.group(1) == '-L':
+ return matchobj.group(1) + subprocess.check_output([u'cygpath',u'-w',matchobj.group(2)]).strip().decode("utf-8")
+ if matchobj.group(1) == '-l':
+ return matchobj.group(1) + matchobj.group(2) + '.lib'
+ return matchobj.group(0)
+
+def ConvertGCCToMSVC(flags):
+ """Rewrites GCC flags into MSVC flags."""
+ # need a better way to determine mingw vs msvc build
+ if 'win32' not in sys.platform or "GCC" in sys.version:
+ return flags
+ return [ flag_regex.sub(FlagReplace,flag) for flag in flags]
def main():
# If this is run on non-Linux platforms, just return nothing and indicate
# success. This allows us to "kind of emulate" a Linux build from other
# platforms.
- if "linux" not in sys.platform:
+ if "linux" not in sys.platform and "win32" not in sys.platform:
print("[[],[],[],[],[]]")
return 0
@@ -121,12 +143,15 @@ def main():
parser.add_option('-a', action='store', dest='arch', type='string')
parser.add_option('--system_libdir', action='store', dest='system_libdir',
type='string', default='lib')
+ parser.add_option('--pkg_config_libdir', action='store', dest='pkg_config_libdir',
+ type='string')
parser.add_option('--atleast-version', action='store',
dest='atleast_version', type='string')
parser.add_option('--libdir', action='store_true', dest='libdir')
parser.add_option('--dridriverdir', action='store_true', dest='dridriverdir')
parser.add_option('--version-as-components', action='store_true',
dest='version_as_components')
+ parser.add_option('--full-path-libs', action='store_true', dest='full_path_libs')
(options, args) = parser.parse_args()
# Make a list of regular expressions to strip out.
@@ -143,6 +168,10 @@ def main():
else:
prefix = ''
+ # Override PKG_CONFIG_LIBDIR
+ if options.pkg_config_libdir:
+ os.environ['PKG_CONFIG_LIBDIR'] = options.pkg_config_libdir
+
if options.atleast_version:
# When asking for the return value, just run pkg-config and print the return
# value, no need to do other work.
@@ -202,7 +231,7 @@ def main():
# For now just split on spaces to get the args out. This will break if
# pkgconfig returns quoted things with spaces in them, but that doesn't seem
# to happen in practice.
- all_flags = flag_string.strip().split(' ')
+ all_flags = ConvertGCCToMSVC(flag_string.strip().split(' '))
sysroot = options.sysroot
@@ -219,7 +248,10 @@ def main():
continue;
if flag[:2] == '-l':
- libs.append(RewritePath(flag[2:], prefix, sysroot))
+ library = RewritePath(flag[2:], prefix, sysroot)
+ # Skip math library on MSVC
+ if library != 'm.lib':
+ libs.append(library)
elif flag[:2] == '-L':
lib_dirs.append(RewritePath(flag[2:], prefix, sysroot))
elif flag[:2] == '-I':
@@ -236,6 +268,14 @@ def main():
else:
cflags.append(flag)
+ if options.full_path_libs:
+ full_path_libs = []
+ for lib_dir in lib_dirs:
+ for lib in libs:
+ if os.path.isfile(lib_dir+"/"+lib):
+ full_path_libs.append(lib_dir+"/"+lib)
+ libs = full_path_libs
+
# Output a GN array, the first one is the cflags, the second are the libs. The
# JSON formatter prints GN compatible lists when everything is a list of
# strings.
diff --git a/config/linux/pkg_config.gni b/config/linux/pkg_config.gni
index cb9b46003..e2428abbe 100644
--- a/config/linux/pkg_config.gni
+++ b/config/linux/pkg_config.gni
@@ -45,6 +45,9 @@ declare_args() {
# in similar fashion by setting the `system_libdir` variable in the build's
# args.gn file to 'lib' or 'lib64' as appropriate for the target architecture.
system_libdir = "lib"
+
+ # Allow directly overriding the PKG_CONFIG_LIBDIR enviroment variable
+ pkg_config_libdir = ""
}
pkg_config_script = "//build/config/linux/pkg-config.py"
@@ -88,6 +91,17 @@ if (host_pkg_config != "") {
host_pkg_config_args = pkg_config_args
}
+if (pkg_config_libdir != "") {
+ pkg_config_args += [
+ "--pkg_config_libdir",
+ pkg_config_libdir,
+ ]
+ host_pkg_config_args += [
+ "--pkg_config_libdir",
+ pkg_config_libdir,
+ ]
+}
+
template("pkg_config") {
assert(defined(invoker.packages),
"Variable |packages| must be defined to be a list in pkg_config.")
diff --git a/config/sanitizers/BUILD.gn b/config/sanitizers/BUILD.gn
index 35b7ba7aa..710b8c2df 100644
--- a/config/sanitizers/BUILD.gn
+++ b/config/sanitizers/BUILD.gn
@@ -216,7 +216,7 @@ config("default_sanitizer_ldflags") {
}
}
}
- } else if (is_win) {
+ } else if (is_msvs) {
# Windows directly calls link.exe instead of the compiler driver when
# linking. Hence, pass the runtime libraries instead of -fsanitize=address
# or -fsanitize=fuzzer.
@@ -317,7 +317,7 @@ config("cfi_flags") {
if (use_cfi_diag) {
cflags += [ "-fno-sanitize-trap=cfi" ]
- if (is_win) {
+ if (is_msvs) {
cflags += [
"/Oy-",
"/Ob0",
diff --git a/config/win/BUILD.gn b/config/win/BUILD.gn
index 692e7adf5..c16c471df 100644
--- a/config/win/BUILD.gn
+++ b/config/win/BUILD.gn
@@ -50,6 +50,7 @@ declare_args() {
# is applied to all targets. It is here to separate out the logic that is
# Windows-only.
config("compiler") {
+ if (is_msvs) {
if (current_cpu == "x86") {
asmflags = [
# When /safeseh is specified, the linker will only produce an image if it
@@ -215,6 +216,19 @@ config("compiler") {
# the source file is a no-op.
"/ignore:4221",
]
+ } else {
+ if (current_cpu == "x86" || current_cpu == "x64") {
+ cflags = [ "-msse3" ]
+ }
+ if (current_cpu == "x86") {
+ ldflags = [ "-m32" ]
+ if (!is_clang) {
+ ldflags += [ "-Wl,--enable-stdcall-fixup" ]
+ }
+ } else if (current_cpu == "x64") {
+ ldflags = [ "-m64" ]
+ }
+ }
}
# This is included by reference in the //build/config/compiler:runtime_library
@@ -315,19 +329,27 @@ config("sdk_link") {
# targets who want different library configurations can remove this and specify
# their own.
config("common_linker_setup") {
- ldflags = [
- "/FIXED:NO",
- "/ignore:4199",
- "/ignore:4221",
- "/NXCOMPAT",
- "/DYNAMICBASE",
- ]
-
- if (win_linker_timing) {
- ldflags += [
- "/time",
- "/verbose:incr",
+ if (is_mingw) {
+ # Enable DEP and ASLR
+ ldflags = [
+ "-Wl,-dynamicbase",
+ "-Wl,-nxcompat",
+ ]
+ } else {
+ ldflags = [
+ "/FIXED:NO",
+ "/ignore:4199",
+ "/ignore:4221",
+ "/NXCOMPAT",
+ "/DYNAMICBASE",
]
+
+ if (win_linker_timing) {
+ ldflags += [
+ "/time",
+ "/verbose:incr",
+ ]
+ }
}
}
@@ -336,7 +358,7 @@ config("default_cfg_compiler") {
# This is needed to allow functions to be called by code that is built
# with CFG enabled, such as system libraries.
# The CFG guards are only emitted if |win_enable_cfg_guards| is enabled.
- if (is_clang) {
+ if (is_msvs && is_clang) {
if (win_enable_cfg_guards) {
cflags = [ "/guard:cf" ]
} else {
@@ -351,7 +373,7 @@ config("disable_guards_cfg_compiler") {
# Emit table of address-taken functions for Control-Flow Guard (CFG).
# This is needed to allow functions to be called by code that is built
# with CFG enabled, such as system libraries.
- if (is_clang) {
+ if (is_msvs && is_clang) {
cflags = [ "/guard:cf,nochecks" ]
}
}
@@ -478,6 +500,7 @@ config("default_crt") {
# when the debug CRT is part of the bottleneck. This also avoids *implicitly*
# defining _DEBUG.
config("release_crt") {
+if (is_msvs) {
if (is_component_build) {
cflags = [ "/MD" ]
@@ -493,8 +516,10 @@ config("release_crt") {
}
}
}
+}
config("dynamic_crt") {
+if (is_msvs) {
if (is_debug) {
# This pulls in the DLL debug CRT and defines _DEBUG
cflags = [ "/MDd" ]
@@ -508,8 +533,10 @@ config("dynamic_crt") {
}
}
}
+}
config("static_crt") {
+if (is_msvs) {
if (is_debug) {
# This pulls in the static debug CRT and defines _DEBUG
cflags = [ "/MTd" ]
@@ -523,27 +550,34 @@ config("static_crt") {
}
}
}
+}
# Subsystem --------------------------------------------------------------------
# This is appended to the subsystem to specify a minimum version.
-if (current_cpu == "x64") {
- # The number after the comma is the minimum required OS version.
- # 5.02 = Windows Server 2003.
- subsystem_version_suffix = ",5.02"
-} else if (current_cpu == "arm64") {
- # Windows ARM64 requires Windows 10.
- subsystem_version_suffix = ",10.0"
-} else {
- # 5.01 = Windows XP.
- subsystem_version_suffix = ",5.01"
+if (is_msvs) {
+ if (current_cpu == "x64") {
+ # The number after the comma is the minimum required OS version.
+ # 5.02 = Windows Server 2003.
+ subsystem_version_suffix = ",5.02"
+ } else if (current_cpu == "arm64") {
+ # Windows ARM64 requires Windows 10.
+ subsystem_version_suffix = ",10.0"
+ } else {
+ # 5.01 = Windows XP.
+ subsystem_version_suffix = ",5.01"
+ }
}
config("console") {
- ldflags = [ "/SUBSYSTEM:CONSOLE$subsystem_version_suffix" ]
+ if (is_msvs) {
+ ldflags = [ "/SUBSYSTEM:CONSOLE$subsystem_version_suffix" ]
+ }
}
config("windowed") {
- ldflags = [ "/SUBSYSTEM:WINDOWS$subsystem_version_suffix" ]
+ if (is_msvs) {
+ ldflags = [ "/SUBSYSTEM:WINDOWS$subsystem_version_suffix" ]
+ }
}
# Incremental linking ----------------------------------------------------------
@@ -609,3 +643,20 @@ config("pdb_larger_than_4gb") {
}
ldflags += [ "/pdbpagesize:8192" ]
}
+
+# Let unit tests see all "for_testing" dll symbols.
+config("export_all_symbols") {
+ if (is_mingw) {
+ ldflags = [ "-Wl,--export-all-symbols" ]
+ }
+}
+
+# Workaround a Mingw ld bug where large debug symbol data
+# causes the produced executable to be corrupted
+# https://stackoverflow.com/questions/22261539/ld-exe-crashing-in-mingw
+# this affects mksnapshot and v8 component.
+config("strip_all_symbols_at_link_time") {
+ if (is_mingw) {
+ ldflags = [ "-Wl,--strip-all" ]
+ }
+}
diff --git a/config/win/manifest.gni b/config/win/manifest.gni
index e1859eacd..bc52040b6 100644
--- a/config/win/manifest.gni
+++ b/config/win/manifest.gni
@@ -72,7 +72,7 @@ segment_heap_manifest = "//build/win/segment_heap.manifest"
# ...
# }
-if (is_win) {
+if (is_msvs) {
template("windows_manifest") {
config_name = "${target_name}__config"
source_set_name = target_name
diff --git a/config/win/visual_studio_version.gni b/config/win/visual_studio_version.gni
index 1da479dd5..6a22dcccd 100644
--- a/config/win/visual_studio_version.gni
+++ b/config/win/visual_studio_version.gni
@@ -18,13 +18,17 @@ declare_args() {
# Full path to the Windows SDK, not including a backslash at the end.
# This value is the default location, override if you have a different
# installation location.
- windows_sdk_path = "C:\Program Files (x86)\Windows Kits\10"
+ if (is_msvs) {
+ windows_sdk_path = "C:\Program Files (x86)\Windows Kits\10"
+ } else {
+ windows_sdk_path = ""
+ }
# Version of the Windows SDK pointed to by the windows_sdk_path.
windows_sdk_version = ""
}
-if (visual_studio_path == "") {
+if (is_msvs && visual_studio_path == "") {
toolchain_data =
exec_script("../../vs_toolchain.py", [ "get_toolchain_dir" ], "scope")
visual_studio_path = toolchain_data.vs_path
@@ -33,7 +37,7 @@ if (visual_studio_path == "") {
visual_studio_version = toolchain_data.vs_version
wdk_path = toolchain_data.wdk_dir
visual_studio_runtime_dirs = toolchain_data.runtime_dirs
-} else {
+} else if (!is_mingw) {
assert(visual_studio_version != "",
"You must set the visual_studio_version if you set the path")