go.conf 32 KB

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