platform: linux
image: docker:///cloudfoundry/cli-ci

inputs:
- name: cli
  path: gopath/src/github.com/cloudfoundry/cli

outputs:
- name: cross-compiled

run:
  path: bash
  args:
  - -c
  - |
    set -ex

    cwd=$PWD

    export GOPATH=$PWD/gopath
    export PATH=$GOPATH/bin:$PATH

    go version

    pushd $GOPATH/src/github.com/cloudfoundry/cli
      bin/replace-sha

      echo "Building 32-bit Linux"
      GOARCH=386 GOOS=linux go build -ldflags '-extldflags "-static"' -o out/cf-cli_linux_i686 ./main

      echo "Building 32-bit Windows"
      GOARCH=386 GOOS=windows go build -o out/cf-cli_win32.exe ./main

      echo "Building 64-bit Linux"
      GOARCH=amd64 GOOS=linux go build -ldflags '-extldflags "-static"' -o out/cf-cli_linux_x86-64 ./main

      echo "Building 64-bit Windows"
      GOARCH=amd64 GOOS=windows go build -o out/cf-cli_winx64.exe ./main

      echo "Creating tarball"
      tar -cvzf $cwd/cross-compiled/cf-cli-binaries.tgz -C out .
    popd

platform: linux
image: docker:///cloudfoundry/cli-ci

inputs:
- name: cli
  path: gopath/src/github.com/cloudfoundry/cli

outputs:
- name: cross-compiled

run:
  path: bash
  args:
  - -c
  - |
    set -ex

    cwd=$PWD

    export GOPATH=$PWD/gopath
    export PATH=$GOPATH/bin:$PATH

    go version

    pushd $GOPATH/src/github.com/cloudfoundry/cli
      bin/replace-sha

      echo "Building 32-bit Linux"
      CGO_ENABLED=0 GOARCH=386 GOOS=linux go build -a -tags netgo -installsuffix netgo -ldflags '-extldflags "-static"' -o out/cf-cli_linux_i686 ./main

      echo "Building 32-bit Windows"
      GOARCH=386 GOOS=windows go build -o out/cf-cli_win32.exe ./main

      echo "Building 64-bit Linux"
      CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -a -tags netgo -installsuffix netgo -ldflags '-extldflags "-static"' -o out/cf-cli_linux_x86-64 ./main

      echo "Building 64-bit Windows"
      GOARCH=amd64 GOOS=windows go build -o out/cf-cli_winx64.exe ./main

      echo "Creating tarball"
      tar -cvzf $cwd/cross-compiled/cf-cli-binaries.tgz -C out .
    popd

Use all these magic flags to build static binaries
Use all these magic flags to build static binaries

Even though the CLI was forcing static linking of C libraries, it
appears that this was not fully working. Through further investigation,
and the recommendation of
https://tschottdorf.github.io/linking-golang-go-statically-cgo-testing/
we added several flags that should force the use of golang's internal
networking libraries (netgo) and should not call out to C.

[Finishes #119703447, 120437611] (Github issue #843, #848)
