Skip to content
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

feat: add Homebrew formula installer support #318

Merged
merged 2 commits into from
Aug 16, 2023
Merged

feat: add Homebrew formula installer support #318

merged 2 commits into from
Aug 16, 2023

Conversation

mistydemeo
Copy link
Contributor

@mistydemeo mistydemeo commented Aug 11, 2023

This starts the work of adding a Homebrew installer. At this point, it generates a usable formula file that installs binaries and doc files, but not other optional features we might want. It also doesn't handle the work of uploading it to a tap yet.

Sample generated formula:

class AkaikatanaRepack < Formula
  if Hardware::CPU.type == :arm
    url "https://github.com/mistydemeo/akaikatana-repack/releases/download/v0.2.0/akaikatana-repack-aarch64-apple-darwin.tar.xz"
    sha256 "774c799b726fbe7982b9c124bda66085ca2631cdf700daed2e5f29617cd99275"
  else
    url "https://github.com/mistydemeo/akaikatana-repack/releases/download/v0.2.0/akaikatana-repack-x86_64-apple-darwin.tar.xz"
    sha256 "b1d7cc630fc1d8d0d6aa2e6f46cec12c5709162e667514dd3e7e4af13e9bfc40"
  end
  license "GPL-2.0-or-later"

  def install
    bin.install "akextract", "akmetadata", "akrepack"

    # Homebrew will automatically install these, so we don't need to do that
    doc_files = Dir["README.*", "readme.*", "LICENSE", "LICENSE.*", "CHANGELOG.*"]
    leftover_contents = Dir["*"] - doc_files

    # Install any leftover files in pkgshare; these are probably config or
    # sample files.
    pkgshare.install *leftover_contents unless leftover_contents.empty?
  end
end

I tested it via brew install, and it works just fine; it installs all of the defined binaries, plus the README and license files.

refs #308

@mistydemeo mistydemeo requested a review from Gankra August 11, 2023 00:55
@@ -36,6 +36,7 @@ thiserror = "1.0.35"
tracing = { version = "0.1.36", features = ["log"] }
serde = { version = "1.0.144", features = ["derive"] }
cargo_metadata = "0.15.0"
cruet = "0.13.3"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't feel great about adding another dep, I just wanted to not have to think about the ClassCase conversion.

/// A brief description of the application
pub desc: Option<String>,
/// AMD64 artifact
pub x86_64: Option<ExecutableZipFragment>,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured that since Homebrew does need to specifically query the x86_64 and ARM binaries, it made sense to promote them to first-class properties of the installer info struct.

Copy link
Contributor

@Gankra Gankra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you figured out the general gist, nice!

Comment on lines +1177 to +1197
if target == X64_MACOS {
x86_64 = Some(fragment.clone());
}
if target == ARM64_MACOS {
arm64 = Some(fragment.clone());
}

if do_rosetta_fallback && target == X64_MACOS {
// Copy the info but respecify it to be arm64 macos
let mut arm_fragment = fragment.clone();
arm_fragment.target_triples = vec![ARM64_MACOS.to_owned()];
artifacts.push(arm_fragment.clone());
arm64 = Some(arm_fragment);
}
artifacts.push(fragment);
Copy link
Contributor

@Gankra Gankra Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume it's intentional that even though we're doing fallback we're not actually assigning the x64 binary to the arm64 var because we want homebrew et al to understand what's going on?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow I should read the lines i link more closely, you do assign it to arm64, interesting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, more or less I'm mirroring the existing behaviour, even if it would result in an unnecessary if statement. It'd definitely be possible to just have one url if the two arches are the same though.

// TODO ensure this is Homebrew-legal
let artifact_name = format!("{release_id}.rb");
let artifact_path = self.inner.dist_dir.join(&artifact_name);
let hint = format!("brew install {artifact_name}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This presumably will need some kind of reference to the tap in the final impl right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's right. For this PR I was focused on getting the formula file rendered out - figured it would make sense to leave the tap stuff to a followup.

@mistydemeo mistydemeo force-pushed the add_homebrew branch 3 times, most recently from b97057b to 4eb0e1c Compare August 15, 2023 22:44
Copy link
Contributor

@Gankra Gankra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on the tests!

// TODO ensure this is Homebrew-legal
let artifact_name = format!("{release_id}.rb");
let artifact_path = self.inner.dist_dir.join(&artifact_name);
let hint = format!("brew install {artifact_name}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be deleted until the tap followup?

@mistydemeo mistydemeo force-pushed the add_homebrew branch 2 times, most recently from 0d3b366 to 8acd6e9 Compare August 16, 2023 16:01
@mistydemeo mistydemeo marked this pull request as ready for review August 16, 2023 16:02
@mistydemeo mistydemeo force-pushed the add_homebrew branch 4 times, most recently from ff7ea29 to abc7aec Compare August 16, 2023 18:52
@mistydemeo mistydemeo merged commit d954686 into main Aug 16, 2023
@mistydemeo mistydemeo deleted the add_homebrew branch August 16, 2023 19:38
@Gankra Gankra mentioned this pull request Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants