libressl/portable

Unable to cross-compile for different architectures on macOS with assembly enabled

Steveice10 opened this issue · 1 comments

Using CMake, cross compiling for ARM64 from x86_64 macOS using -DCMAKE_OSX_ARCHITECTURES=arm64 attempts to compile x86_64 assembly. The same is true of cross compiling for x86_64 from ARM64 macOS; it will attempt to compile ARM64 assembly. Among other things, this prevents compiling for ARM64 with ASM optimizations on GitHub Actions runners, since GitHub only offers x86_64 Macs.

Disabling assembly allows the build to succeed, but this means losing the performance benefits of ASM optimizations.

Had to solve this recently too, since the source tree configures itself based on CMAKE_SYSTEM_PROCESSOR, which isn't overridable from the command line. Though really CMAKE_OSX_ARCHITECTURES is intended to be able to target multiple architectures at once, we're not going to be ready for that without some wrapper files to conditionally compile assembly based on preprocessor defines. But this diff makes life a little easier:

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -306,6 +306,10 @@ if(HAVE_NETINET_IP_H)
        add_definitions(-DHAVE_NETINET_IP_H)
 endif()

+if(APPLE)
+       set(CMAKE_SYSTEM_PROCESSOR "${CMAKE_OSX_ARCHITECTURES}")
+endif()
+
 if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "(aarch64|arm64)")
        set(HOST_AARCH64 true)
 elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm")

Thanks, that seems to work. Even just supporting a single architecture specified would be useful for me. There's enough trouble getting libraries to behave with multiple architectures at once that I've just opted to build separately and combine with lipo.