Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-compile to Android and iOS #1469

Merged
merged 8 commits into from
Dec 21, 2022
Merged
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
6 changes: 5 additions & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[toolchain]
channel = "1.66.0"
components = ["rustfmt", "clippy"]
targets = ["wasm32-unknown-unknown"]
targets = [
"aarch64-apple-ios",
"aarch64-linux-android",
"wasm32-unknown-unknown",
]
83 changes: 61 additions & 22 deletions tools/cross-compiler/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Cross-compiler for the Fornjot build
//!
//! This tools cross-compiles the Fornjot crates that support that to the
//! targets they support. This is less resource-intense then using a `matrix` in
//! targets they support. This is less resource-intense than using a `matrix` in
//! GitHub Actions (which would start one build job per crate and target), and
//! allows for the cross-compilation code to be re-used in `justfile`.

Expand All @@ -10,33 +10,72 @@ use std::process::Command;
use anyhow::anyhow;

fn main() -> anyhow::Result<()> {
let crates = [
"fj",
"fj-export",
"fj-interop",
"fj-kernel",
"fj-math",
"fj-operations",
"fj-proc",
"fj-viewer",
let targets = [
Target {
triple: "aarch64-apple-ios",
crates: &[
"fj",
"fj-export",
"fj-interop",
"fj-kernel",
"fj-math",
"fj-operations",
"fj-proc",
],
},
Target {
triple: "aarch64-linux-android",
crates: &[
"fj",
"fj-export",
"fj-interop",
"fj-kernel",
"fj-math",
"fj-operations",
"fj-proc",
],
},
Target {
triple: "wasm32-unknown-unknown",
crates: &[
"fj",
"fj-export",
"fj-interop",
"fj-kernel",
"fj-math",
"fj-operations",
"fj-proc",
"fj-viewer",
],
},
];

for crate_ in crates {
let mut command = Command::new("cargo");
command
.arg("build")
.arg("--all-features")
.args(["--target", "wasm32-unknown-unknown"])
.args(["-p", crate_])
.env("RUSTFLAGS", "-D warnings");
for target in targets {
for crate_ in target.crates {
let mut command = Command::new("cargo");
command
.arg("build")
.arg("--all-features")
.args(["--target", target.triple])
.args(["-p", crate_])
.env("RUSTFLAGS", "-D warnings");

println!("Running {command:?}");
let status = command.status()?;
println!("Running {command:?}");
let status = command.status()?;

if !status.success() {
return Err(anyhow!("Cargo exited with error code: {status}"));
if !status.success() {
return Err(anyhow!("Cargo exited with error code: {status}"));
}
}
}

Ok(())
}

struct Target {
/// The target triple
triple: &'static str,

/// The crates that are supported on this target
crates: &'static [&'static str],
}