How to build differently for Linux vs Windows

后端 未结 1 888
轻奢々
轻奢々 2021-01-13 17:10

I\'m taking look on Go language. And I have a question: for example I will create a new library, that should use methods from one Go package for Windows and from other for L

相关标签:
1条回答
  • 2021-01-13 17:37

    Use build constraints and file names. See Package build. The source code for Package os has many examples: https://golang.org/src/os/. Go Source Code: https://go.googlesource.com/go or https://github.com/golang/go.

    A build contraint for Unix:

    // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
    

    Some build file names:

    stat_darwin.go     stat_linux.go   stat_openbsd.go  stat_unix.go
    stat_dragonfly.go  stat_nacl.go    stat_plan9.go    stat_windows.go
    stat_freebsd.go    stat_netbsd.go  stat_solaris.go
    

    The Go tools and standard library started out using build file names and then, as the requirements became more complex, began using build constraints.

    0 讨论(0)
提交回复
热议问题