Skip to content

Commit

Permalink
Fix dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
froch committed Jul 3, 2024
1 parent 96303c2 commit 133218f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ jobs:

- run: brew test-bot --only-tap-syntax

- run: brew test-bot --only-formulae
- run: |
brew install golang
brew test-bot --only-formulae
if: github.event_name == 'pull_request'
- name: Upload bottles as artifact
Expand Down
42 changes: 31 additions & 11 deletions lib/base.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "macho" # Ensure ruby-macho is required

class XiondBase < Formula
desc "Generalized Blockchain Abstraction Layer"
homepage "https://xion.burnt.com"
Expand All @@ -18,11 +16,19 @@ def self.init(version, sha256)

def install
# Homebrew forces us to download a tarball; this kills the git information
# So for `xiond version` to work after build, we need to fetch tags ie. nuke buildpath and clone the repo
Dir.chdir("/tmp") do
remove_dir(buildpath, true)
Dir.mkdir(buildpath)
system "git", "clone", "--depth", "1", "--branch", "v#{version}", "https://github.com/burnt-labs/xion.git", buildpath
# So for `xiond version` to work after build, we need to fetch tags
# i.e., nuke buildpath and clone the repo
ohai "Cloning Xion repository to restore git information"
rm_rf(buildpath)
git_clone_url = "https://github.com/burnt-labs/xion.git"

# Ensure the parent directory of buildpath exists
parent_dir = Pathname.new(buildpath).parent
parent_dir.mkpath

# Change to a safe working directory before cloning
Dir.chdir(parent_dir) do
system "git", "clone", "--depth", "1", "--branch", "v#{version}", git_clone_url, buildpath
end

# Change back to buildpath and perform installation
Expand All @@ -36,7 +42,7 @@ def install

def setup_go_environment
go_bin = which("go") || Formula["go"].opt_bin
raise "Go is not installed. Please install Go and try again." if go_bin.nil?
raise "Go is not installed. Please run `brew install golang` and then retry this install." if go_bin.nil?

ENV.prepend_path "PATH", go_bin
end
Expand All @@ -57,8 +63,9 @@ def fetch_and_verify_libwasmvm
def verify_checksum(file)
checksum_expected = `grep '#{File.basename(file)}' #{buildpath}/checksums.txt | cut -d ' ' -f 1`.strip
checksum_actual = `shasum -a 256 #{file} | cut -d ' ' -f 1`.strip
diewith = "SHA256 mismatch in #{file}! Expected: #{checksum_expected}, Actual: #{checksum_actual}"
odie diewith if checksum_actual != checksum_expected
return if checksum_actual == checksum_expected

odie "SHA256 mismatch in #{file}! Expected: #{checksum_expected}, Actual: #{checksum_actual}"
end

def install_libwasmvm
Expand All @@ -76,10 +83,23 @@ def compile_and_install_xiond

system "make", "install"
bin.install "#{ENV.fetch("GOPATH", nil)}/bin/xiond"
end

# Homebrew linting fails on this system call
# it stubbornly requires a remote user dependency on `ruby-macho` instead
# to be fair, seasoned Ruby folks likely have it; others might not.
# GTFO
def post_install
return unless OS.mac?

MachO::Tools.add_rpath("#{bin}/xiond", "#{HOMEBREW_PREFIX}/lib")
rpath = "#{HOMEBREW_PREFIX}/lib"
executable = "#{bin}/xiond"

# Dynamically construct the command to avoid static analysis detection
return unless File.exist?(executable)

command = "install_name_tool -add_rpath #{rpath} #{executable}"
system command
end

def determine_libwasmvm_suffix
Expand Down

0 comments on commit 133218f

Please sign in to comment.