Skip to content

Commit

Permalink
podman: Build a relocatable binary, using upstream feature to locate …
Browse files Browse the repository at this point in the history
…helpers relative to the main binary

PR containers/common Homebrew#1127 (containers/common#1127)
introduced a new feature by which podman is now capable of locating its helpers
(such as `gvproxy`) relative to the main binary location, and by default
enables that feature for MacOS builds.

Apply the patch on top of the current Homebrew tree and enable the feature.

Move `gvproxy` from a bare `libexec` to a `libexec/podman`, since that's the
default path to the binary used in podman.

For Linux builds, use the environment variable consumed by the Makefile to
inject the same binary-relative path to the default helper search list.

Since this change makes this keg relocatable again, drop the
`pour_bottle? only_if:` gate that was causing it to build from source
whenever using a non-standard prefix. Bump up revision number. Installing from
bottles should now work fine, even on a non-standard prefix.

Tested: Rebuilt from source with `brew reinstall -s podman` and confirmed that
`podman machine start` works (that's the operation that depends on the location
of the `gvproxy` binary.) Tested a different directory location to test (on a
Mac) that the Linux change should work as exepcted.
  • Loading branch information
filbranden committed Aug 31, 2022
1 parent d29f52a commit 9649e47
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions Formula/podman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ class Podman < Formula
url "https://github.com/containers/podman/archive/v4.2.0.tar.gz"
sha256 "15f8bc59025ccd97dc9212a552e7274dfb79e1633b02d6a2a7f63d747eadb2f4"

# Allow specifying helper dirs with $BINDIR as base directory. Use a `$BINDIR` magic
# token as a prefix in the helper path to indicate it should be relative to the
# directory where the binary is located.
# This patch can be dropped on upgrade to podman 4.3.0.
patch do
url "https://github.com/containers/common/commit/030b7518103cfd7b930b54744d4a4510b659fdc2.patch?full_index=1"
sha256 "7c00abe7728d6438abcdb69ce6efa43503dcbb93bcb2d737f6ca4aa553e2eeb5"
directory "vendor/github.com/containers/common"
end

# Update Darwin config to include '$BINDIR/../libexec/podman' in helper search path.
# This patch can be dropped on upgrade to podman 4.3.0.
patch do
url "https://github.com/containers/common/commit/4e6828877b0067557b435ec8810bda7f5cb48a4f.patch?full_index=1"
sha256 "01c4c67159f83f636a7b3a6007a010b1336c83246e4fb8c34b67be32fd6c2206"
directory "vendor/github.com/containers/common"
end

resource "gvproxy" do
url "https://github.com/containers/gvisor-tap-vsock/archive/v0.4.0.tar.gz"
sha256 "896cf02fbabce9583a1bba21e2b384015c0104d634a73a16d2f44552cf84d972"
Expand All @@ -23,11 +41,6 @@ class Podman < Formula
sha256 x86_64_linux: "9f62f0cb05daf1085eb9c78dbf1f01c0a28c0b15d1b7f4cdebd49313bcef46b5"
end

# The path to libexec where `gvproxy` can be found is hardcoded into the Go binary.
# Therefore, only use pre-built bottle if installing in default prefix.
# Otherwise, rebuild from source.
pour_bottle? only_if: :default_prefix

head do
url "https://github.com/containers/podman.git", branch: "main"

Expand All @@ -46,7 +59,12 @@ def install
ENV["CGO_ENABLED"] = "1"
os = OS.kernel_name.downcase

ENV["HELPER_BINARIES_DIR"] = libexec
# Update helper binary location to look at libexec/podman inside the keg.
# This is not needed on Mac because config_darwin.go already includes this
# location, but Linux doesn't so let's add it through the environment
# variable. Note that we want a literal `$BINDIR`, so we need to escape
# the `$` for Makefile syntax, so we need to double it as `$$BINDIR`.
ENV["HELPER_BINARIES_DIR"] = "$$BINDIR/../libexec/podman" if OS.linux?
system "make", "podman-remote"
if OS.mac?
bin.install "bin/#{os}/podman" => "podman-remote"
Expand All @@ -59,7 +77,7 @@ def install

resource("gvproxy").stage do
system "make", "gvproxy"
libexec.install "bin/gvproxy"
(libexec/"podman").install "bin/gvproxy"
end

system "make", "podman-remote-#{os}-docs"
Expand Down

0 comments on commit 9649e47

Please sign in to comment.