Repository navigation
Expand file tree
/
Copy pathjustfile
More file actions
185 lines (151 loc) · 6.58 KB
/
Copy pathjustfile
File metadata and controls
185 lines (151 loc) · 6.58 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
set shell := ["bash", "-eu", "-o", "pipefail", "-c"]
# detect platform
_os := os()
_arch := arch()
_is_macos := if _os == "macos" { "true" } else { "false" }
_is_linux := if _os == "linux" { "true" } else { "false" }
# environment variables with platform-aware defaults
export JAVA_HOME := env_var_or_default('JAVA_HOME', if _is_macos == "true" { "/opt/homebrew/opt/openjdk@21/" } else { "/usr/lib/jvm/java-21-openjdk-amd64" })
export ANDROID_SDK_ROOT := env_var_or_default('ANDROID_SDK_ROOT', if _is_macos == "true" { "/opt/homebrew/share/android-commandlinetools" } else { env_var_or_default('ANDROID_HOME', "/usr/local/lib/android/sdk") })
export ANDROID_NDK_HOME := env_var_or_default('ANDROID_NDK_HOME', ANDROID_SDK_ROOT + "/ndk/26.3.11579264")
# some tools expect these aliases
export ANDROID_NDK_ROOT := ANDROID_NDK_HOME
export ANDROID_NDK := ANDROID_NDK_HOME
# platform-specific PATH setup
_platform_tools := ANDROID_SDK_ROOT + "/platform-tools"
_emulator_tools := ANDROID_SDK_ROOT + "/emulator"
export PATH := _platform_tools + ":" + _emulator_tools + ":" + env_var('PATH')
# platform-specific NDK paths
_host_lib_ext := if _is_macos == "true" { "dylib" } else { "so" }
_host_lib_name := "libchroma_jni." + _host_lib_ext
# Full build: setup targets, build for host, test all
build: setup-targets build-for-host test
# Build optimized for host testing (macOS/Linux)
build-for-host: setup-targets _build-rust-host _build-android
@echo "✅ Build for host complete - ready for local testing"
# Build for Android deployment only
build-for-android: setup-targets _build-rust-android _build-android
@echo "✅ Build for Android complete - ready for device deployment"
# Build optimized for CI environment
build-for-ci: setup-targets _build-rust-ci _build-android
@echo "✅ Build for CI complete"
# Install Rust Android targets
setup-targets:
@echo "🔧 Setting up build targets..."
rustup target add aarch64-linux-android
@echo "✅ Build targets ready"
_build-rust-host:
@echo "🖥️ Building Rust JNI library for host ({{_os}})..."
mkdir -p src/test/resources/natives
cd rust && cargo build --release
cp rust/target/release/{{_host_lib_name}} src/test/resources/natives/libchroma_jni.{{_host_lib_ext}}
@echo " ✅ Host library built ({{_host_lib_name}})"
_build-rust-android:
@echo "🤖 Building Rust JNI library for Android via Gradle plugin..."
./gradlew cargoBuild
@echo " ✅ Android library built"
_build-rust-ci: _build-rust-android
@echo "🖥️ Building Rust JNI library for CI host..."
mkdir -p src/test/resources/natives
(cd rust && cargo build --release --lib)
cp rust/target/release/{{_host_lib_name}} src/test/resources/natives/libchroma_jni.{{_host_lib_ext}}
@echo " ✅ CI host library built ({{_host_lib_name}} -> libchroma_jni.{{_host_lib_ext}})"
_build-android:
@echo "📱 Building Android library..."
./gradlew build --build-cache --parallel
@echo "✅ Android library built successfully"
# Run all tests (Rust + Android unit tests)
test: test-host test-android
@echo "✅ All tests passed!"
# Run Rust tests on host platform
test-host:
@echo "🦀 Running Rust tests on host..."
(cd rust && cargo test --lib)
@echo "✅ Host tests passed"
# Run Android unit tests with smart library loading
test-android:
@echo "🧪 Running Android unit tests..."
./gradlew test --build-cache --parallel
@echo "✅ Android unit tests passed"
# Clean all build artifacts
clean:
(cd rust && cargo clean)
./gradlew clean
@echo "🧹 All build artifacts cleaned"
# Format all code (Java + Rust)
format:
@echo "✨ Formatting Java code..."
./gradlew spotlessApply
@echo "✨ Formatting Rust code..."
(cd rust && cargo fmt)
@echo "✅ Code formatting complete"
# Check code formatting without applying changes
format-check:
@echo "🔍 Checking Java code formatting..."
./gradlew spotlessCheck
@echo "🔍 Checking Rust code formatting..."
(cd rust && cargo fmt --check)
@echo "✅ Code formatting check complete"
# Development workflow: clean, build, test
dev: clean build test
# Show built AAR and native library files
show-outputs:
@echo "📦 Build outputs:"
@ls -la build/outputs/aar/ 2>/dev/null || echo "No AAR files yet"
@echo ""
@echo "🔧 Native libraries:"
@ls -la src/main/jniLibs/*/lib*.so 2>/dev/null || echo "No native libraries yet"
# Open Android unit test report in browser
open-test-report:
open build/reports/tests/testDebugUnitTest/index.html
# Build hello-world example app
build-hello-world: build-for-android
./gradlew :examples:hello-world:assembleDebug
@echo "✅ Hello World app built successfully"
# Install hello-world app on connected device
install-hello-world: build-hello-world
adb install -r examples/hello-world/build/outputs/apk/debug/hello-world-debug.apk
@echo "✅ Hello World app installed on device"
# Launch hello-world app on device
run-hello-world: install-hello-world
adb shell am start -n com.trychroma.android.helloworld/.MainActivity
@echo "🚀 Hello World app launched"
# Build Android release AAR
build-android-release:
./gradlew clean cargoBuildArm64 :assembleRelease --no-daemon --parallel
@echo "✅ Android .aar built successfully"
# List available Android Virtual Devices
list-avds:
@echo "📱 Available Android Virtual Devices:"
avdmanager list avd
# Create new Android Virtual Device
create-avd:
@echo "🔧 Creating Android emulator..."
avdmanager create avd -n Pixel_3a_API_34_arm64 -k "system-images;android-34;google_apis;arm64-v8a" --device "pixel_3a"
@echo "✅ AVD created"
# Start Android emulator and wait for boot
emulator-start:
@echo "🤖 Starting Android emulator..."
emulator -avd Pixel_3a_API_34_arm64 -no-snapshot-save &
@echo "⏳ Waiting for emulator to boot..."
adb wait-for-device
@echo "✅ Emulator ready"
# Full demo: start emulator and run hello-world
demo: emulator-start run-hello-world
# View filtered Android logs (Chroma-related only)
adb-logs:
@echo "📱 Viewing Android logs (Ctrl+C to stop)..."
adb logcat | grep -E "(chroma|ChromaNative|com.trychroma.android.helloworld|AndroidRuntime)"
# View all Android logs
adb-logs-all:
@echo "📱 Viewing all Android logs (Ctrl+C to stop)..."
adb logcat
# Look for recent crash logs
adb-logs-crash:
@echo "💥 Looking for recent crash logs..."
adb logcat -d | grep -E "(FATAL|AndroidRuntime|chroma|ChromaNative)" | tail -50
# Clear Android log buffer
adb-logs-clear:
@echo "🧹 Clearing Android log buffer..."
adb logcat -c
@echo "✅ Android logs cleared"