go.conf 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. # tag:go-specific
  2. ### @usage: COLLECT_GO_SWAGGER_FILES(Varname, Dir)
  3. ###
  4. ### Recursively collect files for swagger config creation
  5. macro COLLECT_GO_SWAGGER_FILES(Varname, Dir) {
  6. _GLOB($Varname $Dir/**/*.go ${ARCADIA_ROOT}/go.mod)
  7. }
  8. # tag:go-specific
  9. _GO_HOST_OS__NO_UID__=unknown
  10. when ($HOST_OS_LINUX) {
  11. _GO_HOST_OS__NO_UID__=linux
  12. }
  13. elsewhen ($HOST_OS_DARWIN) {
  14. _GO_HOST_OS__NO_UID__=darwin
  15. }
  16. elsewhen($HOST_OS_WINDOWS) {
  17. _GO_HOST_OS__NO_UID__=windows
  18. }
  19. GO_HOST_OS=$_GO_HOST_OS__NO_UID__
  20. # tag:go-specific
  21. _GO_HOST_ARCH__NO_UID__=unknown
  22. when ($HOST_ARCH_X86_64) {
  23. _GO_HOST_ARCH__NO_UID__=amd64
  24. }
  25. elsewhen($HOST_ARCH_ARM64) {
  26. _GO_HOST_ARCH__NO_UID__=arm64
  27. }
  28. GO_HOST_ARCH=$_GO_HOST_ARCH__NO_UID__
  29. _GO_TC_PATH=${GO_HOST_OS}_${GO_HOST_ARCH}
  30. # tag:go-specific
  31. GO_TARG_OS=unknown
  32. when ($OS_LINUX) {
  33. GO_TARG_OS=linux
  34. }
  35. elsewhen ($OS_DARWIN) {
  36. GO_TARG_OS=darwin
  37. }
  38. elsewhen ($OS_WINDOWS) {
  39. GO_TARG_OS=windows
  40. }
  41. # tag:go-specific
  42. GO_TARG_ARCH=unknwon
  43. when ($ARCH_X86_64) {
  44. GO_TARG_ARCH=amd64
  45. }
  46. elsewhen ($ARCH_I386) {
  47. GO_TARG_ARCH=x86
  48. }
  49. elsewhen ($ARCH_ARM64) {
  50. GO_TARG_ARCH=arm64
  51. }
  52. # tag:go-specific
  53. GO_HOST_TARG_PARAMS=++host-os $GO_HOST_OS ++host-arch $GO_HOST_ARCH ++targ-os $GO_TARG_OS ++targ-arch $GO_TARG_ARCH
  54. # tag:go-specific
  55. GOSTD_VERSION=1.22
  56. when ($GOSTD_VERSION == "1.22") {
  57. GOSTD=contrib/go/_std_1.22/src
  58. }
  59. otherwise {
  60. GOSTD=__unsupported_go_std_library_version_[$GOSTD_VERSION]__
  61. }
  62. # tag:go-specific
  63. GO_DEBUG_PATH_RELATIVE=no
  64. _GO_DEBUG_PATH__NO_UID__=
  65. _GO_COMPILE_SYMABIS_TRIMPATH__NO_UID__=
  66. # tag:go-specific
  67. _GO_BUILDMODE=
  68. _GO_IMPORT_PATH=${MODDIR}
  69. # tag:go-specific
  70. GO_VET=yolint
  71. GO_VET_TOOL=
  72. GO_VET_FLAGS=
  73. GO_VET_EXTRA_FLAGS=
  74. # tag:go-specific
  75. _GO_VET_ADD_CHECK=yes
  76. _GO_FMT_ADD_CHECK=yes
  77. _GO_YDX_FILE=
  78. # tag:go-specific
  79. _GO_CGO1_WRAPPER_FLAGS=--build-prefix=/-B --source-prefix=/-S
  80. _GO_LINK_EXE_EXT_CMD=
  81. # tag:go-specific
  82. GO_WITH_MUSL=
  83. # tag:go-specific
  84. GO_TOOLS_ROOT=${GO_TOOLS_RESOURCE_GLOBAL}
  85. GO_TEST_MINER=${tool:"tools/go_test_miner"}
  86. GO_TEST_IMPORT_PATH=
  87. # tag:go-specific
  88. GO_STD_LIB_PREFIX=${GOSTD}/
  89. GO_STD_CMD_PREFIX=${GOSTD}/cmd/
  90. GO_ARCADIA_PROJECT_PREFIX=a.yandex-team.ru/
  91. GO_CONTRIB_PROJECT_PREFIX=vendor/
  92. GO_SKIP_IMPORTS=unsafe C
  93. GO_VET_INFO_EXT=.vet.out
  94. GO_VET_REPORT_EXT=.vet.txt
  95. GO_VET_OUTPUT_INFO=${output;rootrel;hide;pre=${MODULE_PREFIX};suf=${MODULE_SUFFIX}${GO_VET_INFO_EXT}:REALPRJNAME}
  96. GO_VET_OUTPUT_REPORT=${output;rootrel;hide;pre=${MODULE_PREFIX};suf=${MODULE_SUFFIX}${GO_VET_REPORT_EXT}:REALPRJNAME}
  97. # tag:go-specific tag:codenav
  98. _GO_YNDEXER_EXT=.ydx.pb2
  99. GO_YNDEXER_OUTPUT=${output;pre=${MODULE_PREFIX};suf=${MODULE_SUFFIX}${_GO_YNDEXER_EXT}:REALPRJNAME}
  100. # tag:go-specific
  101. GO_PROJECT_PREFIXES=++std-lib-prefix $GO_STD_LIB_PREFIX ++arc-project-prefix $GO_ARCADIA_PROJECT_PREFIX
  102. # tag:go-specific
  103. _GO_FAKEID=${FAKEID}.${GOSTD_VERSION}.${GO_FAKEID}
  104. _CGO_FAKEID=${_GO_FAKEID}.${CPP_FAKEID}
  105. # tag:go-specific
  106. CGO2_CFLAGS_VALUE=
  107. CGO2_LDFLAGS_VALUE=
  108. # tag:go-specific
  109. GO_ASM_FLAGS_VALUE=
  110. ### @usage: GO_ASM_FLAGS(flags)
  111. ### Add the specified flags to the go asm compile command line.
  112. macro GO_ASM_FLAGS(Flags...) {
  113. SET_APPEND(GO_ASM_FLAGS_VALUE $Flags)
  114. }
  115. # tag:go-specific
  116. GO_CGO1_FLAGS_VALUE=
  117. ### @usage: GO_CGO1_FLAGS(flags)
  118. ### Add the specified flags to the go cgo compile command line.
  119. macro GO_CGO1_FLAGS(Flags...) {
  120. SET_APPEND(GO_CGO1_FLAGS_VALUE $Flags)
  121. }
  122. # tag:go-specific
  123. GO_CGO2_FLAGS_VALUE=
  124. ### @usage: GO_CGO2_FLAGS(flags)
  125. ### Add the specified flags to the go cgo compile command line.
  126. macro GO_CGO2_FLAGS(Flags...) {
  127. SET_APPEND(GO_CGO2_FLAGS_VALUE $Flags)
  128. }
  129. # tag:go-specific
  130. GO_COMPILE_FLAGS_VALUE=$USER_GO_COMPILE_FLAGS
  131. ### @usage: GO_COMPILE_FLAGS(flags)
  132. ### Add the specified flags to the go compile command line.
  133. macro GO_COMPILE_FLAGS(Flags...) {
  134. SET_APPEND(GO_COMPILE_FLAGS_VALUE $Flags)
  135. }
  136. # tag:go-specific
  137. GO_LINK_FLAGS_VALUE=$USER_GO_LINK_FLAGS
  138. ### @usage: GO_LINK_FLAGS(flags)
  139. ### Add the specified flags to the go link command line.
  140. macro GO_LINK_FLAGS(Flags...) {
  141. SET_APPEND(GO_LINK_FLAGS_VALUE $Flags)
  142. }
  143. # tag:go-specific
  144. _GO_LANG_VERSION_VALUE=
  145. macro GOLANG_VERSION(Arg) {
  146. SET(_GO_LANG_VERSION_VALUE $Arg)
  147. }
  148. # tag:go-specific
  149. _GO_TOOL_MODE=
  150. # tag:go-specific
  151. _GO_TOOL_COMMON_FLAGS=\
  152. ++mode $_GO_TOOL_MODE \
  153. $GO_PROJECT_PREFIXES \
  154. ++goversion $GOSTD_VERSION \
  155. ++lang $_GO_LANG_VERSION_VALUE \
  156. ++source-root $ARCADIA_ROOT \
  157. ++build-root $ARCADIA_BUILD_ROOT \
  158. ++output-root $BINDIR \
  159. ++toolchain-root $GO_TOOLS_ROOT \
  160. $GO_HOST_TARG_PARAMS \
  161. ++output $TARGET \
  162. $GO_VET_OUTPUT \
  163. $_GO_YDX_FILE \
  164. $_GO_DEBUG_PATH__NO_UID__ \
  165. ++srcs $AUTO_INPUT ${input:GO_FILES} \
  166. ++asm-flags $GO_ASM_FLAGS_VALUE \
  167. ++compile-flags $GO_COMPILE_FLAGS_VALUE \
  168. ++link-flags $GO_LINK_FLAGS_VALUE \
  169. ++cgo-srcs ${input:CGO_FILES} \
  170. $_GO_EMBED_VALUE \
  171. $_GO_BUILDMODE \
  172. $GO_TOOLCHAIN_ENV
  173. # tag:go-specific
  174. macro _GO_GEN_COVER_GO(GO_FILE, GO_COVER_OUTPUT, VAR_ID) {
  175. .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}
  176. }
  177. # tag:go-specific
  178. macro _GO_COMPILE_SYMABIS(FLAGS[], ASM_FILES...) {
  179. .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"}
  180. .ADDINCL=build/scripts/go_fake_include
  181. }
  182. # tag:go-specific
  183. macro _GO_COMPILE_CGO1(NAME, FLAGS[], FILES...) {
  184. .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"} $GO_TOOLCHAIN_ENV ${kv;hide:"p go"} ${kv;hide:"pc light-blue"} ${kv;hide:"show_out"}
  185. }
  186. # tag:go-specific
  187. macro _GO_COMPILE_CGO2(NAME, C_FILES[], S_FILES[], OBJ_FILES[], FILES...) {
  188. .CMD=${hide:_CGO_FAKEID} $C_COMPILER_OLD $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"}
  189. _USE_LINKER()
  190. }
  191. GO_TOOL=$YMAKE_PYTHON3 ${input:"build/scripts/go_tool.py"} $_PROCESS_WHOLE_ARCHIVE_SCRIPT
  192. # tag:go-specific
  193. macro _GO_LINK_LIB_IMPL(CGO_FILES[], EXTRA_INPUTS[], EXTRA_TEXT_INPUTS[], GO_FILES...) {
  194. .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"}
  195. }
  196. # tag:go-specific
  197. macro _GO_LINK_EXE_IMPL(CGO_FILES[], EXTRA_INPUTS[], EXTRA_TEXT_INPUTS[], GO_FILES...) {
  198. .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} ${_EXTRA_OBJS} ${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
  199. }
  200. # tag:go-specific
  201. macro _GO_LINK_TEST_IMPL(CGO_FILES[], EXTRA_INPUTS[], EXTRA_TEXT_INPUTS[], GO_TEST_FILES[], GO_XTEST_FILES[], GO_FILES...) {
  202. .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"}
  203. }
  204. # tag:go-specific
  205. GO_LINK_LIB=
  206. GO_LINK_LIB+=$GENERATE_MF
  207. GO_LINK_LIB+=&& $_GO_LINK_LIB_IMPL($_GO_SRCS_VALUE CGO_FILES $_CGO_SRCS_VALUE EXTRA_TEXT_INPUTS $_GO_EMBED_INPUTS)
  208. GO_LINK_EXE=
  209. GO_LINK_EXE+=$GENERATE_MF
  210. GO_LINK_EXE+=&& $GENERATE_VCS_C_INFO_NODEP
  211. GO_LINK_EXE+=&& $GENERATE_VCS_GO_INFO_NODEP
  212. GO_LINK_EXE+=&& $_GENERATE_EXTRA_OBJS
  213. GO_LINK_EXE+=&& $_GO_LINK_EXE_IMPL($_GO_SRCS_VALUE CGO_FILES $_CGO_SRCS_VALUE EXTRA_TEXT_INPUTS $_GO_EMBED_INPUTS)
  214. GO_LINK_TEST=
  215. GO_LINK_TEST+=$GENERATE_VCS_C_INFO_NODEP
  216. GO_LINK_TEST+=&& $GENERATE_VCS_GO_INFO_NODEP
  217. 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)
  218. GO_LINK_DLL=
  219. GO_LINK_DLL+=$GO_LINK_EXE
  220. GO_LINK_DLL+=&& $COPY_CMD $BINDIR/_cgo_export.h ${output;pre=${MODULE_PREFIX};suf=.h:REALPRJNAME}
  221. # tag:go-specific
  222. CGO_ENABLED=yes
  223. _GO_LINK_FLAGS_LINKMODE=
  224. when ($OS_WINDOWS == "yes" || $SANITIZER_TYPE && $SANITIZER_TYPE != "no") {
  225. CGO_ENABLED=no
  226. }
  227. elsewhen ($CGO_ENABLED == "yes") {
  228. _GO_LINK_FLAGS_LINKMODE=-linkmode=external
  229. }
  230. # tag:go-specific
  231. GO_PACKAGE_VALUE=
  232. ### @usage: GO_PACKAGE_NAME(Name)
  233. ### Override name of a Go package.
  234. macro GO_PACKAGE_NAME(NAME) {
  235. SET(GO_PACKAGE_VALUE $NAME)
  236. }
  237. # tag:go-specific tag:internal
  238. _GO_SRCS_VALUE=
  239. ### @usage: _GO_SRCS(Files...) # internal
  240. ### This macro shouldn't be used in ya.make files, use SRCS() instead.
  241. ### This is internal macro collecting .go sources for processing within Go modules (GO_PROGRAM and GO_LIBRARY)
  242. macro _GO_SRCS(FILES...) {
  243. GO_FAKE_OUTPUT($FILES)
  244. SET_APPEND(_GO_SRCS_VALUE $FILES)
  245. }
  246. # tag:go-specific
  247. _GO_TEST_SRCS_VALUE=
  248. GO_HAS_INTERNAL_TESTS=no
  249. ### @usage: GO_TEST_SRCS(Files...)
  250. ### .go sources for internal tests of a module
  251. macro GO_TEST_SRCS(FILES...) {
  252. GO_FAKE_OUTPUT($FILES)
  253. _SET_FIRST_VALUE(GO_HAS_INTERNAL_TESTS ${pre=yes :FILES} ${GO_HAS_INTERNAL_TESTS})
  254. SET_APPEND(_GO_TEST_SRCS_VALUE $FILES)
  255. }
  256. # tag:go-specific
  257. _GO_XTEST_SRCS_VALUE=
  258. GO_HAS_EXTERNAL_TESTS=no
  259. ### @usage: GO_XTEST_SRCS(Files...)
  260. ### .go sources for external tests of a module
  261. macro GO_XTEST_SRCS(FILES...) {
  262. GO_FAKE_OUTPUT($FILES)
  263. SET(GO_HAS_EXTERNAL_TESTS yes)
  264. SET_APPEND(_GO_XTEST_SRCS_VALUE $FILES)
  265. }
  266. # tag:go-specific
  267. macro _GO_UNUSED_SRCS(FLAGS...) {
  268. ENABLE(UNUSED_MACRO)
  269. }
  270. # tag:go-specific
  271. _CGO_SRCS_VALUE=
  272. ### @usage: CGO_SRCS(Files...)
  273. ### .go sources to be built with CGO
  274. macro CGO_SRCS(FILES...) {
  275. SET_APPEND(_CGO_SRCS_VALUE $FILES)
  276. PEERDIR(${GOSTD}/syscall)
  277. }
  278. # tag:go-specific
  279. GO_LDFLAGS_GLOBAL=
  280. ### @usage: GO_LDFLAGS(Flags...)
  281. ### Link flags for GO_PROGRAM linking from .go sources
  282. macro GO_LDFLAGS(FLAGS...) {
  283. SET_APPEND(GO_LDFLAGS_GLOBAL $FLAGS)
  284. }
  285. # tag:go-specific
  286. CGO_CFLAGS_VALUE=
  287. ### @usage: CGO_CFLAGS(Flags...)
  288. ### Compiler flags specific to CGO compilation
  289. macro CGO_CFLAGS(FLAGS...) {
  290. SET_APPEND(CGO_CFLAGS_VALUE $FLAGS)
  291. CFLAGS($FLAGS)
  292. }
  293. # tag:go-specific
  294. CGO_LDFLAGS_VALUE=
  295. ### @usage: CGO_LDFLAGS(Files...)
  296. ### Linker flags specific to CGO linking
  297. macro CGO_LDFLAGS(FLAGS...) {
  298. SET_APPEND(CGO_LDFLAGS_VALUE $FLAGS)
  299. GO_LDFLAGS($FLAGS)
  300. }
  301. # tag:go-specific
  302. _GO_SKIP_TEST_VALUE=
  303. ### @usage: GO_SKIP_TESTS(TestNames...)
  304. ###
  305. ### Define a set of tests that should not be run.
  306. ### NB! Subtests are not taken into account!
  307. macro GO_SKIP_TESTS(TESTS...) {
  308. SET_APPEND(_GO_SKIP_TEST_VALUE $TESTS)
  309. RESTRICT_PATH(vendor MSG This macro is prohibited to be used outside the vendor/ directory)
  310. }
  311. # tag:go-specific tag:internal
  312. _GO_EMBED_VALUE=
  313. _GO_EMBED_INPUTS=
  314. ### @usage: _GO_EMBED_PATTERN(PATTERN) # internal
  315. ###
  316. ### Define an embed pattern.
  317. macro _GO_EMBED_PATTERN(XTEST?"_xtest":"", PATTERN, IMPORT_PATH) {
  318. SET(VAR_SALT1 $XTEST $PATTERN $IMPORT_PATH 1)
  319. SET(_PATTERN_GLOB1 uniq_embed_${hash:VAR_SALT1})
  320. _GLOB($_PATTERN_GLOB1 ${ARCADIA_ROOT}/${IMPORT_PATH}/${PATTERN}/**/* EXCLUDE ${ARCADIA_ROOT}/${IMPORT_PATH}/${PATTERN}/**/_* ${ARCADIA_ROOT}/${IMPORT_PATH}/${PATTERN}/**/.*)
  321. SET(VAR_SALT2 $XTEST $PATTERN $IMPORT_PATH 2)
  322. SET(_PATTERN_GLOB2 _uniq_embed_${hash:VAR_SALT2})
  323. _GLOB($_PATTERN_GLOB2 ${ARCADIA_ROOT}/${IMPORT_PATH}/${PATTERN})
  324. SET_APPEND(_GO_EMBED_VALUE ++embed$XTEST ${ARCADIA_ROOT}/${IMPORT_PATH} $PATTERN \$$_PATTERN_GLOB1 \$$_PATTERN_GLOB2)
  325. SET_APPEND(_GO_EMBED_INPUTS \$$_PATTERN_GLOB1 \$$_PATTERN_GLOB2)
  326. }
  327. # tag:go-specific
  328. ### @usage: GO_EMBED_PATTERN(PATTERN)
  329. ###
  330. ### Define an embed pattern.
  331. macro GO_EMBED_PATTERN(PATTERN) {
  332. _GO_EMBED_PATTERN($PATTERN $_GO_IMPORT_PATH)
  333. }
  334. # tag:go-specific
  335. ### @usage: GO_TEST_EMBED_PATTERN(PATTERN)
  336. ###
  337. ### Define an embed pattern for internal go tests.
  338. macro GO_TEST_EMBED_PATTERN(PATTERN) {
  339. _GO_EMBED_PATTERN($PATTERN $_GO_IMPORT_PATH)
  340. }
  341. # tag:go-specific
  342. ### @usage: GO_XTEST_EMBED_PATTERN(PATTERN)
  343. ###
  344. ### Define an embed pattern for external go tests.
  345. macro GO_XTEST_EMBED_PATTERN(PATTERN) {
  346. _GO_EMBED_PATTERN(XTEST $PATTERN $_GO_IMPORT_PATH)
  347. }
  348. # tag:go-specific tag:internal
  349. ### @usage: _GO_EMBED_DIR(PATTERN) # internal
  350. ###
  351. ### Define an embed directory DIR.
  352. macro _GO_EMBED_DIR(XTEST?"_xtest":"", DIR, IMPORT_PATH, ALL?"all:":"", EXCLUDES...) {
  353. SET(VAR_SALT $XTEST $DIR $IMPORT_PATH)
  354. SET(_PATTERN_GLOB uniq_embed_${hash:VAR_SALT})
  355. _GLOB($_PATTERN_GLOB ${ARCADIA_ROOT}/${IMPORT_PATH}/${DIR}/**/* EXCLUDE ${pre=${ARCADIA_ROOT}/${IMPORT_PATH}/${DIR}/**/:EXCLUDES})
  356. SET_APPEND(_GO_EMBED_VALUE ++embed$XTEST ${ARCADIA_ROOT}/${IMPORT_PATH} $ALL$DIR \$$_PATTERN_GLOB)
  357. SET_APPEND(_GO_EMBED_INPUTS \$$_PATTERN_GLOB)
  358. }
  359. # tag:go-specific
  360. ### @usage: GO_EMBED_DIR(DIR)
  361. ###
  362. ### Define an embed directory DIR.
  363. macro GO_EMBED_DIR(ALL?"ALL":"_* .*", DIR) {
  364. _GO_EMBED_DIR($DIR $_GO_IMPORT_PATH ${ALL})
  365. }
  366. # tag:go-specific
  367. ### @usage: GO_EMBED_TEST_DIR(DIR)
  368. ###
  369. ### Define an embed directory DIR for internal go tests.
  370. macro GO_EMBED_TEST_DIR(ALL?"ALL":"_* .*", DIR) {
  371. _GO_EMBED_DIR($DIR $_GO_IMPORT_PATH ${ALL})
  372. }
  373. # tag:go-specific
  374. ### @usage: GO_EMBED_XTEST_DIR(DIR)
  375. ###
  376. ### Define an embed directory DIR for external go tests.
  377. macro GO_EMBED_XTEST_DIR(ALL?"ALL":"_* .*", DIR) {
  378. _GO_EMBED_DIR(XTEST $DIR $_GO_IMPORT_PATH ${ALL})
  379. }
  380. # tag:go-specific tag:internal
  381. ### @usage: _GO_EMBED_BINDIR(DIR)
  382. ###
  383. ### Define an embed directory DIR for files from ARCADIA_BUILD_ROOT
  384. macro _GO_EMBED_BINDIR(XTEST?"_xtest":"", PREFIX, DIR, FILES...) {
  385. SET_APPEND(_GO_EMBED_VALUE ++embed$XTEST ${PREFIX} $DIR ${pre=$PREFIX/:FILES})
  386. SET_APPEND(_GO_EMBED_INPUTS ${pre=$PREFIX/:FILES})
  387. }
  388. # tag:go-specific
  389. ### @usage: GO_EMBED_BINDIR(DIR)
  390. ###
  391. ### Define an embed directory DIR for files from ARCADIA_BUILD_ROOT
  392. macro GO_EMBED_BINDIR(PREFIX="${_GO_IMPORT_PATH}", DIR, FILES[]) {
  393. _GO_EMBED_BINDIR(${ARCADIA_BUILD_ROOT}/${PREFIX} $DIR $FILES)
  394. }
  395. # tag:go-specific
  396. ### @usage: GO_TEST_EMBED_BINDIR(DIR)
  397. ###
  398. ### Define an embed directory DIR for files from ARCADIA_BUILD_ROOT for internal go tests
  399. macro GO_TEST_EMBED_BINDIR(PREFIX="${_GO_IMPORT_PATH}", DIR, FILES[]) {
  400. _GO_EMBED_BINDIR(${ARCADIA_BUILD_ROOT}/$PREFIX $DIR $FILES)
  401. }
  402. # tag:go-specific
  403. ### @usage: GO_XTEST_EMBED_BINDIR(DIR, FILES...)
  404. ###
  405. ### Define an embed directory DIR for files from ARCADIA_BUILD_ROOT for external go tests
  406. macro GO_XTEST_EMBED_BINDIR(PREFIX="${_GO_IMPORT_PATH}", DIR, FILES[]) {
  407. _GO_EMBED_BINDIR(XTEST ${ARCADIA_BUILD_ROOT}/$PREFIX $DIR $FILES)
  408. }
  409. # tag:go-specific
  410. _GO_TOOLCHAIN_ENV_GOARCH=unknown
  411. when ($ARCH_ARM64) {
  412. _GO_TOOLCHAIN_ENV_GOARCH=${env:"GOARCH=arm64"}
  413. }
  414. elsewhen ($ARCH_X86_64) {
  415. _GO_TOOLCHAIN_ENV_GOARCH=${env:"GOARCH=amd64"}
  416. }
  417. # tag:go-specific
  418. _GO_TOOLCHAIN_ENV_GOOS=unknown
  419. when ($OS_DARWIN) {
  420. _GO_TOOLCHAIN_ENV_GOOS=${env:"GOOS=darwin"}
  421. }
  422. elsewhen ($OS_LINUX) {
  423. _GO_TOOLCHAIN_ENV_GOOS=${env:"GOOS=linux"}
  424. }
  425. elsewhen ($OS_WINDOWS) {
  426. _GO_TOOLCHAIN_ENV_GOOS=${env:"GOOS=windows"}
  427. }
  428. _GO_TOOLCHAIN_ENV_PATH=
  429. # tag:go-specific
  430. GO_TOOLCHAIN_ENV=$TOOLCHAIN_ENV $_GO_TOOLCHAIN_ENV_GOARCH $_GO_TOOLCHAIN_ENV_GOOS $_GO_TOOLCHAIN_ENV_PATH
  431. # tag:go-specific
  432. _GO_GRPC_WELLKNOWN=\
  433. vendor/google.golang.org/grpc \
  434. vendor/google.golang.org/grpc \
  435. vendor/google.golang.org/grpc/codes \
  436. vendor/google.golang.org/grpc/grpclog \
  437. vendor/google.golang.org/grpc/status
  438. # tag:go-specific
  439. macro _GO_GRPC() {
  440. SET(GO_PROTO_GEN_PLUGINS plugins=grpc)
  441. SET(GO_PROTO_GRPC_OPTS \$GO_PROTO_GRPC_OPTS_V2)
  442. SET(GO_PROTO_GRPC_OUTS \$GO_PROTO_GRPC_OUTS_V2)
  443. PEERDIR(${GOSTD}/context ${_GO_GRPC_WELLKNOWN})
  444. }
  445. # tag:go-specific
  446. ### @usage: GO_GRPC_GATEWAY_SRCS()
  447. ###
  448. ### Use of grpc-gateway plugin (Supported for Go only).
  449. macro GO_GRPC_GATEWAY_SRCS(FILE...) {
  450. ENABLE(UNUSED_MACRO)
  451. }
  452. # tag:go-specific
  453. ### @usage: GO_GRPC_GATEWAY_SWAGGER_SRCS()
  454. ###
  455. ### Use of grpc-gateway plugin w/ swagger emission (Supported for Go only).
  456. macro GO_GRPC_GATEWAY_SWAGGER_SRCS(FILE...) {
  457. PEERDIR(vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options)
  458. }
  459. # tag:go-specific
  460. _GO_PROTO_GRPC_GATEWAY_OPTS=
  461. _GO_PROTO_GRPC_GATEWAY_OUTS=
  462. # tag:go-specific
  463. macro _GO_GRPC_GATEWAY_SRCS_IMPL(Files...) {
  464. foreach (File : $Files) {
  465. [.proto]=$_GO_PROTO_CMD_IMPL($File $_GO_PROTO_GRPC_GATEWAY_OPTS $_GO_PROTO_GRPC_GATEWAY_OUTS)
  466. }
  467. PEERDIR(${GOSTD}/context ${GOSTD}/io ${GOSTD}/net/http)
  468. PEERDIR(vendor/github.com/golang/protobuf/descriptor)
  469. PEERDIR(vendor/github.com/grpc-ecosystem/grpc-gateway/runtime)
  470. PEERDIR(vendor/github.com/grpc-ecosystem/grpc-gateway/utilities)
  471. PEERDIR(vendor/google.golang.org/grpc/metadata)
  472. }
  473. # tag:go-specific
  474. macro _SETUP_GO_GRPC_GATEWAY() {
  475. 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))
  476. SET(_GO_PROTO_GRPC_GATEWAY_OUTS \${output;hide;norel;nopath;noext;suf=.pb.gw.go:File})
  477. }
  478. # tag:go-specific
  479. macro _GO_GRPC_GATEWAY_SRCS(Files...) {
  480. _SETUP_GO_GRPC_GATEWAY()
  481. _GO_GRPC_GATEWAY_SRCS_IMPL($Files)
  482. }
  483. # tag:go-specific
  484. macro _GO_GRPC_GATEWAY_SWAGGER_SRCS(Files...) {
  485. _SETUP_GO_GRPC_GATEWAY()
  486. 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))
  487. SET_APPEND(_GO_PROTO_GRPC_GATEWAY_OUTS \${output;hide;norel;noauto;nopath;noext;suf=.swagger.json:File})
  488. _GO_GRPC_GATEWAY_SRCS_IMPL($Files)
  489. PEERDIR(vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options)
  490. }
  491. #tag:go-specific
  492. ### @usage: GO_GRPC_GATEWAY_V2_OPENAPI_SRCS(Files...)
  493. ###
  494. ### Use of grpc-gateway plugin w/ openapi v2 emission (Supported for Go only).
  495. macro GO_GRPC_GATEWAY_V2_OPENAPI_SRCS(NO_JSON_NAMES_FOR_FIELDS?"":"", Files...) {
  496. PEERDIR(vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options)
  497. }
  498. macro _GO_GRPC_GATEWAY_V2_OPENAPI_SRCS(NO_JSON_NAMES_FOR_FIELDS?"json_names_for_fields=false":"", Files...) {
  499. _SETUP_GO_GRPC_GATEWAY_V2()
  500. 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))
  501. SET_APPEND(_GO_PROTO_GRPC_GATEWAY_V2_OPTS \${output;hide;norel;noauto;nopath;noext;suf=.swagger.json:File})
  502. _GO_GRPC_GATEWAY_V2_SRCS_IMPL($Files)
  503. PEERDIR(vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options)
  504. }
  505. # tag:go-specific
  506. ### @usage: GO_GRPC_GATEWAY_V2_SRCS()
  507. ###
  508. ### Use of grpc-gateway plugin (Supported for Go only).
  509. macro GO_GRPC_GATEWAY_V2_SRCS(FILE...) {
  510. ENABLE(UNUSED_MACRO)
  511. }
  512. # tag:go-specific
  513. _GO_PROTO_GRPC_GATEWAY_V2_OPTS=
  514. _GO_PROTO_GRPC_GATEWAY_V2_OUTS=
  515. # tag:go-specific
  516. macro _GO_GRPC_GATEWAY_V2_SRCS_IMPL(Files...) {
  517. foreach (File : $Files) {
  518. [.proto]=$_GO_PROTO_CMD_IMPL($File $_GO_PROTO_GRPC_GATEWAY_V2_OPTS $_GO_PROTO_GRPC_GATEWAY_V2_OUTS)
  519. }
  520. PEERDIR(${GOSTD}/context ${GOSTD}/io ${GOSTD}/net/http)
  521. PEERDIR(vendor/github.com/golang/protobuf/descriptor)
  522. PEERDIR(vendor/github.com/grpc-ecosystem/grpc-gateway/v2/runtime)
  523. PEERDIR(vendor/github.com/grpc-ecosystem/grpc-gateway/v2/utilities)
  524. PEERDIR(vendor/google.golang.org/grpc/metadata)
  525. PEERDIR(vendor/google.golang.org/protobuf/proto)
  526. }
  527. # tag:go-specific
  528. macro _SETUP_GO_GRPC_GATEWAY_V2() {
  529. 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))
  530. SET(_GO_PROTO_GRPC_GATEWAY_V2_OUTS \${output;hide;norel;nopath;noext;suf=.pb.gw.go:File})
  531. }
  532. # tag:go-specific
  533. macro _GO_GRPC_GATEWAY_V2_SRCS(Files...) {
  534. _SETUP_GO_GRPC_GATEWAY_V2()
  535. _GO_GRPC_GATEWAY_V2_SRCS_IMPL($Files)
  536. }
  537. # tag:go-specific
  538. when ($MUSL == "yes") {
  539. _GO_DEFAULT_ALLOCATOR=LF
  540. }
  541. otherwise {
  542. _GO_DEFAULT_ALLOCATOR=FAKE
  543. }
  544. # tag:go-specific tag:internal
  545. ### @usage _GO_BASE_UNIT # internal
  546. ###
  547. ### The base module of all golang modules. Defines common properties, dependencies and rules for go build.
  548. module _GO_BASE_UNIT: _BASE_UNIT {
  549. .EXTS=.go .gosrc .o .obj .a .symabis .mf
  550. .CMD=TOUCH_UNIT
  551. .NODE_TYPE=Bundle
  552. .GLOBAL=GO_LDFLAGS OBJADDE_LIB
  553. .PEERDIR_POLICY=as_build_from
  554. .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
  555. .ALLOWED=GO_PROTO_PLUGIN USE_CXX USE_UTIL RESOURCE_FILES
  556. .IGNORED=GO_SKIP_TESTS USE_SKIFF
  557. .RESTRICTED=TEST_SRCS
  558. .DEFAULT_NAME_GENERATOR=UseDirNameOrSetGoPackage
  559. ENABLE(_GO_MODULE)
  560. SET(MODULE_TAG GO)
  561. SET(PEERDIR_TAGS GO GO_PROTO GO_FBS __EMPTY__ RESOURCE_LIB)
  562. DEFAULT(_GO_VET_TOOL)
  563. DEFAULT(_GO_VET_FLAGS)
  564. DEFAULT(_GO_VET_EXTS)
  565. DEFAULT(_GO_SONAME)
  566. NO_RUNTIME()
  567. SET(COVERAGE_FLAGS)
  568. SET(EXTRA_OUTPUT)
  569. SET(MODULE_LANG GO)
  570. ENABLE(FORCE_CONSISTENT_DEBUG)
  571. PEERDIR(build/external_resources/go_tools)
  572. 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
  573. GO_PROTO_GRPC_OUTS_V2=${output;norel;nopath;noext;suf=_grpc.pb.go:File}
  574. select ($GO_PROTO_V2) {
  575. "yes" | "on" ? {
  576. GO_PROTO_OUTS+=${output;hide;norel;nopath;noext;suf=.pb.go:File}
  577. GO_PROTO_OPTS+=--plugin=protoc-gen-go=${tool:_TOOL_PROTOC_GEN_GO_V2} --go_out=${ARCADIA_BUILD_ROOT}/$PROTO_NAMESPACE
  578. _GO_PROTO_CHECK_OUTPUT=--check $GO_PROTO_GRPC_OUTS_V2
  579. GO_PROTO_OPTS+=$GO_PROTO_GRPC_OPTS
  580. }
  581. default ? {
  582. GO_PROTO_OUTS+=${output;hide;norel;nopath;noext;suf=.pb.go:File}
  583. GO_PROTO_OPTS+=--plugin=protoc-gen-go=${tool:_TOOL_PROTOC_GEN_GO} --go_out=$GO_PROTO_GEN_PLUGINS:${ARCADIA_BUILD_ROOT}/$PROTO_NAMESPACE
  584. }
  585. }
  586. when ($COMPILER_PLATFORM && $NEED_PLATFORM_PEERDIRS == "yes") {
  587. PEERDIR+=$COMPILER_PLATFORM
  588. }
  589. when ($CLANG == "yes" || $GCC == "yes") {
  590. CGO_CFLAGS_VALUE += -w -pthread -fpic
  591. CGO2_CFLAGS_VALUE += -Wno-unused-variable
  592. }
  593. select ($GO_VET) {
  594. "yes" | "on" ? {
  595. _GO_VET=yes
  596. _GO_VET_FLAGS+=-cgocall=false
  597. }
  598. "yndexer" ? {
  599. _GO_VET=yes
  600. PEERDIR+=build/external_resources/goyndexer
  601. _GO_VET_TOOL=${GOYNDEXER_RESOURCE_GLOBAL}/goyndexer
  602. _GO_YDX_FILE=++ydx-file ${_GO_YNDEXER_EXT}
  603. _GO_VET_FLAGS=-indexer.arc ${ARCADIA_ROOT} -indexer.indexfile ${GO_YNDEXER_OUTPUT} -indexer.loglevel info
  604. _GO_FMT_ADD_CHECK=no
  605. _GO_VET_ADD_CHECK=no
  606. GO_VET_INFO_EXT=.ydx.out
  607. GO_VET_REPORT_EXT=.ydx.txt
  608. _GO_VET_EXTS=++vet-info-ext .ydx.out ++vet-report-ext .ydx.txt
  609. _GO_CGO1_WRAPPER_FLAGS=--build-prefix=__ARCADIA_BUILD_ROOT_PREFIX__ --source-prefix=__ARCADIA_SOURCE_ROOT_PREFIX__
  610. }
  611. "yolint" ? {
  612. _GO_VET=yes
  613. PEERDIR+=build/external_resources/yolint
  614. _GO_VET_TOOL=${YOLINT_RESOURCE_GLOBAL}/yolint
  615. _GO_VET_FLAGS=-migration.config=${input:"${ARCADIA_ROOT}/build/rules/go/migrations.yaml"} -scopelint.config=${input:"${ARCADIA_ROOT}/build/rules/go/extended_lint.yaml"} -riskyimports.config=${input:"${ARCADIA_ROOT}/build/rules/go/risky_imports.yaml"}
  616. }
  617. "local" ? {
  618. _GO_VET=yes
  619. _GO_VET_FLAGS=-migration.config=${input:"${ARCADIA_ROOT}/build/rules/go/migrations.yaml"} -scopelint.config=${input:"${ARCADIA_ROOT}/build/rules/go/extended_lint.yaml"} -riskyimports.config=${input:"${ARCADIA_ROOT}/build/rules/go/risky_imports.yaml"}
  620. }
  621. default ? {
  622. _GO_VET=no
  623. _GO_VET_FLAGS=
  624. }
  625. }
  626. SET(_GO_VET $_GO_VET)
  627. when ($GO_VET_TOOL == "") {
  628. _GO_VET_TOOL_REAL=$_GO_VET_TOOL
  629. }
  630. otherwise {
  631. _GO_VET_TOOL_REAL=$GO_VET_TOOL
  632. }
  633. when ($GO_VET_FLAGS == "") {
  634. _GO_VET_FLAGS_REAL=$_GO_VET_FLAGS
  635. }
  636. otherwise {
  637. _GO_VET_FLAGS_REAL=$GO_VET_FLAGS
  638. }
  639. when ($_GO_VET == "yes" && $NO_GO_VET != "yes") {
  640. 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
  641. }
  642. otherwise {
  643. GO_VET_OUTPUT=
  644. _GO_VET_ADD_CHECK=no
  645. }
  646. when ($GO_DEBUG_PATH_RELATIVE == "yes") {
  647. _GO_DEBUG_PATH__NO_UID__=++debug-root-map source=;build=;tools= ++tools-root $(TOOL_ROOT)
  648. _GO_COMPILE_SYMABIS_TRIMPATH__NO_UID__=-trimpath $ARCADIA_ROOT=>;$ARCADIA_BUILD_ROOT=>;$(TOOL_ROOT)=>
  649. }
  650. otherwise {
  651. _GO_DEBUG_PATH__NO_UID__=++debug-root-map source=/-S;build=/-B;tools=/-T ++tools-root $(TOOL_ROOT)
  652. _GO_COMPILE_SYMABIS_TRIMPATH__NO_UID__=-trimpath $ARCADIA_ROOT=>/-S;$ARCADIA_BUILD_ROOT=>/-B;$(TOOL_ROOT)=>/-T
  653. }
  654. _GO_PROCESS_SRCS()
  655. when ($CLANG == "yes") {
  656. _GO_EXTLD=clang
  657. GO_TOOLCHAIN_ENV += ${env:"CC=clang"}
  658. }
  659. otherwise {
  660. _GO_EXTLD=gcc
  661. GO_TOOLCHAIN_ENV += ${env:"CC=gcc"}
  662. }
  663. when ($OS_DARWIN) {
  664. PEERDIR+=build/external_resources/go_fake_xcrun
  665. 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
  666. CGO2_LDFLAGS_VALUE += $LD_SDK_VERSION -undefined dynamic_lookup -nodefaultlibs -lc
  667. }
  668. elsewhen ($OS_LINUX) {
  669. 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
  670. CGO2_LDFLAGS_VALUE += -Wl,--unresolved-symbols=ignore-all -nodefaultlibs -lc
  671. }
  672. otherwise {
  673. GO_EXTLD = ++extld $_GO_EXTLD
  674. }
  675. when ($RACE == "yes") {
  676. _GO_COMPILE_FLAGS_RACE=-race
  677. _GO_LINK_FLAGS_RACE=-race
  678. }
  679. otherwise {
  680. _GO_COMPILE_FLAGS_RACE=
  681. _GO_LINK_FLAGS_RACE=
  682. }
  683. when ($PIC == "yes" || $PIE == "yes") {
  684. _GO_COMPILE_FLAGS_SHARED=-shared
  685. _GO_ASM_FLAGS_SHARED=-shared
  686. }
  687. otherwise {
  688. _GO_COMPILE_FLAGS_SHARED=
  689. _GO_ASM_FLAGS_SHARED=
  690. }
  691. GO_ASM_FLAGS_VALUE += $_GO_ASM_FLAGS_SHARED
  692. GO_COMPILE_FLAGS_VALUE += $_GO_COMPILE_FLAGS_RACE $_GO_COMPILE_FLAGS_SHARED
  693. GO_LINK_FLAGS_VALUE += $_GO_LINK_FLAGS_LINKMODE $_GO_LINK_FLAGS_RACE
  694. ADDINCL(${GOSTD}/runtime)
  695. }
  696. # tag:go-specific
  697. ### @usage: GO_LIBRARY([name])
  698. ###
  699. ### Go library module definition.
  700. ### Compile Go module as a library suitable for PEERDIR from other Go modules.
  701. ### Will select Go implementation on PEERDIR to PROTO_LIBRARY.
  702. module GO_LIBRARY: _GO_BASE_UNIT {
  703. .CMD=GO_LINK_LIB
  704. .NODE_TYPE=Bundle
  705. .FINAL_TARGET=no
  706. SET(_GO_TOOL_MODE lib)
  707. SET(MODULE_TYPE LIBRARY)
  708. SET(PEERDIR_TAGS GO GO_PROTO GO_FBS __EMPTY__ RESOURCE_LIB PACKAGE_UNION)
  709. MODULE_SUFFIX=.a
  710. }
  711. # tag:go-specific
  712. ### @usage: GO_PROGRAM([name])
  713. ###
  714. ### Go program module definition.
  715. ### Compile and link Go module to an executable program.
  716. ### Will select Go implementation on PEERDIR to PROTO_LIBRARY.
  717. module GO_PROGRAM: _GO_BASE_UNIT {
  718. .CMD=GO_LINK_EXE
  719. .NODE_TYPE=Program
  720. .PROXY=yes
  721. .SYMLINK_POLICY=EXE
  722. .ALLOWED=INDUCED_DEPS
  723. .FINAL_TARGET=yes
  724. SET(MODULE_TAG GO_PROGRAM)
  725. SET(_GO_TOOL_MODE exe)
  726. SET(MODULE_TYPE PROGRAM)
  727. SET(GO_VET_OUTPUT_INFO)
  728. ALLOCATOR($_GO_DEFAULT_ALLOCATOR)
  729. _USE_LINKER()
  730. ENABLE(COMMON_LINK_SETTINGS)
  731. when ($MUSL == "yes") {
  732. PEERDIR += contrib/libs/musl/full
  733. }
  734. when ($RACE == "yes") {
  735. PEERDIR += contrib/libs/cxxsupp/builtins
  736. }
  737. when ($MSVC == "yes" || $CYGWIN == "yes") {
  738. MODULE_SUFFIX=.exe
  739. }
  740. PEERDIR(${GOSTD}/runtime library/go/core/buildinfo)
  741. when ($CGO_ENABLED == "yes") {
  742. PEERDIR += ${GOSTD}/runtime/cgo
  743. }
  744. when ($RACE == "yes") {
  745. PEERDIR += ${GOSTD}/runtime/cgo
  746. PEERDIR += ${GOSTD}/runtime/race
  747. }
  748. when ($MUSL == "yes") {
  749. GO_WITH_MUSL = ++musl
  750. }
  751. when ($HARDENING == "yes") {
  752. _GO_BUILDMODE=++buildmode=pie
  753. }
  754. when ($OPENSOURCE == "yes" && $AUTOCHECK == "yes") {
  755. # FIXME: Replace AUTOCHECK == yes with _not a host platform_ check after YMAKE-218
  756. MODULE_LICENSES_RESTRICTION_TYPES = ALLOW_ONLY
  757. MODULE_LICENSES_RESTRICTIONS = SERVICE REQUIRE_CITATION REQUIRE_MODIFICATIONS_DISCLOSURE
  758. }
  759. when ($OS_IOS == "yes" || $OS_ANDROID == "yes" || $MAPSMOBI_BUILD_TARGET == "yes") {
  760. MODULE_LICENSES_RESTRICTION_TYPES = ALLOW_ONLY
  761. MODULE_LICENSES_RESTRICTIONS = SERVICE REQUIRE_CITATION
  762. }
  763. }
  764. # tag:go-specific
  765. module _GO_DLL_BASE_UNIT: GO_PROGRAM {
  766. .CMD=GO_LINK_DLL
  767. .SYMLINK_POLICY=SO
  768. .ALLOWED=WHOLE_ARCHIVE
  769. .ARGS_PARSER=DLL
  770. .NODE_TYPE=Library
  771. .PROXY=yes
  772. SET(_GO_TOOL_MODE dll)
  773. SET(MODULE_TYPE DLL)
  774. GO_PACKAGE_NAME(main)
  775. when ($MSVC == "yes" || $CYGWIN == "yes") {
  776. MODULE_SUFFIX=.dll
  777. }
  778. elsewhen ($DARWIN == "yes" || $OS_IOS == "yes") {
  779. MODULE_PREFIX=lib
  780. MODULE_SUFFIX=.dylib$MODULE_VERSION
  781. }
  782. otherwise {
  783. MODULE_PREFIX=lib
  784. MODULE_SUFFIX=.so$MODULE_VERSION
  785. }
  786. when ($OS_DARWIN) {
  787. _GO_SONAME=-Wl,-install_name,$SONAME
  788. }
  789. elsewhen ($OS_LINUX) {
  790. _GO_SONAME=-Wl,-soname,$SONAME
  791. }
  792. when ($MODULE_VERSION) {
  793. when ($OS_LINUX || $OS_DARWIN) {
  794. _GO_LINK_EXE_EXT_CMD+= && $LINK_OR_COPY_CMD $TARGET ${output;nopath;noext:SONAME}
  795. }
  796. }
  797. }
  798. # tag:go-specific
  799. ### @usage: GO_DLL(name major_ver [minor_ver] [PREFIX prefix])
  800. ###
  801. ### Go ishared object module definition.
  802. ### Compile and link Go module to a shared object.
  803. ### Will select Go implementation on PEERDIR to PROTO_LIBRARY.
  804. module GO_DLL: _GO_DLL_BASE_UNIT {
  805. }
  806. # tag:go-specific tag:test
  807. ### @usage: GO_BENCH_TIMEOUT(x)
  808. ###
  809. ### Sets timeout in seconds for 1 Benchmark in go benchmark suite
  810. ###
  811. ### Documentation about the system test: https://wiki.yandex-team.ru/yatool/test/
  812. macro GO_BENCH_TIMEOUT(bench_timeout) {
  813. SET(GO_BENCH_TIMEOUT $bench_timeout)
  814. }
  815. # tag:go-specific tag:test
  816. ### @usage: GO_TEST([name])
  817. ###
  818. ### Go test module definition.
  819. ### Compile and link Go module as a test suitable for running with Arcadia testing support.
  820. ### All usual testing support macros like DATA, DEPENDS, SIZE, REQUIREMENTS etc. are supported.
  821. ### Will select Go implementation on PEERDIR to PROTO_LIBRARY.
  822. module GO_TEST: GO_PROGRAM {
  823. .CMD=GO_LINK_TEST
  824. .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
  825. .ALLOWED=GO_SKIP_TESTS YT_SPEC
  826. .FINAL_TARGET=no
  827. SET(MODULE_TAG GO_TEST)
  828. SET(PEERDIR_TAGS GO GO_PROGRAM GO_PROTO GO_FBS __EMPTY__ RESOURCE_LIB)
  829. SET(_GO_TOOL_MODE test)
  830. SET(MODULE_TYPE PROGRAM)
  831. ENABLE(GO_TEST_MODULE)
  832. SET(GO_COVER_INFO_VALUE)
  833. # We have to add uncoditionaly PEERDIR to ${GOSTD}/os here thouth it is really
  834. # needed when TestMain is defined in the source code of the test
  835. PEERDIR(${GOSTD}/os)
  836. PEERDIR(${GOSTD}/testing/internal/testdeps)
  837. PEERDIR(${GOSTD}/testing)
  838. PEERDIR(library/go/test/yatest)
  839. ADD_YTEST($MODULE_PREFIX$REALPRJNAME go.test)
  840. ADD_YTEST($MODULE_PREFIX$REALPRJNAME go.bench)
  841. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS canondata/result.json)
  842. }
  843. # tag:go-specific
  844. macro GO_MOCKGEN_FROM(Path) {
  845. SET(MOCKGEN_FROM ${Path})
  846. SET(MOCKGEN_MODULE ${GO_ARCADIA_PROJECT_PREFIX}${Path})
  847. }
  848. # tag:go-specific
  849. macro GO_MOCKGEN_CONTRIB_FROM(Path) {
  850. SET(MOCKGEN_FROM ${GO_CONTRIB_PROJECT_PREFIX}${Path})
  851. SET(MOCKGEN_MODULE ${Path})
  852. }
  853. # tag:go-specific
  854. macro GO_MOCKGEN_TYPES(Types...) {
  855. SET(MOCKGEN_TYPES ${join=\\${__COMMA__}:Types})
  856. }
  857. # tag:go-specific
  858. macro GO_MOCKGEN_REFLECT() {
  859. PEERDIR(${GOSTD}/encoding/gob)
  860. PEERDIR(${GOSTD}/flag)
  861. PEERDIR(${GOSTD}/fmt)
  862. PEERDIR(${GOSTD}/os)
  863. PEERDIR(${GOSTD}/path)
  864. PEERDIR(${GOSTD}/reflect)
  865. PEERDIR(vendor/go.uber.org/mock/mockgen/model)
  866. PEERDIR(${MOCKGEN_FROM})
  867. RUN_PROGRAM(vendor/go.uber.org/mock/mockgen -prog_only $MOCKGEN_MODULE $MOCKGEN_TYPES STDOUT main.go CWD $ARCADIA_BUILD_ROOT)
  868. }
  869. # tag:go-specific
  870. _GO_EXE_SUFFIX=
  871. when ($OS_WINDOWS == "yes") {
  872. _GO_EXE_SUFFIX=.exe
  873. }
  874. # tag:go-specific
  875. macro GO_MOCKGEN_MOCKS() {
  876. PEERDIR(${GOSTD}/reflect)
  877. PEERDIR(vendor/go.uber.org/mock/gomock)
  878. # Unfortunately ${rootrel;tool:TOOL} doesn't work currently, so we use this ugly workaround $MODDIR/gen/gen$_GO_EXE_SUFFIX
  879. RUN_PROGRAM(vendor/go.uber.org/mock/mockgen -package mocks -exec_only $MODDIR/gen/gen$_GO_EXE_SUFFIX ${GO_ARCADIA_PROJECT_PREFIX}${MOCKGEN_FROM} $MOCKGEN_TYPES STDOUT main.go TOOL $MODDIR/gen CWD $ARCADIA_BUILD_ROOT)
  880. }