Skip to content

Commit fad31ed

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

20 files changed

+1359
-60
lines changed

.github/workflows/android-build.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,45 @@ jobs:
2121
with:
2222
distribution: "temurin"
2323
java-version: 17
24+
- name: Set up NDK
25+
uses: nttld/setup-ndk@v1
26+
with:
27+
ndk-version: r28c
28+
link-to-sdk: true
29+
local-cache: true
30+
- name: Install Rust
31+
uses: dtolnay/rust-toolchain@stable
32+
with:
33+
toolchain: stable
34+
- name: Cache Rust dependencies
35+
uses: actions/cache@v4
36+
with:
37+
path: |
38+
~/.cargo/bin/
39+
~/.cargo/registry/index/
40+
~/.cargo/registry/cache/
41+
~/.cargo/git/db/
42+
file_operations/target/
43+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
44+
restore-keys: |
45+
${{ runner.os }}-cargo-
46+
- name: Setup Rust for Android
47+
run: |
48+
cd file_operations
49+
chmod +x setup_rust_android.sh
50+
./setup_rust_android.sh
51+
- name: Verify Rust setup
52+
run: |
53+
cd file_operations
54+
echo "🔍 Verifying Rust Android targets..."
55+
rustup target list --installed | grep android || echo "No Android targets found"
56+
echo "🔍 Verifying cargo configuration..."
57+
if [ -f .cargo/config.toml ]; then
58+
echo "✅ .cargo/config.toml exists"
59+
else
60+
echo "❌ .cargo/config.toml missing"
61+
exit 1
62+
fi
2463
- name: Check formatting using spotless
2564
uses: gradle/actions/setup-gradle@v3
2665
with:
@@ -36,6 +75,39 @@ jobs:
3675
with:
3776
distribution: "temurin"
3877
java-version: 17
78+
- name: Install Rust
79+
uses: dtolnay/rust-toolchain@stable
80+
with:
81+
toolchain: stable
82+
- name: Cache Rust dependencies
83+
uses: actions/cache@v4
84+
with:
85+
path: |
86+
~/.cargo/bin/
87+
~/.cargo/registry/index/
88+
~/.cargo/registry/cache/
89+
~/.cargo/git/db/
90+
file_operations/target/
91+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
92+
restore-keys: |
93+
${{ runner.os }}-cargo-
94+
- name: Setup Rust for Android
95+
run: |
96+
cd file_operations
97+
chmod +x setup_rust_android.sh
98+
./setup_rust_android.sh
99+
- name: Verify Rust setup
100+
run: |
101+
cd file_operations
102+
echo "🔍 Verifying Rust Android targets..."
103+
rustup target list --installed | grep android || echo "No Android targets found"
104+
echo "🔍 Verifying cargo configuration..."
105+
if [ -f .cargo/config.toml ]; then
106+
echo "✅ .cargo/config.toml exists"
107+
else
108+
echo "❌ .cargo/config.toml missing"
109+
exit 1
110+
fi
39111
- name: Build with Gradle
40112
uses: gradle/actions/setup-gradle@v3
41113
with:

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

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

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

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

.github/workflows/android-feature.yml

100644100755
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,19 @@ jobs:
2222
with:
2323
distribution: "temurin"
2424
java-version: 17
25+
- name: Set up NDK
26+
id: setup-ndk
27+
uses: nttld/setup-ndk@v1
28+
with:
29+
ndk-version: r28c
30+
link-to-sdk: true
31+
local-cache: true
2532
- name: Check formatting using spotless
2633
uses: gradle/actions/setup-gradle@v3
2734
with:
2835
arguments: spotlessCheck --stacktrace
36+
env:
37+
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
2938

3039
build:
3140
name: Build debug and run Jacoco tests
@@ -37,6 +46,39 @@ jobs:
3746
with:
3847
distribution: "temurin"
3948
java-version: 17
49+
- name: Install Rust
50+
uses: dtolnay/rust-toolchain@stable
51+
with:
52+
toolchain: stable
53+
- name: Cache Rust dependencies
54+
uses: actions/cache@v4
55+
with:
56+
path: |
57+
~/.cargo/bin/
58+
~/.cargo/registry/index/
59+
~/.cargo/registry/cache/
60+
~/.cargo/git/db/
61+
file_operations/target/
62+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
63+
restore-keys: |
64+
${{ runner.os }}-cargo-
65+
- name: Setup Rust for Android
66+
run: |
67+
cd file_operations
68+
chmod +x setup_rust_android.sh
69+
./setup_rust_android.sh
70+
- name: Verify Rust setup
71+
run: |
72+
cd file_operations
73+
echo "🔍 Verifying Rust Android targets..."
74+
rustup target list --installed | grep android || echo "No Android targets found"
75+
echo "🔍 Verifying cargo configuration..."
76+
if [ -f .cargo/config.toml ]; then
77+
echo "✅ .cargo/config.toml exists"
78+
else
79+
echo "❌ .cargo/config.toml missing"
80+
exit 1
81+
fi
4082
- name: Build with Gradle
4183
uses: gradle/actions/setup-gradle@v3
4284
with:

.github/workflows/android-main.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ jobs:
2222
with:
2323
distribution: "temurin"
2424
java-version: 17
25+
- name: Set up NDK
26+
uses: nttld/setup-ndk@v1
27+
with:
28+
ndk-version: r28c
29+
link-to-sdk: true
30+
local-cache: true
2531
- name: Check formatting using spotless
2632
uses: gradle/actions/setup-gradle@v3
2733
with:
@@ -39,6 +45,39 @@ jobs:
3945
with:
4046
distribution: "temurin"
4147
java-version: 17
48+
- name: Install Rust
49+
uses: dtolnay/rust-toolchain@stable
50+
with:
51+
toolchain: stable
52+
- name: Cache Rust dependencies
53+
uses: actions/cache@v4
54+
with:
55+
path: |
56+
~/.cargo/bin/
57+
~/.cargo/registry/index/
58+
~/.cargo/registry/cache/
59+
~/.cargo/git/db/
60+
file_operations/target/
61+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
62+
restore-keys: |
63+
${{ runner.os }}-cargo-
64+
- name: Setup Rust for Android
65+
run: |
66+
cd file_operations
67+
chmod +x setup_rust_android.sh
68+
./setup_rust_android.sh
69+
- name: Verify Rust setup
70+
run: |
71+
cd file_operations
72+
echo "🔍 Verifying Rust Android targets..."
73+
rustup target list --installed | grep android || echo "No Android targets found"
74+
echo "🔍 Verifying cargo configuration..."
75+
if [ -f .cargo/config.toml ]; then
76+
echo "✅ .cargo/config.toml exists"
77+
else
78+
echo "❌ .cargo/config.toml missing"
79+
exit 1
80+
fi
4281
- name: Build with Gradle
4382
uses: gradle/actions/setup-gradle@v3
4483
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)