From aa2bd399696c16c90bf627e8b7b078330e3100b5 Mon Sep 17 00:00:00 2001 From: Caleb Xavier Berger Date: Mon, 18 Jan 2021 03:41:46 -0500 Subject: [PATCH] Use go build instead of go install go install doesn't like to cross-compile things. (Try running build.sh with GOARCH set to something other than what it "should" be.) With go build, it appears that cross-compilation is really, really straightforward. Simply install a compiler for your target platform and set `GOARCH` and `CC` accordingly. --- build.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index e5e7fe8f2..542b10872 100755 --- a/build.sh +++ b/build.sh @@ -17,6 +17,13 @@ else export FLAGS="" fi -go install -trimpath -ldflags "$FLAGS" -v $PWD/`dirname $0`/cmd/... +for pkg in ./cmd/*; do + if [[ -d "$pkg" && ! -L "$pkg" ]]; then + # https://unix.stackexchange.com/a/94307/125869 + pkg_x="$(basename -- "$pkg"; echo .)" + base="${pkg_x%??}" + CGO_ENABLED=1 go build -trimpath -ldflags "$FLAGS" -v -o "./bin/$base" "./cmd/$base" + fi +done -GOOS=js GOARCH=wasm go build -trimpath -ldflags "$FLAGS" -o bin/main.wasm ./cmd/dendritejs +CGO_ENABLED=0 GOOS=js GOARCH=wasm go build -trimpath -ldflags "$FLAGS" -o bin/main.wasm ./cmd/dendritejs