-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmakefile
More file actions
166 lines (151 loc) · 6.4 KB
/
makefile
File metadata and controls
166 lines (151 loc) · 6.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
.DEFAULT_GOAL := help
PROJECTNAME=$(shell basename "$(PWD)")
.PHONY: help
help: makefile
@echo
@echo " Available actions in "$(PROJECTNAME)":"
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo
.PHONY: init fmt codegen example android-debug android-release android-run ios-debug ios-release ios-run clean
## init: Install missing dependencies.
init:
cargo install flutter_rust_bridge_codegen --version 2.11.1 --locked
cargo install --force --locked bindgen-cli
## fmt: Format Rust code.
fmt:
cd rust && cargo fmt --all
## all: Initialize, format, and generate code.
all: init fmt codegen
## codegen: Generate Flutter Rust Bridge code with proper environment
codegen:
@echo "[GENERATING FRB CODE]"
@if [ "$$(uname)" = "Linux" ]; then \
echo "Setting up environment for Linux..."; \
export CPATH="$$(clang -v 2>&1 | grep "Selected GCC installation" | rev | cut -d' ' -f1 | rev)/include" && \
export RUSTFLAGS="--cfg tokio_unstable" && \
echo "CPATH set to: $$CPATH" && \
flutter_rust_bridge_codegen generate; \
elif [ "$$(uname)" = "Darwin" ]; then \
echo "Setting up environment for macOS..."; \
export CPATH="$$(xcrun --show-sdk-path)/usr/include"; \
export LIBRARY_PATH="$$(xcrun --show-sdk-path)/usr/lib"; \
export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"; \
export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"; \
export RUSTFLAGS="--cfg tokio_unstable"; \
echo "SDK path: $$(xcrun --show-sdk-path)"; \
flutter_rust_bridge_codegen generate; \
else \
echo "Running on $$(uname)..."; \
export RUSTFLAGS="--cfg tokio_unstable" && \
flutter_rust_bridge_codegen generate; \
fi
@echo "[Done ✅]"
## example: Run the example app with optional flags
example:
@echo "[RUNNING EXAMPLE APP]"
@if [ "$$(uname)" = "Linux" ]; then \
echo "Clearing problematic environment variables on Linux..."; \
unset CPATH CPLUS_INCLUDE_PATH C_INCLUDE_PATH && cd example && flutter run $(filter-out $@,$(MAKECMDGOALS)); \
else \
echo "Running on $$(uname)..."; \
cd example && flutter run $(filter-out $@,$(MAKECMDGOALS)); \
fi
# This prevents make from trying to run the flags as targets
%:
@:
## android-debug: Build Android debug APK with clean environment
android-debug:
@echo "[BUILDING ANDROID APK]"
@if [ "$$(uname)" = "Linux" ]; then \
echo "Clearing problematic environment variables on Linux..."; \
unset CPATH CPLUS_INCLUDE_PATH C_INCLUDE_PATH && cd example && flutter build apk --debug; \
else \
echo "Building on $$(uname)..."; \
cd example && flutter build apk --debug; \
fi
@echo "[Android APK build complete ✅]"
## android-release: Build Android release APK with clean environment
android-release:
@echo "[BUILDING ANDROID RELEASE APK]"
@if [ "$$(uname)" = "Linux" ]; then \
echo "Clearing problematic environment variables on Linux..."; \
unset CPATH CPLUS_INCLUDE_PATH C_INCLUDE_PATH && cd example && flutter build apk --release; \
else \
echo "Building on $$(uname)..."; \
cd example && flutter build apk --release; \
fi
@echo "[Android release APK build complete ✅]"
## android-run: Run Android app with optional device and other flutter run flags
android-run:
@echo "[RUNNING ANDROID APP]"
@if [ "$$(uname)" = "Linux" ]; then \
echo "Clearing problematic environment variables on Linux..."; \
unset CPATH CPLUS_INCLUDE_PATH C_INCLUDE_PATH && cd example && flutter run $(filter-out $@,$(MAKECMDGOALS)); \
else \
echo "Running on $$(uname)..."; \
cd example && flutter run $(filter-out $@,$(MAKECMDGOALS)); \
fi
@echo "[Android app run complete ✅]"
## ios-debug: Build iOS debug app with proper environment setup
ios-debug:
@echo "[BUILDING IOS DEBUG APP]"
@echo "Setting up iOS build environment..."
@export CARGO_CFG_TARGET_OS=ios && \
export CARGO_CFG_TARGET_ARCH=aarch64 && \
export IPHONEOS_DEPLOYMENT_TARGET=12.0 && \
export BINDGEN_EXTRA_CLANG_ARGS="-isysroot $$(xcrun --show-sdk-path) -I$$(xcrun --show-sdk-path)/usr/include" && \
export CMAKE_SYSTEM_NAME=iOS && \
export CMAKE_OSX_ARCHITECTURES=arm64 && \
export CMAKE_OSX_DEPLOYMENT_TARGET=12.0 && \
export CC_aarch64_apple_ios="$$(xcrun --find clang)" && \
export CXX_aarch64_apple_ios="$$(xcrun --find clang++)" && \
export AR_aarch64_apple_ios="$$(xcrun --find ar)" && \
cd example && flutter build ios --debug --simulator --verbose
@echo "[iOS debug build complete ✅]"
## ios-release: Build iOS release app with proper environment setup
ios-release:
@echo "[BUILDING IOS RELEASE APP]"
@echo "Setting up iOS build environment..."
@export CARGO_CFG_TARGET_OS=ios && \
export CARGO_CFG_TARGET_ARCH=aarch64 && \
export IPHONEOS_DEPLOYMENT_TARGET=12.0 && \
export BINDGEN_EXTRA_CLANG_ARGS="-isysroot $$(xcrun --show-sdk-path) -I$$(xcrun --show-sdk-path)/usr/include" && \
export CMAKE_SYSTEM_NAME=iOS && \
export CMAKE_OSX_ARCHITECTURES=arm64 && \
export CMAKE_OSX_DEPLOYMENT_TARGET=12.0 && \
export CC_aarch64_apple_ios="$$(xcrun --find clang)" && \
export CXX_aarch64_apple_ios="$$(xcrun --find clang++)" && \
export AR_aarch64_apple_ios="$$(xcrun --find ar)" && \
cd example && flutter build ios --release
@echo "[iOS release build complete ✅]"
## ios-run: Run iOS app with optional device and other flutter run flags
ios-run:
@echo "[RUNNING IOS APP]"
@echo "Setting up iOS run environment..."
@export CARGO_CFG_TARGET_OS=ios && \
export CARGO_CFG_TARGET_ARCH=aarch64 && \
export IPHONEOS_DEPLOYMENT_TARGET=12.0 && \
export BINDGEN_EXTRA_CLANG_ARGS="-isysroot $$(xcrun --show-sdk-path) -I$$(xcrun --show-sdk-path)/usr/include" && \
export CMAKE_SYSTEM_NAME=iOS && \
export CMAKE_OSX_ARCHITECTURES=arm64 && \
export CMAKE_OSX_DEPLOYMENT_TARGET=12.0 && \
export CC_aarch64_apple_ios="$$(xcrun --find clang)" && \
export CXX_aarch64_apple_ios="$$(xcrun --find clang++)" && \
export AR_aarch64_apple_ios="$$(xcrun --find ar)" && \
cd example && flutter run $(filter-out $@,$(MAKECMDGOALS))
@echo "[iOS app run complete ✅]"
## clean: Clean build artifacts and caches
clean:
@echo "[CLEANING BUILD ARTIFACTS]"
@echo "Cleaning Rust target directory..."
@cd rust && cargo clean
@echo "Cleaning Flutter build cache..."
@cd example && flutter clean
@echo "Cleaning iOS build cache..."
@if [ -d "example/ios/build" ]; then rm -rf example/ios/build; fi
@if [ -d "example/build" ]; then rm -rf example/build; fi
@echo "Cleaning Pods cache..."
@if [ -d "example/ios/Pods" ]; then rm -rf example/ios/Pods; fi
@if [ -f "example/ios/Podfile.lock" ]; then rm example/ios/Podfile.lock; fi
@echo "[Clean complete ✅]"