Top Level Namespace

Constant Summary collapse

VERSION =
File.read(File.expand_path("../../VERSION", __dir__)).strip rescue "0.0.0"
GITHUB_REPO =
"bivvy-dev/bivvy"

Instance Method Summary collapse

Instance Method Details

#download_binaryObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'ext/extconf.rb', line 32

def download_binary
  url = "https://github.com/#{GITHUB_REPO}/releases/download/#{VERSION}/bivvy-#{platform}.tar.gz"
  puts "Downloading bivvy from #{url}"

  uri = URI(url)
  response = Net::HTTP.get_response(uri)

  # Follow redirects
  while response.is_a?(Net::HTTPRedirection)
    uri = URI(response["location"])
    response = Net::HTTP.get_response(uri)
  end

  raise "Download failed: #{response.code}" unless response.is_a?(Net::HTTPSuccess)

  # Extract tar.gz
  bin_dir = File.expand_path("../../exe", __dir__)
  FileUtils.mkdir_p(bin_dir)

  Gem::Package::TarReader.new(Zlib::GzipReader.new(StringIO.new(response.body))) do |tar|
    tar.each do |entry|
      if entry.file? && entry.full_name == "bivvy"
        File.open(File.join(bin_dir, "bivvy-bin"), "wb") do |f|
          f.write(entry.read)
        end
        FileUtils.chmod(0o755, File.join(bin_dir, "bivvy-bin"))
      end
    end
  end

  puts "bivvy installed successfully"
end

#platformObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'ext/extconf.rb', line 15

def platform
  os = case RbConfig::CONFIG["host_os"]
       when /darwin/i then "darwin"
       when /linux/i then "linux"
       when /mswin|mingw|cygwin/i then "windows"
       else raise "Unsupported OS: #{RbConfig::CONFIG["host_os"]}"
       end

  arch = case RbConfig::CONFIG["host_cpu"]
         when /x86_64|amd64/i then "x64"
         when /arm64|aarch64/i then "arm64"
         else raise "Unsupported architecture: #{RbConfig::CONFIG["host_cpu"]}"
         end

  "#{os}-#{arch}"
end