Go有哪些构建系统? [英] What build systems work with Go?

查看:182
本文介绍了Go有哪些构建系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Go源代码中有一个Makefile(它位于 $ GOROOT / doc ),我现在正在使用它,但还有其他流行的构建系统支持去吧?有没有人为 scons 编写脚本, waf 等...

I know that the Go source comes with a Makefile (It's in $GOROOT/doc) which I am using right now, but have other popular build systems added support for Go yet? Has anyone written build scripts for scons, waf etc...

你用什么来建立你的Go程序?

What do you use to build your Go programs?

推荐答案

我一直在使用scons;这是一个示例 SConstruct file:

I've been using scons; this is an example SConstruct file:

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有哪些构建系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆