Skip to content

Commit 05f8221

Browse files
authored
Merge pull request #4431 from TranceLove/feature/rust-file-operations
2 parents f11a365 + 9e968fb commit 05f8221

20 files changed

+1165
-65
lines changed

.github/workflows/android-build.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,39 @@ jobs:
2727
ndk-version: r28c
2828
link-to-sdk: true
2929
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
3063
- name: Check formatting using spotless
3164
uses: gradle/actions/setup-gradle@v3
3265
with:
@@ -42,6 +75,39 @@ jobs:
4275
with:
4376
distribution: "temurin"
4477
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
45111
- name: Build with Gradle
46112
uses: gradle/actions/setup-gradle@v3
47113
with:

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,39 @@ jobs:
4646
ndk-version: r28c
4747
link-to-sdk: true
4848
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
4982
- name: Build with Gradle
5083
uses: gradle/actions/setup-gradle@v3
5184
with:

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,39 @@ jobs:
2020
ndk-version: r28c
2121
link-to-sdk: true
2222
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
2356
- name: Build with Gradle
2457
uses: gradle/actions/setup-gradle@v3
2558
with:

.github/workflows/android-feature.yml

100644100755
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
distribution: "temurin"
2424
java-version: 17
2525
- name: Set up NDK
26+
id: setup-ndk
2627
uses: nttld/setup-ndk@afb4c9964b521afb97c864b7d40b11e6911bd410
2728
with:
2829
ndk-version: r28c
@@ -32,6 +33,8 @@ jobs:
3233
uses: gradle/actions/setup-gradle@v3
3334
with:
3435
arguments: spotlessCheck --stacktrace
36+
env:
37+
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
3538

3639
build:
3740
name: Build debug and run Jacoco tests
@@ -43,6 +46,39 @@ jobs:
4346
with:
4447
distribution: "temurin"
4548
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
4682
- name: Build with Gradle
4783
uses: gradle/actions/setup-gradle@v3
4884
with:

.github/workflows/android-main.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,39 @@ jobs:
4545
with:
4646
distribution: "temurin"
4747
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
4881
- name: Build with Gradle
4982
uses: gradle/actions/setup-gradle@v3
5083
with:

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ If we feel your PR is a significant help to us, we'll award you a bounty with an
3838

3939
- Please follow [Android/JAVA code style](https://source.android.com/docs/setup/contribute/code-style) for writing any code. Please see [this](https://github.com/TeamAmaze/AmazeFileManager/issues/986) issue too.
4040
- Also, follow [Android Material Design guidelines](https://m3.material.io/get-started) in case you make changes to any UI element.
41+
- The `file_operations` module contains native code in Rust. Please see [file_operations/src/main/rust/README.md](file_operations/src/main/rust/README.md) for more details on how to work with it.
4142

4243
## PS: please make sure to
4344

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)