T
Task16mo ago
leaanthony

Default to $GOARCH

Seems like a daft question: How can I pass a custom arch to a task but have that task default to $GOARCH? I've tried:
build:
cmds:
- GOOS=darwin GOARCH={{.ARCH}} go build -tags production -ldflags="-w -s" -o build/bin/{{.APP_NAME}}
vars:
ARCH: $GOARCH
build:
cmds:
- GOOS=darwin GOARCH={{.ARCH}} go build -tags production -ldflags="-w -s" -o build/bin/{{.APP_NAME}}
vars:
ARCH: $GOARCH
Can't seem to find anything in the docs about it
2 Replies
leaanthony
leaanthonyOP16mo ago
I just discovered {{ARCH}} but that seems to match the arch Task was compiled on, even though {{OS}} matches the current OS... https://taskfile.dev/usage/#gos-template-engine. I guess it wouldn't matter in the majority of cases as the binary will be aligned to the arch? Would be good to have GOOS and GOARCH available though.
Usage | Task
Getting started
andreynering
andreynering16mo ago
Hi @leaanthony, You are probably looking to something like this:
arch:
vars:
ARCH: '{{.ARCH | default ARCH}}'
cmds:
- echo "{{.ARCH}}"
arch:
vars:
ARCH: '{{.ARCH | default ARCH}}'
cmds:
- echo "{{.ARCH}}"

Did you find this page helpful?