opus icon indicating copy to clipboard operation
opus copied to clipboard

Add support for cross-compiling on Mac #186

Open andrewgrant opened this issue 4 years ago • 9 comments

Adds support for cross-compiling to different targets when building on Mac.

E.g the following builds Opus for an arm64 Mac target (Apple silicon)

./configure --host=aarch64-apple-macos make && make install

This allows building Opus for both architectures and using lipo to create a universal binary.

andrewgrant avatar Jul 07 '20 00:07 andrewgrant

@mark4o && @rillian for review?

Should neon be presumed for apple silicone? Add config to .travis ci for coverage?

xnorpx avatar Jul 07 '20 04:07 xnorpx

NEON has been in all Apple silicon since 3GS, so it would be reasonable.

silverbacknet avatar Jul 07 '20 22:07 silverbacknet

Good point RE Neon. I'll add that and resubmit in the next day or so.

andrewgrant avatar Jul 08 '20 14:07 andrewgrant

Can you please also document your rationale in the commit message, or a comment. I assume this is to work around autoconf's built-in cross-compiler detection not supporting Apple's new configuration, but it seems like there are several ways to do that. Why the separate clang_arch variables, for example, and why not set the flags directly in configure. That's the sort of thing someone having to maintain the changes later would need to know.

rillian avatar Jul 09 '20 16:07 rillian

It's not part of this PR, but I found that the CMake build system is also doing dubious stuff here that pessimizes x64 builds on arm64: https://github.com/xiph/opus/blob/ccaaffa9a3ee427e9401c4dcf6462e378d9a4694/cmake/OpusConfig.cmake#L42

From my understanding, CMAKE_SYSTEM_PROCESSOR matches arm64 here, causing the build system to check for NEON availability rather than SSE availability:

-- Looking for arm_neon.h
-- Looking for arm_neon.h - not found

The resulting binary is still compiled for x64, but without SIMD optimiations.

Edit: I think that's being tracked in this issue: https://github.com/xiph/opus/issues/198

j-schultz avatar Apr 08 '22 14:04 j-schultz

@j-schultz so the issue is cross compiling to x64 on a m1/m2 mac for cmake?

https://stackoverflow.com/questions/69803659/what-is-the-proper-way-to-build-for-macos-x86-64-using-cmake-on-apple-m1-arm

will try to test this

xnorpx avatar Jun 30 '22 04:06 xnorpx

so the issue is cross compiling to x64 on a m1/m2 mac for cmake?

Correct. And probably the other way around, too (missing NEON optimizations when cross-compiling for arm64)

j-schultz avatar Jun 30 '22 07:06 j-schultz

@j-schultz m1 stuff seems pretty hairy, unlikely I will get fixes in this release.

xnorpx avatar Jul 08 '22 04:07 xnorpx

Is cross-compiling now supposed to work on Mac M1 ? I tried to cross-compile for Mac Intel (x86_64) from a Mac M1 using this cmd ./configure --host=x86_64-apple-macos and got the following error : configure: error: no supported Get CPU Info method, please disable run-time CPU capabilities detection or intrinsics

Any advice ? Thanks

charlifiiiii avatar Jul 05 '23 15:07 charlifiiiii