用於Go 開發的替代構建系統
雖然Go 附帶了自己的Makefile 用於構建程序,但開發人員可能會尋求提供額外功能的替代建置系統功能或不同的開發工作流程。
流行的構建系統
幾個流行的構建系統添加了對Go 的支持,包括:
Scons 範例
SConstruct 文件:
archs = {'amd64': '6', '386': '8', 'arm': '5',} def gc(source, target, env, for_signature): targets = target[0] sources = ' '.join(str(s) for s in source) flags = '' for include in env.get('GOINCLUDE', []): flags += '-I %s ' % (include) return '%s -o %s %s %s' % (env['GOCOMPILER'], targets, flags, sources) def ld(source, target, env, for_signature): targets = target[0] sources = ' '.join(str(s) for s in source) return '%s -o %s %s' % (env['GOLINKER'], targets, sources) def _go_object_suffix(env, sources): return "." + archs[env['ENV']['GOARCH']] def _go_program_prefix(env, sources): return env['PROGPREFIX'] def _go_program_suffix(env, sources): return env['PROGSUFFIX'] go_compiler = Builder(generator=gc, suffix=_go_object_suffix, src_suffix='.go',) go_linker = Builder(generator=ld, prefix=_go_program_prefix, suffix=_go_program_suffix,) # Create environment import os env = Environment(BUILDERS={'Go': go_compiler, 'GoProgram': go_linker}, ENV=os.environ,) arch_prefix = archs[os.environ['GOARCH']] env.SetDefault(GOCOMPILER=os.path.join(os.environ['GOBIN'], arch_prefix + 'g')) env.SetDefault(GOLINKER=os.path.join(os.environ['GOBIN'], arch_prefix + 'l')) # Build programs # Modify this to suit your program main_package = env.Go(target='main', source='main.go') program = env.GoProgram(target='program', source=[main_package])
以上是為什麼應該考慮 Go 開發的替代構建系統?的詳細內容。更多資訊請關注PHP中文網其他相關文章!