Skip to content

Commit

Permalink
feat: Add universal-darwin-macos build target, closes #3317 (#3318)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
  • Loading branch information
betamos and lucasfernog authored Feb 4, 2022
1 parent 3d77bd3 commit 83f52fd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changes/universal-apple-target.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cli.rs": patch
---

Add support to building Universal macOS Binaries through the virtual target `universal-apple-darwin` (run `tauri build --target universal-apple-darwin`).
2 changes: 2 additions & 0 deletions tooling/bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ impl Settings {
"arm"
} else if self.target.starts_with("aarch64") {
"aarch64"
} else if self.target.starts_with("universal") {
"universal"
} else {
panic!("Unexpected target triple {}", self.target)
}
Expand Down
41 changes: 37 additions & 4 deletions tooling/cli.rs/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ pub struct Options {
/// Enables verbose logging
#[clap(short, long)]
verbose: bool,
/// Target triple to build against
/// Target triple to build against.
/// It must be one of the values outputted by `$rustc --print target-list` or `universal-apple-darwin` for an universal macOS application.
/// Note that compiling an universal macOS application requires both `aarch64-apple-darwin` and `x86_64-apple-darwin` targets to be installed.
#[clap(short, long)]
target: Option<String>,
/// List of cargo features to activate
Expand Down Expand Up @@ -132,9 +134,6 @@ pub fn command(options: Options) -> Result<()> {
cargo_features.extend(features);
}

crate::interface::rust::build_project(runner, &options.target, cargo_features, options.debug)
.with_context(|| "failed to build app")?;

let app_settings = crate::interface::rust::AppSettings::new(config_)?;

let out_dir = app_settings
Expand All @@ -151,6 +150,40 @@ pub fn command(options: Options) -> Result<()> {
#[cfg(not(windows))]
let bin_path = out_dir.join(&bin_name);

if options.target == Some("universal-apple-darwin".into()) {
std::fs::create_dir_all(&out_dir).with_context(|| "failed to create project out directory")?;

let mut lipo_cmd = Command::new("lipo");
lipo_cmd
.arg("-create")
.arg("-output")
.arg(out_dir.join(&bin_name));
for triple in ["aarch64-apple-darwin", "x86_64-apple-darwin"] {
crate::interface::rust::build_project(
runner.clone(),
&Some(triple.into()),
cargo_features.clone(),
options.debug,
)
.with_context(|| format!("failed to build {} binary", triple))?;
let triple_out_dir = app_settings
.get_out_dir(Some(triple.into()), options.debug)
.with_context(|| format!("failed to get {} out dir", triple))?;
lipo_cmd.arg(triple_out_dir.join(&bin_name));
}

let lipo_status = lipo_cmd.status()?;
if !lipo_status.success() {
return Err(anyhow::anyhow!(format!(
"Result of `lipo` command was unsuccessful: {}. (Is `lipo` installed?)",
lipo_status
)));
}
} else {
crate::interface::rust::build_project(runner, &options.target, cargo_features, options.debug)
.with_context(|| "failed to build app")?;
}

#[cfg(unix)]
if !options.debug {
strip(&bin_path, &logger)?;
Expand Down

0 comments on commit 83f52fd

Please sign in to comment.