tinygo
tinygo copied to clipboard
tinygo 0.27 cannot compile to GOOS=darwin
Anytime I try to add GOOS=darwin
during compile-time, I get the following error:
GOOS=darwin tinygo build .
# runtime
/usr/local/lib/tinygo/src/runtime/scheduler.go:22:24: undefined: GOOS
/usr/local/lib/tinygo/src/runtime/runtime_unix.go:181:17: undefined: clock_MONOTONIC_RAW
/usr/local/lib/tinygo/src/runtime/runtime_unix.go:191:16: undefined: clock_REALTIME
/usr/local/lib/tinygo/src/runtime/runtime_unix.go:225:34: undefined: flag_PROT_READ
/usr/local/lib/tinygo/src/runtime/runtime_unix.go:225:49: undefined: flag_PROT_WRITE
/usr/local/lib/tinygo/src/runtime/runtime_unix.go:225:66: undefined: flag_MAP_PRIVATE
/usr/local/lib/tinygo/src/runtime/runtime_unix.go:225:83: undefined: flag_MAP_ANONYMOUS
- Using tinygo_0.27.0_arm64.deb on linux docker image (host machine is m1 macbook).
- Also doesn't work when using amd64 linux image.
- WORKS with GOOS=linux and GOOS=windows
I can't reproduce this in a Debian LXC container (on arm64).
I suspect something went wrong with your installation. Can you share the output of which tinygo
and tinygo env
?
I develop entirely on Darwin and I also don't have this problem. Definitely something with the install.
I am using golang:1.20 image from dockerhub:
root@3ad92dcfe559:/app/tinyVisualizer# cat /etc/*release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
root@3ad92dcfe559:/app/tinyVisualizer# which tinygo
/usr/local/bin/tinygo
root@3ad92dcfe559:/app/tinyVisualizer# tinygo env
GOOS="linux"
GOARCH="arm64"
GOROOT="/usr/local/go"
GOPATH="/go"
GOCACHE="/root/.cache/tinygo"
CGO_ENABLED="0"
TINYGOROOT="/usr/local/lib/tinygo"
dockerfile to reproduce issue (omited copy sourcecode step) :
FROM --platform=linux/arm64 golang:1.20 as builder
USER root
WORKDIR /app/
RUN apt-get update && apt-get install wget -y
ENV GOPATH=/go
ENV CGO_ENABLED=0
RUN echo "package main\n\nimport \"fmt\"\n\nfunc main() {\n fmt.Println(\"Hello, World!\")\n}" > main.go
RUN go mod init tiny
RUN wget https://github.com/tinygo-org/tinygo/releases/download/v0.27.0/tinygo_0.27.0_arm64.deb \
&& dpkg -i tinygo_0.27.0_arm64.deb
RUN GOOS=darwin GOARCH=arm64 tinygo build .
result:
docker build -t test .
[+] Building 121.5s (10/10) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 507B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/golang:1.20 2.5s
=> [1/7] FROM docker.io/library/golang:1.20@sha256:9911e9376e45de1ba865b16d878c0f7d063391fe4b7cedf39869874126741e62 0.0s
=> CACHED [2/7] WORKDIR /app/ 0.0s
=> [3/7] RUN apt-get update && apt-get install wget -y 24.4s
=> [4/7] RUN echo "package main\n\nimport "fmt"\n\nfunc main() {\n fmt.Println("Hello, World!")\n}" > main.go 0.4s
=> [5/7] RUN go mod init tiny 0.2s
=> [6/7] RUN wget https://github.com/tinygo-org/tinygo/releases/download/v0.27.0/tinygo_0.27.0_arm64.deb && dpkg -i tinygo_0.27.0_arm64.deb 93.3s
=> ERROR [7/7] RUN GOOS=darwin GOARCH=arm64 tinygo build . 0.5s
------
> [7/7] RUN GOOS=darwin GOARCH=arm64 tinygo build .:
#10 0.457 # runtime
#10 0.457 /usr/local/lib/tinygo/src/runtime/scheduler.go:22:24: undefined: GOOS
#10 0.457 /usr/local/lib/tinygo/src/runtime/gc_blocks.go:419:2: undefined: markGlobals
#10 0.457 /usr/local/lib/tinygo/src/runtime/runtime_unix.go:181:17: undefined: clock_MONOTONIC_RAW
#10 0.457 /usr/local/lib/tinygo/src/runtime/runtime_unix.go:191:16: undefined: clock_REALTIME
#10 0.457 /usr/local/lib/tinygo/src/runtime/runtime_unix.go:225:34: undefined: flag_PROT_READ
#10 0.457 /usr/local/lib/tinygo/src/runtime/runtime_unix.go:225:49: undefined: flag_PROT_WRITE
#10 0.457 /usr/local/lib/tinygo/src/runtime/runtime_unix.go:225:66: undefined: flag_MAP_PRIVATE
#10 0.457 /usr/local/lib/tinygo/src/runtime/runtime_unix.go:225:83: undefined: flag_MAP_ANONYMOUS
I'm getting the same error with the docker container tinygo/tinygo:0.30.0, I am trying to cross compile by exporting GOOS=darwin and I get the error.
$ tinygo env
GOOS="darwin"
GOARCH="amd64"
GOROOT="/usr/local/go"
GOPATH="/home/tinygo/go"
GOCACHE="/home/tinygo/.cache/tinygo"
CGO_ENABLED="0"
TINYGOROOT="/usr/local/tinygo"
@tristanmorgan can you provide steps to reproduce this issue? (I'm not very familiar with Docker).
Hi @aykevl,
The steps I took were: I created an empty folder with a basic hello world program.
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
and
module example.com/test
go 1.21.1
then ran the following to get an interactive prompt in the docker container.
docker run --rm -it -v ${PWD}:/src tinygo/tinygo:0.30.0 /bin/sh
next inside the container I exported environment variables and tried to compile.
$ cd /src
$ export GOOS=darwin
$ export GOARCH=arm64
$ export CGO_ENABLED=0
$ tinygo env
GOOS="darwin"
GOARCH="arm64"
GOROOT="/usr/local/go"
GOPATH="/home/tinygo/go"
GOCACHE="/home/tinygo/.cache/tinygo"
CGO_ENABLED="0"
TINYGOROOT="/usr/local/tinygo"
$ tinygo build -o test
# runtime
/usr/local/tinygo/src/runtime/scheduler.go:22:24: undefined: GOOS
/usr/local/tinygo/src/runtime/gc_blocks.go:423:2: undefined: findGlobals
/usr/local/tinygo/src/runtime/runtime_unix.go:181:17: undefined: clock_MONOTONIC_RAW
/usr/local/tinygo/src/runtime/runtime_unix.go:191:16: undefined: clock_REALTIME
/usr/local/tinygo/src/runtime/runtime_unix.go:225:34: undefined: flag_PROT_READ
/usr/local/tinygo/src/runtime/runtime_unix.go:225:49: undefined: flag_PROT_WRITE
/usr/local/tinygo/src/runtime/runtime_unix.go:225:66: undefined: flag_MAP_PRIVATE
/usr/local/tinygo/src/runtime/runtime_unix.go:225:83: undefined: flag_MAP_ANONYMOUS
$ exit
What does seem to make a big difference is CGO_ENABLED=0
, if CGO is enabled it will compile correctly, disabled it breaks.
When I try a slightly more complex program with CGO enabled it hits the error in #3907
$ tinygo build -o tree_darwin
# os/user
/usr/local/go/src/os/user/cgo_lookup_unix.go:177:30: undefined: syscall.ERANGE
What does seem to make a big difference is
CGO_ENABLED=0
, if CGO is enabled it will compile correctly, disabled it breaks.
Ah, so this is the issue. TinyGo requires CGo and will break for some targets if it isn't enabled.
I've made a PR to fix this here: https://github.com/tinygo-org/tinygo/pull/4136
In the meantime, make sure you use CGO_ENABLED=1
for TinyGo.
Closing because while this is certainly confusing, it's not necessarily a bug and I've made a PR to avoid these kinds of issues in the future.