Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions .github/patches/mobile-bench-rs-browserstack-devices.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
diff --git a/crates/mobench-sdk/src/builders/android.rs b/crates/mobench-sdk/src/builders/android.rs
index 0f18c9a..9fcc7da 100644
--- a/crates/mobench-sdk/src/builders/android.rs
+++ b/crates/mobench-sdk/src/builders/android.rs
@@ -326,7 +326,7 @@ impl AndroidBuilder {
// Check that at least one native library exists in jniLibs
let jni_libs_dir = self.output_dir.join("android/app/src/main/jniLibs");
let lib_name = format!("lib{}.so", self.crate_name.replace("-", "_"));
- let required_abis = ["arm64-v8a", "armeabi-v7a", "x86_64"];
+ let required_abis = ["arm64-v8a"];
let mut found_libs = 0;
for abi in &required_abis {
let lib_path = jni_libs_dir.join(abi).join(&lib_name);
@@ -458,7 +458,7 @@ impl AndroidBuilder {
self.check_cargo_ndk()?;

// Android ABIs to build for
- let abis = vec!["arm64-v8a", "armeabi-v7a", "x86_64"];
+ let abis = vec!["arm64-v8a"];
let release_flag = if matches!(config.profile, BuildProfile::Release) {
"--release"
} else {
diff --git a/crates/mobench-sdk/src/codegen.rs b/crates/mobench-sdk/src/codegen.rs
index 693156a..2ba0a35 100644
--- a/crates/mobench-sdk/src/codegen.rs
+++ b/crates/mobench-sdk/src/codegen.rs
@@ -335,6 +335,19 @@ pub fn generate_android_project(
default_function: &str,
) -> Result<(), BenchError> {
let target_dir = output_dir.join("android");
+ let assets_backup_dir = output_dir.join(".android-assets-backup");
+ let existing_assets_dir = target_dir.join("app/src/main/assets");
+ if existing_assets_dir.exists() {
+ if assets_backup_dir.exists() {
+ fs::remove_dir_all(&assets_backup_dir).map_err(|e| {
+ BenchError::Build(format!(
+ "Failed to clear Android assets backup at {:?}: {}",
+ assets_backup_dir, e
+ ))
+ })?;
+ }
+ copy_dir_recursive(&existing_assets_dir, &assets_backup_dir)?;
+ }
reset_generated_project_dir(&target_dir)?;
let library_name = project_slug.replace('-', "_");
let project_pascal = to_pascal_case(project_slug);
@@ -378,6 +391,54 @@ pub fn generate_android_project(
// The package "dev.world.{project_slug}" maps to directory "dev/world/{project_slug}/"
move_kotlin_files_to_package_dir(&target_dir, &package_name)?;

+ if assets_backup_dir.exists() {
+ let restored_assets_dir = target_dir.join("app/src/main/assets");
+ copy_dir_recursive(&assets_backup_dir, &restored_assets_dir)?;
+ let _ = fs::remove_dir_all(&assets_backup_dir);
+ }
+
+ Ok(())
+}
+
+fn copy_dir_recursive(src: &Path, dst: &Path) -> Result<(), BenchError> {
+ fs::create_dir_all(dst).map_err(|e| {
+ BenchError::Build(format!(
+ "Failed to create directory {:?} while copying assets: {}",
+ dst, e
+ ))
+ })?;
+
+ for entry in fs::read_dir(src).map_err(|e| {
+ BenchError::Build(format!(
+ "Failed to read directory {:?} while copying assets: {}",
+ src, e
+ ))
+ })? {
+ let entry = entry.map_err(|e| {
+ BenchError::Build(format!(
+ "Failed to read entry under {:?} while copying assets: {}",
+ src, e
+ ))
+ })?;
+ let entry_path = entry.path();
+ let dest_path = dst.join(entry.file_name());
+ if entry.file_type().map_err(|e| {
+ BenchError::Build(format!(
+ "Failed to inspect {:?} while copying assets: {}",
+ entry_path, e
+ ))
+ })?.is_dir() {
+ copy_dir_recursive(&entry_path, &dest_path)?;
+ } else {
+ fs::copy(&entry_path, &dest_path).map_err(|e| {
+ BenchError::Build(format!(
+ "Failed to copy {:?} to {:?}: {}",
+ entry_path, dest_path, e
+ ))
+ })?;
+ }
+ }
+
Ok(())
}
97 changes: 97 additions & 0 deletions .github/workflows/mobile-bench-pr-auto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Mobile Bench PR Auto

on:
pull_request:
types: [labeled]
workflow_run:
workflows: ["Cargo Build & Test"]
types: [completed]

permissions:
contents: read
actions: write
pull-requests: read
checks: read

jobs:
resolve:
name: Check compile gate and resolve context
runs-on: ubuntu-latest
if: >-
(github.event_name == 'pull_request' && github.event.action == 'labeled') ||
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')
outputs:
should_run: ${{ steps.pr.outputs.should_run }}
pr_number: ${{ steps.pr.outputs.pr_number }}
head_sha: ${{ steps.pr.outputs.head_sha }}
requested_by: ${{ steps.pr.outputs.requested_by }}
steps:
- name: Resolve PR context
id: pr
env:
GH_TOKEN: ${{ github.token }}
EVENT_NAME: ${{ github.event_name }}
PR_NUMBER_EVENT: ${{ github.event.pull_request.number }}
HEAD_SHA_PR: ${{ github.event.pull_request.head.sha }}
BASE_REF_PR: ${{ github.event.pull_request.base.ref }}
HEAD_SHA_WR: ${{ github.event.workflow_run.head_sha }}
REPO: ${{ github.repository }}
run: |
set -euo pipefail

if [ "$EVENT_NAME" = "pull_request" ]; then
PR_NUMBER="$PR_NUMBER_EVENT"
HEAD_SHA="$HEAD_SHA_PR"
REQUESTED_BY="auto:pull_request"
else
pr_json=$(gh api "repos/${REPO}/pulls?state=open&sort=updated&direction=desc&per_page=50" \
--jq ".[] | select(.head.sha == \"${HEAD_SHA_WR}\") | {number, base_ref: .base.ref}" \
| head -1)
if [ -z "$pr_json" ]; then
echo "::notice::No open PR found for SHA ${HEAD_SHA_WR}, skipping"
echo "should_run=false" >> "$GITHUB_OUTPUT"
exit 0
fi

PR_NUMBER=$(jq -r '.number' <<<"$pr_json")
HEAD_SHA="$HEAD_SHA_WR"
REQUESTED_BY="auto:workflow_run"
fi

has_label=$(gh api "repos/${REPO}/issues/${PR_NUMBER}/labels" \
--jq '.[].name' | grep -qx 'bench' && echo "true" || echo "false")
if [ "$has_label" != "true" ]; then
echo "::notice::PR #${PR_NUMBER} does not have 'bench' label, skipping"
echo "should_run=false" >> "$GITHUB_OUTPUT"
exit 0
fi

gate_status=$(gh api "repos/${REPO}/commits/${HEAD_SHA}/check-runs" \
--jq '.check_runs[] | select(.name == "Cargo Build & Test" or (.app.name == "GitHub Actions" and .name == "Cargo Build & Test")) | .conclusion' \
| head -1)
if [ "$gate_status" != "success" ]; then
echo "::notice::Compile gate 'Cargo Build & Test' not yet passed for ${HEAD_SHA} (status: ${gate_status:-pending})"
echo "should_run=false" >> "$GITHUB_OUTPUT"
exit 0
fi

echo "pr_number=${PR_NUMBER}" >> "$GITHUB_OUTPUT"
echo "head_sha=${HEAD_SHA}" >> "$GITHUB_OUTPUT"
echo "requested_by=${REQUESTED_BY}" >> "$GITHUB_OUTPUT"
echo "should_run=true" >> "$GITHUB_OUTPUT"

browserstack:
name: Run BrowserStack benchmarks
needs: resolve
if: needs.resolve.outputs.should_run == 'true'
uses: ./.github/workflows/mobile-bench-reusable.yml
secrets: inherit
with:
crate_path: ./bench-mobile
functions: '["bench_mobile::bench_passport_complete_age_check_prepare","bench_mobile::bench_passport_complete_age_check_prove","bench_mobile::bench_passport_complete_age_check_verify","bench_mobile::bench_passport_complete_age_check_e2e"]'
platform: both
iterations: "30"
warmup: "5"
pr_number: ${{ needs.resolve.outputs.pr_number }}
requested_by: ${{ needs.resolve.outputs.requested_by }}
head_sha: ${{ needs.resolve.outputs.head_sha }}
114 changes: 114 additions & 0 deletions .github/workflows/mobile-bench-pr-command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Mobile Bench PR Command

on:
issue_comment:
types: [created]

permissions:
contents: read
actions: write
pull-requests: read
issues: read

jobs:
resolve:
name: Parse /mobench and resolve context
if: >-
github.event_name == 'issue_comment' &&
github.event.action == 'created' &&
github.event.issue.pull_request &&
startsWith(github.event.comment.body, '/mobench')
runs-on: ubuntu-latest
outputs:
trusted: ${{ steps.trust.outputs.trusted }}
platform: ${{ steps.parse.outputs.platform }}
iterations: ${{ steps.parse.outputs.iterations }}
warmup: ${{ steps.parse.outputs.warmup }}
head_sha: ${{ steps.pr.outputs.head_sha }}
pr_number: ${{ github.event.issue.number }}
requested_by: ${{ github.event.comment.user.login }}
steps:
- name: Check trust
id: trust
env:
AUTHOR_ASSOCIATION: ${{ github.event.comment.author_association }}
run: |
if echo "OWNER,MEMBER,COLLABORATOR" | tr ',' '\n' | grep -qx "$AUTHOR_ASSOCIATION"; then
echo "trusted=true" >> "$GITHUB_OUTPUT"
else
echo "::warning::Untrusted author association: $AUTHOR_ASSOCIATION"
echo "trusted=false" >> "$GITHUB_OUTPUT"
fi

- name: Parse command
if: steps.trust.outputs.trusted == 'true'
id: parse
env:
COMMENT_BODY: ${{ github.event.comment.body }}
run: |
set -euo pipefail
line=$(echo "$COMMENT_BODY" | head -1)

extract_val() {
echo "$line" | sed -n "s/.*${1}=\([^ ]*\).*/\1/p"
}

platform=$(extract_val platform)
device_profile=$(extract_val device_profile)
iterations=$(extract_val iterations)
warmup=$(extract_val warmup)

case "${platform:-both}" in
android|ios|both) platform="${platform:-both}" ;;
*) echo "::warning::Invalid platform '${platform}', defaulting to 'both'"; platform="both" ;;
esac

case "${device_profile:-triad}" in
triad|low-spec|mid-spec|high-spec|flagship) device_profile="${device_profile:-triad}" ;;
*) echo "::warning::Invalid device_profile '${device_profile}', defaulting to 'triad'"; device_profile="triad" ;;
esac

if ! [[ "${iterations:-30}" =~ ^[0-9]+$ ]]; then
echo "::warning::Invalid iterations '${iterations}', defaulting to '30'"
iterations="30"
else
iterations="${iterations:-30}"
fi

if ! [[ "${warmup:-5}" =~ ^[0-9]+$ ]]; then
echo "::warning::Invalid warmup '${warmup}', defaulting to '5'"
warmup="5"
else
warmup="${warmup:-5}"
fi

echo "platform=${platform}" >> "$GITHUB_OUTPUT"
echo "device_profile=${device_profile}" >> "$GITHUB_OUTPUT"
echo "iterations=${iterations}" >> "$GITHUB_OUTPUT"
echo "warmup=${warmup}" >> "$GITHUB_OUTPUT"

- name: Resolve PR refs
if: steps.trust.outputs.trusted == 'true'
id: pr
env:
GH_TOKEN: ${{ github.token }}
PR_URL: ${{ github.event.issue.pull_request.url }}
run: |
head_sha=$(gh api "$PR_URL" --jq '.head.sha')
echo "head_sha=${head_sha}" >> "$GITHUB_OUTPUT"

browserstack:
name: Run BrowserStack benchmarks
needs: resolve
if: needs.resolve.outputs.trusted == 'true'
uses: ./.github/workflows/mobile-bench-reusable.yml
secrets: inherit
with:
crate_path: ./bench-mobile
functions: '["bench_mobile::bench_passport_complete_age_check_prepare","bench_mobile::bench_passport_complete_age_check_prove","bench_mobile::bench_passport_complete_age_check_verify","bench_mobile::bench_passport_complete_age_check_e2e"]'
platform: ${{ needs.resolve.outputs.platform }}
iterations: ${{ needs.resolve.outputs.iterations }}
warmup: ${{ needs.resolve.outputs.warmup }}
pr_number: ${{ needs.resolve.outputs.pr_number }}
requested_by: ${{ needs.resolve.outputs.requested_by }}
head_sha: ${{ needs.resolve.outputs.head_sha }}
Loading
Loading