sonic-pi-net / sonic-pi

Code. Music. Live.
https://sonic-pi.net
Other
10.82k stars 922 forks source link

Build fails on Apple Silicon: attempting to link with file built for macOS-x86_64 #3284

Open bdelacretaz opened 1 year ago

bdelacretaz commented 1 year ago

The build fails on my M1 macbook, running mac-build-all.sh on a fresh checkout at commit 71f0796.

First I get this warning, the first time mac-config.sh runs:

CMake Warning:
Manually-specified variables were not used by the project:
CMAKE_OSC_ARCHITECTURES

Then the build fails with:

 ld: warning: ignoring file /Users/yawaa/workspace/xxx/4upstream-sonic-pi/app/build/aubio-package/lib/libaubio.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
....
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[2]: *** [external/CMakeFiles/aubio_onset.dir/build.make:119: external/aubio_onset] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:311: external/CMakeFiles/aubio_onset.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2

And a number of .o files seem to have been built for the x64 architecture:

$ file $(find build -name *.o) | head -6
build/CMakeFiles/3.26.3/CompilerIdC/CMakeCCompilerId.o:                                                      Mach-O 64-bit object arm64
build/CMakeFiles/3.26.3/CompilerIdCXX/CMakeCXXCompilerId.o:                                                  Mach-O 64-bit object arm64
build/external/sp_midi-prefix/src/sp_midi-build/CMakeFiles/libsp_midi.dir/external_libs/rtmidi/RtMidi.cpp.o: Mach-O 64-bit object x86_64
build/external/sp_midi-prefix/src/sp_midi-build/CMakeFiles/libsp_midi.dir/src/utils.cpp.o:                   Mach-O 64-bit object x86_64
build/external/sp_midi-prefix/src/sp_midi-build/CMakeFiles/libsp_midi.dir/src/sp_midi.cpp.o:                 Mach-O 64-bit object x86_64
build/external/sp_midi-prefix/src/sp_midi-build/CMakeFiles/libsp_midi.dir/src/midiout.cpp.o:                 Mach-O 64-bit object x86_64

Here's the output of mac-config in case it helps:

$ ./mac-config.sh
Creating build directory...
Generating makefiles...
-- CMakeLists: Sonic Pi
-- TARGET_MAC
-- System: Darwin-21.3.0
-- Compiler: AppleClang
-- Compiler Version: 13.1.6.13160021
-- Debug Flags: -g -D_DEBUG -DDEBUG
-- Release Flags: -O3 -DNDEBUG
-- Externals Builder
-- USE_SYSTEM_LIBS: OFF
-- ImGui Interface: ON
-- CMakeLists: Sonic Pi Qt GUI
-- Setting prefix to Homebrew's Qt install location: /usr/local/opt/qt@5
-- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
-- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
-- App Root: /Users/yawaa/workspace/xxx/4upstream-sonic-pi/app
-- Configuring done (0.9s)
-- Generating done (0.1s)
-- Build files have been written to: /Users/yawaa/workspace/xxx/4upstream-sonic-pi/app/build
samaaron commented 1 year ago

Not sure what's going on here, sorry. I just did a fresh clone and ran the mac-build-all.sh script in /app and it built just fine on my Apple Silicon machine.

samaaron commented 1 year ago

Perhaps you have some old build artefacts from a previous build? Did you checkout into a brand new directory or over an old directory?

samaaron commented 1 year ago

Also, what does the following output when you run it in a terminal for you: uname -m

bdelacretaz commented 1 year ago

It's a fresh empty folder, just did git clone, cd <folder>/app, ./mac-build-all.sh, so I don't think it can be old artefacts.

uname -m returns arm64

Maybe there's a difference in some tool versions?

Note that I'm not really blocked by this, I'm preparing a contribution of new synths and wanted to test them on my own build, but I can also submit a synths PR "blindly", just checking the syntax of the synthinfo.rb file.

samaaron commented 1 year ago

Interesting. One thing that might be different is that on my machine I specifically did not install Rosetta to ensure everything was all arm64. Perhaps there's something in the toolchain that defaults to x64 when Rosetta is present?

emlyn commented 1 year ago

I tried building it on my machine (M1 with Rosetta installed) from a fresh checkout. I ran into a couple of issues with it not finding my Homebrew QT5 install (it assumes Homebrew is installed in /usr/local, but mine is in /opt/homebrew), but after editing the build files I got mac-buildall.sh to run successfully to completion.

I wasn't able to run the generated app though, it gets immediately killed, and in the error report window that pops up, it says: EXC_BAD_ACCESS (SIGKILL (Code Signature Invalid)).

samaaron commented 1 year ago

That's useful to know, thanks. For the record I never personally use homebrew Qt - I always install it manually as you get more control over versions and updating etc.