-
Notifications
You must be signed in to change notification settings - Fork 97
osx maxxed out #237
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
Merged
mdsteele
merged 14 commits into
burtonageo:master
from
philocalyst:feature/macos-osx-improvements
May 26, 2026
+257
−9
Merged
osx maxxed out #237
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7c98155
osx localizaiton helper func
philocalyst af3c60d
writing localizations on macos
philocalyst 78bfc6c
simplified the bundle writing process
philocalyst f82737e
Move tempfile to main dependencies for DMG bundling
philocalyst 1a15d64
Add OsxDmg package type and osx_localizations setting
philocalyst a25b96c
dmg_bundle header text
philocalyst 03d03d2
helper functions
philocalyst bfa8d84
DMG BUNDLING PIPELINE
philocalyst 1946193
Integrate DMG bundle into mod.rs dispatch
philocalyst 43f1c32
Add DMG and localization round-trip tests
philocalyst 4039b08
Apply cargo fmt formatting
philocalyst 40aca6e
clippy fixes
philocalyst 1ca3804
removed indirection
philocalyst bdeb334
cleanup of bundle min logic
philocalyst 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
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,165 @@ | ||
| // A macOS DMG (disk image) bundle is a compressed disk image that contains the | ||
| // application bundle and a symlink to /Applications so the user can simply | ||
| // drag-and-drop to install. | ||
| // | ||
| // The layout inside the mounted volume is: | ||
| // | ||
| // <AppName>.dmg (read-only compressed UDZO image) | ||
| // <AppName>.app # the application bundle | ||
| // Applications -> /Applications # drag-and-drop install target | ||
| // | ||
| // Building requires macOS because the `hdiutil` command is used to create and | ||
| // convert the disk image. | ||
|
|
||
| use super::common; | ||
| use crate::Settings; | ||
| use crate::bundle::osx_bundle; | ||
| use anyhow::Context; | ||
| use std::fs; | ||
| use std::path::PathBuf; | ||
| use std::process::Command; | ||
|
|
||
| pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> { | ||
| const BUNDLE_MINIMUM: u64 = 52_428_800; | ||
|
|
||
| let dmg_name = format!("{}.dmg", settings.bundle_name()); | ||
| common::print_bundling(&dmg_name)?; | ||
|
|
||
| let base_dir = settings.project_out_directory().join("bundle/dmg"); | ||
| fs::create_dir_all(&base_dir) | ||
| .with_context(|| format!("Failed to create bundle directory {base_dir:?}"))?; | ||
|
|
||
| // Build the .app bundle into the DMG staging directory. | ||
| let app_bundle_name = format!("{}.app", settings.bundle_name()); | ||
| let app_bundle_path = base_dir.join(&app_bundle_name); | ||
| if app_bundle_path.exists() { | ||
| fs::remove_dir_all(&app_bundle_path) | ||
| .with_context(|| format!("Failed to remove existing {app_bundle_name}"))?; | ||
| } | ||
|
|
||
| osx_bundle::bundle_project_at(settings, &base_dir) | ||
| .with_context(|| "Failed to create app bundle for DMG")?; | ||
|
|
||
| let dmg_path = base_dir.join(&dmg_name); | ||
| if dmg_path.exists() { | ||
| fs::remove_file(&dmg_path) | ||
| .with_context(|| format!("Failed to remove existing {dmg_name}"))?; | ||
| } | ||
|
|
||
| // Determine the size of the app bundle and add a generous overhead. | ||
| let bundle_size = dir_size(&app_bundle_path)?; | ||
| let image_size_bytes = bundle_size + BUNDLE_MINIMUM; // at least 50 MiB | ||
|
|
||
| let temp_dir = tempfile::tempdir() | ||
| .with_context(|| "Failed to create temporary directory for DMG staging")?; | ||
|
|
||
| let staging_dmg = temp_dir.path().join("staging.dmg"); | ||
|
|
||
| // Create a writable HFS+ disk image large enough for the bundle. | ||
| let status = Command::new("hdiutil") | ||
| .args([ | ||
| "create", | ||
| staging_dmg.to_str().unwrap(), | ||
| "-ov", | ||
| "-fs", | ||
| "HFS+", | ||
| "-size", | ||
| &image_size_bytes.to_string(), | ||
| "-volname", | ||
| settings.bundle_name(), | ||
| ]) | ||
| .status() | ||
| .with_context(|| "Failed to run hdiutil create (macOS only)")?; | ||
|
|
||
| if !status.success() { | ||
| anyhow::bail!("hdiutil create failed"); | ||
| } | ||
|
|
||
| // Mount the writable image. | ||
| let output = Command::new("hdiutil") | ||
| .args([ | ||
| "attach", | ||
| staging_dmg.to_str().unwrap(), | ||
| "-nobrowse", | ||
| "-noverify", | ||
| "-noautoopen", | ||
| "-noautofsck", | ||
| ]) | ||
| .output() | ||
| .with_context(|| "Failed to mount staging DMG")?; | ||
|
|
||
| if !output.status.success() { | ||
| anyhow::bail!("hdiutil attach failed"); | ||
| } | ||
|
|
||
| let mount_point = parse_mount_point(&output.stdout) | ||
| .with_context(|| "Could not determine DMG mount point from hdiutil output")?; | ||
|
|
||
| // Copy the app bundle and create the /Applications symlink inside the image. | ||
| let copy_result = (|| -> crate::Result<()> { | ||
| common::copy_dir(&app_bundle_path, &mount_point.join(&app_bundle_name))?; | ||
| #[cfg(unix)] | ||
| std::os::unix::fs::symlink("/Applications", mount_point.join("Applications")) | ||
| .with_context(|| "Failed to create /Applications symlink")?; | ||
| Ok(()) | ||
| })(); | ||
|
|
||
| // Always unmount, even if copying failed. | ||
| let _ = Command::new("hdiutil") | ||
| .args(["detach", mount_point.to_str().unwrap()]) | ||
| .status(); | ||
|
|
||
| copy_result?; | ||
|
|
||
| // Convert the writable image to a read-only compressed UDZO image. | ||
| let status = Command::new("hdiutil") | ||
| .args([ | ||
| "convert", | ||
| staging_dmg.to_str().unwrap(), | ||
| "-ov", | ||
| "-format", | ||
| "UDZO", | ||
| "-imagekey", | ||
| "zlib-level=9", | ||
| "-o", | ||
| dmg_path.to_str().unwrap(), | ||
| ]) | ||
| .status() | ||
| .with_context(|| "Failed to run hdiutil convert")?; | ||
|
|
||
| if !status.success() { | ||
| anyhow::bail!("hdiutil convert failed"); | ||
| } | ||
|
|
||
| Ok(vec![dmg_path]) | ||
| } | ||
|
|
||
| /// Walk a directory and sum the sizes of all contained files. | ||
| fn dir_size(dir: &std::path::Path) -> crate::Result<u64> { | ||
| let mut total: u64 = 0; | ||
| for entry in walkdir::WalkDir::new(dir) { | ||
| let entry = entry?; | ||
| if entry.file_type().is_file() { | ||
| total += entry.metadata()?.len(); | ||
| } | ||
| } | ||
| Ok(total) | ||
| } | ||
|
|
||
| fn parse_mount_point(stdout: &[u8]) -> crate::Result<PathBuf> { | ||
| let text = std::str::from_utf8(stdout)?; | ||
|
|
||
| // hdiutil attach prints a tab-separated line whose last field is the mount | ||
| // point, e.g.: /dev/disk2s1 Apple_HFS /Volumes/MyApp | ||
| for line in text.lines().rev() { | ||
| let parts: Vec<&str> = line.split('\t').collect(); | ||
| if let Some(path) = parts.last() { | ||
| let path = path.trim(); | ||
| if path.starts_with("/Volumes/") { | ||
| return Ok(PathBuf::from(path)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| anyhow::bail!("Could not find a /Volumes/… mount point in hdiutil output") | ||
| } |
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
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.
Should we be testing the other
PackageTypes similarly?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.
Probably... not, it's just a fluff test, I kind of wanted to just fold that into the display implementation rather than the .to_short_name helper, would that be okay?