首页 >后端开发 >Golang >有哪些与 Go 编程语言兼容的构建系统?

有哪些与 Go 编程语言兼容的构建系统?

Susan Sarandon
Susan Sarandon原创
2024-11-02 23:52:29413浏览

What are the build systems compatible with the Go programming language?

构建与 Go 兼容的系统

除了 Go 的原生 Makefile,其他几个流行的构建系统也提供对该语言的支持。其中包括:

  • 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 的灵活性允许开发人员选择最符合他们的偏好和项目要求的构建系统。

以上是有哪些与 Go 编程语言兼容的构建系统?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn