Skip to content

Commit d5069d5

Browse files
ssddOnToptusharmathautofix-ci[bot]
committed
chore: add support for ARM android (#1788)
Co-authored-by: Tushar Mathur <tusharmath@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 39cc92d commit d5069d5

12 files changed

Lines changed: 110 additions & 25 deletions

File tree

.github/workflows/ci.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ jobs:
154154
cross: 'false'
155155
os: windows-latest
156156
target: aarch64-pc-windows-msvc
157+
- binary_name: forge-aarch64-linux-android
158+
binary_path: target/aarch64-linux-android/release/forge
159+
cross: 'true'
160+
os: ubuntu-latest
161+
target: aarch64-linux-android
157162
steps:
158163
- name: Checkout Code
159164
uses: actions/checkout@v5
@@ -163,17 +168,18 @@ jobs:
163168
with:
164169
target: ${{ matrix.target }}
165170
- name: Add Rust target
171+
if: ${{ matrix.cross == 'false' }}
166172
run: rustup target add ${{ matrix.target }}
167173
- name: Set Rust Flags
168-
if: '!contains(matrix.target, ''-unknown-linux-'')'
174+
if: '!(contains(matrix.target, ''-unknown-linux-'') || contains(matrix.target, ''-android''))'
169175
run: echo "RUSTFLAGS=-C target-feature=+crt-static" >> $GITHUB_ENV
170176
- name: Build Binary
171177
uses: ClementTsang/cargo-action@v0.0.7
172178
with:
173179
command: build --release
174180
args: --target ${{ matrix.target }}
175181
use-cross: ${{ matrix.cross }}
176-
cross-version: 0.2.4
182+
cross-version: 0.2.5
177183
env:
178184
RUSTFLAGS: ${{ env.RUSTFLAGS }}
179185
POSTHOG_API_SECRET: ${{secrets.POSTHOG_API_SECRET}}
@@ -238,6 +244,11 @@ jobs:
238244
cross: 'false'
239245
os: windows-latest
240246
target: aarch64-pc-windows-msvc
247+
- binary_name: forge-aarch64-linux-android
248+
binary_path: target/aarch64-linux-android/release/forge
249+
cross: 'true'
250+
os: ubuntu-latest
251+
target: aarch64-linux-android
241252
steps:
242253
- name: Checkout Code
243254
uses: actions/checkout@v5
@@ -247,17 +258,18 @@ jobs:
247258
with:
248259
target: ${{ matrix.target }}
249260
- name: Add Rust target
261+
if: ${{ matrix.cross == 'false' }}
250262
run: rustup target add ${{ matrix.target }}
251263
- name: Set Rust Flags
252-
if: '!contains(matrix.target, ''-unknown-linux-'')'
264+
if: '!(contains(matrix.target, ''-unknown-linux-'') || contains(matrix.target, ''-android''))'
253265
run: echo "RUSTFLAGS=-C target-feature=+crt-static" >> $GITHUB_ENV
254266
- name: Build Binary
255267
uses: ClementTsang/cargo-action@v0.0.7
256268
with:
257269
command: build --release
258270
args: --target ${{ matrix.target }}
259271
use-cross: ${{ matrix.cross }}
260-
cross-version: 0.2.4
272+
cross-version: 0.2.5
261273
env:
262274
RUSTFLAGS: ${{ env.RUSTFLAGS }}
263275
POSTHOG_API_SECRET: ${{secrets.POSTHOG_API_SECRET}}

.github/workflows/release.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ jobs:
7373
cross: 'false'
7474
os: windows-latest
7575
target: aarch64-pc-windows-msvc
76+
- binary_name: forge-aarch64-linux-android
77+
binary_path: target/aarch64-linux-android/release/forge
78+
cross: 'true'
79+
os: ubuntu-latest
80+
target: aarch64-linux-android
7681
steps:
7782
- name: Checkout Code
7883
uses: actions/checkout@v5
@@ -82,17 +87,18 @@ jobs:
8287
with:
8388
target: ${{ matrix.target }}
8489
- name: Add Rust target
90+
if: ${{ matrix.cross == 'false' }}
8591
run: rustup target add ${{ matrix.target }}
8692
- name: Set Rust Flags
87-
if: '!contains(matrix.target, ''-unknown-linux-'')'
93+
if: '!(contains(matrix.target, ''-unknown-linux-'') || contains(matrix.target, ''-android''))'
8894
run: echo "RUSTFLAGS=-C target-feature=+crt-static" >> $GITHUB_ENV
8995
- name: Build Binary
9096
uses: ClementTsang/cargo-action@v0.0.7
9197
with:
9298
command: build --release
9399
args: --target ${{ matrix.target }}
94100
use-cross: ${{ matrix.cross }}
95-
cross-version: 0.2.4
101+
cross-version: 0.2.5
96102
env:
97103
RUSTFLAGS: ${{ env.RUSTFLAGS }}
98104
POSTHOG_API_SECRET: ${{secrets.POSTHOG_API_SECRET}}

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cross.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
[build]
2+
# Build the build script in the container to avoid GLIBC mismatch
3+
build-std = false
4+
default-target = "x86_64-unknown-linux-gnu"
5+
16
[build.env]
27
passthrough = [
38
"APP_VERSION",
49
"POSTHOG_API_SECRET",
510
]
11+
12+
[target.aarch64-linux-android]
13+
image = "ghcr.io/cross-rs/aarch64-linux-android:edge"

crates/forge_ci/src/jobs/release_build_job.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@ impl From<ReleaseBuilderJob> for Job {
4646
.if_condition(Expression::new("${{ matrix.cross == 'false' }}")),
4747
)
4848
// Explicitly add the target to ensure it's available
49-
.add_step(Step::new("Add Rust target").run("rustup target add ${{ matrix.target }}"))
49+
.add_step(
50+
Step::new("Add Rust target")
51+
.run("rustup target add ${{ matrix.target }}")
52+
.if_condition(Expression::new("${{ matrix.cross == 'false' }}")),
53+
)
5054
// Build add link flags
5155
.add_step(
5256
Step::new("Set Rust Flags")
5357
.run(r#"echo "RUSTFLAGS=-C target-feature=+crt-static" >> $GITHUB_ENV"#)
5458
.if_condition(Expression::new(
55-
"!contains(matrix.target, '-unknown-linux-')",
59+
"!(contains(matrix.target, '-unknown-linux-') || contains(matrix.target, '-android'))",
5660
)),
5761
)
5862
// Build release binary
@@ -62,7 +66,7 @@ impl From<ReleaseBuilderJob> for Job {
6266
.add_with(("command", "build --release"))
6367
.add_with(("args", "--target ${{ matrix.target }}"))
6468
.add_with(("use-cross", "${{ matrix.cross }}"))
65-
.add_with(("cross-version", "0.2.4"))
69+
.add_with(("cross-version", "0.2.5"))
6670
.add_env(("RUSTFLAGS", "${{ env.RUSTFLAGS }}"))
6771
.add_env(("POSTHOG_API_SECRET", "${{secrets.POSTHOG_API_SECRET}}"))
6872
.add_env(("APP_VERSION", value.version.to_string())),

crates/forge_ci/src/release_matrix.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ impl Default for ReleaseMatrix {
7474
binary_path: "target/aarch64-pc-windows-msvc/release/forge.exe",
7575
cross: "false",
7676
},
77+
MatrixEntry {
78+
os: "ubuntu-latest",
79+
target: "aarch64-linux-android",
80+
binary_name: "forge-aarch64-linux-android",
81+
binary_path: "target/aarch64-linux-android/release/forge",
82+
cross: "true",
83+
},
7784
])
7885
}
7986
}

crates/forge_tracker/Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ derive_more.workspace = true
99
url.workspace = true
1010
serde.workspace = true
1111
serde_json.workspace = true
12-
machineid-rs.workspace = true
1312
tokio.workspace = true
1413
tracing.workspace = true
1514
sysinfo.workspace = true
@@ -25,6 +24,14 @@ tracing-subscriber.workspace = true
2524
anyhow.workspace = true
2625
forge_domain.workspace = true
2726
lazy_static.workspace = true
27+
dirs.workspace = true
28+
29+
# Platform-specific dependencies
30+
[target.'cfg(not(target_os = "android"))'.dependencies]
31+
machineid-rs.workspace = true
32+
33+
[target.'cfg(target_os = "android")'.dependencies]
34+
uuid.workspace = true
2835

2936
[dev-dependencies]
3037
tokio = { workspace = true, features = ["macros", "rt", "time", "test-util"] }
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use std::path::PathBuf;
2+
3+
use uuid::Uuid;
4+
5+
const CLIENT_ID_FILE: &str = ".forge_client_id";
6+
7+
/// Gets or creates a persistent client ID for Android
8+
pub fn get_or_create_client_id() -> anyhow::Result<String> {
9+
let home_dir = dirs::home_dir().unwrap_or(PathBuf::from("."));
10+
11+
let client_id_path: PathBuf = home_dir.join(CLIENT_ID_FILE);
12+
13+
if let Ok(existing_id) = std::fs::read_to_string(&client_id_path) {
14+
let trimmed = existing_id.trim();
15+
if !trimmed.is_empty() {
16+
return Ok(trimmed.to_string());
17+
}
18+
}
19+
20+
let new_id = Uuid::new_v4().to_string();
21+
std::fs::write(&client_id_path, &new_id)?;
22+
23+
Ok(new_id)
24+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use machineid_rs::{Encryption, HWIDComponent, IdBuilder};
2+
3+
const PARAPHRASE: &str = "forge_key";
4+
5+
/// Gets or creates a persistent client ID for non-Android platforms
6+
pub fn get_or_create_client_id() -> anyhow::Result<String> {
7+
let mut builder = IdBuilder::new(Encryption::SHA256);
8+
builder
9+
.add_component(HWIDComponent::SystemID)
10+
.add_component(HWIDComponent::CPUCores);
11+
12+
builder
13+
.build(PARAPHRASE)
14+
.map_err(|e| anyhow::anyhow!("Failed to generate machine ID: {}", e))
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#[cfg(target_os = "android")]
2+
mod android;
3+
#[cfg(not(target_os = "android"))]
4+
mod generic;
5+
6+
#[cfg(target_os = "android")]
7+
pub use android::get_or_create_client_id;
8+
#[cfg(not(target_os = "android"))]
9+
pub use generic::get_or_create_client_id;
10+
11+
pub const DEFAULT_CLIENT_ID: &str = "<anonymous>";

0 commit comments

Comments
 (0)