-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
111 lines (96 loc) · 4.13 KB
/
Copy pathMakefile
File metadata and controls
111 lines (96 loc) · 4.13 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
.PHONY: generate specs aar-specs jni java clean lint test test-tools build prove examples aar-resolve
# JDK detection for host tests (jni.h and libjvm.so).
JDK_HOME ?= $(shell readlink -f $$(which javac) 2>/dev/null | sed 's|/bin/javac$$||')
JNI_INCLUDE ?= $(JDK_HOME)/include
LIBJVM_DIR ?= $(shell find $(JDK_HOME) -name libjvm.so -printf '%h' -quit 2>/dev/null)
# Android SDK platform JAR for specgen.
ANDROID_JAR ?= $(ANDROID_HOME)/platforms/android-36/android.jar
# Run all generators (proto/grpc/cli generation moved to jni-proxy repo)
generate: specs jni java
# Run specgen — generates YAML specs from ref/ .class files
specs:
go run ./tools/cmd/specgen/ -ref ref -classpath $(ANDROID_JAR) -output spec/java/ -go-module github.com/AndroidGoLab/jni
# Generate YAML specs for AndroidX/Material classes from the cycle 2 AAR
# closure produced by `make aar-resolve` and extracted by lock-paths.
# Requires .aar-cache/lock.json plus the .aar-cache/extracted/ tree.
# Tradeoff: `make specs` does not pass -jars-dir, so re-running it after
# `make aar-specs` may regenerate without the AAR-sourced classes; treat
# `make aar-specs` as the superset target until the two are unified.
aar-specs:
go run ./tools/cmd/specgen/ \
-ref ref \
-jars-dir .aar-cache/extracted \
-classpath $(ANDROID_JAR) \
-output spec/java/ \
-go-module github.com/AndroidGoLab/jni
# Run jnigen only — generates capi/ and root package idiomatic files
jni:
go run ./tools/cmd/jnigen/ -spec spec/jni.yaml -overlay spec/overlays/jni.yaml -templates templates/jni/ -output .
# Run javagen only — generates high-level Android API packages
java:
go run ./tools/cmd/javagen/ -specs spec/java/ -overlays spec/overlays/java/ -templates templates/java/ -output . -go-module github.com/AndroidGoLab/jni
# Remove all generated files (identified by "DO NOT EDIT" header), excluding tools/
clean:
grep -rl "Code generated by jnigen\. DO NOT EDIT\." --include="*.go" --exclude-dir=tools . | xargs -r rm -f
grep -rl "Code generated by javagen\. DO NOT EDIT\." --include="*.go" --exclude-dir=tools . | xargs -r rm -f
find . -path '*/consts' -type d -empty -not -path './tools/*' -delete 2>/dev/null || true
rm -f capi/cgo_vtable_dispatch.h
# Run golangci-lint
lint:
golangci-lint run ./...
# Run all tests (requires JDK for jni.h)
test:
@if [ -z "$(JDK_HOME)" ] || [ ! -d "$(JNI_INCLUDE)" ]; then \
echo "Error: JDK not found. Install a JDK or set JDK_HOME."; \
exit 1; \
fi
C_INCLUDE_PATH="$(JNI_INCLUDE):$(JNI_INCLUDE)/linux" \
LD_LIBRARY_PATH="$(LIBJVM_DIR)" \
go test ./...
# Run only tool tests (no JDK needed)
test-tools:
go test ./tools/...
# Resolve the Material 3 AAR/JAR closure (Cycle 2 of material3-widget-bindings).
# Top-level coordinates: appcompat 1.7.0 + material 1.12.0 + recyclerview 1.3.2
# + constraintlayout 2.1.4. Output: .aar-cache/lock.json plus a SHA-256 verified
# cache under .aar-cache/.
aar-resolve:
go run ./tools/cmd/aar-resolve \
--top androidx.appcompat:appcompat:1.7.0 \
--top com.google.android.material:material:1.12.0 \
--top androidx.recyclerview:recyclerview:1.3.2 \
--top androidx.constraintlayout:constraintlayout:2.1.4 \
--top androidx.drawerlayout:drawerlayout:1.1.1 \
--cache .aar-cache \
--lock .aar-cache/lock.json \
--max-concurrency 8
# Verify Lean proofs (requires elan/lake)
prove:
@command -v lake >/dev/null 2>&1 || { echo "lake not found. Install elan: https://github.com/leanprover/elan"; exit 1; }
cd proofs && lake build
# Build all example APKs (requires Android SDK + NDK)
EXAMPLE_DIRS := $(sort $(dir $(wildcard examples/*/Makefile)))
examples:
@failed=""; \
for d in $(EXAMPLE_DIRS); do \
name=$$(basename $$d); \
printf " %-20s" "$$name"; \
if $(MAKE) -C $$d build >/dev/null 2>&1; then \
echo "OK"; \
else \
echo "FAIL"; \
failed="$$failed $$name"; \
fi; \
done; \
if [ -n "$$failed" ]; then \
echo "Failed:$$failed"; \
exit 1; \
fi; \
echo "All examples built."
# Cross-compile libraries for android/arm64 (requires NDK toolchain)
build:
CGO_ENABLED=1 \
GOOS=android \
GOARCH=arm64 \
CC=$(shell echo $$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang) \
go build ./...