11STRIP ?= strip
2- EMCXX ?= em++
32SED ?= sed
3+ # WebGL toolchain
4+ EMAR ?= emar
5+ EMCXX ?= em++
6+ # Android setup
47ANDROID_NDK_ROOT ?=
8+ # macOS
59CODESIGN ?= codesign
610MACOS_CODESIGN_SIGNATURE ?=
711
812LINKFLAGS += -shared
9- CXXFLAGS += -Iyoga~ - std=c++20 -fvisibility=hidden
13+ CXXFLAGS += -std=c++20 -fvisibility=hidden
1014ifeq ($(DEBUG ) ,1)
1115 CXXFLAGS += -O0 -g
1216else
@@ -16,24 +20,37 @@ endif
1620BUILD_DIRS = \
1721 build/windows/x86_64 build/windows/x86 \
1822 build/linux/x86_64 \
19- build/macos build/ios build/tvos build/visionos \
23+ build/macos \
2024 build/android/arm64 build/android/arm32 build/android/x86 build/android/x86_64 \
2125 build/webgl
2226
2327# Misc
2428$(BUILD_DIRS ) :
2529 mkdir -p $@
2630
27- % /flex-ui.dll : src~/flex-ui.cpp | %
31+ # Requires `cpp-amalgamate`, install with `cargo install cpp-amalgamate`
32+ # Reference: https://github.com/Felerius/cpp-amalgamate
33+ #
34+ # The sed script prepends an underscore to all Yoga symbols to avoid symbol clashes with
35+ # the version of Yoga embedded within Unity, fixing iOS / tvOS / visionOS / WebGL builds.
36+ flex-ui-amalgamated.cpp : src~/flex-ui.cpp yoga~
37+ cpp-amalgamate -d yoga~ $< | $(SED ) ' s/\bYG/_YG/g' > $@
38+
39+ % /flex-ui-amalgamated.o~ : flex-ui-amalgamated.cpp | %
40+ $(CXX ) -c -o $@ $< $(CXXFLAGS )
41+ % /libflex-ui.a : % /flex-ui-amalgamated.o~
42+ $(AR ) r $@ $<
43+
44+ % /flex-ui.dll : flex-ui-amalgamated.cpp | %
2845 $(CXX ) -o $@ $< $(CXXFLAGS ) $(LINKFLAGS )
2946 $(STRIP ) -x $@
3047
3148% /libflex-ui.so : CXXFLAGS += -fPIC
32- % /libflex-ui.so : src~/ flex-ui.cpp | %
49+ % /libflex-ui.so : flex-ui-amalgamated .cpp | %
3350 $(CXX ) -o $@ $< $(CXXFLAGS ) $(LINKFLAGS )
3451 $(STRIP ) -x $@
3552
36- % /libflex-ui.dylib : src~/ flex-ui.cpp | %
53+ % /libflex-ui.dylib : flex-ui-amalgamated .cpp | %
3754 $(CXX ) -o $@ $< $(CXXFLAGS ) $(LINKFLAGS )
3855 install_name_tool -id @rpath/$(@F ) $@
3956 $(STRIP ) -x $@
4461# macOS
4562build/macos/libflex-ui.dylib : CXXFLAGS += -arch x86_64 -arch arm64
4663
47- # iOS
48- build/ios/libflex-ui.dylib : CXXFLAGS += -arch arm64 -isysroot $(shell xcrun --show-sdk-path --sdk iphoneos)
49-
50- # tvOS
51- build/tvos/libflex-ui.dylib : CXXFLAGS += -arch arm64 -isysroot $(shell xcrun --show-sdk-path --sdk appletvos)
52-
53- # visionOS
54- build/visionos/libflex-ui.dylib : CXXFLAGS += -arch arm64 -isysroot $(shell xcrun --show-sdk-path --sdk xros)
55-
5664# Android
5765check-ndk-root :
5866ifndef ANDROID_NDK_ROOT
@@ -72,13 +80,8 @@ build/android/x86/libflex-ui.so: CXX = $(wildcard $(ANDROID_NDK_ROOT)/toolchains
7280build/android/x86/libflex-ui.so : check-ndk-root
7381
7482# WebGL
75- build/webgl/libflex-ui.bc : src~/flex-ui.cpp | build/webgl
76- # Workaround: prepend Yoga symbols with a '_' to avoid build errors,
77- # since Unity already exports some of them (used by UI Toolkit).
78- # C++ -> LLVM IR -> rename functions in text -> LLVM Bitcode
79- $(EMCXX) -c $< $(CXXFLAGS) -emit-llvm -S -o - \
80- | $(SED) -e 's/@YG/@_YG/' \
81- | $(EMCXX) -o $@ -c -emit-llvm -x ir -
83+ build/webgl/libflex-ui.a : CXX = $(EMCXX )
84+ build/webgl/libflex-ui.a : AR = $(EMAR )
8285
8386# Targets
8487windows-x86_64 : build/windows/x86_64/flex-ui.dll
@@ -100,18 +103,15 @@ linux-x86_64: build/linux/x86_64/libflex-ui.so
100103all-linux : linux-x86_64
101104
102105macos-universal : build/macos/libflex-ui.dylib
103- ios-arm64 : build/ios/libflex-ui.dylib
104- tvos-arm64 : build/tvos/libflex-ui.dylib
105- visionos-arm64 : build/visionos/libflex-ui.dylib
106- all-apple : macos-universal ios-arm64 tvos-arm64 visionos-arm64
106+ all-apple : macos-universal
107107
108108android-arm64 : build/android/arm64/libflex-ui.so
109109android-arm32 : build/android/arm32/libflex-ui.so
110110android-x86_64 : build/android/x86_64/libflex-ui.so
111111android-x86 : build/android/x86/libflex-ui.so
112112all-android : android-arm64 android-arm32 android-x86_64 android-x86
113113
114- webgl : build/webgl/libflex-ui.bc
114+ webgl : build/webgl/libflex-ui.a
115115all-webgl : webgl
116116
117117# Dockerized builds
0 commit comments