feat(bundler): check target arch at runtime, closes #2286 (#2422)

This commit is contained in:
Lucas Fernandes Nogueira 2021-08-13 18:05:18 -03:00 committed by GitHub
parent 4a031add69
commit 5ebf389f6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 11 deletions

View File

@ -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.

View File

@ -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
@ -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") {