Skip to content

Commit eaf1897

Browse files
authored
Add support for universal binaries on OSX (#2060)
When building for multiple architectures on OSX, it's necessary to use compiler macros to conditionally include architecture-specific code rather than conditionally including architecture-specific assembly files via cmake. See https://developer.apple.com/documentation/apple-silicon/building-a-universal-macos-binary and https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_ARCHITECTURES.html for more details. Co-authored-by: Zoraaver Singh <zoraaver@amazon.co.uk>
1 parent 08a4a7c commit eaf1897

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
*/
5+
6+
#if defined(__aarch64__)
7+
#if WASM_ENABLE_SIMD == 0
8+
#include "invokeNative_aarch64.s"
9+
#else
10+
#include "invokeNative_aarch64_simd.s"
11+
#endif
12+
#else
13+
#if WASM_ENABLE_SIMD == 0
14+
#include "invokeNative_em64.s"
15+
#else
16+
#include "invokeNative_em64_simd.s"
17+
#endif
18+
#endif

core/iwasm/common/iwasm_common.cmake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ if (WAMR_DISABLE_APP_ENTRY EQUAL 1)
1414
list(REMOVE_ITEM c_source_all "${IWASM_COMMON_DIR}/wasm_application.c")
1515
endif ()
1616

17+
if (CMAKE_OSX_ARCHITECTURES)
18+
string(TOLOWER "${CMAKE_OSX_ARCHITECTURES}" OSX_ARCHS)
19+
20+
list(FIND OSX_ARCHS arm64 OSX_AARCH64)
21+
list(FIND OSX_ARCHS x86_64 OSX_X86_64)
22+
23+
if (NOT "${OSX_AARCH64}" STREQUAL "-1" AND NOT "${OSX_X86_64}" STREQUAL "-1")
24+
set(OSX_UNIVERSAL_BUILD 1)
25+
endif()
26+
endif()
27+
1728
if (WAMR_BUILD_INVOKE_NATIVE_GENERAL EQUAL 1)
1829
# Use invokeNative C version instead of asm code version
1930
# if WAMR_BUILD_INVOKE_NATIVE_GENERAL is explicitly set.
@@ -24,6 +35,8 @@ if (WAMR_BUILD_INVOKE_NATIVE_GENERAL EQUAL 1)
2435
# in arm and mips need to be 8-bytes aligned, and some arguments
2536
# of x86_64 are passed by registers but not stack
2637
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_general.c)
38+
elseif (OSX_UNIVERSAL_BUILD EQUAL 1)
39+
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_osx_universal.s)
2740
elseif (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
2841
if (NOT WAMR_BUILD_SIMD EQUAL 1)
2942
if (WAMR_BUILD_PLATFORM STREQUAL "windows")

0 commit comments

Comments
 (0)