Skip to content

Instantly share code, notes, and snippets.

@santrancisco
Created May 28, 2021 14:36
Show Gist options
  • Save santrancisco/6fd1e84b57a43ae1eb675614b02bacac to your computer and use it in GitHub Desktop.
Save santrancisco/6fd1e84b57a43ae1eb675614b02bacac to your computer and use it in GitHub Desktop.
A Dockerfile and Makefile to test out Allen Dang's cross platform rapid GUI framework https://github.com/AllenDang/giu/

This gist contains my personal messy note to get the toolchain for cross compiling golang gui app built with Allen's rapid GUI framework.

  • Drop Makefile and Dockerfile into a folder
  • Run docker build . -t giubuild
  • Copy any example (https://github.com/AllenDang/giu/tree/master/examples) code into main.go
  • Get into interactive shell of cointainer so we can build the app docker run --rm -it -v pwd:/app giubuild bash
  • Inside docker container:
    • cd /app and then go mod init example. You probably want to target the latest version of the giu library so modify go.mod file to require github.com/AllenDang/giu latest.
    • Use vend to download dependencies to vendor folder instead of go mod vendor. Reason for using vend is because many header files/non-go files are ignored when using official "go mod vendor". This cause compiler to fail.
    • Finally, if all goes well, run make. This should take a while but once finished, you should have nix, mac and windows version of the example app in bin folder.
  • Recompiling take a lot quicker!
FROM ubuntu:20.04
RUN apt update
ENV DEBIAN_FRONTEND="noninteractive"
RUN apt-get install -y libgl1-mesa-dev xorg-dev
RUN apt install -y libxi-dev
RUN apt install -y libxinerama-dev
RUN apt install -y libxcursor-dev
RUN apt install -y libx11-dev
RUN apt install -y libglfw3-dev
RUN apt-get install -y gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64
RUN apt install -y clang llvm-dev uuid-dev libssl-dev libbz2-dev
RUN apt install -y git curl
RUN git clone https://github.com/tpoechtrager/osxcross.git /opt/osxcross
RUN curl -L "https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz" -o /opt/osxcross/tarballs/MacOSX11.3.sdk.tar.xz
RUN apt install -y build-essential
RUN apt install -y cmake libxml2-dev patch make tar xz-utils bzip2 gzip sed cpio libbz2-dev
RUN apt install -y bash
RUN echo "y"|bash -c /opt/osxcross/build.sh
RUN curl -s -N -L https://golang.org/dl/go1.16.4.linux-amd64.tar.gz -o - | tar -zxv -C /opt
ENV PATH="${PATH}:/opt/osxcross/target/bin"
ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/osxcross/target/lib"
ENV OSXCROSS_ROOT="/opt/osxcross"
ENV GOROOT=/opt/go
RUN go get github.com/nomad-software/vend
prep_release:
@rm -f bin/*
@mkdir -p bin
linux:
GOARCH=amd64 GOOS=linux go build -ldflags '-s -w' -o bin/main
darwin:
CGO_ENABLED=1 CC=o64-clang CXX=o64-clang++ GOARCH=amd64 GOOS=darwin go build -ldflags '-s -w' -o bin/main_mac.app
windows:
CGO_LDFLAGS='-static -s' CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ GOARCH=amd64 GOOS=windows go build -ldflags '-s -w -H=windowsgui' -o bin/main_win.exe
all: prep_release linux darwin windows
.DEFAULT_GOAL:=all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment