Skip to content

Commit

Permalink
contrib: Use xgo to use Cgo in cross-compiled release builds. (#5120)
Browse files Browse the repository at this point in the history
This updates the release.sh script to use xgo for Linux, Windows,
and Darwin builds. This uses
https://github.com/techknowlogick/xgo/, which is a maintained
fork of https://github.com/karalabe/xgo.

This fixes the panics related to Badger compression which only
uses Zstd when Cgo is enabled. See #4995.

v20.03.0 and v20.03.1 were already built with this change to fix
macOS and Windows binaries. Linux builds were working fine.

Fixes #4995, DGRAPH-1139
  • Loading branch information
danielmai committed May 28, 2020
1 parent 5fc7b50 commit 06b04af
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions contrib/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ go get -u github.com/dgraph-io/dgo
go get -u github.com/dgraph-io/badger
go get -u github.com/golang/protobuf/protoc-gen-go
go get -u github.com/gogo/protobuf/protoc-gen-gofast
go get -u src.techknowlogick.com/xgo

pushd $GOPATH/src/google.golang.org/grpc
git checkout v1.13.0
Expand Down Expand Up @@ -119,66 +120,57 @@ popd

# Build Windows.
pushd $basedir/dgraph/dgraph
env GOOS=windows GOARCH=amd64 go get -v -d .
env GOOS=windows GOARCH=amd64 GO111MODULE=on go build -v -o dgraph-windows-amd64.exe -ldflags \
xgo -go="go-$GOVERSION" --targets=windows/amd64 -ldflags \
"-X $release=$release_version -X $branch=$gitBranch -X $commitSHA1=$lastCommitSHA1 -X '$commitTime=$lastCommitTime'" .
mkdir $TMP/windows
mv dgraph-windows-amd64.exe $TMP/windows/dgraph.exe
mv dgraph-windows-4.0-amd64.exe $TMP/windows/dgraph.exe
popd

pushd $basedir/badger/badger
env GOOS=windows GOARCH=amd64 go get -v -d .
env GOOS=windows GOARCH=amd64 GO111MODULE=on go build -v -o badger-windows-amd64.exe .
mv badger-windows-amd64.exe $TMP/windows/badger.exe
xgo -go="go-$GOVERSION" --targets=windows/amd64 .
mv badger-windows-4.0-amd64.exe $TMP/windows/badger.exe
popd

pushd $basedir/ratel
env GOOS=windows GOARCH=amd64 go get -v -d .
env GOOS=windows GOARCH=amd64 go build -v -o ratel-windows-amd64.exe -ldflags "-X $ratel_release=$release_version" .
mv ratel-windows-amd64.exe $TMP/windows/dgraph-ratel.exe
xgo -go="go-$GOVERSION" --targets=windows/amd64 -ldflags "-X $ratel_release=$release_version" .
mv ratel-windows-4.0-amd64.exe $TMP/windows/dgraph-ratel.exe
popd

# Build Darwin.
pushd $basedir/dgraph/dgraph
env GOOS=darwin GOARCH=amd64 go get -v -d .
env GOOS=darwin GOARCH=amd64 GO111MODULE=on go build -v -o dgraph-darwin-amd64 -ldflags \
"-X $release=$release_version -X $branch=$gitBranch -X $commitSHA1=$lastCommitSHA1 -X '$commitTime=$lastCommitTime'" .
xgo -go="go-$GOVERSION" --targets=darwin-10.9/amd64 -ldflags \
"-X $release=$release_version -X $branch=$gitBranch -X $commitSHA1=$lastCommitSHA1 -X '$commitTime=$lastCommitTime'" .
mkdir $TMP/darwin
mv dgraph-darwin-amd64 $TMP/darwin/dgraph
mv dgraph-darwin-10.9-amd64 $TMP/darwin/dgraph
popd

pushd $basedir/badger/badger
env GOOS=darwin GOARCH=amd64 go get -v -d .
env GOOS=darwin GOARCH=amd64 GO111MODULE=on go build -v -o badger-darwin-amd64 .
mv badger-darwin-amd64 $TMP/darwin/badger
xgo -go="go-$GOVERSION" --targets=darwin-10.9/amd64 .
mv badger-darwin-10.9-amd64 $TMP/darwin/badger
popd

pushd $basedir/ratel
env GOOS=darwin GOARCH=amd64 go get -v -d .
env GOOS=darwin GOARCH=amd64 go build -v -o ratel-darwin-amd64 -v -ldflags "-X $ratel_release=$release_version" .
mv ratel-darwin-amd64 $TMP/darwin/dgraph-ratel
xgo -go="go-$GOVERSION" --targets=darwin-10.9/amd64 -ldflags "-X $ratel_release=$release_version" .
mv ratel-darwin-10.9-amd64 $TMP/darwin/dgraph-ratel
popd

# Build Linux.
pushd $basedir/dgraph/dgraph
env GOOS=linux GOARCH=amd64 go get -v -d .
env GOOS=linux GOARCH=amd64 GO111MODULE=on go build -v -o dgraph-linux-amd64 -ldflags \
xgo -go="go-$GOVERSION" --targets=linux/amd64 -ldflags \
"-X $release=$release_version -X $branch=$gitBranch -X $commitSHA1=$lastCommitSHA1 -X '$commitTime=$lastCommitTime'" .
strip -x dgraph-linux-amd64
mkdir $TMP/linux
mv dgraph-linux-amd64 $TMP/linux/dgraph
popd

pushd $basedir/badger/badger
env GOOS=linux GOARCH=amd64 go get -v -d .
env GOOS=linux GOARCH=amd64 GO111MODULE=on go build -v -o badger-linux-amd64 .
xgo -go="go-$GOVERSION" --targets=linux/amd64 .
strip -x badger-linux-amd64
mv badger-linux-amd64 $TMP/linux/badger
popd

pushd $basedir/ratel
env GOOS=linux GOARCH=amd64 go get -v -d .
env GOOS=linux GOARCH=amd64 go build -v -o ratel-linux-amd64 -ldflags "-X $ratel_release=$release_version" .
xgo -go="go-$GOVERSION" --targets=linux/amd64 -ldflags "-X $ratel_release=$release_version" .
strip -x ratel-linux-amd64
mv ratel-linux-amd64 $TMP/linux/dgraph-ratel
popd
Expand Down

0 comments on commit 06b04af

Please sign in to comment.