Skip to content

Commit

Permalink
Cross Compile in Parallel two archs at a time (#825)
Browse files Browse the repository at this point in the history
* Cross Compile in Parallel two archs at a time

Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>

* Remove echo. Fix args

Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
  • Loading branch information
dvaldivia authored Jun 18, 2021
1 parent b14d67e commit 83ca73e
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 9 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/crosscompile-1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Go

on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:
build:
name: Cross compile
runs-on: ${{ matrix.os }}
strategy:
matrix:
go-version: [1.16.x]
os: [ubuntu-latest]
steps:
- name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Build on ${{ matrix.os }}
env:
GO111MODULE: on
GOOS: linux
run: |
make crosscompile arg1="'linux/ppc64le linux/mips64'"
34 changes: 34 additions & 0 deletions .github/workflows/crosscompile-2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Go

on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:
build:
name: Cross compile
runs-on: ${{ matrix.os }}
strategy:
matrix:
go-version: [1.16.x]
os: [ubuntu-latest]
steps:
- name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Build on ${{ matrix.os }}
env:
GO111MODULE: on
GOOS: linux
run: |
make crosscompile arg1="'linux/arm64 linux/s390x'"
34 changes: 34 additions & 0 deletions .github/workflows/crosscompile-3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Go

on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:
build:
name: Cross compile
runs-on: ${{ matrix.os }}
strategy:
matrix:
go-version: [1.16.x]
os: [ubuntu-latest]
steps:
- name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Build on ${{ matrix.os }}
env:
GO111MODULE: on
GOOS: linux
run: |
make crosscompile arg1="'darwin/amd64 freebsd/amd64'"
34 changes: 34 additions & 0 deletions .github/workflows/crosscompile-4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Go

on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:
build:
name: Cross compile
runs-on: ${{ matrix.os }}
strategy:
matrix:
go-version: [1.16.x]
os: [ubuntu-latest]
steps:
- name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Build on ${{ matrix.os }}
env:
GO111MODULE: on
GOOS: linux
run: |
make crosscompile arg1="'windows/amd64 linux/arm'"
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
GO111MODULE: on
GOOS: linux
run: |
make crosscompile
make crosscompile arg1="'linux/386 netbsd/amd64'"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fmt:
@GO111MODULE=on gofmt -d cluster/

crosscompile:
@(env bash $(PWD)/cross-compile.sh)
@(env bash $(PWD)/cross-compile.sh $(arg1))

lint:
@echo "Running $@ check"
Expand Down
13 changes: 6 additions & 7 deletions cross-compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ set -e
# Enable tracing if set.
[ -n "$BASH_XTRACEFD" ] && set -x

_init() {
## All binaries are static make sure to disable CGO.
export CGO_ENABLED=0
## All binaries are static make sure to disable CGO.
export CGO_ENABLED=0

## List of architectures and OS to test coss compilation.
SUPPORTED_OSARCH="linux/ppc64le linux/mips64 linux/arm64 linux/s390x darwin/amd64 freebsd/amd64 windows/amd64 linux/arm linux/386 netbsd/amd64"
}
## List of architectures and OS to test cross compilation.
SUPPORTED_OSARCH_DEFAULTS="linux/ppc64le linux/mips64 linux/arm64 linux/s390x darwin/amd64 freebsd/amd64 windows/amd64 linux/arm linux/386 netbsd/amd64"
SUPPORTED_OSARCH=${1:-$SUPPORTED_OSARCH_DEFAULTS}

_build() {
local osarch=$1
Expand All @@ -31,4 +30,4 @@ main() {
done
}

_init && main "$@"
main "$@"

0 comments on commit 83ca73e

Please sign in to comment.