# vim: filetype=yaml sw=2
version: '1.23.8'
filename: '[% project %]-[% c("version") %]-[% c("var/osname") %]-[% c("var/build_id") %].tar.[% c("compress_tar") %]'
container:
  use_container: 1

var:
  source_sha256: 0ca1f1e37ea255e3ce283af3f4e628502fb444587da987a5bb96d6c6f15930d4
  no_crosscompile: 1
  setup: |
    mkdir -p /var/tmp/dist
    tar -C /var/tmp/dist -xf $rootdir/[% c("go_tarfile") %]
    [% IF pc(c("origin_project"), "var/no_crosscompile") -%]
      export GOOS=linux
      export GOARCH=amd64
    [% ELSE -%]
      export GOOS=[% c("var/GOOS") %]
      export GOARCH=[% c("var/GOARCH") %]
    [% END -%]
    export PATH=/var/tmp/dist/go/bin:/var/tmp/dist/gopath/bin:"$PATH"
    [% IF c("var/linux") -%]
      export CGO_LDFLAGS_ALLOW="-z|noexecstack"
      export CGO_LDFLAGS="-z noexecstack"
    [% END -%]
    [% IF c("var/cgo") -%]
      export CGO_ENABLED=1
    [% END -%]
    export GOTMPDIR=/var/tmp/build/go-tmp
    mkdir -p "$GOTMPDIR"

  # Template build script for building a go library.
  # This can be called as projects/go/var/build_go_lib.
  # You need to define /var/go_lib, and optionally var/go_lib_install as
  # a list of install targets.
  build_go_lib: |
    #!/bin/bash
    [% c("var/set_default_env") -%]
    [% pc('go', 'var/setup', { go_tarfile => c('input_files_by_name/go') }) %]
    # Run in GOPATH mode: https://golang.org/cmd/go/#hdr-Module_support. (see:
    # #32027)
    export GO111MODULE=off
    export GOPATH=/var/tmp/dist/gopath
    distdir=/var/tmp/dist/[% project %]
    mkdir -p /var/tmp/build
    tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.[% c('compress_tar') %]
    [% FOREACH dep = c("var/go_lib_deps") -%]
      tar -C /var/tmp/dist -xf [% c('input_files_by_name/' _ dep) %]
    [% END -%]
    mkdir -p $(dirname "$GOPATH/src/[% c("var/go_lib") %]")
    mv /var/tmp/build/[% project %]-[% c('version') %] "$GOPATH/src/[% c("var/go_lib") %]"
    cd "$GOPATH/src/[% c("var/go_lib") %]"
    for p in $(ls -1 $rootdir/*.patch 2> /dev/null | sort)
    do
      patch -p1 < $p
    done
    # Run in GOPATH mode: https://golang.org/cmd/go/#hdr-Module_support. (see:
    # #32027)
    export GO111MODULE=off
    [% IF c("var/build_go_lib_pre"); GET c("var/build_go_lib_pre"); END; -%]
    [% IF c("var/go_lib_install") -%]
      [% FOREACH inst IN c("var/go_lib_install") %]
        go install [% inst %]
      [% END %]
    [% ELSE %]
      go install [% c("var/go_lib") %]
    [% END %]
    cd /var/tmp/dist
    [% c('tar', {
            tar_src => [ 'gopath' ],
            tar_args => '-caf ' _ dest_dir _ '/' _ c('filename'),
        }) %]

targets:
  windows:
    var:
      GOOS: windows
  windows-i686:
    var:
      GOARCH: 386
  windows-x86_64:
    var:
      GOARCH: amd64
  macos-x86_64:
    var:
      GOARCH: amd64
  macos-aarch64:
    var:
      GOARCH: arm64
  macos:
    version: 1.22.12
    var:
      source_sha256: 012a7e1f37f362c0918c1dfa3334458ac2da1628c4b9cf4d9ca02db986e17d71
      GOOS: darwin
  linux:
    var:
      GOOS: linux
  linux-x86_64:
    var:
      GOARCH: amd64
  linux-i686:
    var:
      GOARCH: 386
  linux-aarch64:
    var:
      GOARCH: arm64
  linux-arm:
    var:
      GOARCH: arm
  android:
    var:
      GOOS: android
  android-x86:
    var:
      GOARCH: 386
  android-x86_64:
    var:
      GOARCH: amd64
  android-armv7:
    var:
      GOARCH: arm
  android-aarch64:
    var:
      GOARCH: arm64

input_files:
  - project: container-image
  - name: '[% c("var/compiler") %]'
    project: '[% c("var/compiler") %]'
    enable: '[% ! c("var/linux") %]'
  - URL: 'https://go.dev/dl/go[% c("version") %].src.tar.gz'
    name: go
    sha256sum: '[% c("var/source_sha256") %]'
  - project: go-bootstrap
    name: go-bootstrap
    target_replace:
      '^.*browser-(?!testbuild).*': 'basebrowser-linux-x86_64'
  - filename: 0001-Use-fixed-go-build-tmp-directory.patch
    enable: '[% c("var/android") %]'
