Properly added xgo

This commit is contained in:
konrad 2019-04-27 11:12:36 +02:00
parent 0b49e973dd
commit 764966bddb
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
10 changed files with 428 additions and 75 deletions

2
go.mod
View File

@ -6,11 +6,11 @@ require (
github.com/fzipp/gocyclo v0.0.0-20150627053110-6acd4345c835 github.com/fzipp/gocyclo v0.0.0-20150627053110-6acd4345c835
github.com/gordonklaus/ineffassign v0.0.0-20180909121442-1003c8bd00dc github.com/gordonklaus/ineffassign v0.0.0-20180909121442-1003c8bd00dc
github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/karalabe/xgo v0.0.0-20181007145344-72da7d1d3970
github.com/mitchellh/go-homedir v1.0.0 github.com/mitchellh/go-homedir v1.0.0
github.com/prometheus/client_golang v0.9.2 github.com/prometheus/client_golang v0.9.2
github.com/spf13/cobra v0.0.3 github.com/spf13/cobra v0.0.3
github.com/spf13/viper v1.3.1 github.com/spf13/viper v1.3.1
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3 golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3
golang.org/x/tools v0.0.0-20181128225727-c5b00d9557fd // indirect golang.org/x/tools v0.0.0-20181128225727-c5b00d9557fd // indirect
src.techknowlogick.com/xgo v0.0.0-20190415010919-1502273fab15
) )

5
go.sum
View File

@ -22,8 +22,6 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/karalabe/xgo v0.0.0-20181007145344-72da7d1d3970 h1:0+1ZURVRim6FxA/jhWhJklsgoWc69q1sxlIu2Ztnhy0=
github.com/karalabe/xgo v0.0.0-20181007145344-72da7d1d3970/go.mod h1:iYGcTYIPUvEWhFo6aKUuLchs+AV4ssYdyuBbQJZGcBk=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
@ -64,6 +62,7 @@ golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3 h1:x/bBzNauLQAlE3fLku/xy92Y8QwKX5HZymrMz2IiKFc= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3 h1:x/bBzNauLQAlE3fLku/xy92Y8QwKX5HZymrMz2IiKFc=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a h1:1n5lsVfiQW3yfsRGu98756EH1YthsFqr/5mxHduZW2A= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a h1:1n5lsVfiQW3yfsRGu98756EH1YthsFqr/5mxHduZW2A=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@ -75,3 +74,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
src.techknowlogick.com/xgo v0.0.0-20190415010919-1502273fab15 h1:pHKgCq4abc5TAZRZGcSCxuJOTvRwzGfnbZdgTsFDgng=
src.techknowlogick.com/xgo v0.0.0-20190415010919-1502273fab15/go.mod h1:Ood88figJtEukTnU20P1IrXhyAkbOIGi4YzmeHVtGH0=

View File

@ -42,6 +42,6 @@ import (
_ "github.com/client9/misspell/cmd/misspell" _ "github.com/client9/misspell/cmd/misspell"
_ "github.com/fzipp/gocyclo" _ "github.com/fzipp/gocyclo"
_ "github.com/gordonklaus/ineffassign" _ "github.com/gordonklaus/ineffassign"
_ "github.com/karalabe/xgo"
_ "golang.org/x/lint/golint" _ "golang.org/x/lint/golint"
_ "src.techknowlogick.com/xgo"
) )

4
vendor/modules.txt vendored
View File

@ -24,8 +24,6 @@ github.com/hashicorp/hcl/json/scanner
github.com/hashicorp/hcl/json/token github.com/hashicorp/hcl/json/token
# github.com/inconshreveable/mousetrap v1.0.0 # github.com/inconshreveable/mousetrap v1.0.0
github.com/inconshreveable/mousetrap github.com/inconshreveable/mousetrap
# github.com/karalabe/xgo v0.0.0-20181007145344-72da7d1d3970
github.com/karalabe/xgo
# github.com/magiconair/properties v1.8.0 # github.com/magiconair/properties v1.8.0
github.com/magiconair/properties github.com/magiconair/properties
# github.com/matttproud/golang_protobuf_extensions v1.0.1 # github.com/matttproud/golang_protobuf_extensions v1.0.1
@ -79,3 +77,5 @@ golang.org/x/tools/go/gcexportdata
golang.org/x/tools/go/internal/gcimporter golang.org/x/tools/go/internal/gcimporter
# gopkg.in/yaml.v2 v2.2.2 # gopkg.in/yaml.v2 v2.2.2
gopkg.in/yaml.v2 gopkg.in/yaml.v2
# src.techknowlogick.com/xgo v0.0.0-20190415010919-1502273fab15
src.techknowlogick.com/xgo

53
vendor/src.techknowlogick.com/xgo/.drone.jsonnet generated vendored Normal file
View File

@ -0,0 +1,53 @@
local BuildSwitchDryRun(version='go-latest', tags='latest', dry=false) = {
name: if dry then 'dry-run-' + version else 'build-' + version,
pull: 'always',
image: 'plugins/docker',
settings: {
dockerfile: 'docker/' + version + '/Dockerfile',
context: 'docker/' + version,
password: {
from_secret: 'docker_password'
},
username: {
from_secret: 'docker_username'
},
repo: 'techknowlogick/xgo',
tags: tags,
dry_run: dry
},
[if !dry then 'when']: {
branch: ['master'],
event: {exclude: ['pull_request']}
},
[if dry then 'when']: {
event: {include: ['pull_request']}
},
};
local BuildWithDiffTags(version='go-latest', tags='latest') = BuildSwitchDryRun(version, tags, false);
local BuildWithDiffTagsDry(version='go-latest', tags='latest') = BuildSwitchDryRun(version, tags, true);
local BuildStep(version='go-latest') = BuildWithDiffTags(version, version);
local BuildStepDry(version='go-latest') = BuildSwitchDryRun(version, version, true);
{
kind: 'pipeline',
name: 'default',
steps: [
BuildStepDry('base'),
BuildStepDry('go-1.12.4'),
BuildStepDry('go-1.11.9'),
BuildStep('base'),
BuildStep('go-1.12.4'),
BuildStep('go-1.12.x'),
BuildWithDiffTags(),
BuildStep('go-1.11.9'),
BuildStep('go-1.11.x'),
BuildStep('go-1.12.3'),
BuildStep('go-1.12.2'),
BuildStep('go-1.12.1'),
BuildStep('go-1.12.0'),
BuildStep('go-1.11.8'),
BuildStep('go-1.11.7'),
]
}

289
vendor/src.techknowlogick.com/xgo/.drone.yml generated vendored Normal file
View File

@ -0,0 +1,289 @@
---
kind: pipeline
name: default
platform:
os: linux
arch: amd64
steps:
- name: dry-run-base
pull: always
image: plugins/docker
settings:
context: docker/base
dockerfile: docker/base/Dockerfile
dry_run: true
password:
from_secret: docker_password
repo: techknowlogick/xgo
tags: base
username:
from_secret: docker_username
when:
event:
- pull_request
- name: dry-run-go-1.12.4
pull: always
image: plugins/docker
settings:
context: docker/go-1.12.4
dockerfile: docker/go-1.12.4/Dockerfile
dry_run: true
password:
from_secret: docker_password
repo: techknowlogick/xgo
tags: go-1.12.4
username:
from_secret: docker_username
when:
event:
- pull_request
- name: dry-run-go-1.11.9
pull: always
image: plugins/docker
settings:
context: docker/go-1.11.9
dockerfile: docker/go-1.11.9/Dockerfile
dry_run: true
password:
from_secret: docker_password
repo: techknowlogick/xgo
tags: go-1.11.9
username:
from_secret: docker_username
when:
event:
- pull_request
- name: build-base
pull: always
image: plugins/docker
settings:
context: docker/base
dockerfile: docker/base/Dockerfile
password:
from_secret: docker_password
repo: techknowlogick/xgo
tags: base
username:
from_secret: docker_username
when:
branch:
- master
event:
exclude:
- pull_request
- name: build-go-1.12.4
pull: always
image: plugins/docker
settings:
context: docker/go-1.12.4
dockerfile: docker/go-1.12.4/Dockerfile
password:
from_secret: docker_password
repo: techknowlogick/xgo
tags: go-1.12.4
username:
from_secret: docker_username
when:
branch:
- master
event:
exclude:
- pull_request
- name: build-go-1.12.x
pull: always
image: plugins/docker
settings:
context: docker/go-1.12.x
dockerfile: docker/go-1.12.x/Dockerfile
password:
from_secret: docker_password
repo: techknowlogick/xgo
tags: go-1.12.x
username:
from_secret: docker_username
when:
branch:
- master
event:
exclude:
- pull_request
- name: build-go-latest
pull: always
image: plugins/docker
settings:
context: docker/go-latest
dockerfile: docker/go-latest/Dockerfile
password:
from_secret: docker_password
repo: techknowlogick/xgo
tags: latest
username:
from_secret: docker_username
when:
branch:
- master
event:
exclude:
- pull_request
- name: build-go-1.11.9
pull: always
image: plugins/docker
settings:
context: docker/go-1.11.9
dockerfile: docker/go-1.11.9/Dockerfile
password:
from_secret: docker_password
repo: techknowlogick/xgo
tags: go-1.11.9
username:
from_secret: docker_username
when:
branch:
- master
event:
exclude:
- pull_request
- name: build-go-1.11.x
pull: always
image: plugins/docker
settings:
context: docker/go-1.11.x
dockerfile: docker/go-1.11.x/Dockerfile
password:
from_secret: docker_password
repo: techknowlogick/xgo
tags: go-1.11.x
username:
from_secret: docker_username
when:
branch:
- master
event:
exclude:
- pull_request
- name: build-go-1.12.3
pull: always
image: plugins/docker
settings:
context: docker/go-1.12.3
dockerfile: docker/go-1.12.3/Dockerfile
password:
from_secret: docker_password
repo: techknowlogick/xgo
tags: go-1.12.3
username:
from_secret: docker_username
when:
branch:
- master
event:
exclude:
- pull_request
- name: build-go-1.12.2
pull: always
image: plugins/docker
settings:
context: docker/go-1.12.2
dockerfile: docker/go-1.12.2/Dockerfile
password:
from_secret: docker_password
repo: techknowlogick/xgo
tags: go-1.12.2
username:
from_secret: docker_username
when:
branch:
- master
event:
exclude:
- pull_request
- name: build-go-1.12.1
pull: always
image: plugins/docker
settings:
context: docker/go-1.12.1
dockerfile: docker/go-1.12.1/Dockerfile
password:
from_secret: docker_password
repo: techknowlogick/xgo
tags: go-1.12.1
username:
from_secret: docker_username
when:
branch:
- master
event:
exclude:
- pull_request
- name: build-go-1.12.0
pull: always
image: plugins/docker
settings:
context: docker/go-1.12.0
dockerfile: docker/go-1.12.0/Dockerfile
password:
from_secret: docker_password
repo: techknowlogick/xgo
tags: go-1.12.0
username:
from_secret: docker_username
when:
branch:
- master
event:
exclude:
- pull_request
- name: build-go-1.11.8
pull: always
image: plugins/docker
settings:
context: docker/go-1.11.8
dockerfile: docker/go-1.11.8/Dockerfile
password:
from_secret: docker_password
repo: techknowlogick/xgo
tags: go-1.11.8
username:
from_secret: docker_username
when:
branch:
- master
event:
exclude:
- pull_request
- name: build-go-1.11.7
pull: always
image: plugins/docker
settings:
context: docker/go-1.11.7
dockerfile: docker/go-1.11.7/Dockerfile
password:
from_secret: docker_password
repo: techknowlogick/xgo
tags: go-1.11.7
username:
from_secret: docker_username
when:
branch:
- master
event:
exclude:
- pull_request
...

View File

@ -38,12 +38,12 @@ a single command to compile a Go package to various platforms and architectures.
Although you could build the container manually, it is available as an automatic Although you could build the container manually, it is available as an automatic
trusted build from Docker's container registry (not insignificant in size): trusted build from Docker's container registry (not insignificant in size):
docker pull karalabe/xgo-latest docker pull techknowlogick/xgo:latest
To prevent having to remember a potentially complex Docker command every time, To prevent having to remember a potentially complex Docker command every time,
a lightweight Go wrapper was written on top of it. a lightweight Go wrapper was written on top of it.
go get github.com/karalabe/xgo go get src.techknowlogick.com/xgo
## Usage ## Usage
@ -202,8 +202,6 @@ versions of the same operating system. This however can lead to issues if a used
dependency is only supported by more recent systems. As such, `xgo` supports the dependency is only supported by more recent systems. As such, `xgo` supports the
selection of specific platform versions by appending them to the OS target string. selection of specific platform versions by appending them to the OS target string.
* `--targets=ios-8.1/*`: cross compile to iOS 8.1
* `--targets=android-16/*`: cross compile to Android Jelly Bean
* `--targets=darwin-10.9/*`: cross compile to Mac OS X Mavericks * `--targets=darwin-10.9/*`: cross compile to Mac OS X Mavericks
* `--targets=windows-6.0/*`: cross compile to Windows Vista * `--targets=windows-6.0/*`: cross compile to Windows Vista
@ -211,24 +209,7 @@ The supported platforms are:
* All Android APIs up to Android Lollipop 5.0 ([API level ids](https://source.android.com/source/build-numbers.html)) * All Android APIs up to Android Lollipop 5.0 ([API level ids](https://source.android.com/source/build-numbers.html))
* All Windows APIs up to Windows 8.1 limited by `mingw-w64` ([API level ids](https://en.wikipedia.org/wiki/Windows_NT#Releases)) * All Windows APIs up to Windows 8.1 limited by `mingw-w64` ([API level ids](https://en.wikipedia.org/wiki/Windows_NT#Releases))
* OSX APIs in the range of 10.6 - 10.11 * OSX APIs in the range of 10.6 - 10.14
* All iOS APIs up to iOS 9.3
### Mobile libraries
Apart from the usual runnable binaries, `xgo` also supports building library
archives for Android (`android/aar`) and iOS (`ios/framework`). Opposed to
`gomobile` however `xgo` does not derive library APIs from the Go code, so
proper CGO C external methods must be defined within the package.
In the case of Android archives, all architectures will be bundled that are
supported by the requested Android platform version. For iOS frameworks `xgo`
will bundle armv7 and arm64 by default, and also the x86_64 simulator builds
if the iPhoneSimulator.sdk was injected by the user:
* Create a new docker image based on xgo: `FROM karalabe/xgo-latest`
* Inject the simulator SDK: `ADD iPhoneSimulator9.3.sdk.tar.xz /iPhoneSimulator9.3.sdk.tar.xz`
* Bootstrap the simulator SDK: `$UPDATE_IOS /iPhoneSimulator9.3.sdk.tar.xz`
### CGO dependencies ### CGO dependencies

View File

@ -26,11 +26,10 @@ var layers = []struct {
tag string tag string
dir string dir string
}{ }{
{"karalabe/xgo-base", "base"}, {"techknowlogick/xgo:base", "base"},
{"karalabe/xgo-1.6.2", "go-1.6.2"}, {"techknowlogick/xgo:1.12.4", "go-1.12.4"},
{"karalabe/xgo-1.6.x", "go-1.6.x"}, {"techknowlogick/xgo:1.12.x", "go-1.12.x"},
{"karalabe/xgo-latest", "go-latest"}, {"techknowlogick/xgo:latest", "go-latest"},
//{"karalabe/xgo-latest-ios", "go-latest-ios"}, // Non-public layer (XCode licensing)
} }
// tests defaines all the input test cases and associated arguments the cross // tests defaines all the input test cases and associated arguments the cross
@ -44,12 +43,11 @@ var tests = []struct {
{"github.com/karalabe/xgo/tests/embedded_cpp", nil}, {"github.com/karalabe/xgo/tests/embedded_cpp", nil},
// Baseline projects to ensure minimal requirements // Baseline projects to ensure minimal requirements
//{"github.com/project-iris/iris", nil}, // Deps failed, disable
{"github.com/ethereum/go-ethereum/cmd/geth", []string{"--branch", "develop"}}, {"github.com/ethereum/go-ethereum/cmd/geth", []string{"--branch", "develop"}},
// Third party projects using xgo, smoke test that they don't break // Third party projects using xgo, smoke test that they don't break
{"github.com/rwcarlsen/cyan/cmd/cyan", nil}, {"github.com/rwcarlsen/cyan/cmd/cyan", nil},
{"github.com/cockroachdb/cockroach", []string{"--targets", "darwin-10.11/amd64"}}, {"github.com/cockroachdb/cockroach", []string{"--targets", "darwin-10.6/amd64"}},
} }
func main() { func main() {

View File

@ -4,7 +4,7 @@
// Released under the MIT license. // Released under the MIT license.
// Wrapper around the GCO cross compiler docker container. // Wrapper around the GCO cross compiler docker container.
package main package main // import "src.techknowlogick.com/xgo"
import ( import (
"bytes" "bytes"
@ -39,8 +39,8 @@ func init() {
} }
// Cross compilation docker containers // Cross compilation docker containers
var dockerBase = "karalabe/xgo-base" var dockerBase = "techknowlogick/xgo:base"
var dockerDist = "karalabe/xgo-" var dockerDist = "techknowlogick/xgo:"
// Command line arguments to fine tune the compilation // Command line arguments to fine tune the compilation
var ( var (
@ -233,49 +233,58 @@ func pullDockerImage(image string) error {
func compile(image string, config *ConfigFlags, flags *BuildFlags, folder string) error { func compile(image string, config *ConfigFlags, flags *BuildFlags, folder string) error {
// If a local build was requested, find the import path and mount all GOPATH sources // If a local build was requested, find the import path and mount all GOPATH sources
locals, mounts, paths := []string{}, []string{}, []string{} locals, mounts, paths := []string{}, []string{}, []string{}
var usesModules bool
if strings.HasPrefix(config.Repository, string(filepath.Separator)) || strings.HasPrefix(config.Repository, ".") { if strings.HasPrefix(config.Repository, string(filepath.Separator)) || strings.HasPrefix(config.Repository, ".") {
// Resolve the repository import path from the file path // Resolve the repository import path from the file path
config.Repository = resolveImportPath(config.Repository) config.Repository = resolveImportPath(config.Repository)
// Determine if this is a module-based repository
var modFile = config.Repository + "/go.mod"
_, err := os.Stat(modFile)
usesModules = !os.IsNotExist(err)
// Iterate over all the local libs and export the mount points // Iterate over all the local libs and export the mount points
if os.Getenv("GOPATH") == "" { if os.Getenv("GOPATH") == "" && !usesModules {
log.Fatalf("No $GOPATH is set or forwarded to xgo") log.Fatalf("No $GOPATH is set or forwarded to xgo")
} }
for _, gopath := range strings.Split(os.Getenv("GOPATH"), string(os.PathListSeparator)) { if !usesModules {
// Since docker sandboxes volumes, resolve any symlinks manually for _, gopath := range strings.Split(os.Getenv("GOPATH"), string(os.PathListSeparator)) {
sources := filepath.Join(gopath, "src") // Since docker sandboxes volumes, resolve any symlinks manually
filepath.Walk(sources, func(path string, info os.FileInfo, err error) error { sources := filepath.Join(gopath, "src")
// Skip any folders that errored out filepath.Walk(sources, func(path string, info os.FileInfo, err error) error {
if err != nil { // Skip any folders that errored out
log.Printf("Failed to access GOPATH element %s: %v", path, err) if err != nil {
log.Printf("Failed to access GOPATH element %s: %v", path, err)
return nil
}
// Skip anything that's not a symlink
if info.Mode()&os.ModeSymlink == 0 {
return nil
}
// Resolve the symlink and skip if it's not a folder
target, err := filepath.EvalSymlinks(path)
if err != nil {
return nil
}
if info, err = os.Stat(target); err != nil || !info.IsDir() {
return nil
}
// Skip if the symlink points within GOPATH
if filepath.HasPrefix(target, sources) {
return nil
}
// Folder needs explicit mounting due to docker symlink security
locals = append(locals, target)
mounts = append(mounts, filepath.Join("/ext-go", strconv.Itoa(len(locals)), "src", strings.TrimPrefix(path, sources)))
paths = append(paths, filepath.Join("/ext-go", strconv.Itoa(len(locals))))
return nil return nil
} })
// Skip anything that's not a symlink // Export the main mount point for this GOPATH entry
if info.Mode()&os.ModeSymlink == 0 { locals = append(locals, sources)
return nil mounts = append(mounts, filepath.Join("/ext-go", strconv.Itoa(len(locals)), "src"))
}
// Resolve the symlink and skip if it's not a folder
target, err := filepath.EvalSymlinks(path)
if err != nil {
return nil
}
if info, err = os.Stat(target); err != nil || !info.IsDir() {
return nil
}
// Skip if the symlink points within GOPATH
if filepath.HasPrefix(target, sources) {
return nil
}
// Folder needs explicit mounting due to docker symlink security
locals = append(locals, target)
mounts = append(mounts, filepath.Join("/ext-go", strconv.Itoa(len(locals)), "src", strings.TrimPrefix(path, sources)))
paths = append(paths, filepath.Join("/ext-go", strconv.Itoa(len(locals)))) paths = append(paths, filepath.Join("/ext-go", strconv.Itoa(len(locals))))
return nil }
})
// Export the main mount point for this GOPATH entry
locals = append(locals, sources)
mounts = append(mounts, filepath.Join("/ext-go", strconv.Itoa(len(locals)), "src"))
paths = append(paths, filepath.Join("/ext-go", strconv.Itoa(len(locals))))
} }
} }
// Assemble and run the cross compilation command // Assemble and run the cross compilation command
@ -299,10 +308,32 @@ func compile(image string, config *ConfigFlags, flags *BuildFlags, folder string
"-e", fmt.Sprintf("FLAG_BUILDMODE=%s", flags.Mode), "-e", fmt.Sprintf("FLAG_BUILDMODE=%s", flags.Mode),
"-e", "TARGETS=" + strings.Replace(strings.Join(config.Targets, " "), "*", ".", -1), "-e", "TARGETS=" + strings.Replace(strings.Join(config.Targets, " "), "*", ".", -1),
} }
for i := 0; i < len(locals); i++ { if usesModules {
args = append(args, []string{"-v", fmt.Sprintf("%s:%s:ro", locals[i], mounts[i])}...) args = append(args, []string{"-e", "GO111MODULE=on"}...)
args = append(args, []string{"-v", os.Getenv("GOPATH") + ":/go"}...)
// Map this repository to the /source folder
absRepository, err := filepath.Abs(config.Repository)
if err != nil {
log.Fatalf("Failed to locate requested module repository: %v.", err)
}
args = append(args, []string{"-v", absRepository + ":/source"}...)
fmt.Printf("Enabled Go module support\n")
// Check whether it has a vendor folder, and if so, use it
vendorPath := absRepository + "/vendor"
vendorfolder, err := os.Stat(vendorPath)
if !os.IsNotExist(err) && vendorfolder.Mode().IsDir() {
args = append(args, []string{"-e", "FLAG_MOD=vendor"}...)
fmt.Printf("Using vendored Go module dependencies\n")
}
} else {
for i := 0; i < len(locals); i++ {
args = append(args, []string{"-v", fmt.Sprintf("%s:%s:ro", locals[i], mounts[i])}...)
}
args = append(args, []string{"-e", "EXT_GOPATH=" + strings.Join(paths, ":")}...)
} }
args = append(args, []string{"-e", "EXT_GOPATH=" + strings.Join(paths, ":")}...)
args = append(args, []string{image, config.Repository}...) args = append(args, []string{image, config.Repository}...)
return run(exec.Command("docker", args...)) return run(exec.Command("docker", args...))