-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(bundler): add macos pkg installer support with custom signing #14611
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
Draft
pierrekin
wants to merge
6
commits into
tauri-apps:dev
Choose a base branch
from
pierrekin:ph-macos-pkg
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+470
−13
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
de54853
Add macOS PKG installer support to tauri-bundler
pierrekin a166f61
Add native macOS PKG signing support
pierrekin 35a4fa4
Add custom signing command support for macOS bundles
pierrekin 36aa055
Add custom signing command support for macOS bundles
pierrekin e3c0cbd
Run custom commands in directory tauri build was run
pierrekin 6066199
Add .changes entry
pierrekin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| --- | ||
| tauri-bundler: minor:feat | ||
| tauri-utils: minor:feat | ||
| tauri-cli: minor:feat | ||
| --- | ||
|
|
||
| Add macOS PKG installer support with custom signing commands. | ||
|
|
||
| Implements support for creating macOS PKG installers using pkgbuild and productbuild, with native signing via productsign and support for custom signing commands (useful for HSM-based signing solutions). | ||
|
|
||
| Features: | ||
| - Create PKG installers from .app bundles using distribution.xml from project root | ||
| - Native PKG signing with productsign using signingIdentity or APPLE_CERTIFICATE | ||
| - Custom signing command support for .app bundles, .pkg installers, and .dmg disk images | ||
| - Custom commands use %1 placeholder for artifact path and run in build directory for relative path support | ||
|
|
||
| Configuration fields added to MacOsSettings: | ||
| - `appSignCommand`: Custom command for signing .app bundles | ||
| - `pkgSignCommand`: Custom command for signing .pkg installers | ||
| - `dmgSignCommand`: Custom command for signing .dmg disk images |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,4 +7,5 @@ pub mod app; | |
| pub mod dmg; | ||
| pub mod icon; | ||
| pub mod ios; | ||
| pub mod pkg; | ||
| pub mod sign; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| // Copyright 2016-2019 Cargo-Bundle developers <https://github.com/burtonageo/cargo-bundle> | ||
| // Copyright 2019-2024 Tauri Programme within The Commons Conservancy | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| use super::app; | ||
| use crate::{ | ||
| bundle::{settings::Arch, Bundle}, | ||
| utils::CommandExt, | ||
| PackageType, Settings, | ||
| }; | ||
|
|
||
| use std::{ | ||
| fs, | ||
| path::PathBuf, | ||
| process::Command, | ||
| }; | ||
|
|
||
| pub struct Bundled { | ||
| pub pkg: Vec<PathBuf>, | ||
| pub app: Vec<PathBuf>, | ||
| } | ||
|
|
||
| /// Bundles the project into a macOS PKG installer. | ||
| /// Returns a vector of PathBuf that shows where the PKG was created. | ||
| pub fn bundle_project(settings: &Settings, bundles: &[Bundle]) -> crate::Result<Bundled> { | ||
| // generate the .app bundle if needed | ||
| let app_bundle_paths = if !bundles | ||
| .iter() | ||
| .any(|bundle| bundle.package_type == PackageType::MacOsBundle) | ||
| { | ||
| app::bundle_project(settings)? | ||
| } else { | ||
| Vec::new() | ||
| }; | ||
|
|
||
| // get the target path | ||
| let output_path = settings.project_out_directory().join("bundle/macos"); | ||
| let pkg_output_path = output_path.parent().unwrap().join("pkg"); | ||
|
|
||
| fs::create_dir_all(&pkg_output_path)?; | ||
|
|
||
| let package_base_name = format!( | ||
| "{}_{}_{}", | ||
| settings.product_name(), | ||
| settings.version_string(), | ||
| match settings.binary_arch() { | ||
| Arch::X86_64 => "x64", | ||
| Arch::AArch64 => "aarch64", | ||
| Arch::Universal => "universal", | ||
| target => { | ||
| return Err(crate::Error::ArchError(format!( | ||
| "Unsupported architecture: {target:?}" | ||
| ))); | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| let pkg_name = format!("{}.pkg", &package_base_name); | ||
| let pkg_path = pkg_output_path.join(&pkg_name); | ||
|
|
||
| let product_name = settings.product_name(); | ||
| let bundle_file_name = format!("{product_name}.app"); | ||
| let app_bundle_path = output_path.join(&bundle_file_name); | ||
|
|
||
| log::info!(action = "Bundling"; "{} ({})", pkg_name, pkg_path.display()); | ||
|
|
||
| // Step 1: Create a component package using pkgbuild | ||
| // This packages the .app bundle into a component package | ||
| let component_pkg_path = pkg_output_path.join("component.pkg"); | ||
|
|
||
| let mut pkgbuild_cmd = Command::new("pkgbuild"); | ||
| pkgbuild_cmd | ||
| .arg("--component") | ||
| .arg(&app_bundle_path) | ||
| .arg("--install-location") | ||
| .arg("/Applications") | ||
| .arg(&component_pkg_path); | ||
|
|
||
| log::info!(action = "Running"; "pkgbuild (component package)"); | ||
| pkgbuild_cmd | ||
| .output_ok() | ||
| .map_err(|e| crate::Error::ShellScriptError(format!("pkgbuild failed: {}", e)))?; | ||
|
|
||
| // Step 2: Read distribution.xml from project root | ||
| // User must provide this file for PKG bundling | ||
| let distribution_xml_path = std::env::current_dir()?.join("distribution.xml"); | ||
| if !distribution_xml_path.exists() { | ||
| return Err(crate::Error::GenericError( | ||
| "distribution.xml not found in project root. PKG bundling requires a distribution.xml file.".to_string() | ||
| )); | ||
| } | ||
|
|
||
| log::info!(action = "Using"; "distribution.xml from {}", distribution_xml_path.display()); | ||
|
|
||
| // Step 3: Create the distribution package using productbuild | ||
| // This combines the component package(s) into a final installer | ||
| let mut productbuild_cmd = Command::new("productbuild"); | ||
| productbuild_cmd | ||
| .arg("--distribution") | ||
| .arg(&distribution_xml_path) | ||
| .arg("--package-path") | ||
| .arg(&pkg_output_path) | ||
| .arg(&pkg_path); | ||
|
|
||
| log::info!(action = "Running"; "productbuild (distribution package)"); | ||
| productbuild_cmd | ||
| .output_ok() | ||
| .map_err(|e| crate::Error::ShellScriptError(format!("productbuild failed: {}", e)))?; | ||
|
|
||
| // Sign PKG if needed | ||
| if !settings.no_sign() { | ||
| if let Some(pkg_sign_command) = &settings.macos().pkg_sign_command { | ||
| // Use custom signing command | ||
| super::sign::sign_pkg_custom(&pkg_path, pkg_sign_command)?; | ||
| } else { | ||
| // Use native productsign | ||
| let identity = settings.macos().signing_identity.as_deref(); | ||
| if identity != Some("-") { | ||
| if let Some(identity) = identity { | ||
| super::sign::sign_pkg(&pkg_path, identity, settings)?; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| log::info!(action = "Finished"; "PKG installer at {}", pkg_path.display()); | ||
|
|
||
| Ok(Bundled { | ||
| pkg: vec![pkg_path], | ||
| app: app_bundle_paths, | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i won't annotate every line but logs like this one are honestly a bit too verbose, at least for the
infolevel, perhaps tracing or debug.