首頁  >  文章  >  後端開發  >  有哪些與 Go 程式語言相容的建置系統?

有哪些與 Go 程式語言相容的建置系統?

Susan Sarandon
Susan Sarandon原創
2024-11-02 23:52:29331瀏覽

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