-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
91 lines (74 loc) · 3.77 KB
/
Makefile
File metadata and controls
91 lines (74 loc) · 3.77 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
.PHONY: generate specs jni java proto protoc grpc cli clean lint test test-tools build prove
# 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
# Output directory for gRPC proxy code (proto/, grpc/, cmd/jnicli/).
# Set PROXY_DIR to a jni-proxy checkout to generate into that repo.
PROXY_DIR ?= .
# Run all generators
generate: specs jni java proto protoc grpc cli
# 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
# 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
# Run protogen — generates .proto files from Java API specs
# Output goes to PROXY_DIR (set to jni-proxy checkout path).
proto:
go run ./tools/cmd/protogen/ -specs spec/java/ -overlays spec/overlays/java/ -output $(PROXY_DIR)/proto/ -go-module github.com/AndroidGoLab/jni-proxy
@mkdir -p $(PROXY_DIR)/proto/handlestore
@cp spec/handlestore.proto $(PROXY_DIR)/proto/handlestore/handlestore.proto
# Run protoc — compiles .proto files to Go stubs
protoc: proto
@command -v protoc >/dev/null 2>&1 || { echo "protoc not found. Install: https://grpc.io/docs/protoc-installation/"; exit 1; }
@for dir in $(PROXY_DIR)/proto/*/; do \
pkg=$$(basename "$$dir"); \
protoc -I. --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
"$$dir$$pkg.proto"; \
done
# Run grpcgen — generates gRPC server and client wrappers
grpc: protoc
go run ./tools/cmd/grpcgen/ -specs spec/java/ -overlays spec/overlays/java/ -output $(PROXY_DIR) -go-module github.com/AndroidGoLab/jni-proxy
# Run cligen — generates jnicli cobra commands from Java API specs
cli: grpc
go run ./tools/cmd/cligen/ -specs spec/java/ -overlays spec/overlays/java/ -output $(PROXY_DIR)/cmd/jnicli/ -go-module github.com/AndroidGoLab/jni-proxy
# 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/...
# 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
# 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 ./...