如何针对Linux与Windows进行不同的构建 [英] How to build differently for Linux vs Windows
问题描述
我正在研究Go语言. 我有一个问题:例如,我将创建一个新的库,该库应使用Windows的一个Go软件包中的方法,而Linux使用的是其他软件包中的方法.
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 Linux.
我只是问,有没有一种方便的方式来组织构建过程? 当然,我可以为每个操作系统创建一个项目,并为每个操作系统更改导入名称.
I'm just asking, is there a convenient way of organizing build process? Of course, I can just make a project for every OS and change import name for every OS.
推荐答案
使用构建约束和文件名.请参阅软件包构建. Package os 的源代码有很多示例: https://go.googlesource.com/go 或
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.
用于Unix的构建约束
A build contraint for Unix:
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
一些构建文件名:
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
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.
这篇关于如何针对Linux与Windows进行不同的构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!