Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ArneAnka opened this issue Mar 5, 2021 · 21 comments
Closed

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

ArneAnka opened this issue Mar 5, 2021 · 21 comments
Assignees

Comments

@ArneAnka
Copy link

ArneAnka commented Mar 5, 2021

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

@tomkidd
Copy link
Member

tomkidd commented Mar 5, 2021

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 NuclearMonster changed the title How do i compile for Apple Silicone? M1? How do i compile for Apple Silicon? M1? Mar 16, 2021
@NuclearMonster
Copy link
Member

#481

@klische
Copy link

klische commented Jul 16, 2021

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
Copy link
Member

tomkidd commented Jul 16, 2021

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

@klische
Copy link

klische commented Jul 16, 2021

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
Copy link
Member

tomkidd commented Jul 17, 2021

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
Copy link

klische commented Jul 17, 2021 via email

@klische
Copy link

klische commented Jul 17, 2021

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
Copy link

klische commented Jul 17, 2021

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

Returns only x86_64. Looking into it now.

@tomkidd
Copy link
Member

tomkidd commented Jul 17, 2021

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
Copy link

klische commented Jul 17, 2021

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
Copy link

klische commented Jul 17, 2021

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

image

@tomkidd
Copy link
Member

tomkidd commented Jul 17, 2021

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
Copy link

klische commented Jul 17, 2021

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
Copy link
Member

tomkidd commented Jul 20, 2021

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
Copy link

klische commented Jul 22, 2021

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
Copy link
Author

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

@tomkidd
Copy link
Member

tomkidd commented Jul 22, 2021

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
Copy link
Member

tomkidd commented Jul 22, 2021

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
Copy link
Member

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

@tomkidd
Copy link
Member

tomkidd commented Oct 22, 2021

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

@tomkidd tomkidd closed this as completed Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants