g3n / engine

Go 3D Game Engine (http://g3n.rocks)
https://discord.gg/NfaeVr8zDg
BSD 2-Clause "Simplified" License
2.82k stars 298 forks source link

Add Apple silicon cgo flags #236

Closed mat007 closed 3 years ago

mat007 commented 3 years ago

What I did: I duplicated the darwin #cgo lines for both CFLAGS and LDFLAGS, and added arm64 specific settings. This makes 'go install' work on Apple silicon out of the box after installing the dependencies with brew on a freshly installed machine.

Hopefully fixes https://github.com/g3n/g3nd/issues/33

Before:

$ go install ./...
# github.com/g3n/engine/audio/al
audio/al/al.go:18:11: fatal error: 'al.h' file not found
 #include "al.h"
          ^~~~~~
1 error generated.
# github.com/g3n/engine/audio/vorbis
ld: library not found for -lvorbis
clang: error: linker command failed with exit code 1 (use -v to see invocation)
# github.com/g3n/engine/audio/ov
ld: library not found for -lvorbisfile
clang: error: linker command failed with exit code 1 (use -v to see invocation)

After

$ go install ./...

I also verified that switching to the g3n/g3nd folder and adding to go.mod

replace github.com/g3n/engine => ../g3n-engine

I was able to go install and run the demos.

mat007 commented 3 years ago

I am not a brew expert, it looks a bit suspicious to me that installing the dependencies doesn’t create links from the usual include and lib locations (e.g. /usr/local/include, /usr/local/lib and such). 🤔

danaugrs commented 3 years ago

Hi and thanks for the PR! Any reason to mix darwin, <arch> (comma meaning AND) and darwin <arch> (space meaning OR)?

A build constraint is evaluated as the OR of space-separated options. Each option evaluates as the AND of its comma-separated terms. source

If not, could you please update it to use commas only? Otherwise it looks great and I can merge it.

mat007 commented 3 years ago

Any reason to mix darwin, (comma meaning AND) and darwin (space meaning OR)?

Oh no, it’s a typo! Good catch, sorry about that. I should be all commas. I just re-pushed!

danaugrs commented 3 years ago

Great, thanks!