aboutsummaryrefslogtreecommitdiffstats
path: root/build/conf/go.conf
blob: c58492e17cdd42e05d652f61afce8b990fea7549 (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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
# tag:go-specific
### @usage: COLLECT_GO_SWAGGER_FILES(Varname, Dir)
###
### Recursively collect files for swagger config creation
macro COLLECT_GO_SWAGGER_FILES(Varname, Dir) {
    _GLOB($Varname $Dir/**/*.go ${ARCADIA_ROOT}/go.mod)
}

# tag:go-specific
_GO_HOST_OS__NO_UID__=unknown
when ($HOST_OS_LINUX) {
    _GO_HOST_OS__NO_UID__=linux
}
elsewhen ($HOST_OS_DARWIN) {
    _GO_HOST_OS__NO_UID__=darwin
}
elsewhen($HOST_OS_WINDOWS) {
    _GO_HOST_OS__NO_UID__=windows
}
GO_HOST_OS=$_GO_HOST_OS__NO_UID__

# tag:go-specific
_GO_HOST_ARCH__NO_UID__=unknown
when ($HOST_ARCH_X86_64) {
    _GO_HOST_ARCH__NO_UID__=amd64
}
elsewhen($HOST_ARCH_ARM64) {
    _GO_HOST_ARCH__NO_UID__=arm64
}
GO_HOST_ARCH=$_GO_HOST_ARCH__NO_UID__

_GO_TC_PATH=${GO_HOST_OS}_${GO_HOST_ARCH}

# tag:go-specific
GO_TARG_OS=unknown
when ($OS_LINUX) {
    GO_TARG_OS=linux
}
elsewhen ($OS_DARWIN) {
    GO_TARG_OS=darwin
}
elsewhen ($OS_WINDOWS) {
    GO_TARG_OS=windows
}

# tag:go-specific
GO_TARG_ARCH=unknwon
when ($ARCH_X86_64) {
    GO_TARG_ARCH=amd64
}
elsewhen ($ARCH_I386) {
    GO_TARG_ARCH=x86
}
elsewhen ($ARCH_ARM64) {
    GO_TARG_ARCH=arm64
}

# tag:go-specific
GO_HOST_TARG_PARAMS=++host-os $GO_HOST_OS ++host-arch $GO_HOST_ARCH ++targ-os $GO_TARG_OS ++targ-arch $GO_TARG_ARCH

# tag:go-specific
GOSTD_VERSION=1.21
when ($GOSTD_VERSION == "1.21") {
    GOSTD=contrib/go/_std_1.21/src
}
elsewhen ($GOSTD_VERSION == "1.20") {
    GOSTD=contrib/go/_std_1.20/src
}
otherwise {
    GOSTD=__unsupported_go_std_library_version_[$GOSTD_VERSION]__
}

# tag:go-specific
GO_DEBUG_PATH_RELATIVE=no
_GO_DEBUG_PATH__NO_UID__=
_GO_COMPILE_SYMABIS_TRIMPATH__NO_UID__=

# tag:go-specific
_GO_BUILDMODE=
_GO_IMPORT_PATH=${MODDIR}

# tag:go-specific
GO_VET=yolint
GO_VET_TOOL=
GO_VET_FLAGS=
GO_VET_EXTRA_FLAGS=

# tag:go-specific
_GO_VET_ADD_CHECK=yes
_GO_FMT_ADD_CHECK=yes
_GO_YDX_FILE=

# tag:go-specific
_GO_CGO1_WRAPPER_FLAGS=--build-prefix=/-B --source-prefix=/-S
_GO_LINK_EXE_EXT_CMD=

# tag:go-specific
GO_WITH_MUSL=

# tag:go-specific
GO_TOOLS_ROOT=${GO_TOOLS_RESOURCE_GLOBAL}
GO_TEST_MINER=${tool:"tools/go_test_miner"}
GO_TEST_IMPORT_PATH=

# tag:go-specific
GO_STD_LIB_PREFIX=${GOSTD}/
GO_STD_CMD_PREFIX=${GOSTD}/cmd/
GO_ARCADIA_PROJECT_PREFIX=a.yandex-team.ru/
GO_CONTRIB_PROJECT_PREFIX=vendor/
GO_SKIP_IMPORTS=unsafe C
GO_VET_INFO_EXT=.vet.out
GO_VET_REPORT_EXT=.vet.txt
GO_VET_OUTPUT_INFO=${output;rootrel;hide;pre=${MODULE_PREFIX};suf=${MODULE_SUFFIX}${GO_VET_INFO_EXT}:REALPRJNAME}
GO_VET_OUTPUT_REPORT=${output;rootrel;hide;pre=${MODULE_PREFIX};suf=${MODULE_SUFFIX}${GO_VET_REPORT_EXT}:REALPRJNAME}

# tag:go-specific tag:codenav
_GO_YNDEXER_EXT=.ydx.pb2
GO_YNDEXER_OUTPUT=${output;pre=${MODULE_PREFIX};suf=${MODULE_SUFFIX}${_GO_YNDEXER_EXT}:REALPRJNAME}

# tag:go-specific
GO_PROJECT_PREFIXES=++std-lib-prefix $GO_STD_LIB_PREFIX ++arc-project-prefix $GO_ARCADIA_PROJECT_PREFIX

# tag:go-specific
_GO_FAKEID=${FAKEID}.${BUILD_TYPE}.${GOSTD_VERSION}.${GO_FAKEID}
_CGO_FAKEID=${_GO_FAKEID}.${CPP_FAKEID}

# tag:go-specific
CGO2_CFLAGS_VALUE=
CGO2_LDFLAGS_VALUE=

# tag:go-specific
GO_ASM_FLAGS_VALUE=
### @usage: GO_ASM_FLAGS(flags)
### Add the specified flags to the go asm compile command line.
macro GO_ASM_FLAGS(Flags...) {
    SET_APPEND(GO_ASM_FLAGS_VALUE $Flags)
}

# tag:go-specific
GO_CGO1_FLAGS_VALUE=
### @usage: GO_CGO1_FLAGS(flags)
### Add the specified flags to the go cgo compile command line.
macro GO_CGO1_FLAGS(Flags...) {
    SET_APPEND(GO_CGO1_FLAGS_VALUE $Flags)
}

# tag:go-specific
GO_CGO2_FLAGS_VALUE=
### @usage: GO_CGO2_FLAGS(flags)
### Add the specified flags to the go cgo compile command line.
macro GO_CGO2_FLAGS(Flags...) {
    SET_APPEND(GO_CGO2_FLAGS_VALUE $Flags)
}

# tag:go-specific
GO_COMPILE_FLAGS_VALUE=$USER_GO_COMPILE_FLAGS
### @usage: GO_COMPILE_FLAGS(flags)
### Add the specified flags to the go compile command line.
macro GO_COMPILE_FLAGS(Flags...) {
    SET_APPEND(GO_COMPILE_FLAGS_VALUE $Flags)
}

# tag:go-specific
GO_LINK_FLAGS_VALUE=$USER_GO_LINK_FLAGS
### @usage: GO_LINK_FLAGS(flags)
### Add the specified flags to the go link command line.
macro GO_LINK_FLAGS(Flags...) {
    SET_APPEND(GO_LINK_FLAGS_VALUE $Flags)
}

# tag:go-specific
_GO_LANG_VERSION_VALUE=
macro GOLANG_VERSION(Arg) {
    SET(_GO_LANG_VERSION_VALUE $Arg)
}

# tag:go-specific
_GO_TOOL_MODE=

# tag:go-specific
_GO_TOOL_COMMON_FLAGS=\
    ++mode $_GO_TOOL_MODE \
    $GO_PROJECT_PREFIXES \
    ++goversion $GOSTD_VERSION \
    ++lang $_GO_LANG_VERSION_VALUE \
    ++source-root $ARCADIA_ROOT \
    ++build-root $ARCADIA_BUILD_ROOT \
    ++output-root $BINDIR \
    ++toolchain-root $GO_TOOLS_ROOT \
    $GO_HOST_TARG_PARAMS \
    ++output $TARGET \
    $GO_VET_OUTPUT \
    $_GO_YDX_FILE \
    $_GO_DEBUG_PATH__NO_UID__ \
    ++srcs $AUTO_INPUT ${input:GO_FILES} \
    ++asm-flags $GO_ASM_FLAGS_VALUE \
    ++compile-flags $GO_COMPILE_FLAGS_VALUE \
    ++link-flags $GO_LINK_FLAGS_VALUE \
    ++cgo-srcs ${input:CGO_FILES} \
    $_GO_EMBED_VALUE \
    $_GO_BUILDMODE \
    $GO_TOOLCHAIN_ENV

# tag:go-specific
macro _GO_GEN_COVER_GO(GO_FILE, GO_COVER_OUTPUT, VAR_ID) {
    .CMD=${hide:_GO_FAKEID} $GO_TOOLS_ROOT/pkg/tool/$_GO_TC_PATH/cover -mode set -var $VAR_ID -o ${output;noext;suf=.cover.go:GO_COVER_OUTPUT} ${input:GO_FILE}
}

# tag:go-specific
macro _GO_COMPILE_SYMABIS(FLAGS[], ASM_FILES...) {
    .CMD=${hide:_CGO_FAKEID} $GO_TOOLS_ROOT/pkg/tool/$_GO_TC_PATH/asm $_GO_COMPILE_SYMABIS_TRIMPATH__NO_UID__ ${pre=-I :_C__INCLUDE} -I $GO_TOOLS_ROOT/pkg/include -D GOOS_${GO_TARG_OS} -D GOARCH_${GO_TARG_ARCH} $FLAGS $GO_ASM_FLAGS_VALUE -gensymabis -o ${output:"gen.symabis"} ${input:ASM_FILES} ${kv;hide:"p go"} ${kv;hide:"pc light-blue"} ${kv;hide:"show_out"}
    .ADDINCL=build/scripts/go_fake_include
}

# tag:go-specific
macro _GO_COMPILE_CGO1(NAME, FLAGS[], FILES...) {
    .CMD=${hide:_CGO_FAKEID} ${cwd:ARCADIA_ROOT} $YMAKE_PYTHON ${input:"build/scripts/cgo1_wrapper.py"} $_GO_CGO1_WRAPPER_FLAGS --build-root ${ARCADIA_BUILD_ROOT} --source-root ${ARCADIA_ROOT} --cgo1-files ${output;noext:FILES.cgo1.go} --cgo2-files ${output;noauto;noext:FILES.cgo2.c} -- ${GO_TOOLS_ROOT}/pkg/tool/$_GO_TC_PATH/cgo -objdir $BINDIR -importpath $NAME $GO_CGO1_FLAGS_VALUE $FLAGS -- $C_FLAGS_PLATFORM ${pre=-I:_C__INCLUDE} ${CGO_CFLAGS_VALUE} ${input:FILES} ${output;hide:"_cgo_export.h"} ${output;hide:"_cgo_export.c"} ${output;hide:"_cgo_gotypes.go"} ${output;noauto;hide:"_cgo_main.c"} ${output;noauto;hide:"_cgo_flags"} $GO_TOOLCHAIN_ENV ${kv;hide:"p go"} ${kv;hide:"pc light-blue"} ${kv;hide:"show_out"}
}

# tag:go-specific
macro _GO_COMPILE_CGO2(NAME, C_FILES[], S_FILES[], OBJ_FILES[], FILES...) {
    .CMD=${hide:_CGO_FAKEID} $C_COMPILER $C_FLAGS_PLATFORM ${pre=-I:_C__INCLUDE} $CGO_CFLAGS_VALUE ${input;tobindir:"_cgo_main.c"} -c -o ${tmp;noauto;suf=${OBJECT_SUF}:"_cgo_main.c"} && $C_COMPILER $C_FLAGS_PLATFORM ${pre=-I:_C__INCLUDE} -o ${tmp;noauto;suf=${OBJECT_SUF}:"_cgo_"} $LDFLAGS $LDFLAGS_GLOBAL $CGO2_LDFLAGS_VALUE ${input;hide:"_cgo_export.h"} ${tmp;noauto;suf=${OBJECT_SUF}:"_cgo_main.c"} ${input;suf=${OBJECT_SUF}:"_cgo_export.c"} ${input;nopath;noext;suf=.cgo2.c${OBJECT_SUF}:FILES} ${input;suf=${OBJECT_SUF}:C_FILES} ${input;suf=.o:S_FILES} ${input:OBJ_FILES} $CGO_LDFLAGS_VALUE && ${GO_TOOLS_ROOT}/pkg/tool/$_GO_TC_PATH/cgo -dynpackage $NAME -dynimport ${tmp;noauto;suf=${OBJECT_SUF}:"_cgo_"} -dynout ${output:"_cgo_import.go"} -dynlinker $GO_CGO2_FLAGS_VALUE $GO_TOOLCHAIN_ENV ${kv;hide:"p go"} ${kv;hide:"pc light-blue"} ${kv;hide:"show_out"}

    _USE_LINKER()
}

GO_TOOL=$YMAKE_PYTHON3 ${input:"build/scripts/go_tool.py"} $_PROCESS_WHOLE_ARCHIVE_SCRIPT

# tag:go-specific
macro _GO_LINK_LIB_IMPL(CGO_FILES[], EXTRA_INPUTS[], EXTRA_TEXT_INPUTS[], GO_FILES...) {
    .CMD=${hide:_GO_FAKEID} $GO_TOOL ${hide;input:EXTRA_INPUTS} ${hide;input;context=TEXT:EXTRA_TEXT_INPUTS} --ya-start-command-file $_GO_TOOL_COMMON_FLAGS ++peers ${rootrel;tags_in=local,GO|local,GO_PROTO|local,GO_FBS:PEERS} --ya-end-command-file ${kv;hide:"p GO"} ${kv;hide:"pc light-red"} ${kv;hide:"show_out"}
}

# tag:go-specific
macro _GO_LINK_EXE_IMPL(CGO_FILES[], EXTRA_INPUTS[], EXTRA_TEXT_INPUTS[], GO_FILES...) {
    .CMD=${hide:_GO_FAKEID} $GO_TOOL ${hide;input:EXTRA_INPUTS} ${hide;input;context=TEXT:EXTRA_TEXT_INPUTS} --ya-start-command-file $_GO_TOOL_COMMON_FLAGS ++vcs $VCS_GO $GO_WITH_MUSL $GO_EXTLD ++peers ${rootrel;tags_in=local,GO|local,GO_PROTO|local,GO_FBS:PEERS} ++non-local-peers ${rootrel;tags_in=GO|GO_PROTO|GO_FBS;tags_out=local:PEERS} ++cgo-peers ${VCS_C_OBJ_RR} ${rootrel;tags_out=GO|GO_PROTO|GO_FBS:PEERS} --ya-end-command-file ${kv;hide:"p LD"} ${kv;hide:"pc light-red"} ${kv;hide:"show_out"} $_GO_LINK_EXE_EXT_CMD
}

# tag:go-specific
macro _GO_LINK_TEST_IMPL(CGO_FILES[], EXTRA_INPUTS[], EXTRA_TEXT_INPUTS[], GO_TEST_FILES[], GO_XTEST_FILES[], GO_FILES...) {
    .CMD=${hide:_GO_FAKEID} $GO_TOOL ${hide;input:EXTRA_INPUTS} ${hide;input;context=TEXT:EXTRA_TEXT_INPUTS} --ya-start-command-file $_GO_TOOL_COMMON_FLAGS ++vcs $VCS_GO $GO_WITH_MUSL $GO_EXTLD ++test-miner $GO_TEST_MINER ++test-import-path $GO_TEST_IMPORT_PATH ++peers ${rootrel;tags_in=local,GO|local,GO_PROGRAM|local,GO_PROTO|local,GO_FBS:PEERS} ++non-local-peers ${rootrel;tags_in=GO|GO_PROTO|GO_FBS;tags_out=local:PEERS} ++cgo-peers ${VCS_C_OBJ_RR} ${rootrel;tags_out=GO|GO_PROGRAM|GO_PROTO|GO_FBS:PEERS} ++test_srcs ${input:GO_TEST_FILES} ++xtest_srcs ${input:GO_XTEST_FILES} ++cover_info $GO_COVER_INFO_VALUE ++skip-tests $_GO_SKIP_TEST_VALUE --ya-end-command-file ${kv;hide:"p GO"} ${kv;hide:"pc light-red"} ${kv;hide:"show_out"}
}

# tag:go-specific
GO_LINK_LIB=
GO_LINK_LIB+=$GENERATE_MF
GO_LINK_LIB+=&& $_GO_LINK_LIB_IMPL($_GO_SRCS_VALUE CGO_FILES $_CGO_SRCS_VALUE EXTRA_TEXT_INPUTS $_GO_EMBED_INPUTS)

GO_LINK_EXE=
GO_LINK_EXE+=$GENERATE_MF
GO_LINK_EXE+=&& $GENERATE_VCS_C_INFO_NODEP
GO_LINK_EXE+=&& $GENERATE_VCS_GO_INFO_NODEP
GO_LINK_EXE+=&& $_GO_LINK_EXE_IMPL($_GO_SRCS_VALUE CGO_FILES $_CGO_SRCS_VALUE EXTRA_TEXT_INPUTS $_GO_EMBED_INPUTS)

GO_LINK_TEST=
GO_LINK_TEST+=$GENERATE_VCS_C_INFO_NODEP
GO_LINK_TEST+=&& $GENERATE_VCS_GO_INFO_NODEP
GO_LINK_TEST+=&& $_GO_LINK_TEST_IMPL($_GO_SRCS_VALUE CGO_FILES $_CGO_SRCS_VALUE EXTRA_TEXT_INPUTS $_GO_EMBED_INPUTS GO_TEST_FILES $_GO_TEST_SRCS_VALUE GO_XTEST_FILES $_GO_XTEST_SRCS_VALUE)

GO_LINK_DLL=
GO_LINK_DLL+=$GO_LINK_EXE
GO_LINK_DLL+=&& $COPY_CMD $BINDIR/_cgo_export.h ${output;pre=${MODULE_PREFIX};suf=.h:REALPRJNAME}

# tag:go-specific
CGO_ENABLED=yes
_GO_LINK_FLAGS_LINKMODE=
when ($OS_WINDOWS == "yes" || $SANITIZER_TYPE && $SANITIZER_TYPE != "no") {
    CGO_ENABLED=no
}
elsewhen ($CGO_ENABLED == "yes") {
    _GO_LINK_FLAGS_LINKMODE=-linkmode=external
}

# tag:go-specific
GO_PACKAGE_VALUE=
### @usage: GO_PACKAGE_NAME(Name)
### Override name of a Go package.
macro GO_PACKAGE_NAME(NAME) {
    SET(GO_PACKAGE_VALUE $NAME)
}

# tag:go-specific tag:internal
_GO_SRCS_VALUE=
### @usage: _GO_SRCS(Files...) # internal
### This macro shouldn't be used in ya.make files, use SRCS() instead.
### This is internal macro collecting .go sources for processing within Go modules (GO_PROGRAM and GO_LIBRARY)
macro _GO_SRCS(FILES...) {
    GO_FAKE_OUTPUT($FILES)
    SET_APPEND(_GO_SRCS_VALUE $FILES)
}

# tag:go-specific
_GO_TEST_SRCS_VALUE=
GO_HAS_INTERNAL_TESTS=no
### @usage: GO_TEST_SRCS(Files...)
### .go sources for internal tests of a module
macro GO_TEST_SRCS(FILES...) {
    GO_FAKE_OUTPUT($FILES)
    _SET_FIRST_VALUE(GO_HAS_INTERNAL_TESTS ${pre=yes :FILES} ${GO_HAS_INTERNAL_TESTS})
    SET_APPEND(_GO_TEST_SRCS_VALUE $FILES)
}

# tag:go-specific
_GO_XTEST_SRCS_VALUE=
GO_HAS_EXTERNAL_TESTS=no
### @usage: GO_XTEST_SRCS(Files...)
### .go sources for external tests of a module
macro GO_XTEST_SRCS(FILES...) {
    GO_FAKE_OUTPUT($FILES)
    SET(GO_HAS_EXTERNAL_TESTS yes)
    SET_APPEND(_GO_XTEST_SRCS_VALUE $FILES)
}

# tag:go-specific
macro _GO_UNUSED_SRCS(FLAGS...) {
    ENABLE(UNUSED_MACRO)
}

# tag:go-specific
_CGO_SRCS_VALUE=
### @usage: CGO_SRCS(Files...)
### .go sources to be built with CGO
macro CGO_SRCS(FILES...) {
    SET_APPEND(_CGO_SRCS_VALUE $FILES)
    PEERDIR(${GOSTD}/syscall)
}

# tag:go-specific
GO_LDFLAGS_GLOBAL=
### @usage: GO_LDFLAGS(Flags...)
### Link flags for GO_PROGRAM linking from .go sources
macro GO_LDFLAGS(FLAGS...) {
    SET_APPEND(GO_LDFLAGS_GLOBAL $FLAGS)
}

# tag:go-specific
CGO_CFLAGS_VALUE=
### @usage: CGO_CFLAGS(Flags...)
### Compiler flags specific to CGO compilation
macro CGO_CFLAGS(FLAGS...) {
    SET_APPEND(CGO_CFLAGS_VALUE $FLAGS)
    CFLAGS($FLAGS)
}

# tag:go-specific
CGO_LDFLAGS_VALUE=
### @usage: CGO_LDFLAGS(Files...)
### Linker flags specific to CGO linking
macro CGO_LDFLAGS(FLAGS...) {
    SET_APPEND(CGO_LDFLAGS_VALUE $FLAGS)
    GO_LDFLAGS($FLAGS)
}

# tag:go-specific
_GO_SKIP_TEST_VALUE=
### @usage: GO_SKIP_TESTS(TestNames...)
###
### Define a set of tests that should not be run.
### NB! Subtests are not taken into account!
macro GO_SKIP_TESTS(TESTS...) {
    SET_APPEND(_GO_SKIP_TEST_VALUE $TESTS)
    RESTRICT_PATH(vendor MSG This macro is prohibited to be used outside the vendor/ directory)
}

# tag:go-specific tag:internal
_GO_EMBED_VALUE=
_GO_EMBED_INPUTS=
### @usage: _GO_EMBED_PATTERN(PATTERN) # internal
###
### Define an embed pattern.
macro _GO_EMBED_PATTERN(XTEST?"_xtest":"", PATTERN, IMPORT_PATH) {
    SET(VAR_SALT1 $XTEST $PATTERN $IMPORT_PATH 1)
    SET(_PATTERN_GLOB1 uniq_embed_${hash:VAR_SALT1})
    _GLOB($_PATTERN_GLOB1 ${ARCADIA_ROOT}/${IMPORT_PATH}/${PATTERN}/**/* EXCLUDE ${ARCADIA_ROOT}/${IMPORT_PATH}/${PATTERN}/**/_* ${ARCADIA_ROOT}/${IMPORT_PATH}/${PATTERN}/**/.*)
    SET(VAR_SALT2 $XTEST $PATTERN $IMPORT_PATH 2)
    SET(_PATTERN_GLOB2 _uniq_embed_${hash:VAR_SALT2})
    _GLOB($_PATTERN_GLOB2 ${ARCADIA_ROOT}/${IMPORT_PATH}/${PATTERN})
    SET_APPEND(_GO_EMBED_VALUE ++embed$XTEST ${ARCADIA_ROOT}/${IMPORT_PATH} $PATTERN \$$_PATTERN_GLOB1 \$$_PATTERN_GLOB2)
    SET_APPEND(_GO_EMBED_INPUTS \$$_PATTERN_GLOB1 \$$_PATTERN_GLOB2)
}

# tag:go-specific
### @usage: GO_EMBED_PATTERN(PATTERN)
###
### Define an embed pattern.
macro GO_EMBED_PATTERN(PATTERN) {
    _GO_EMBED_PATTERN($PATTERN $_GO_IMPORT_PATH)
}

# tag:go-specific
### @usage: GO_TEST_EMBED_PATTERN(PATTERN)
###
### Define an embed pattern for internal go tests.
macro GO_TEST_EMBED_PATTERN(PATTERN) {
    _GO_EMBED_PATTERN($PATTERN $_GO_IMPORT_PATH)
}

# tag:go-specific
### @usage: GO_XTEST_EMBED_PATTERN(PATTERN)
###
### Define an embed pattern for external go tests.
macro GO_XTEST_EMBED_PATTERN(PATTERN) {
    _GO_EMBED_PATTERN(XTEST $PATTERN $_GO_IMPORT_PATH)
}

# tag:go-specific tag:internal
### @usage: _GO_EMBED_DIR(PATTERN) # internal
###
### Define an embed directory DIR.
macro _GO_EMBED_DIR(XTEST?"_xtest":"", DIR, IMPORT_PATH, ALL?"all:":"", EXCLUDES...) {
    SET(VAR_SALT $XTEST $DIR $IMPORT_PATH)
    SET(_PATTERN_GLOB uniq_embed_${hash:VAR_SALT})
    _GLOB($_PATTERN_GLOB ${ARCADIA_ROOT}/${IMPORT_PATH}/${DIR}/**/* EXCLUDE ${pre=${ARCADIA_ROOT}/${IMPORT_PATH}/${DIR}/**/:EXCLUDES})
    SET_APPEND(_GO_EMBED_VALUE ++embed$XTEST ${ARCADIA_ROOT}/${IMPORT_PATH} $ALL$DIR \$$_PATTERN_GLOB)
    SET_APPEND(_GO_EMBED_INPUTS \$$_PATTERN_GLOB)
}

# tag:go-specific
### @usage: GO_EMBED_DIR(DIR)
###
### Define an embed directory DIR.
macro GO_EMBED_DIR(ALL?"ALL":"_* .*", DIR) {
    _GO_EMBED_DIR($DIR $_GO_IMPORT_PATH ${ALL})
}

# tag:go-specific
### @usage: GO_EMBED_TEST_DIR(DIR)
###
### Define an embed directory DIR for internal go tests.
macro GO_EMBED_TEST_DIR(ALL?"ALL":"_* .*", DIR) {
    _GO_EMBED_DIR($DIR $_GO_IMPORT_PATH ${ALL})
}

# tag:go-specific
### @usage: GO_EMBED_XTEST_DIR(DIR)
###
### Define an embed directory DIR for external go tests.
macro GO_EMBED_XTEST_DIR(ALL?"ALL":"_* .*", DIR) {
    _GO_EMBED_DIR(XTEST $DIR $_GO_IMPORT_PATH ${ALL})
}

# tag:go-specific tag:internal
### @usage: _GO_EMBED_BINDIR(DIR)
###
### Define an embed directory DIR for files from ARCADIA_BUILD_ROOT
macro _GO_EMBED_BINDIR(XTEST?"_xtest":"", PREFIX, DIR, FILES...) {
    SET_APPEND(_GO_EMBED_VALUE ++embed$XTEST ${PREFIX} $DIR ${pre=$PREFIX/:FILES})
    SET_APPEND(_GO_EMBED_INPUTS ${pre=$PREFIX/:FILES})
}

# tag:go-specific
### @usage: GO_EMBED_BINDIR(DIR)
###
### Define an embed directory DIR for files from ARCADIA_BUILD_ROOT
macro GO_EMBED_BINDIR(PREFIX="${_GO_IMPORT_PATH}", DIR, FILES[]) {
    _GO_EMBED_BINDIR(${ARCADIA_BUILD_ROOT}/${PREFIX} $DIR $FILES)
}

# tag:go-specific
### @usage: GO_TEST_EMBED_BINDIR(DIR)
###
### Define an embed directory DIR for files from ARCADIA_BUILD_ROOT for internal go tests
macro GO_TEST_EMBED_BINDIR(PREFIX="${_GO_IMPORT_PATH}", DIR, FILES[]) {
    _GO_EMBED_BINDIR(${ARCADIA_BUILD_ROOT}/$PREFIX $DIR $FILES)
}

# tag:go-specific
### @usage: GO_XTEST_EMBED_BINDIR(DIR, FILES...)
###
### Define an embed directory DIR for files from ARCADIA_BUILD_ROOT for external go tests
macro GO_XTEST_EMBED_BINDIR(PREFIX="${_GO_IMPORT_PATH}", DIR, FILES[]) {
    _GO_EMBED_BINDIR(XTEST ${ARCADIA_BUILD_ROOT}/$PREFIX $DIR $FILES)
}

# tag:go-specific
_GO_TOOLCHAIN_ENV_GOARCH=unknown
when ($ARCH_ARM64) {
    _GO_TOOLCHAIN_ENV_GOARCH=${env:"GOARCH=arm64"}
}
elsewhen ($ARCH_X86_64) {
    _GO_TOOLCHAIN_ENV_GOARCH=${env:"GOARCH=amd64"}
}

# tag:go-specific
_GO_TOOLCHAIN_ENV_GOOS=unknown
when ($OS_DARWIN) {
    _GO_TOOLCHAIN_ENV_GOOS=${env:"GOOS=darwin"}
}
elsewhen ($OS_LINUX) {
    _GO_TOOLCHAIN_ENV_GOOS=${env:"GOOS=linux"}
}
elsewhen ($OS_WINDOWS) {
    _GO_TOOLCHAIN_ENV_GOOS=${env:"GOOS=windows"}
}
_GO_TOOLCHAIN_ENV_PATH=

# tag:go-specific
GO_TOOLCHAIN_ENV=$TOOLCHAIN_ENV $_GO_TOOLCHAIN_ENV_GOARCH $_GO_TOOLCHAIN_ENV_GOOS $_GO_TOOLCHAIN_ENV_PATH

# tag:go-specific
_GO_GRPC_WELLKNOWN=\
    vendor/google.golang.org/grpc \
    vendor/google.golang.org/grpc \
    vendor/google.golang.org/grpc/codes \
    vendor/google.golang.org/grpc/grpclog \
    vendor/google.golang.org/grpc/status

# tag:go-specific
macro _GO_GRPC() {
    SET(GO_PROTO_GEN_PLUGINS plugins=grpc)
    SET(GO_PROTO_GRPC_OPTS \$GO_PROTO_GRPC_OPTS_V2)
    SET(GO_PROTO_GRPC_OUTS \$GO_PROTO_GRPC_OUTS_V2)
    PEERDIR(${GOSTD}/context ${_GO_GRPC_WELLKNOWN})
}

# tag:go-specific
### @usage: GO_GRPC_GATEWAY_SRCS()
###
### Use of grpc-gateway plugin (Supported for Go only).
macro GO_GRPC_GATEWAY_SRCS(FILE...) {
    ENABLE(UNUSED_MACRO)
}

# tag:go-specific
### @usage: GO_GRPC_GATEWAY_SWAGGER_SRCS()
###
### Use of grpc-gateway plugin w/ swagger emission (Supported for Go only).
macro GO_GRPC_GATEWAY_SWAGGER_SRCS(FILE...) {
    PEERDIR(vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options)
}

# tag:go-specific
_GO_PROTO_GRPC_GATEWAY_OPTS=
_GO_PROTO_GRPC_GATEWAY_OUTS=

# tag:go-specific
macro _GO_GRPC_GATEWAY_SRCS_IMPL(Files...) {
    foreach (File : $Files) {
        [.proto]=$_GO_PROTO_CMD_IMPL($File $_GO_PROTO_GRPC_GATEWAY_OPTS $_GO_PROTO_GRPC_GATEWAY_OUTS)
    }

    PEERDIR(${GOSTD}/context ${GOSTD}/io ${GOSTD}/net/http)
    PEERDIR(vendor/github.com/golang/protobuf/descriptor)
    PEERDIR(vendor/github.com/grpc-ecosystem/grpc-gateway/runtime)
    PEERDIR(vendor/github.com/grpc-ecosystem/grpc-gateway/utilities)
    PEERDIR(vendor/google.golang.org/grpc/metadata)
}

# tag:go-specific
macro _SETUP_GO_GRPC_GATEWAY() {
    SET(_GO_PROTO_GRPC_GATEWAY_OPTS $_PROTO_PLUGIN_ARGS_BASE(go_grpc_gw vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway allow_repeated_fields_in_body=true))
    SET(_GO_PROTO_GRPC_GATEWAY_OUTS \${output;hide;norel;nopath;noext;suf=.pb.gw.go:File})
}

# tag:go-specific
macro _GO_GRPC_GATEWAY_SRCS(Files...) {
    _SETUP_GO_GRPC_GATEWAY()
    _GO_GRPC_GATEWAY_SRCS_IMPL($Files)
}

# tag:go-specific
macro _GO_GRPC_GATEWAY_SWAGGER_SRCS(Files...) {
    _SETUP_GO_GRPC_GATEWAY()
    SET_APPEND(_GO_PROTO_GRPC_GATEWAY_OPTS  $_PROTO_PLUGIN_ARGS_BASE(swagger vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger logtostderr=true allow_repeated_fields_in_body=true))
    SET_APPEND(_GO_PROTO_GRPC_GATEWAY_OUTS \${output;hide;norel;noauto;nopath;noext;suf=.swagger.json:File})

    _GO_GRPC_GATEWAY_SRCS_IMPL($Files)
    PEERDIR(vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options)
}

#tag:go-specific
### @usage: GO_GRPC_GATEWAY_V2_OPENAPI_SRCS(Files...)
###
### Use of grpc-gateway plugin w/ openapi v2 emission (Supported for Go only).
macro GO_GRPC_GATEWAY_V2_OPENAPI_SRCS(NO_JSON_NAMES_FOR_FIELDS?"":"", Files...) {
    PEERDIR(vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options)
}

macro _GO_GRPC_GATEWAY_V2_OPENAPI_SRCS(NO_JSON_NAMES_FOR_FIELDS?"json_names_for_fields=false":"", Files...) {
    _SETUP_GO_GRPC_GATEWAY_V2()

    SET_APPEND(_GO_PROTO_GRPC_GATEWAY_V2_OPTS $_PROTO_PLUGIN_ARGS_BASE(openapiv2 vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 $NO_JSON_NAMES_FOR_FIELDS logtostderr=true))
    SET_APPEND(_GO_PROTO_GRPC_GATEWAY_V2_OPTS \${output;hide;norel;noauto;nopath;noext;suf=.swagger.json:File})

    _GO_GRPC_GATEWAY_V2_SRCS_IMPL($Files)
    PEERDIR(vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options)
}

# tag:go-specific
### @usage: GO_GRPC_GATEWAY_V2_SRCS()
###
### Use of grpc-gateway plugin (Supported for Go only).
macro GO_GRPC_GATEWAY_V2_SRCS(FILE...) {
    ENABLE(UNUSED_MACRO)
}

# tag:go-specific
_GO_PROTO_GRPC_GATEWAY_V2_OPTS=
_GO_PROTO_GRPC_GATEWAY_V2_OUTS=

# tag:go-specific
macro _GO_GRPC_GATEWAY_V2_SRCS_IMPL(Files...) {
    foreach (File : $Files) {
        [.proto]=$_GO_PROTO_CMD_IMPL($File $_GO_PROTO_GRPC_GATEWAY_V2_OPTS $_GO_PROTO_GRPC_GATEWAY_V2_OUTS)
    }

    PEERDIR(${GOSTD}/context ${GOSTD}/io ${GOSTD}/net/http)
    PEERDIR(vendor/github.com/golang/protobuf/descriptor)
    PEERDIR(vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime)
    PEERDIR(vendor/github.com/grpc-ecosystem/grpc-gateway/v2/utilities)
    PEERDIR(vendor/google.golang.org/grpc/metadata)
    PEERDIR(vendor/google.golang.org/protobuf/proto)
}

# tag:go-specific
macro _SETUP_GO_GRPC_GATEWAY_V2() {
    SET(_GO_PROTO_GRPC_GATEWAY_V2_OPTS $_PROTO_PLUGIN_ARGS_BASE(go_grpc_gw vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway allow_repeated_fields_in_body=true))
    SET(_GO_PROTO_GRPC_GATEWAY_V2_OUTS \${output;hide;norel;nopath;noext;suf=.pb.gw.go:File})
}

# tag:go-specific
macro _GO_GRPC_GATEWAY_V2_SRCS(Files...) {
    _SETUP_GO_GRPC_GATEWAY_V2()
    _GO_GRPC_GATEWAY_V2_SRCS_IMPL($Files)
}

# tag:go-specific
when ($MUSL == "yes") {
    _GO_DEFAULT_ALLOCATOR=LF
}
otherwise {
    _GO_DEFAULT_ALLOCATOR=FAKE
}

# tag:go-specific tag:internal
### @usage _GO_BASE_UNIT # internal
###
### The base module of all golang modules. Defines common properties, dependencies and rules for go build.
module _GO_BASE_UNIT: _BASE_UNIT {
    .EXTS=.go .gosrc .o .obj .a .symabis .mf
    .CMD=TOUCH_UNIT
    .NODE_TYPE=Bundle
    .GLOBAL=GO_LDFLAGS OBJADDE_LIB
    .PEERDIR_POLICY=as_build_from
    .ALIASES=SRCS=_GO_SRCS RESOURCE=_GO_RESOURCE GO_TEST_SRCS=_GO_UNUSED_SRCS GO_XTEST_SRCS=_GO_UNUSED_SRCS GRPC=_GO_GRPC GO_GRPC_GATEWAY_SRCS=_GO_GRPC_GATEWAY_SRCS GO_GRPC_GATEWAY_SWAGGER_SRCS=_GO_GRPC_GATEWAY_SWAGGER_SRCS CFLAGS=CGO_CFLAGS GO_TEST_EMBED_PATTERN=_GO_UNUSED_SRCS GO_XTEST_EMBED_PATTERN=_GO_UNUSED_SRCS GO_TEST_EMBED_DIR=_GO_UNUSED_SRCS GO_XTEST_EMBED_DIR=_GO_UNUSED_SRCS GO_TEST_EMBED_BINDIR=_GO_UNUSED_SRCS GO_XTEST_EMBED_BINDIR=_GO_UNUSED_SRCS GO_GRPC_GATEWAY_V2_SRCS=_GO_GRPC_GATEWAY_V2_SRCS GO_GRPC_GATEWAY_V2_OPENAPI_SRCS=_GO_GRPC_GATEWAY_V2_OPENAPI_SRCS
    .ALLOWED=GO_PROTO_PLUGIN USE_CXX USE_UTIL RESOURCE_FILES
    .IGNORED=GO_SKIP_TESTS USE_SKIFF
    .RESTRICTED=TEST_SRCS
    .DEFAULT_NAME_GENERATOR=UseDirNameOrSetGoPackage

    ENABLE(_GO_MODULE)
    SET(MODULE_TAG GO)
    SET(PEERDIR_TAGS GO GO_PROTO GO_FBS __EMPTY__)
    DEFAULT(_GO_VET_TOOL)
    DEFAULT(_GO_VET_FLAGS)
    DEFAULT(_GO_VET_EXTS)
    DEFAULT(_GO_SONAME)

    NO_RUNTIME()

    SET(COVERAGE_FLAGS)
    SET(EXTRA_OUTPUT)
    SET(MODULE_LANG GO)
    ENABLE(FORCE_CONSISTENT_DEBUG)

    PEERDIR(build/external_resources/go_tools)

    GO_PROTO_GRPC_OPTS_V2=--plugin=protoc-gen-go-grpc=${tool:_TOOL_PROTOC_GEN_GO_GRPC_V2} --go-grpc_out=${ARCADIA_BUILD_ROOT}/$PROTO_NAMESPACE
    GO_PROTO_GRPC_OUTS_V2=${output;norel;nopath;noext;suf=_grpc.pb.go:File}
    select ($GO_PROTO_V2) {
        "yes" | "on" ? {
            GO_PROTO_OUTS+=${output;hide;norel;nopath;noext;suf=.pb.go:File}
            GO_PROTO_OPTS+=--plugin=protoc-gen-go=${tool:_TOOL_PROTOC_GEN_GO_V2} --go_out=${ARCADIA_BUILD_ROOT}/$PROTO_NAMESPACE
            _GO_PROTO_CHECK_OUTPUT=--check $GO_PROTO_GRPC_OUTS_V2
            GO_PROTO_OPTS+=$GO_PROTO_GRPC_OPTS
        }
        default ? {
            GO_PROTO_OUTS+=${output;hide;norel;nopath;noext;suf=.pb.go:File}
            GO_PROTO_OPTS+=--plugin=protoc-gen-go=${tool:_TOOL_PROTOC_GEN_GO} --go_out=$GO_PROTO_GEN_PLUGINS:${ARCADIA_BUILD_ROOT}/$PROTO_NAMESPACE
        }
    }

    when ($COMPILER_PLATFORM && $NEED_PLATFORM_PEERDIRS == "yes") {
        PEERDIR+=$COMPILER_PLATFORM
    }

    when ($CLANG == "yes" || $GCC == "yes") {
        CGO_CFLAGS_VALUE += -w -pthread -fpic
        CGO2_CFLAGS_VALUE += -Wno-unused-variable
    }

    select ($GO_VET) {
        "yes" | "on" ? {
            _GO_VET=yes
            _GO_VET_FLAGS+=-cgocall=false
        }
        "yndexer" ? {
            _GO_VET=yes
            PEERDIR+=build/external_resources/goyndexer
            _GO_VET_TOOL=${GOYNDEXER_RESOURCE_GLOBAL}/goyndexer
            _GO_YDX_FILE=++ydx-file ${_GO_YNDEXER_EXT}
            _GO_VET_FLAGS=-indexer.arc ${ARCADIA_ROOT} -indexer.indexfile ${GO_YNDEXER_OUTPUT} -indexer.loglevel info
            _GO_FMT_ADD_CHECK=no
            _GO_VET_ADD_CHECK=no
            GO_VET_INFO_EXT=.ydx.out
            GO_VET_REPORT_EXT=.ydx.txt
            _GO_VET_EXTS=++vet-info-ext .ydx.out ++vet-report-ext .ydx.txt
            _GO_CGO1_WRAPPER_FLAGS=--build-prefix=__ARCADIA_BUILD_ROOT_PREFIX__ --source-prefix=__ARCADIA_SOURCE_ROOT_PREFIX__
        }
        "yolint" ? {
            _GO_VET=yes
            PEERDIR+=build/external_resources/yolint
            _GO_VET_TOOL=${YOLINT_RESOURCE_GLOBAL}/yolint
            _GO_VET_FLAGS=-migration.config=${input:"${ARCADIA_ROOT}/build/rules/go/migrations.yaml"} -scopelint.config=${input:"${ARCADIA_ROOT}/build/rules/go/extended_lint.yaml"}
        }
        "local" ? {
            _GO_VET=yes
            _GO_VET_FLAGS=-migration.config=${input:"${ARCADIA_ROOT}/build/rules/go/migrations.yaml"} -scopelint.config=${input:"${ARCADIA_ROOT}/build/rules/go/extended_lint.yaml"}
        }
        default ? {
            _GO_VET=no
            _GO_VET_FLAGS=
        }
    }
    SET(_GO_VET $_GO_VET)

    when ($GO_VET_TOOL == "") {
        _GO_VET_TOOL_REAL=$_GO_VET_TOOL
    }
    otherwise {
        _GO_VET_TOOL_REAL=$GO_VET_TOOL
    }

    when ($GO_VET_FLAGS == "") {
        _GO_VET_FLAGS_REAL=$_GO_VET_FLAGS
    }
    otherwise {
        _GO_VET_FLAGS_REAL=$GO_VET_FLAGS
    }

    when ($_GO_VET == "yes" && $NO_GO_VET != "yes") {
        GO_VET_OUTPUT=++vet $_GO_VET_TOOL_REAL ++vet-flags $_GO_VET_FLAGS_REAL $GO_VET_EXTRA_FLAGS $GO_VET_OUTPUT_INFO $GO_VET_OUTPUT_REPORT $_GO_VET_EXTS
    }
    otherwise {
        GO_VET_OUTPUT=
        _GO_VET_ADD_CHECK=no
    }

    when ($GO_DEBUG_PATH_RELATIVE == "yes") {
        _GO_DEBUG_PATH__NO_UID__=++debug-root-map source=;build=;tools= ++tools-root $(TOOL_ROOT)
        _GO_COMPILE_SYMABIS_TRIMPATH__NO_UID__=-trimpath $ARCADIA_ROOT=>;$ARCADIA_BUILD_ROOT=>;$(TOOL_ROOT)=>
    }
    otherwise {
        _GO_DEBUG_PATH__NO_UID__=++debug-root-map source=/-S;build=/-B;tools=/-T ++tools-root $(TOOL_ROOT)
        _GO_COMPILE_SYMABIS_TRIMPATH__NO_UID__=-trimpath $ARCADIA_ROOT=>/-S;$ARCADIA_BUILD_ROOT=>/-B;$(TOOL_ROOT)=>/-T
    }

    _GO_PROCESS_SRCS()

    when ($CLANG == "yes") {
        _GO_EXTLD=clang
        GO_TOOLCHAIN_ENV += ${env:"CC=clang"}
    }
    otherwise {
        _GO_EXTLD=gcc
        GO_TOOLCHAIN_ENV += ${env:"CC=gcc"}
    }

    when ($OS_DARWIN) {
        PEERDIR+=build/external_resources/go_fake_xcrun
        GO_EXTLD = ++extld $_GO_EXTLD ++extldflags $_GO_SONAME $LD_SDK_VERSION -undefined dynamic_lookup $C_FLAGS_PLATFORM --sysroot=$MACOS_SDK_RESOURCE_GLOBAL --start-wa ${rootrel;ext=.a:SRCS_GLOBAL} --end-wa ${rootrel;ext=.o:SRCS_GLOBAL} --cgo-peers $LDFLAGS $LDFLAGS_GLOBAL $OBJADDE $OBJADDE_LIB $OBJADDE_LIB_GLOBAL $GO_LDFLAGS_GLOBAL $C_LIBRARY_PATH $C_SYSTEM_LIBRARIES_INTERCEPT $C_SYSTEM_LIBRARIES $STRIP_FLAG
        CGO2_LDFLAGS_VALUE += $LD_SDK_VERSION -undefined dynamic_lookup -nodefaultlibs -lc
    }
    elsewhen ($OS_LINUX) {
        GO_EXTLD = ++extld $_GO_EXTLD ++extldflags $_GO_SONAME $C_FLAGS_PLATFORM --sysroot=$OS_SDK_ROOT_RESOURCE_GLOBAL -Wl,--whole-archive ${rootrel;ext=.a:SRCS_GLOBAL} -Wl,--no-whole-archive ${rootrel;ext=.o:SRCS_GLOBAL} --cgo-peers $LDFLAGS $LDFLAGS_GLOBAL $OBJADDE $OBJADDE_LIB $OBJADDE_LIB_GLOBAL $GO_LDFLAGS_GLOBAL $C_LIBRARY_PATH $C_SYSTEM_LIBRARIES_INTERCEPT $C_SYSTEM_LIBRARIES $STRIP_FLAG
        CGO2_LDFLAGS_VALUE += -Wl,--unresolved-symbols=ignore-all -nodefaultlibs -lc
    }
    otherwise {
        GO_EXTLD = ++extld $_GO_EXTLD
    }

    when ($RACE == "yes") {
        _GO_COMPILE_FLAGS_RACE=-race
        _GO_LINK_FLAGS_RACE=-race
    }
    otherwise {
        _GO_COMPILE_FLAGS_RACE=
        _GO_LINK_FLAGS_RACE=
    }

    when ($PIC == "yes" || $PIE == "yes") {
        _GO_COMPILE_FLAGS_SHARED=-shared
        _GO_ASM_FLAGS_SHARED=-shared
    }
    otherwise {
        _GO_COMPILE_FLAGS_SHARED=
        _GO_ASM_FLAGS_SHARED=
    }

    GO_ASM_FLAGS_VALUE += $_GO_ASM_FLAGS_SHARED
    GO_COMPILE_FLAGS_VALUE += $_GO_COMPILE_FLAGS_RACE $_GO_COMPILE_FLAGS_SHARED
    GO_LINK_FLAGS_VALUE += $_GO_LINK_FLAGS_LINKMODE $_GO_LINK_FLAGS_RACE

    ADDINCL(${GOSTD}/runtime)
}

# tag:go-specific
### @usage: GO_LIBRARY([name])
###
### Go library module definition.
### Compile Go module as a library suitable for PEERDIR from other Go modules.
### Will select Go implementation on PEERDIR to PROTO_LIBRARY.
module GO_LIBRARY: _GO_BASE_UNIT {
    .CMD=GO_LINK_LIB
    .NODE_TYPE=Bundle
    .FINAL_TARGET=no
    SET(_GO_TOOL_MODE lib)
    SET(MODULE_TYPE LIBRARY)
    SET(PEERDIR_TAGS GO GO_PROTO GO_FBS __EMPTY__ PACKAGE_UNION)

    MODULE_SUFFIX=.a
}

# tag:go-specific
### @usage: GO_PROGRAM([name])
###
### Go program module definition.
### Compile and link Go module to an executable program.
### Will select Go implementation on PEERDIR to PROTO_LIBRARY.
module GO_PROGRAM: _GO_BASE_UNIT {
    .CMD=GO_LINK_EXE
    .NODE_TYPE=Program
    .PROXY=yes
    .SYMLINK_POLICY=EXE
    .ALLOWED=INDUCED_DEPS
    .FINAL_TARGET=yes
    SET(MODULE_TAG GO_PROGRAM)
    SET(_GO_TOOL_MODE exe)
    SET(MODULE_TYPE PROGRAM)
    SET(GO_VET_OUTPUT_INFO)

    ALLOCATOR($_GO_DEFAULT_ALLOCATOR)

    _USE_LINKER()

    ENABLE(COMMON_LINK_SETTINGS)

    when ($MUSL == "yes") {
        PEERDIR += contrib/libs/musl/full
    }
    when ($RACE == "yes") {
        PEERDIR += contrib/libs/cxxsupp/builtins
    }

    when ($MSVC == "yes" || $CYGWIN == "yes") {
        MODULE_SUFFIX=.exe
    }

    PEERDIR(${GOSTD}/runtime library/go/core/buildinfo)

    when ($RACE == "yes") {
        PEERDIR += ${GOSTD}/runtime/cgo
        PEERDIR += ${GOSTD}/runtime/race
    }

    when ($MUSL == "yes") {
        GO_WITH_MUSL = ++musl
    }

    when ($HARDENING == "yes") {
        _GO_BUILDMODE=++buildmode=pie
    }

    when ($OPENSOURCE == "yes" && $AUTOCHECK == "yes") {
        # FIXME: Replace AUTOCHECK == yes with _not a host platform_ check after YMAKE-218
        MODULE_LICENSES_RESTRICTION_TYPES = ALLOW_ONLY
        MODULE_LICENSES_RESTRICTIONS = SERVICE REQUIRE_CITATION REQUIRE_MODIFICATIONS_DISCLOSURE
    }
    when ($OS_IOS == "yes" || $OS_ANDROID == "yes" || $MAPSMOBI_BUILD_TARGET == "yes") {
        MODULE_LICENSES_RESTRICTION_TYPES = ALLOW_ONLY
        MODULE_LICENSES_RESTRICTIONS = SERVICE REQUIRE_CITATION
    }
}

# tag:go-specific
module _GO_DLL_BASE_UNIT: GO_PROGRAM {
    .CMD=GO_LINK_DLL
    .SYMLINK_POLICY=SO
    .ALLOWED=WHOLE_ARCHIVE
    .ARGS_PARSER=DLL
    .NODE_TYPE=Library
    .PROXY=yes
    SET(_GO_TOOL_MODE dll)
    SET(MODULE_TYPE DLL)

    GO_PACKAGE_NAME(main)

    when ($MSVC == "yes" || $CYGWIN == "yes") {
        MODULE_SUFFIX=.dll
    }
    elsewhen ($DARWIN == "yes" || $OS_IOS == "yes") {
        MODULE_PREFIX=lib
        MODULE_SUFFIX=.dylib$MODULE_VERSION
    }
    otherwise {
        MODULE_PREFIX=lib
        MODULE_SUFFIX=.so$MODULE_VERSION
    }

    when ($OS_DARWIN) {
        _GO_SONAME=-Wl,-install_name,$SONAME
    }
    elsewhen ($OS_LINUX) {
        _GO_SONAME=-Wl,-soname,$SONAME
    }

    when ($MODULE_VERSION) {
        when ($OS_LINUX || $OS_DARWIN) {
            _GO_LINK_EXE_EXT_CMD+= && $LINK_OR_COPY_CMD $TARGET ${output;nopath;noext:SONAME}
        }
    }
}

# tag:go-specific
### @usage: GO_DLL(name major_ver [minor_ver] [PREFIX prefix])
###
### Go ishared object module definition.
### Compile and link Go module to a shared object.
### Will select Go implementation on PEERDIR to PROTO_LIBRARY.
module GO_DLL: _GO_DLL_BASE_UNIT {
}

# tag:go-specific tag:test
### @usage: GO_BENCH_TIMEOUT(x)
###
### Sets timeout in seconds for 1 Benchmark in go benchmark suite
###
### Documentation about the system test: https://wiki.yandex-team.ru/yatool/test/
macro GO_BENCH_TIMEOUT(bench_timeout) {
    SET(GO_BENCH_TIMEOUT $bench_timeout)
}

# tag:go-specific tag:test
### @usage: GO_TEST([name])
###
### Go test module definition.
### Compile and link Go module as a test suitable for running with Arcadia testing support.
### All usual testing support macros like DATA, DEPENDS, SIZE, REQUIREMENTS etc. are supported.
### Will select Go implementation on PEERDIR to PROTO_LIBRARY.
module GO_TEST: GO_PROGRAM {
    .CMD=GO_LINK_TEST
    .ALIASES=GO_TEST_SRCS=GO_TEST_SRCS GO_XTEST_SRCS=GO_XTEST_SRCS GO_TEST_EMBED_PATTERN=GO_TEST_EMBED_PATTERN GO_XTEST_EMBED_PATTERN=GO_XTEST_EMBED_PATTERN GO_TEST_EMBED_DIR=GO_TEST_EMBED_DIR GO_XTEST_EMBED_DIR=GO_XTEST_EMBED_DIR GO_TEST_EMBED_BINDIR=GO_TEST_EMBED_BINDIR GO_XTEST_EMBED_BINDIR=GO_XTEST_EMBED_BINDIR
    .ALLOWED=GO_SKIP_TESTS YT_SPEC
    .FINAL_TARGET=no
    SET(MODULE_TAG GO_TEST)
    SET(PEERDIR_TAGS GO GO_PROGRAM GO_PROTO GO_FBS __EMPTY__)
    SET(_GO_TOOL_MODE test)
    SET(MODULE_TYPE PROGRAM)
    ENABLE(GO_TEST_MODULE)
    SET(GO_COVER_INFO_VALUE)

    # We have to add uncoditionaly PEERDIR to ${GOSTD}/os here thouth it is really
    # needed when TestMain is defined in the source code of the test
    PEERDIR(${GOSTD}/os)

    PEERDIR(${GOSTD}/testing/internal/testdeps)
    PEERDIR(${GOSTD}/testing)

    PEERDIR(library/go/test/yatest)

    ADD_YTEST($MODULE_PREFIX$REALPRJNAME go.test)
    ADD_YTEST($MODULE_PREFIX$REALPRJNAME go.bench)

    SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS canondata/result.json)
}

# tag:go-specific
macro GO_MOCKGEN_FROM(Path) {
    SET(MOCKGEN_FROM ${Path})
    SET(MOCKGEN_MODULE ${GO_ARCADIA_PROJECT_PREFIX}${Path})
}

# tag:go-specific
macro GO_MOCKGEN_CONTRIB_FROM(Path) {
    SET(MOCKGEN_FROM ${GO_CONTRIB_PROJECT_PREFIX}${Path})
    SET(MOCKGEN_MODULE ${Path})
}

# tag:go-specific
macro GO_MOCKGEN_TYPES(Types...) {
    SET(MOCKGEN_TYPES ${join=\\${__COMMA__}:Types})
}

# tag:go-specific
macro GO_MOCKGEN_REFLECT() {
    PEERDIR(${GOSTD}/encoding/gob)
    PEERDIR(${GOSTD}/flag)
    PEERDIR(${GOSTD}/fmt)
    PEERDIR(${GOSTD}/os)
    PEERDIR(${GOSTD}/path)
    PEERDIR(${GOSTD}/reflect)
    PEERDIR(vendor/go.uber.org/mock/mockgen/model)
    PEERDIR(${MOCKGEN_FROM})

    RUN_PROGRAM(vendor/go.uber.org/mock/mockgen -prog_only $MOCKGEN_MODULE $MOCKGEN_TYPES STDOUT main.go)
}

# tag:internal
macro _TOOL(TOOL) {
    .CMD=${tool:TOOL}
}

# tag:go-specific
macro GO_MOCKGEN_MOCKS() {
    PEERDIR(${GOSTD}/reflect)
    PEERDIR(vendor/go.uber.org/mock/gomock)

    .CMD=${tool:"vendor/go.uber.org/mock/mockgen"} -package mocks -exec_only $_TOOL($MODDIR/gen) ${GO_ARCADIA_PROJECT_PREFIX}${MOCKGEN_FROM} $MOCKGEN_TYPES ${output;stdout:"main.go"}
}