ioquake / ioq3

The ioquake3 community effort to continue supporting/developing id's Quake III Arena
https://ioquake3.org/
GNU General Public License v2.0
2.37k stars 528 forks source link

How do i compile for Apple Silicon? M1? #486

Closed ArneAnka closed 2 years ago

ArneAnka commented 3 years ago

Is it possible to compile for the Apple Silicone M1 chip? If is, how do I proceed with that?

tomkidd commented 3 years ago

I have a fork here that reportedly works with Apple Silicon, you build the makefile for arm64: .\make-macosx.sh arm64

https://github.com/tomkidd/ioq3/tree/xcode

There's also an updated Xcode project in the misc/xcode folder

I don't have an M1 processor myself but I have at least one report of it working.

There's a PR with it we haven't merged yet, if you wouldn't mind please report back here on how well works for you.

NuclearMonster commented 3 years ago

https://github.com/ioquake/ioq3/pull/481

klische commented 3 years ago

I have a fork here that reportedly works with Apple Silicon, you build the makefile for arm64: .\make-macosx.sh arm64

https://github.com/tomkidd/ioq3/tree/xcode

There's also an updated Xcode project in the misc/xcode folder

I don't have an M1 processor myself but I have at least one report of it working.

There's a PR with it we haven't merged yet, if you wouldn't mind please report back here on how well works for you.

./make-macosx.sh arm64 Invalid architecture: arm64 Valid architectures are x86, x86_64 or ppc

Opening the ioquake3.xcworkspace in misc/xcode and building the target ioqake3 on an M1 Mac results in several errors:

/ioq3/misc/xcode/renderer_opengl1.xcodeproj The linked library 'libSDL2-2.0.0.dylib' is missing one or more architectures required by this target: arm64. /ioq3/misc/xcode/renderer_opengl2.xcodeproj The linked library 'libSDL2-2.0.0.dylib' is missing one or more architectures required by this target: arm64.

tomkidd commented 3 years ago

If you have cloned my particular fork (tomkidd/ioq3) make sure you have switched to the "xcode" branch.

klische commented 3 years ago

Thank you for the response. It compiled successfully, however running ioq3/build/release-darwin-arm64/ioquake3.app results in

image
Process:               ioquake3 [9263]
Path:                  /Users/USER/*/ioquake3.app/Contents/MacOS/ioquake3
Identifier:            org.ioquake.ioquake3
Version:               1.36 (1.36)
Code Type:             ARM-64 (Native)
Parent Process:        ??? [1]
Responsible:           ioquake3 [9263]
User ID:               501

Date/Time:             2021-07-16 10:57:57.045 -0700
OS Version:            macOS 11.4 (20F71)
Report Version:        12
Anonymous UUID:        486439FE-8127-2147-5269-51DE193D65DB

Time Awake Since Boot: 880 seconds

System Integrity Protection: enabled

Crashed Thread:        0

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    DYLD, [0x5] Code Signature

Application Specific Information:
dyld: launch, loading dependent libraries

Dyld Error Message:
  Library not loaded: @executable_path/libSDL2-2.0.0.dylib
  Referenced from: /Users/USER/*/ioquake3.app/Contents/MacOS/ioquake3
  Reason: no suitable image found.  Did find:
    /Users/pizza/Code/ioq3/build/release-darwin-arm64/ioquake3.app/Contents/MacOS/libSDL2-2.0.0.dylib: code signature in (/Users/pizza/Code/ioq3/build/release-darwin-arm64/ioquake3.app/Contents/MacOS/libSDL2-2.0.0.dylib) not valid for use in process using Library Validation: Trying to load an unsigned library
    /Users/pizza/Code/ioq3/build/release-darwin-arm64/ioquake3.app/Contents/MacOS/libSDL2-2.0.0.dylib: code signature in (/Users/pizza/Code/ioq3/build/release-darwin-arm64/ioquake3.app/Contents/MacOS/libSDL2-2.0.0.dylib) not valid for use in process using Library Validation: Trying to load an unsigned library
    /Users/pizza/Code/ioq3/build/release-darwin-arm64/ioquake3.app/Contents/MacOS/libSDL2-2.0.0.dylib: stat() failed with errno=1

Binary Images:
       0x1024e4000 -        0x10262ffff +org.ioquake.ioquake3 (1.36 - 1.36) <996B1CA9-3CE5-3A4B-B1AC-F34CB53364A5> /Users/USER/*/ioquake3.app/Contents/MacOS/ioquake3
       0x104314000 -        0x104393fff  dyld (852) <CF624584-51D6-329D-91C5-6BEDFADFB2D2> /usr/lib/dyld
       0x1942d0000 -        0x19439bfff  com.apple.framework.IOKit (2.0.2 - 1845.120.6) <962CB4C0-6CC8-3AEC-BEE6-8CAF46010E08> /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit

Model: MacBookAir10,1, BootROM 6723.120.36, proc 8:4:4 processors, 16 GB, SMC 
Graphics: kHW_AppleM1Item, Apple M1, spdisplays_builtin
Memory Module: LPDDR4
AirPort: spairport_wireless_card_type_airport_extreme, wl0: Apr 28 2021 19:53:33 version 18.50.40.7.7.8.119 FWID 01-e6894c69
Bluetooth: Version 8.0.5d7, 3 services, 27 devices, 1 incoming serial ports
Network Service: Wi-Fi, AirPort, en0
USB Device: USB 3.1 Bus
USB Device: USB 3.1 Bus
Thunderbolt Bus: MacBook Air, Apple Inc.
Thunderbolt Bus: MacBook Air, Apple Inc.
tomkidd commented 3 years ago

Yeah this is pretty much where we're at - it doesn't like the code signing of the SDL library. However the error you're pasting there is different than what I've seen before (and I recently updated it) so that's progress.

Some reading indicates that macOS on M1 are less forgiving about unsigned libraries (the Intel version loads the unsigned library fine) so I can try something and do another checkin later.

Until I can get real hardware this "toss it over the wall" approach is all we've got.

klische commented 3 years ago

I can try to look at the codesigning and see if I can figure it out. If I do, I’ll make a PR

klische commented 3 years ago

Interestingly enough, the Xcode project throws different errors when targeting the M1 Mac (my Mac):


Prepare build
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description

Build target renderer_opengl1 of project renderer_opengl1 with configuration Debug
error: The linked library 'libjpeg8.a' is missing one or more architectures required by this target: arm64. (in target 'renderer_opengl1' from project 'renderer_opengl1')

Build target ioquake3 of project ioquake3 with configuration Debug
error: The linked library 'libopus.dylib' is missing one or more architectures required by this target: arm64. (in target 'ioquake3' from project 'ioquake3')
error: The linked library 'botlib.a' is missing one or more architectures required by this target: arm64. (in target 'ioquake3' from project 'ioquake3')
error: The linked library 'renderer_opengl1.dylib' is missing one or more architectures required by this target: arm64. (in target 'ioquake3' from project 'ioquake3')

Build target renderer_opengl2 of project renderer_opengl2 with configuration Debug
error: The linked library 'libjpeg8.a' is missing one or more architectures required by this target: arm64. (in target 'renderer_opengl2' from project 'renderer_opengl2')
klische commented 3 years ago

lipo -archs /Users/*/Library/Developer/Xcode/DerivedData/ioquake3-gfvzchdfjqprxbgkpemjmvmyrzvv/Build/Products/Debug/renderer_opengl1.dylib

Returns only x86_64. Looking into it now.

tomkidd commented 3 years ago

In the Xcode project be sure to build the "all ioquake3" scheme before firing off the "ioquake3 - baseq3" scheme (the one with the icon)

This is how the project has always worked but I may change that. But the "all ioquake3" scheme should be building the renderers, etc. for ARM64.

klische commented 3 years ago

Yep, I just figured that out. Had to also clean the build folder and it's now successfully compiling. I'm going to see if I can use the ioquake3.app file with Urban Terror

klische commented 3 years ago

The good news is that it's looking for the actual game files (lol note the non retina dialog)

image
tomkidd commented 3 years ago

Note that, for reasons I haven't sussed out yet, the "ioquake3.app" that Xcode comes up with (as in, what it buries in DerivedData) won't actually run outside of being attached to an Xcode debugger. This happens on Intel too.

In the interim you can fire off mods with either command line arguments in the scheme editor or (possibly) the mods menu in the game.

My guess is that the reason you don't get the code signing error on SDL2 when running from Xcode is that Xcode is just signing the thing for you well enough for it to use it.

klische commented 3 years ago

IT WORKS! I tried both plain Quake 3 and also Urban Terror. For those getting here looking for Urban Terror, you need to set the hunk megs in the command console (using tilde ~), before you launch the mod from the menu. I could not get the UT mod to launch using the scheme editor's launch argument. Performance seemed better than before, but not as good as the Intel MacBook.

Agreed on the code signing error vs running it from Xcode. I tried archiving it with code signing, but got an error with not finding cgame.dylib

tomkidd commented 3 years ago

Some information I'm reading says that dylibs on M1 have to be at least ad hoc signed.

I don't know if me doing that will fix it for everyone or not but in any event I've gone in and ad hoc signed libSDL2-2.0.0.dylib and checked it in, if you could try the makefile version of the build I'd appreciate it.

https://github.com/tomkidd/ioq3/tree/xcode

klische commented 3 years ago

make-macosx.sh arm64 outputs a binary that just works! Do you have a link of the source you found that helped with this re: ad hoc signing?

ArneAnka commented 3 years ago

Guys, for xcode beginners (as myself), a step by step tutorial on how the build process should be executed would be welcomed

tomkidd commented 3 years ago

make-macosx.sh arm64 outputs a binary that just works! Do you have a link of the source you found that helped with this re: ad hoc signing?

I found a couple of things mentioning it and gave them a shot

https://bogo.wtf/arm64-to-sim-dylibs.html

https://discourse.panda3d.org/t/pip-install-om-m1-mac-works-after-some-pain/27360/6

So, are you saying that when running make-macosx.sh arm64 you have an executable (in the release-darwin-arm64 directory) that runs on the M1, but if you run make-macosx-ub2.sh you wind up with an ioquake3.app bundle that does not run on the M1? If that's the case then it sounds like perhaps the code signing issue is (at least temporarily) addressed but the packaging script (which is a new thing I wrote) is flawed.

tomkidd commented 3 years ago

Guys, for xcode beginners (as myself), a step by step tutorial on how the build process should be executed would be welcomed

One we get everything sorted out with this that will be something we address, though for right now the short version is

To build the ioquake3.app for your architecture of choice ./make-macosx.sh x86_64 for Intel-based Macs made since 2008 or so ./make-macosx.sh arm64 for Apple Silicon (M1) based Macs

The result will be in the build/release-darwin-(arch)/ directory. Note that how well it works on Apple Silicon is still being hammered out.

The actual Xcode project is a different affair, you use that if you want to do debugging or have an IDE to edit files with. The scripts above use the Makefile, the Xcode project does not.

NuclearMonster commented 2 years ago

An M1 build is now available! https://ioquake3.org/ioquake3/legacy-and-m1-macos-ioquake3-support/

tomkidd commented 2 years ago

The code to compile for M1 is now in the main branch.