Skip to content

Commit b7a81e3

Browse files
committed
add patch for simulator
Applies patch from PR: google/filament#7704
1 parent af0e6a2 commit b7a81e3

File tree

1 file changed

+397
-0
lines changed

1 file changed

+397
-0
lines changed
Lines changed: 397 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,397 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index b18c4a5b4ed..e032ccb20bd 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -604,7 +604,11 @@ endif()
6+
string(TOLOWER "${DIST_ARCH}" DIST_ARCH)
7+
string(REPLACE "amd64" "x86_64" DIST_ARCH "${DIST_ARCH}")
8+
if (NOT DIST_DIR)
9+
- set(DIST_DIR "${DIST_ARCH}")
10+
+ if(PLATFORM_NAME)
11+
+ set(DIST_DIR "${DIST_ARCH}-${PLATFORM_NAME}")
12+
+ else()
13+
+ set(DIST_DIR "${DIST_ARCH}")
14+
+ endif()
15+
endif()
16+
17+
# ==================================================================================================
18+
diff --git a/build.sh b/build.sh
19+
index 56562cc1c6c..e4b26a99d85 100755
20+
--- a/build.sh
21+
+++ b/build.sh
22+
@@ -581,9 +581,9 @@ function build_ios_target {
23+
local platform=$3
24+
25+
echo "Building iOS ${lc_target} (${arch}) for ${platform}..."
26+
- mkdir -p "out/cmake-ios-${lc_target}-${arch}"
27+
+ mkdir -p "out/cmake-ios-${lc_target}-${arch}-${platform}"
28+
29+
- pushd "out/cmake-ios-${lc_target}-${arch}" > /dev/null
30+
+ pushd "out/cmake-ios-${lc_target}-${arch}-${platform}" > /dev/null
31+
32+
if [[ ! -d "CMakeFiles" ]] || [[ "${ISSUE_CMAKE_ALWAYS}" == "true" ]]; then
33+
cmake \
34+
@@ -598,14 +598,14 @@ function build_ios_target {
35+
${MATDBG_OPTION} \
36+
${MATOPT_OPTION} \
37+
../..
38+
- ln -sf "out/cmake-ios-${lc_target}-${arch}/compile_commands.json" \
39+
+ ln -sf "out/cmake-ios-${lc_target}-${arch}-${platform}/compile_commands.json" \
40+
../../compile_commands.json
41+
fi
42+
43+
${BUILD_COMMAND}
44+
45+
if [[ "${INSTALL_COMMAND}" ]]; then
46+
- echo "Installing ${lc_target} in out/${lc_target}/filament..."
47+
+ echo "Installing ${lc_target}-${arch}-${platform} in out/${lc_target}/filament..."
48+
${BUILD_COMMAND} ${INSTALL_COMMAND}
49+
fi
50+
51+
@@ -640,16 +640,26 @@ function build_ios {
52+
if [[ "${ISSUE_DEBUG_BUILD}" == "true" ]]; then
53+
build_ios_target "Debug" "arm64" "iphoneos"
54+
if [[ "${IOS_BUILD_SIMULATOR}" == "true" ]]; then
55+
+ build_ios_target "Debug" "arm64" "iphonesimulator"
56+
build_ios_target "Debug" "x86_64" "iphonesimulator"
57+
fi
58+
-
59+
+
60+
if [[ "${BUILD_UNIVERSAL_LIBRARIES}" == "true" ]]; then
61+
build/ios/create-universal-libs.sh \
62+
- -o out/ios-debug/filament/lib/universal \
63+
- out/ios-debug/filament/lib/arm64 \
64+
- out/ios-debug/filament/lib/x86_64
65+
- rm -rf out/ios-debug/filament/lib/arm64
66+
- rm -rf out/ios-debug/filament/lib/x86_64
67+
+ -o ./out/ios-debug/filament/lib/universal \
68+
+ ./out/ios-debug/filament/lib/arm64-iphonesimulator \
69+
+ ./out/ios-debug/filament/lib/x86_64-iphonesimulator
70+
+
71+
+ rm -rf out/ios-debug/filament/lib/x86_64-iphonesimulator
72+
+ rm -rf out/ios-debug/filament/lib/arm64-iphonesimulator
73+
+
74+
+ build/ios/create-xc-frameworks.sh \
75+
+ -o out/ios-debug/filament/lib \
76+
+ out/ios-debug/filament/lib/arm64-iphoneos \
77+
+ out/ios-debug/filament/lib/universal
78+
+
79+
+ rm -rf out/ios-debug/filament/lib/universal
80+
+ rm -rf out/ios-debug/filament/lib/arm64-iphoneos
81+
fi
82+
83+
archive_ios "Debug"
84+
@@ -658,16 +668,26 @@ function build_ios {
85+
if [[ "${ISSUE_RELEASE_BUILD}" == "true" ]]; then
86+
build_ios_target "Release" "arm64" "iphoneos"
87+
if [[ "${IOS_BUILD_SIMULATOR}" == "true" ]]; then
88+
+ build_ios_target "Release" "arm64" "iphonesimulator"
89+
build_ios_target "Release" "x86_64" "iphonesimulator"
90+
fi
91+
-
92+
+
93+
if [[ "${BUILD_UNIVERSAL_LIBRARIES}" == "true" ]]; then
94+
build/ios/create-universal-libs.sh \
95+
- -o out/ios-release/filament/lib/universal \
96+
- out/ios-release/filament/lib/arm64 \
97+
- out/ios-release/filament/lib/x86_64
98+
- rm -rf out/ios-release/filament/lib/arm64
99+
- rm -rf out/ios-release/filament/lib/x86_64
100+
+ -o ./out/ios-release/filament/lib/universal \
101+
+ ./out/ios-release/filament/lib/arm64-iphonesimulator \
102+
+ ./out/ios-release/filament/lib/x86_64-iphonesimulator
103+
+
104+
+ rm -rf out/ios-release/filament/lib/x86_64-iphonesimulator
105+
+ rm -rf out/ios-release/filament/lib/arm64-iphonesimulator
106+
+
107+
+ build/ios/create-xc-frameworks.sh \
108+
+ -o out/ios-release/filament/lib \
109+
+ out/ios-release/filament/lib/arm64-iphoneos \
110+
+ out/ios-release/filament/lib/universal
111+
+
112+
+ rm -rf out/ios-release/filament/lib/universal
113+
+ rm -rf out/ios-release/filament/lib/arm64-iphoneos
114+
fi
115+
116+
archive_ios "Release"
117+
diff --git a/build/ios/create-xc-frameworks.sh b/build/ios/create-xc-frameworks.sh
118+
new file mode 100755
119+
index 00000000000..d8981ec9c36
120+
--- /dev/null
121+
+++ b/build/ios/create-xc-frameworks.sh
122+
@@ -0,0 +1,107 @@
123+
+#!/usr/bin/env bash
124+
+
125+
+set -e
126+
+
127+
+function print_help {
128+
+ local SELF_NAME
129+
+ SELF_NAME=$(basename "$0")
130+
+ echo "$SELF_NAME. Combine multiple single-architecture or universal libraries into xc-frameworks."
131+
+ echo ""
132+
+ echo "Usage:"
133+
+ echo " $SELF_NAME [options] <path>..."
134+
+ echo ""
135+
+ echo "Options:"
136+
+ echo " -h"
137+
+ echo " Print this help message."
138+
+ echo " -o"
139+
+ echo " Output directory to store the xcframeworks libraries."
140+
+ echo ""
141+
+ echo "Example:"
142+
+ echo " Given the follow directories:"
143+
+ echo " ├── universal/"
144+
+ echo " │ └── libfoo.a <- universal library - ensure they share the same platform (iphone/simulator)"
145+
+ echo " └── arm64-iphoneos/"
146+
+ echo " └── libfoo.a <- arm64 iphoneos platform"
147+
+ echo ""
148+
+ echo " $SELF_NAME -o frameworks/ arm64-iphoneos/ universal/"
149+
+ echo ""
150+
+ echo " Each library is combined into an xc-framework:"
151+
+ echo " └── frameworks/"
152+
+ echo " └── libfoo.xcframework"
153+
+ echo ""
154+
+ echo "Each <path> should contain one or more single or universal-architecture static libraries."
155+
+ echo "All <path>s should contain the same number of libraries, with the same names."
156+
+}
157+
+
158+
+OUTPUT_DIR=""
159+
+while getopts "ho:" opt; do
160+
+ case ${opt} in
161+
+ h)
162+
+ print_help
163+
+ exit 1
164+
+ ;;
165+
+ o)
166+
+ OUTPUT_DIR="${OPTARG}"
167+
+ ;;
168+
+ *)
169+
+ print_help
170+
+ exit 1
171+
+ ;;
172+
+ esac
173+
+done
174+
+
175+
+shift $((OPTIND - 1))
176+
+
177+
+PATHS=("$@")
178+
+
179+
+if [[ ! "${PATHS[*]}" ]]; then
180+
+ echo "One or more paths required."
181+
+ print_help
182+
+ exit 1
183+
+fi
184+
+
185+
+if [[ ! "${OUTPUT_DIR}" ]]; then
186+
+ echo "Output directory required."
187+
+ print_help
188+
+ exit 1
189+
+fi
190+
+
191+
+# Create the output directory, if it doesn't exist already.
192+
+mkdir -p "${OUTPUT_DIR}"
193+
+
194+
+# Use the first path as the "leader" path. All paths should contain the same number of files with
195+
+# the same names, so it doesn't matter which we chose.
196+
+LEADER_PATH="${PATHS[0]}"
197+
+
198+
+echo "Creating universal libraries from path: ${LEADER_PATH}..."
199+
+
200+
+# Loop through each file in the leader path. For each library we find, we'll collect additional
201+
+# architectures in the other paths and combine them all into a universal library.
202+
+for FILE in "${LEADER_PATH}"/*.a; do
203+
+ [ -f "${FILE}" ] || continue
204+
+
205+
+ # The static library file name, like "libfilament.a"
206+
+ LIBRARY_NAME="${FILE##*/}"
207+
+
208+
+ INPUT_FILES=("-library ${LEADER_PATH}/${LIBRARY_NAME}")
209+
+ for ARCH_PATH in "${PATHS[@]:1}"; do
210+
+ THIS_FILE="${ARCH_PATH}/${LIBRARY_NAME}"
211+
+ if [[ -f "${THIS_FILE}" ]]; then
212+
+ INPUT_FILES+=("-library ${THIS_FILE}")
213+
+ else
214+
+ echo "Error: ${THIS_FILE} does not exist."
215+
+ exit 1
216+
+ fi
217+
+ done
218+
+
219+
+ # Remove the .a extension
220+
+ LIBRARY_NAME="${LIBRARY_NAME%.a}"
221+
+
222+
+ OUTPUT="${OUTPUT_DIR}/${LIBRARY_NAME}.xcframework"
223+
+ # Delete previous xcframework
224+
+ rm -rf $OUTPUT
225+
+
226+
+ # Create the xcframework command and execute it
227+
+ CMD="xcodebuild -create-xcframework ${INPUT_FILES[@]} -output ${OUTPUT}"
228+
+ eval $CMD
229+
+done
230+
diff --git a/ios/CocoaPods/Filament.podspec b/ios/CocoaPods/Filament.podspec
231+
index 513d6c19752..d93a1ed1abd 100644
232+
--- a/ios/CocoaPods/Filament.podspec
233+
+++ b/ios/CocoaPods/Filament.podspec
234+
@@ -8,12 +8,6 @@ Pod::Spec.new do |spec|
235+
spec.platform = :ios, "11.0"
236+
spec.source = { :http => "https://github.com/google/filament/releases/download/v1.51.0/filament-v1.51.0-ios.tgz" }
237+
238+
- # Fix linking error with Xcode 12; we do not yet support the simulator on Apple silicon.
239+
- spec.pod_target_xcconfig = {
240+
- 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64'
241+
- }
242+
- spec.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
243+
-
244+
spec.subspec "filament" do |ss|
245+
ss.source_files =
246+
"include/filament/*.h",
247+
@@ -23,13 +17,13 @@ Pod::Spec.new do |spec|
248+
"include/ibl/*.h",
249+
"include/geometry/*.h"
250+
ss.header_mappings_dir = "include"
251+
- ss.vendored_libraries =
252+
- "lib/universal/libfilament.a",
253+
- "lib/universal/libbackend.a",
254+
- "lib/universal/libfilabridge.a",
255+
- "lib/universal/libfilaflat.a",
256+
- "lib/universal/libibl.a",
257+
- "lib/universal/libgeometry.a"
258+
+ ss.vendored_frameworks =
259+
+ "lib/libfilament.xcframework",
260+
+ "lib/libbackend.xcframework",
261+
+ "lib/libfilabridge.xcframework",
262+
+ "lib/libfilaflat.xcframework",
263+
+ "lib/libibl.xcframework",
264+
+ "lib/libgeometry.xcframework"
265+
ss.dependency "Filament/utils"
266+
ss.dependency "Filament/math"
267+
end
268+
@@ -40,11 +34,11 @@ Pod::Spec.new do |spec|
269+
"include/filament/MaterialChunkType.h",
270+
"include/filament/MaterialEnums.h"
271+
ss.header_mappings_dir = "include"
272+
- ss.vendored_libraries =
273+
- "lib/universal/libfilamat.a",
274+
- "lib/universal/libshaders.a",
275+
- "lib/universal/libsmol-v.a",
276+
- "lib/universal/libfilabridge.a"
277+
+ ss.vendored_frameworks =
278+
+ "lib/libfilamat.xcframework",
279+
+ "lib/libshaders.xcframework",
280+
+ "lib/libsmol-v.xcframework",
281+
+ "lib/libfilabridge.xcframework"
282+
ss.dependency "Filament/utils"
283+
ss.dependency "Filament/math"
284+
end
285+
@@ -52,11 +46,11 @@ Pod::Spec.new do |spec|
286+
spec.subspec "gltfio_core" do |ss|
287+
ss.source_files = "include/gltfio/**/*.h"
288+
ss.header_mappings_dir = "include"
289+
- ss.vendored_libraries =
290+
- "lib/universal/libgltfio_core.a",
291+
- "lib/universal/libdracodec.a",
292+
- "lib/universal/libuberarchive.a",
293+
- "lib/universal/libstb.a"
294+
+ ss.vendored_frameworks =
295+
+ "lib/libgltfio_core.xcframework",
296+
+ "lib/libdracodec.xcframework",
297+
+ "lib/libuberarchive.xcframework",
298+
+ "lib/libstb.xcframework"
299+
ss.dependency "Filament/filament"
300+
ss.dependency "Filament/ktxreader"
301+
ss.dependency "Filament/uberz"
302+
@@ -64,23 +58,23 @@ Pod::Spec.new do |spec|
303+
304+
spec.subspec "camutils" do |ss|
305+
ss.source_files = "include/camutils/*.h"
306+
- ss.vendored_libraries = "lib/universal/libcamutils.a"
307+
+ ss.vendored_frameworks = "lib/libcamutils.xcframework"
308+
ss.header_dir = "camutils"
309+
ss.dependency "Filament/math"
310+
end
311+
312+
spec.subspec "filameshio" do |ss|
313+
ss.source_files = "include/filameshio/*.h"
314+
- ss.vendored_libraries =
315+
- "lib/universal/libfilameshio.a",
316+
- "lib/universal/libmeshoptimizer.a"
317+
+ ss.vendored_frameworks =
318+
+ "lib/libfilameshio.xcframework",
319+
+ "lib/libmeshoptimizer.xcframework"
320+
ss.header_dir = "filameshio"
321+
ss.dependency "Filament/filament"
322+
end
323+
324+
spec.subspec "image" do |ss|
325+
ss.source_files = "include/image/*.h"
326+
- ss.vendored_libraries = "lib/universal/libimage.a"
327+
+ ss.vendored_frameworks = "lib/libimage.xcframework"
328+
ss.header_dir = "image"
329+
ss.dependency "Filament/filament"
330+
end
331+
@@ -88,7 +82,7 @@ Pod::Spec.new do |spec|
332+
spec.subspec "utils" do |ss|
333+
ss.source_files = "include/utils/**/*.h"
334+
ss.header_mappings_dir = "include"
335+
- ss.vendored_libraries = "lib/universal/libutils.a"
336+
+ ss.vendored_frameworks = "lib/libutils.xcframework"
337+
ss.dependency "Filament/tsl"
338+
end
339+
340+
@@ -105,9 +99,9 @@ Pod::Spec.new do |spec|
341+
spec.subspec "ktxreader" do |ss|
342+
ss.source_files = "include/ktxreader/*.h"
343+
ss.header_mappings_dir = "include"
344+
- ss.vendored_libraries =
345+
- "lib/universal/libktxreader.a",
346+
- "lib/universal/libbasis_transcoder.a"
347+
+ ss.vendored_frameworks =
348+
+ "lib/libktxreader.xcframework",
349+
+ "lib/libbasis_transcoder.xcframework"
350+
ss.dependency "Filament/image"
351+
ss.dependency "Filament/filament"
352+
end
353+
@@ -115,9 +109,9 @@ Pod::Spec.new do |spec|
354+
spec.subspec "viewer" do |ss|
355+
ss.source_files = "include/viewer/*.h"
356+
ss.header_mappings_dir = "include"
357+
- ss.vendored_libraries =
358+
- "lib/universal/libviewer.a",
359+
- "lib/universal/libcivetweb.a"
360+
+ ss.vendored_frameworks =
361+
+ "lib/libviewer.xcframework",
362+
+ "lib/libcivetweb.xcframework"
363+
ss.dependency "Filament/filament"
364+
ss.dependency "Filament/gltfio_core"
365+
end
366+
@@ -125,9 +119,9 @@ Pod::Spec.new do |spec|
367+
spec.subspec "uberz" do |ss|
368+
ss.source_files = "include/uberz/*.h"
369+
ss.header_mappings_dir = "include"
370+
- ss.vendored_libraries =
371+
- "lib/universal/libuberzlib.a",
372+
- "lib/universal/libzstd.a"
373+
+ ss.vendored_frameworks =
374+
+ "lib/libuberzlib.xcframework",
375+
+ "lib/libzstd.xcframework"
376+
ss.header_dir = "uberz"
377+
ss.dependency "Filament/filamat"
378+
ss.dependency "Filament/tsl"
379+
diff --git a/third_party/clang/iOS.cmake b/third_party/clang/iOS.cmake
380+
index a5619558834..6153cf8641e 100644
381+
--- a/third_party/clang/iOS.cmake
382+
+++ b/third_party/clang/iOS.cmake
383+
@@ -103,7 +103,12 @@ IF (NOT DEFINED IOS_MIN_TARGET)
384+
OUTPUT_STRIP_TRAILING_WHITESPACE)
385+
ENDIF()
386+
387+
-SET(IOS_COMMON_FLAGS "-m${PLATFORM_FLAG_NAME}-version-min=${IOS_MIN_TARGET}")
388+
+if(PLATFORM_NAME STREQUAL "iphonesimulator")
389+
+ # Ensure that the simulator is built with the correct target
390+
+ SET(IOS_COMMON_FLAGS "-m${PLATFORM_FLAG_NAME}-version-min=${IOS_MIN_TARGET} -target ${IOS_ARCH}-apple-ios-simulator")
391+
+else()
392+
+ SET(IOS_COMMON_FLAGS "-m${PLATFORM_FLAG_NAME}-version-min=${IOS_MIN_TARGET}")
393+
+endif()
394+
395+
SET(CMAKE_C_FLAGS_INIT "${IOS_COMMON_FLAGS}")
396+
SET(CMAKE_CXX_FLAGS_INIT "${IOS_COMMON_FLAGS}")
397+

0 commit comments

Comments
 (0)