bvschaik / julius

An open source re-implementation of Caesar III
GNU Affero General Public License v3.0
2.83k stars 316 forks source link

Apple silicon support #579

Closed pingwinator closed 2 years ago

pingwinator commented 3 years ago

Hi. The 1.6 version works great via roseta2 support. I have tried to build it for my self and it works. I installed dependencies via HomeBrew, but they have support only for arm (not-fat binary). Also, I tried to build it via ci scripts by adding -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" and found that sdl 2.0.14 is a fat bin, but sdl_mixer 2.0.4 not (only x86_64 build). I could build a fat binary on my mac, but I think it's better to have this solution on the CI.

crudelios commented 3 years ago

I agree we should support Apple Silicon, however none of us have such a system to test things on. Would you be willing to test our CI build attempts?

pingwinator commented 3 years ago

yes, sure. I can help with testing. I have tried to build it via ci, but the problem with sdl_mixer build. and I can't rebuild it for arm64. I used bottles from homebrew and did arm only build.

julius.dmg.zip

bvschaik commented 3 years ago

The problem is indeed with SDL mixer not providing an ARM-enabled build. I've opened an issue at the SDL bug tracker, hopefully they'll add support soon. If I don't hear back in a week or so I'll try to compile SDL_mixer on the CI, but I'd rather go the "official" route.

pingwinator commented 3 years ago

please, let me know about any updates. I want to help you with it

crudelios commented 3 years ago

I think there's a pending 2.0.5 release, so hopefully they'll compile with Apple Silicon support then.

bvschaik commented 3 years ago

I really hope they do.

I just did some experiments: we need to compile SDL_mixer as a framework using xcodebuild so we get a redistributable library, rather than a non-portable one (like homebrew). If I try to compile SDL_mixer, it complains that mpg123, vorbis, flac, etc are missing support for arm7. If I then try to build mpg123, it throws compile errors at me. Some libraries don't even have an Xcode project file, so I really wonder how one is supposed to build the .framework bundle on Mac.

The only thing we can do right now is wait for support.

pingwinator commented 3 years ago

I really hope they do.

I just did some experiments: we need to compile SDL_mixer as a framework using xcodebuild so we get a redistributable library, rather than a non-portable one (like homebrew). If I try to compile SDL_mixer, it complains that mpg123, vorbis, flac, etc are missing support for arm7. If I then try to build mpg123, it throws compile errors at me. Some libraries don't even have an Xcode project file, so I really wonder how one is supposed to build the .framework bundle on Mac.

The only thing we can do right now is wait for support.

you don't need arm7 support, you need only arm64 and without other flac and other formats support. ps - you could download binaries from homebrew https://formulae.brew.sh/api/formula/sdl2_mixer.json. Btw, homebrew uses the ./configure --prefix=/opt/homebrew/Cellar/sdl2_mixer/2.0.4 --disable-music-flac --disable-music-flac-shared --disable-music-mid build command. In theory could add CFLAGS="-arch arm64 -mmacosx-version-min=11.0 -arch x86_64" or only CFLAGS="-arch arm64" for build only arm build. I'm able to reproduce it, but I can't build the game with those libs (lost in search paths)

bvschaik commented 3 years ago

Apologies, I was mixing arm stuff up since I also do mobile Android development. It's indeed telling me: ld: symbol(s) not found for architecture arm64 for all library functions that are provided by mpg123, etc.

Using homebrew (or ./configure) is not an option since those create 'thin' libraries that cannot be redistributed to other architectures.

I'm not familiar with the xcode build system or how to disable any libraries from there, so I'd rather wait for official support in SDL_mixer instead of sinking time into this. The game works using the x86_64 bridge, so there's no urgency here.

crudelios commented 3 years ago

Since this an SDL_mixer issue that will be fixed by itself when support is added (I'm guessing when v2.0.5 comes along), should we keep this open? I mean, there's really nothing we can do about this.

bvschaik commented 3 years ago

Good question. I don't mind keeping this open a little longer. On the other hand, it doesn't look like ARM support has priority on the SDL mixer side: we can reopen this issue for testing later when support lands in the mixer library.

crudelios commented 3 years ago

@pingwinator The latest git build of sdl_mixer has added support for Apple M1.

Can you give it a go, compile it yourself please? Thanks!

bvschaik commented 3 years ago

@pingwinator I created a build, could you test this one? (DMG in zip because github doesn't allow uploading DMG files directly...) julius.dmg.zip

pingwinator commented 3 years ago

@pingwinator I created a build, could you test this one? (DMG in zip because github doesn't allow uploading DMG files directly...) julius.dmg.zip

unfortunately, crash on m1 and works fine via rosetta j_m1.crash.txt

pingwinator commented 3 years ago
lipo -info ulius.app/Contents/Frameworks/libpng16.16.dylib
Non-fat file: julius.app/Contents/Frameworks/libpng16.16.dylib is architecture: x86_64

arm64 is missing for this lib

bvschaik commented 3 years ago

I think the PNG lib is a leftover from a previous build, I compiled the last .app without external libs. The real reason it crashes is because the code isn't signed:

Termination Reason:    Namespace CODESIGNING, Code 0x2

I don't have an apple developer account so I cannot sign it.

Could you try compiling it yourself?

  1. Check out the latest SDL_mixer source
  2. Go to the xcode folder and run xcodebuild
  3. Copy the resulting SDL mixer framework to a location where Julius can find it
  4. Build Julius with the following cmake options: cmake -DSYSTEM_LIBS=OFF -DCMAKE_OSX_ARCHITECTURES "x86_64;arm64"
pingwinator commented 3 years ago

@bvschaik I tried to build the framework and the app. I have the same result. I have an apple dev account and will try to build it later with apple certificates.

pingwinator commented 3 years ago

@bvschaik I have found the problem. I build a framework with another recommended codesign option and it works. SDL2_mixer.framework.zip can you try build the app with this framework or build it from my fork? https://github.com/pingwinator/SDL_mixer

Screenshot 2021-07-04 at 18 53 02
bvschaik commented 3 years ago

can you try build the app with this framework or build it from my fork? https://github.com/pingwinator/SDL_mixer

I can try but since I don't have an Apple dev certificate that will also result in an unsigned binary :(

pingwinator commented 3 years ago

you don't need a dev cert to build it.

crudelios commented 3 years ago

@pingwinator I'm not versed in mac architecture but I think the problem stems from the fact that we would like to have an automated build that would create a fat (meaning both x86 and arm compatible) binary which could be downloaded and run directly by users, which doesn't seem possible without having an Apple dev certificate.

crudelios commented 3 years ago

@bvschaik The latest unstable builds of sdl_mixer seem to have fat binaries of the mpg123 framework, is there age chance we could get this to work now or do we still need some sort of code signing?

bvschaik commented 3 years ago

Unfortunately ARM builds require code signing to work at all on macOS 😞 I'm waiting for a new official release of SDL_mixer, then I may attempt to get that set up.

crudelios commented 3 years ago

We can always provide mac builds as homebrew packages, granted it's not perfect but at least we skip the code signing hassle...

bvschaik commented 3 years ago

Homebrew is only for command-line programs. There's homebrew cask for gui apps, but I think then we still need to sign Julius.

crudelios commented 3 years ago

I had the idea that homebrew apps were built from source on the destination computer so they were self-signed, bypassing the need for a certificate.

bvschaik commented 3 years ago

Nope, they have different flavors of each program for different macos versions but the command line apps are pre-compiled. And Cask is only a package installer to make managing gui apps easier: it doesn't build and sign Chrome, for example. In short, we cannot distribute through homebrew because we are not a command line tool. And for cask we still need to sign ourselves.

kambala-decapitator commented 2 years ago

Unfortunately ARM builds require code signing to work at all on macOS

ad-hoc signing is sufficient, it doesn't require paid certificate. See implementation example at https://github.com/vcmi/vcmi/pull/890

Re: homebrew. It either performs ad-hoc signing when building from source or removes the "quarantine" flag during setup:

xattr -d com.apple.quarantine /path/to/bundle/or/binary
bvschaik commented 2 years ago

@kambala-decapitator Thanks for the pointer. I've tried to add ad-hoc signing to the macos build (in a feature branch). Could you perhaps test the build from the bottom of this page on an ARM mac? I only have access to Intel-based macs.

kambala-decapitator commented 2 years ago

@kambala-decapitator Thanks for the pointer. I've tried to add ad-hoc signing to the macos build (in a feature branch). Could you perhaps test the build from the bottom of this page on an ARM mac? I only have access to Intel-based macs.

seems to work: I wasn't told to move the file to Bin. (first attempt: just press ok, then launch via right-click - Open) But I don't have game files, so I didn't get past the directory selection.

pingwinator commented 2 years ago
lipo -info /Volumes/Julius/julius.app/Contents/MacOS/julius 
Architectures in the fat file: /Volumes/Julius/julius.app/Contents/MacOS/julius are: x86_64 arm64 
Screenshot 2022-10-19 at 11 29 00

yes, it has both arch. and for run you need a right click on the file.

bvschaik commented 2 years ago

Thanks both for verifying, this is ready to merge then 😃