distributable:
  url: https://github.com/xo/usql/archive/refs/tags/v{{version}}.tar.gz
  strip-components: 1

versions:
  github: xo/usql

provides:
  - bin/usql

build:
  dependencies:
    go.dev: ^1.21
    crates.io/sd: "*"
  script:
    - sd 0.0.0-dev v{{version}} text/text.go
    - go mod download
    - mkdir -p "{{ prefix }}"/bin
    - go build -v -trimpath -ldflags="$LDFLAGS" -o $BUILDLOC .
  env:
    GOPROXY: https://proxy.golang.org,direct
    GOSUMDB: sum.golang.org
    GO111MODULE: on
    CGO_ENABLED: 1
    BUILDLOC: "{{prefix}}/bin/usql"
    LDFLAGS:
      - -s
      - -w
    linux:
      # or segmentation fault
      # fix found here https://github.com/docker-library/golang/issues/402#issuecomment-982204575
      LDFLAGS:
        - -buildmode=pie

test:
  script:
    # No LDFLAGS
    # https://github.com/xo/usql/blob/master/text/text.go#L13
    - test "$(usql --version)" = "usql v{{version}}"
