Skip to content

Commit dcc5789

Browse files
authored
Merge pull request #175 from aojea/mmobile
Support sam-node on Android and iOS
2 parents ecb7acd + 1ad6a4e commit dcc5789

105 files changed

Lines changed: 4079 additions & 1025 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ env:
2929

3030
jobs:
3131
bats_tests:
32-
runs-on: ubuntu-22.04
32+
runs-on: ubuntu-22.04-16core
3333
name: Bats e2e tests
3434
steps:
3535
- name: Checkout
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
name: Test Flutter App
15+
16+
on:
17+
push:
18+
branches:
19+
- 'main'
20+
- 'mmobile'
21+
tags:
22+
- 'v*'
23+
pull_request:
24+
branches: [ main, mmobile ]
25+
26+
env:
27+
GO_VERSION: "1.26"
28+
29+
jobs:
30+
build-ffi:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6
34+
with:
35+
go-version: ${{ env.GO_VERSION }}
36+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v6
37+
- run: make mobile-ffi-host
38+
39+
analyze-flutter:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v6
43+
- uses: subosito/flutter-action@1a449444c387b1966244ae4d4f8c696479add0b2 # v2
44+
with:
45+
channel: 'stable'
46+
- name: Install dependencies
47+
run: flutter pub get
48+
working-directory: mobile/sam-node-app
49+
- name: Analyze code
50+
run: flutter analyze
51+
working-directory: mobile/sam-node-app
52+
53+
e2e-android:
54+
runs-on: ubuntu-22.04-16core
55+
steps:
56+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v6
57+
- uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6
58+
with:
59+
go-version: ${{ env.GO_VERSION }}
60+
- uses: subosito/flutter-action@1a449444c387b1966244ae4d4f8c696479add0b2 # v2
61+
with:
62+
channel: 'stable'
63+
- name: Set up JDK
64+
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
65+
with:
66+
java-version: '17'
67+
distribution: 'temurin'
68+
- name: Enable KVM group perms
69+
run: |
70+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
71+
sudo udevadm control --reload-rules
72+
sudo udevadm trigger --name-match=kvm
73+
- name: Run E2E Integration Test in Android Emulator
74+
uses: ReactiveCircus/android-emulator-runner@b86636dcd5723ef0161e7f288e9bd0ad01258791 # v2.30.0
75+
with:
76+
api-level: 30
77+
target: google_apis
78+
arch: x86_64
79+
disable-animations: true
80+
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
81+
emulator-boot-timeout: 300
82+
script: ./mobile/mobile_e2e.sh

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ tests/integration/scratch/
3838
__pycache__/
3939
.venv/
4040
*.egg-info/
41+
keys.db
42+
mobile/logcat.txt
43+

Makefile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,62 @@ OUT_DIR=$(REPO_ROOT)/bin
55
CGO_ENABLED=0
66
export GOROOT GO111MODULE CGO_ENABLED
77

8+
# Autodetect Android SDK and NDK
9+
ANDROID_HOME_RESOLVED:=$(if $(ANDROID_HOME),$(ANDROID_HOME),$(firstword $(wildcard $(HOME)/Android/Sdk $(HOME)/Library/Android/sdk)))
10+
ANDROID_NDK_LATEST:=$(shell ls -d $(ANDROID_HOME_RESOLVED)/ndk/* 2>/dev/null | sort -V | tail -n 1)
11+
12+
UNAME_S := $(shell uname -s)
13+
HOST_OS_NAME := linux-x86_64
14+
ifeq ($(UNAME_S),Darwin)
15+
HOST_OS_NAME := darwin-x86_64
16+
endif
17+
18+
ANDROID_NDK_TOOLCHAIN=$(ANDROID_NDK_LATEST)/toolchains/llvm/prebuilt/$(HOST_OS_NAME)/bin
19+
ANDROID_CC_ARM64=$(ANDROID_NDK_TOOLCHAIN)/aarch64-linux-android30-clang
20+
ANDROID_CC_X86_64=$(ANDROID_NDK_TOOLCHAIN)/x86_64-linux-android30-clang
21+
22+
823
build:
924
go build -v -o "$(OUT_DIR)/sam-node" ./cmd/sam-node
1025
go build -v -o "$(OUT_DIR)/sam-hub" ./cmd/sam-hub
1126
go build -v -o "$(OUT_DIR)/mcp-client" ./cmd/mcp-client
1227

28+
.PHONY: mobile-ffi-host mobile-ffi-android mobile-ffi-android-x86_64 mobile-ffi-ios mobile-ffi mobile-app-apk mobile-app-apk-emulator
29+
mobile-ffi-host:
30+
mkdir -p "$(OUT_DIR)"
31+
CGO_ENABLED=1 go build -v -buildmode=c-shared -o "$(OUT_DIR)/libsam.so" ./mobile/sam-node-ffi
32+
33+
mobile-ffi-android:
34+
@if [ -z "$(ANDROID_NDK_LATEST)" ]; then \
35+
echo "Error: Android NDK not found under $(ANDROID_HOME_RESOLVED)/ndk/. Please install NDK (Side-by-side) via Android Studio or sdkmanager." >&2; \
36+
exit 1; \
37+
fi
38+
GOOS=android GOARCH=arm64 CGO_ENABLED=1 CC=$(ANDROID_CC_ARM64) go build -v -ldflags="-checklinkname=0" -buildmode=c-shared -o "$(OUT_DIR)/android/libsam.so" ./mobile/sam-node-ffi
39+
40+
mobile-ffi-android-x86_64:
41+
@if [ -z "$(ANDROID_NDK_LATEST)" ]; then \
42+
echo "Error: Android NDK not found under $(ANDROID_HOME_RESOLVED)/ndk/. Please install NDK (Side-by-side) via Android Studio or sdkmanager." >&2; \
43+
exit 1; \
44+
fi
45+
mkdir -p "$(OUT_DIR)/android-x86_64"
46+
GOOS=android GOARCH=amd64 CGO_ENABLED=1 CC=$(ANDROID_CC_X86_64) go build -v -ldflags="-checklinkname=0" -buildmode=c-shared -o "$(OUT_DIR)/android-x86_64/libsam.so" ./mobile/sam-node-ffi
47+
48+
mobile-ffi-ios:
49+
mkdir -p "$(OUT_DIR)/ios"
50+
GOOS=ios GOARCH=arm64 CGO_ENABLED=1 go build -v -buildmode=c-archive -o "$(OUT_DIR)/ios/libsam.a" ./mobile/sam-node-ffi
51+
52+
mobile-ffi: mobile-ffi-host mobile-ffi-android mobile-ffi-android-x86_64 mobile-ffi-ios
53+
54+
mobile-app-apk: mobile-ffi-android
55+
mkdir -p mobile/sam-node-app/android/app/src/main/jniLibs/arm64-v8a
56+
cp "$(OUT_DIR)/android/libsam.so" mobile/sam-node-app/android/app/src/main/jniLibs/arm64-v8a/libsam.so
57+
cd mobile/sam-node-app && flutter build apk --release
58+
59+
mobile-app-apk-emulator: mobile-ffi-android-x86_64
60+
mkdir -p mobile/sam-node-app/android/app/src/main/jniLibs/x86_64
61+
cp "$(OUT_DIR)/android-x86_64/libsam.so" mobile/sam-node-app/android/app/src/main/jniLibs/x86_64/libsam.so
62+
cd mobile/sam-node-app && flutter build apk --release
63+
1364
.PHONY: proto
1465
proto:
1566
./hack/gen-proto.sh

0 commit comments

Comments
 (0)