Skip to content

Commit

Permalink
feat(bundler): check target arch at runtime, closes #2286 (#2422)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Aug 13, 2021
1 parent 4a031ad commit 5ebf389
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changes/bundler-runtime-target-arch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-bundler": patch
---

Check target architecture at runtime running `$ RUSTC_BOOTSTRAP=1 rustc -Z unstable-options --print target-spec-json` and parsing the `llvm-target` field, fixing macOS M1 sidecar check until we can compile the CLI with M1 target on GitHub Actions.
48 changes: 37 additions & 11 deletions tooling/bundler/src/bundle/platform.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
use std::{io::Cursor, process::Command};

#[derive(Debug, serde::Deserialize)]
struct TargetSpec {
#[serde(rename = "llvm-target")]
llvm_target: String,
}

// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
Expand All @@ -12,18 +20,36 @@
/// * Errors:
/// * Unexpected system config
pub fn target_triple() -> Result<String, crate::Error> {
let arch = if cfg!(target_arch = "x86") {
"i686"
} else if cfg!(target_arch = "x86_64") {
"x86_64"
} else if cfg!(target_arch = "arm") {
"armv7"
} else if cfg!(target_arch = "aarch64") {
"aarch64"
let output = Command::new("rustc")
.args(&["-Z", "unstable-options", "--print", "target-spec-json"])
.env("RUSTC_BOOTSTRAP", "1")
.output()?;
let arch = if output.status.success() {
let target_spec: TargetSpec = serde_json::from_reader(Cursor::new(output.stdout))?;
target_spec
.llvm_target
.split('-')
.next()
.unwrap()
.to_string()
} else {
return Err(crate::Error::ArchError(String::from(
"Unable to determine target-architecture",
)));
super::common::print_info(&format!(
"failed to determine target arch using rustc, error: `{}`. The fallback is the architecture of the machine that compiled this crate.",
String::from_utf8_lossy(&output.stderr),
))?;
if cfg!(target_arch = "x86") {
"i686".into()
} else if cfg!(target_arch = "x86_64") {
"x86_64".into()
} else if cfg!(target_arch = "arm") {
"armv7".into()
} else if cfg!(target_arch = "aarch64") {
"aarch64".into()
} else {
return Err(crate::Error::ArchError(String::from(
"Unable to determine target-architecture",
)));
}
};

let os = if cfg!(target_os = "linux") {
Expand Down

0 comments on commit 5ebf389

Please sign in to comment.