Skip to content

Commit 1915417

Browse files
committed
Migrate file_operations to use Rust
1 parent 39c2bec commit 1915417

20 files changed

+1350
-60
lines changed

.github/workflows/android-build.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,39 @@ jobs:
2121
with:
2222
distribution: "temurin"
2323
java-version: 17
24+
- name: Install Rust
25+
uses: dtolnay/rust-toolchain@stable
26+
with:
27+
toolchain: stable
28+
- name: Cache Rust dependencies
29+
uses: actions/cache@v4
30+
with:
31+
path: |
32+
~/.cargo/bin/
33+
~/.cargo/registry/index/
34+
~/.cargo/registry/cache/
35+
~/.cargo/git/db/
36+
file_operations/target/
37+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
38+
restore-keys: |
39+
${{ runner.os }}-cargo-
40+
- name: Setup Rust for Android
41+
run: |
42+
cd file_operations
43+
chmod +x setup_rust_android.sh
44+
./setup_rust_android.sh
45+
- name: Verify Rust setup
46+
run: |
47+
cd file_operations
48+
echo "🔍 Verifying Rust Android targets..."
49+
rustup target list --installed | grep android || echo "No Android targets found"
50+
echo "🔍 Verifying cargo configuration..."
51+
if [ -f .cargo/config.toml ]; then
52+
echo "✅ .cargo/config.toml exists"
53+
else
54+
echo "❌ .cargo/config.toml missing"
55+
exit 1
56+
fi
2457
- name: Check formatting using spotless
2558
uses: gradle/actions/setup-gradle@v3
2659
with:
@@ -36,6 +69,39 @@ jobs:
3669
with:
3770
distribution: "temurin"
3871
java-version: 17
72+
- name: Install Rust
73+
uses: dtolnay/rust-toolchain@stable
74+
with:
75+
toolchain: stable
76+
- name: Cache Rust dependencies
77+
uses: actions/cache@v4
78+
with:
79+
path: |
80+
~/.cargo/bin/
81+
~/.cargo/registry/index/
82+
~/.cargo/registry/cache/
83+
~/.cargo/git/db/
84+
file_operations/target/
85+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
86+
restore-keys: |
87+
${{ runner.os }}-cargo-
88+
- name: Setup Rust for Android
89+
run: |
90+
cd file_operations
91+
chmod +x setup_rust_android.sh
92+
./setup_rust_android.sh
93+
- name: Verify Rust setup
94+
run: |
95+
cd file_operations
96+
echo "🔍 Verifying Rust Android targets..."
97+
rustup target list --installed | grep android || echo "No Android targets found"
98+
echo "🔍 Verifying cargo configuration..."
99+
if [ -f .cargo/config.toml ]; then
100+
echo "✅ .cargo/config.toml exists"
101+
else
102+
echo "❌ .cargo/config.toml missing"
103+
exit 1
104+
fi
39105
- name: Build with Gradle
40106
uses: gradle/actions/setup-gradle@v3
41107
with:

.github/workflows/android-debug-artifact-ondemand.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,39 @@ jobs:
4040
with:
4141
distribution: "temurin"
4242
java-version: 17
43+
- name: Install Rust
44+
uses: dtolnay/rust-toolchain@stable
45+
with:
46+
toolchain: stable
47+
- name: Cache Rust dependencies
48+
uses: actions/cache@v4
49+
with:
50+
path: |
51+
~/.cargo/bin/
52+
~/.cargo/registry/index/
53+
~/.cargo/registry/cache/
54+
~/.cargo/git/db/
55+
file_operations/target/
56+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
57+
restore-keys: |
58+
${{ runner.os }}-cargo-
59+
- name: Setup Rust for Android
60+
run: |
61+
cd file_operations
62+
chmod +x setup_rust_android.sh
63+
./setup_rust_android.sh
64+
- name: Verify Rust setup
65+
run: |
66+
cd file_operations
67+
echo "🔍 Verifying Rust Android targets..."
68+
rustup target list --installed | grep android || echo "No Android targets found"
69+
echo "🔍 Verifying cargo configuration..."
70+
if [ -f .cargo/config.toml ]; then
71+
echo "✅ .cargo/config.toml exists"
72+
else
73+
echo "❌ .cargo/config.toml missing"
74+
exit 1
75+
fi
4376
- name: Build with Gradle
4477
uses: gradle/actions/setup-gradle@v3
4578
with:

.github/workflows/android-debug-artifact-release.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,39 @@ jobs:
1414
with:
1515
distribution: "temurin"
1616
java-version: 17
17+
- name: Install Rust
18+
uses: dtolnay/rust-toolchain@stable
19+
with:
20+
toolchain: stable
21+
- name: Cache Rust dependencies
22+
uses: actions/cache@v4
23+
with:
24+
path: |
25+
~/.cargo/bin/
26+
~/.cargo/registry/index/
27+
~/.cargo/registry/cache/
28+
~/.cargo/git/db/
29+
file_operations/target/
30+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
31+
restore-keys: |
32+
${{ runner.os }}-cargo-
33+
- name: Setup Rust for Android
34+
run: |
35+
cd file_operations
36+
chmod +x setup_rust_android.sh
37+
./setup_rust_android.sh
38+
- name: Verify Rust setup
39+
run: |
40+
cd file_operations
41+
echo "🔍 Verifying Rust Android targets..."
42+
rustup target list --installed | grep android || echo "No Android targets found"
43+
echo "🔍 Verifying cargo configuration..."
44+
if [ -f .cargo/config.toml ]; then
45+
echo "✅ .cargo/config.toml exists"
46+
else
47+
echo "❌ .cargo/config.toml missing"
48+
exit 1
49+
fi
1750
- name: Build with Gradle
1851
uses: gradle/actions/setup-gradle@v3
1952
with:

.github/workflows/android-feature.yml

100644100755
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ jobs:
2222
with:
2323
distribution: "temurin"
2424
java-version: 17
25+
- name: Install NDK
26+
run: |
27+
echo "y" | sdkmanager --install "ndk;${{ env.NDK_VERSION }}"
28+
env:
29+
NDK_VERSION: ${{ steps.extract_version.outputs.ndk_version }}
30+
- id: extract_version
31+
name: Extract NDK Version
32+
run: echo "ndk_version=$(grep '^ndk' gradle/libs.versions.toml | cut -d'=' -f2 | tr -d '\"')" >> $GITHUB_ENV
2533
- name: Check formatting using spotless
2634
uses: gradle/actions/setup-gradle@v3
2735
with:
@@ -32,15 +40,64 @@ jobs:
3240
runs-on: ubuntu-latest
3341
steps:
3442
- uses: actions/checkout@v4
43+
3544
- name: Set up JDK 17
3645
uses: actions/setup-java@v4
3746
with:
3847
distribution: "temurin"
3948
java-version: 17
49+
50+
- name: Install NDK
51+
run: |
52+
echo "y" | sdkmanager --install "ndk;${{ env.NDK_VERSION }}"
53+
env:
54+
NDK_VERSION: ${{ steps.extract_version.outputs.ndk_version }}
55+
- id: extract_version
56+
name: Extract NDK Version
57+
run: echo "ndk_version=$(grep '^ndk' gradle/libs.versions.toml | cut -d'=' -f2 | tr -d '\"')" >> $GITHUB_ENV
58+
59+
- name: Install Rust
60+
uses: dtolnay/rust-toolchain@stable
61+
with:
62+
toolchain: stable
63+
64+
- name: Cache Rust dependencies
65+
uses: actions/cache@v4
66+
with:
67+
path: |
68+
~/.cargo/bin/
69+
~/.cargo/registry/index/
70+
~/.cargo/registry/cache/
71+
~/.cargo/git/db/
72+
file_operations/target/
73+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
74+
restore-keys: |
75+
${{ runner.os }}-cargo-
76+
77+
- name: Setup Rust for Android
78+
run: |
79+
cd file_operations
80+
chmod +x setup_rust_android.sh
81+
./setup_rust_android.sh
82+
83+
- name: Verify Rust setup
84+
run: |
85+
cd file_operations
86+
echo "🔍 Verifying Rust Android targets..."
87+
rustup target list --installed | grep android || echo "No Android targets found"
88+
echo "🔍 Verifying cargo configuration..."
89+
if [ -f .cargo/config.toml ]; then
90+
echo "✅ .cargo/config.toml exists"
91+
else
92+
echo "❌ .cargo/config.toml missing"
93+
exit 1
94+
fi
95+
4096
- name: Build with Gradle
4197
uses: gradle/actions/setup-gradle@v3
4298
with:
4399
arguments: assembledebug --stacktrace
100+
44101
- name: Run test cases
45102
uses: gradle/actions/setup-gradle@v3
46103
with:

.github/workflows/android-main.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,39 @@ jobs:
3939
with:
4040
distribution: "temurin"
4141
java-version: 17
42+
- name: Install Rust
43+
uses: dtolnay/rust-toolchain@stable
44+
with:
45+
toolchain: stable
46+
- name: Cache Rust dependencies
47+
uses: actions/cache@v4
48+
with:
49+
path: |
50+
~/.cargo/bin/
51+
~/.cargo/registry/index/
52+
~/.cargo/registry/cache/
53+
~/.cargo/git/db/
54+
file_operations/target/
55+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
56+
restore-keys: |
57+
${{ runner.os }}-cargo-
58+
- name: Setup Rust for Android
59+
run: |
60+
cd file_operations
61+
chmod +x setup_rust_android.sh
62+
./setup_rust_android.sh
63+
- name: Verify Rust setup
64+
run: |
65+
cd file_operations
66+
echo "🔍 Verifying Rust Android targets..."
67+
rustup target list --installed | grep android || echo "No Android targets found"
68+
echo "🔍 Verifying cargo configuration..."
69+
if [ -f .cargo/config.toml ]; then
70+
echo "✅ .cargo/config.toml exists"
71+
else
72+
echo "❌ .cargo/config.toml missing"
73+
exit 1
74+
fi
4275
- name: Build with Gradle
4376
uses: gradle/actions/setup-gradle@v3
4477
with:

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ buildscript {
1111
classpath libs.kotlin.gradle.plugin
1212
classpath libs.easylauncher
1313
classpath libs.jacoco.android.plugin
14+
classpath libs.rust.android.gradle
1415
// NOTE: Do not place your application dependencies here; they belong
1516
// in the individual module build.gradle files
1617
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Cargo configuration for Android cross-compilation
2+
# This file configures the linkers for different Android architectures
3+
# Generated from config.toml.template by setup_rust_android.sh
4+
5+
[target.aarch64-linux-android]
6+
linker = "{{NDK_PATH}}/aarch64-linux-android{{API_LEVEL}}-clang{{EXE_SUFFIX}}"
7+
8+
[target.armv7-linux-androideabi]
9+
linker = "{{NDK_PATH}}/armv7a-linux-androideabi{{API_LEVEL}}-clang{{EXE_SUFFIX}}"
10+
11+
[target.i686-linux-android]
12+
linker = "{{NDK_PATH}}/i686-linux-android{{API_LEVEL}}-clang{{EXE_SUFFIX}}"
13+
14+
[target.x86_64-linux-android]
15+
linker = "{{NDK_PATH}}/x86_64-linux-android{{API_LEVEL}}-clang{{EXE_SUFFIX}}"
16+
17+
# Note: This file is auto-generated. Do not edit manually.
18+
# To regenerate, run: ./setup_rust_android.sh
19+
#
20+
# Configuration details:
21+
# - API level: {{API_LEVEL}} (matching minSdkVersion from build.gradle)
22+
# - Platform: {{PLATFORM}}
23+
# - NDK version: {{NDK_VERSION}}
24+
# - Android SDK: {{ANDROID_SDK_PATH}}

file_operations/.gitignore

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
/build
1+
# Rust build artifacts
2+
target/
3+
**/*.rs.bk
4+
Cargo.lock
25

3-
# External native build folder generated in Android Studio 2.2 and later
4-
.externalNativeBuild
5-
.cxx/
6+
# Auto-generated configuration (generated from template)
7+
.cargo/config.toml
8+
9+
# Android build artifacts
10+
.cxx/
11+
build/

file_operations/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "rootoperations"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[lib]
7+
name = "rootoperations"
8+
crate-type = ["cdylib"]
9+
path = "src/main/rust/lib.rs"
10+
11+
[dependencies]
12+
jni = "0.21"
13+
libc = "0.2"
14+
15+
[target.'cfg(target_os = "android")'.dependencies]
16+
android_logger = "0.11"
17+
log = "0.4"

0 commit comments

Comments
 (0)