1
1
STRIP ?= strip
2
- EMCXX ?= em++
3
2
SED ?= sed
3
+ # WebGL toolchain
4
+ EMAR ?= emar
5
+ EMCXX ?= em++
6
+ # Android setup
4
7
ANDROID_NDK_ROOT ?=
8
+ # macOS
5
9
CODESIGN ?= codesign
6
10
MACOS_CODESIGN_SIGNATURE ?=
7
11
8
12
LINKFLAGS += -shared
9
- CXXFLAGS += -Iyoga~ - std=c++20 -fvisibility=hidden
13
+ CXXFLAGS += -std=c++20 -fvisibility=hidden
10
14
ifeq ($(DEBUG ) ,1)
11
15
CXXFLAGS += -O0 -g
12
16
else
@@ -16,24 +20,37 @@ endif
16
20
BUILD_DIRS = \
17
21
build/windows/x86_64 build/windows/x86 \
18
22
build/linux/x86_64 \
19
- build/macos build/ios build/tvos build/visionos \
23
+ build/macos \
20
24
build/android/arm64 build/android/arm32 build/android/x86 build/android/x86_64 \
21
25
build/webgl
22
26
23
27
# Misc
24
28
$(BUILD_DIRS ) :
25
29
mkdir -p $@
26
30
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 | %
28
45
$(CXX ) -o $@ $< $(CXXFLAGS ) $(LINKFLAGS )
29
46
$(STRIP ) -x $@
30
47
31
48
% /libflex-ui.so : CXXFLAGS += -fPIC
32
- % /libflex-ui.so : src~/ flex-ui.cpp | %
49
+ % /libflex-ui.so : flex-ui-amalgamated .cpp | %
33
50
$(CXX ) -o $@ $< $(CXXFLAGS ) $(LINKFLAGS )
34
51
$(STRIP ) -x $@
35
52
36
- % /libflex-ui.dylib : src~/ flex-ui.cpp | %
53
+ % /libflex-ui.dylib : flex-ui-amalgamated .cpp | %
37
54
$(CXX ) -o $@ $< $(CXXFLAGS ) $(LINKFLAGS )
38
55
install_name_tool -id @rpath/$(@F ) $@
39
56
$(STRIP ) -x $@
44
61
# macOS
45
62
build/macos/libflex-ui.dylib : CXXFLAGS += -arch x86_64 -arch arm64
46
63
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
-
56
64
# Android
57
65
check-ndk-root :
58
66
ifndef ANDROID_NDK_ROOT
@@ -72,13 +80,8 @@ build/android/x86/libflex-ui.so: CXX = $(wildcard $(ANDROID_NDK_ROOT)/toolchains
72
80
build/android/x86/libflex-ui.so : check-ndk-root
73
81
74
82
# 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 )
82
85
83
86
# Targets
84
87
windows-x86_64 : build/windows/x86_64/flex-ui.dll
@@ -100,18 +103,15 @@ linux-x86_64: build/linux/x86_64/libflex-ui.so
100
103
all-linux : linux-x86_64
101
104
102
105
macos-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
107
107
108
108
android-arm64 : build/android/arm64/libflex-ui.so
109
109
android-arm32 : build/android/arm32/libflex-ui.so
110
110
android-x86_64 : build/android/x86_64/libflex-ui.so
111
111
android-x86 : build/android/x86/libflex-ui.so
112
112
all-android : android-arm64 android-arm32 android-x86_64 android-x86
113
113
114
- webgl : build/webgl/libflex-ui.bc
114
+ webgl : build/webgl/libflex-ui.a
115
115
all-webgl : webgl
116
116
117
117
# Dockerized builds
0 commit comments