go.conf 35 KB

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