Closed jkassis closed 1 year ago
Hi @jkassis, it seems like the project is being compiled statically. In that case, the SDL2 apt packages shouldn't be needed. You can reference the following steps to compile for macOS M1. Let me know if it helps! I just added initial M1 static compilation support on v0.4.32
.
Run a container. This example uses Debian image with Podman.
podman run -it --name debian debian:latest bash
Install required packages.
apt update && apt install -y vim git curl xz-utils clang make cmake libxml2-dev libssl-dev libz-dev
Clone osxcross
cd /opt
git clone https://github.com/tpoechtrager/osxcross
Build macOS SDK
cd /opt/osxcross/tarballs
curl -O https://s3.veand.co/go-sdl2/MacOSX11.3.sdk.tar.xz
cd /opt/osxcross
SDK_VERSION=11.3 ./build.sh
Download and extract Go
cd /opt
curl -L -O https://go.dev/dl/go1.20.linux-amd64.tar.gz
tar xf go1.20.linux-amd64.tar.gz
Set up PATH for Go by editing ~/.profile
vim ~/.profile
Put the following content at the bottom of ~/.profile
:
export GOROOT="/opt/go"
export GOPATH="/opt/.go"
export PATH="$GOPATH/bin:$GOROOT/bin:$PATH"
Reload .profile
. ~/.profile
cd /opt
mkdir example
cd /opt/example
go mod init example
vim main.go
Put the following code in main.go
:
package main
import (
"github.com/veandco/go-sdl2/sdl"
"github.com/veandco/go-sdl2/ttf"
"github.com/veandco/go-sdl2/img"
"github.com/veandco/go-sdl2/mix"
)
func main() {
sdl.Init(sdl.INIT_EVERYTHING)
ttf.Init()
img.Init(img.INIT_PNG)
mix.Init(mix.INIT_MP3)
}
Then download the dependencies using:
go mod tidy
vim build.sh
Put the following content in build.sh
:
#!/usr/bin/env bash
export TARGET="x86_64-apple-darwin20.4"
export OSXCROSS="/opt/osxcross"
export SDK_VERSION=11.3
export DARWIN="${OSXCROSS}/target"
export DARWIN_SDK="${DARWIN}/SDK/MacOSX${SDK_VERSION}.sdk"
export PATH="${DARWIN}/bin:${DARWIN_SDK}/bin:${PATH}"
export LDFLAGS="-L${DARWIN_SDK}/lib -mmacosx-version-min=10.10"
export CC="${TARGET}-clang"
export CXX="${TARGET}-clang++"
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -tags static -ldflags "-s -w"
Then make it executable and run it:
chmod +x build.sh
./build.sh
podman cp debian:/opt/example/example .
i forgot to mention in my original posts that my project is (was) vendored.
v0.4.32
works with your instructions here (without the apts installed) unless building from vendor'd libs.
go mod -vendor probably pruned the static C code needed to build this?!? any thoughts about how to prevent this?
Hi @jkassis, I have pushed new commits that have workarounds for it. Would you mind trying the v0.4.x
branch and let me know if it works for you? I will create another tag if it works for you. Thanks!
very nice. works! thank you!
Thank you for testing it! I have pushed a new tag v0.4.33
.
Go version: 1.20
Go-SDL2 version: latest
SDL2 version: debian bullseye
Docker OS: Debian Bullseye
Host OS: Apple Silicon M2
In my Dockerfile, I do this...
My build script...
The output is this...