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

Susan Sarandon
Release: 2024-11-02 23:52:29
Original
398 people have browsed it

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

Build Systems Compatible with Go

Alongside Go's native Makefile, several other popular build systems also offer support for the language. These include:

  • scons: An effective alternative, this example SConstruct file demonstrates its capabilities:

    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])
    Copy after login

Go's flexibility allows developers to select the build system that best aligns with their preferences and project requirements.

The above is the detailed content of What are the build systems compatible with the Go programming language?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template