Skip to content

Commit 3fe4418

Browse files
authored
Add ios support for product-mini (#1602)
Generate `xcodeproj`, that could build iwasm shared library for iOS or iOS Simulator Signed-off-by: HangedFish <[email protected]>
1 parent ace05b1 commit 3fe4418

File tree

2 files changed

+155
-0
lines changed

2 files changed

+155
-0
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
cmake_minimum_required (VERSION 3.21)
5+
6+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=hard")
7+
8+
project (iwasm)
9+
10+
set (WAMR_BUILD_PLATFORM "darwin")
11+
set (WAMR_BUILD_TYPE Release)
12+
set (WAMR_BUILD_INTERP 1)
13+
set (WAMR_BUILD_AOT 0)
14+
set (WAMR_BUILD_LIBC_BUILTIN 1)
15+
set (WAMR_BUILD_LIBC_WASI 1)
16+
17+
# Reset default linker flags
18+
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
19+
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
20+
21+
# Set WAMR_BUILD_TARGET, currently values supported:
22+
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
23+
# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
24+
if (NOT DEFINED WAMR_BUILD_TARGET)
25+
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
26+
set (WAMR_BUILD_TARGET "AARCH64")
27+
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
28+
set (WAMR_BUILD_TARGET "RISCV64")
29+
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
30+
# Build as X86_64 by default in 64-bit platform
31+
set (WAMR_BUILD_TARGET "X86_64")
32+
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
33+
# Build as X86_32 by default in 32-bit platform
34+
set (WAMR_BUILD_TARGET "X86_32")
35+
else ()
36+
message(SEND_ERROR "Unsupported build target platform!")
37+
endif ()
38+
endif ()
39+
40+
if (NOT CMAKE_BUILD_TYPE)
41+
set(CMAKE_BUILD_TYPE Release)
42+
endif ()
43+
44+
set(CMAKE_CXX_STANDARD 14)
45+
46+
if (NOT DEFINED WAMR_BUILD_INTERP)
47+
# Enable Interpreter by default
48+
set (WAMR_BUILD_INTERP 1)
49+
endif ()
50+
51+
if (NOT DEFINED WAMR_BUILD_AOT)
52+
# Enable AOT by default.
53+
set (WAMR_BUILD_AOT 1)
54+
endif ()
55+
56+
if (NOT DEFINED WAMR_BUILD_JIT)
57+
# Disable JIT by default.
58+
set (WAMR_BUILD_JIT 0)
59+
endif ()
60+
61+
if (NOT DEFINED WAMR_BUILD_FAST_JIT)
62+
# Disable Fast JIT by default
63+
set (WAMR_BUILD_FAST_JIT 0)
64+
endif ()
65+
66+
if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
67+
# Enable libc builtin support by default
68+
set (WAMR_BUILD_LIBC_BUILTIN 1)
69+
endif ()
70+
71+
if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
72+
# Enable libc wasi support by default
73+
set (WAMR_BUILD_LIBC_WASI 1)
74+
endif ()
75+
76+
if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
77+
# Enable fast interpreter
78+
set (WAMR_BUILD_FAST_INTERP 1)
79+
endif ()
80+
81+
if (NOT DEFINED WAMR_BUILD_MULTI_MODULE)
82+
# Disable multiple module by default
83+
set (WAMR_BUILD_MULTI_MODULE 0)
84+
endif ()
85+
86+
if (NOT DEFINED WAMR_BUILD_LIB_PTHREAD)
87+
# Disable pthread library by default
88+
set (WAMR_BUILD_LIB_PTHREAD 1)
89+
endif ()
90+
91+
if (NOT DEFINED WAMR_BUILD_MINI_LOADER)
92+
# Disable wasm mini loader by default
93+
set (WAMR_BUILD_MINI_LOADER 0)
94+
endif ()
95+
96+
if (NOT DEFINED WAMR_BUILD_SIMD)
97+
# Enable SIMD by default
98+
set (WAMR_BUILD_SIMD 1)
99+
endif ()
100+
101+
if (NOT DEFINED WAMR_BUILD_DEBUG_INTERP)
102+
# Disable Debug feature by default
103+
set (WAMR_BUILD_DEBUG_INTERP 0)
104+
endif ()
105+
106+
if (WAMR_BUILD_DEBUG_INTERP EQUAL 1)
107+
set (WAMR_BUILD_FAST_INTERP 0)
108+
set (WAMR_BUILD_MINI_LOADER 0)
109+
set (WAMR_BUILD_SIMD 0)
110+
endif ()
111+
112+
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
113+
114+
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
115+
116+
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -pie -fPIE")
117+
118+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security")
119+
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion")
120+
121+
if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
122+
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
123+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")
124+
endif ()
125+
endif ()
126+
127+
# The following flags are to enhance security, but it may impact performance,
128+
# we disable them by default.
129+
#if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
130+
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftrapv -D_FORTIFY_SOURCE=2")
131+
#endif ()
132+
#set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong --param ssp-buffer-size=4")
133+
#set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,noexecstack,-z,relro,-z,now")
134+
135+
add_library (iwasm SHARED ${WAMR_RUNTIME_LIB_SOURCE})
136+
if (CMAKE_BUILD_TYPE STREQUAL Release)
137+
target_link_libraries (iwasm ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -s)
138+
else()
139+
target_link_libraries (iwasm ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl)
140+
endif()
141+
142+
set (distribution_DIR ${CMAKE_BINARY_DIR}/distribution)
143+
set_target_properties (iwasm PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${distribution_DIR}/wasm/lib")
144+
145+
add_custom_command (TARGET iwasm POST_BUILD
146+
COMMAND "${CMAKE_COMMAND}" -E copy_directory "${WAMR_ROOT_DIR}/core/iwasm/include" "${distribution_DIR}/wasm/include/"
147+
COMMENT "Copying iwasm to output directory")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
# Copyright (C) 2022 Intel Corporation. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
rm -rf ./iwasm-proj
7+
git clone https://github.com/leetal/ios-cmake.git ios-cmake
8+
cmake -Biwasm-proj -G Xcode -DDEPLOYMENT_TARGET=11.0 -DPLATFORM=OS64 -DENABLE_BITCODE=0 -DCMAKE_TOOLCHAIN_FILE=ios-cmake/ios.toolchain.cmake .

0 commit comments

Comments
 (0)