Skip to content

Commit

Permalink
Merge pull request #1469 from hannobraun/cross-compile
Browse files Browse the repository at this point in the history
Cross-compile to Android and iOS
  • Loading branch information
hannobraun authored Dec 21, 2022
2 parents b596faf + 14401bc commit 15a62eb
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 23 deletions.
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],
}

0 comments on commit 15a62eb

Please sign in to comment.