build: improve cross compilation setup (#22804)
This PR cleans up the CI build system and fixes a couple of issues. - The go tool launcher code has been moved to internal/build. With the new toolchain functions, the environment of the host Go (i.e. the one that built ci.go) and the target Go (i.e. the toolchain downloaded by -dlgo) are isolated more strictly. This is important to make cross compilation and -dlgo work correctly in more cases. - The -dlgo option now skips the download and uses the host Go if the running Go version matches dlgoVersion exactly. - The 'test' command now supports -dlgo, -cc and -arch. Running unit tests with foreign GOARCH is occasionally useful. For example, it can be used to run 32-bit tests on Windows. It can also be used to run darwin/amd64 tests on darwin/arm64 using Rosetta 2. - The 'aar', 'xcode' and 'xgo' commands now use a slightly different method to install external tools. They previously used `go get`, but this comes with the annoying side effect of modifying go.mod. They now use `go install` instead, which is the recommended way of installing tools without modifying the local module. - The old build warning about outdated Go version has been removed because we're much better at keeping backwards compatibility now.
This commit is contained in:
@ -38,6 +38,7 @@ var (
|
||||
|
||||
// Environment contains metadata provided by the build environment.
|
||||
type Environment struct {
|
||||
CI bool
|
||||
Name string // name of the environment
|
||||
Repo string // name of GitHub repo
|
||||
Commit, Date, Branch, Tag string // Git info
|
||||
@ -61,6 +62,7 @@ func Env() Environment {
|
||||
commit = os.Getenv("TRAVIS_COMMIT")
|
||||
}
|
||||
return Environment{
|
||||
CI: true,
|
||||
Name: "travis",
|
||||
Repo: os.Getenv("TRAVIS_REPO_SLUG"),
|
||||
Commit: commit,
|
||||
@ -77,6 +79,7 @@ func Env() Environment {
|
||||
commit = os.Getenv("APPVEYOR_REPO_COMMIT")
|
||||
}
|
||||
return Environment{
|
||||
CI: true,
|
||||
Name: "appveyor",
|
||||
Repo: os.Getenv("APPVEYOR_REPO_NAME"),
|
||||
Commit: commit,
|
||||
|
Reference in New Issue
Block a user