go.conf 35 KB

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