Skip to content

Instantly share code, notes, and snippets.

@developerfred
Forked from gcv/rust_nightly.rb
Created November 14, 2019 01:30
Show Gist options
  • Save developerfred/0c76138868dc806bae9c452c85d35b59 to your computer and use it in GitHub Desktop.
Save developerfred/0c76138868dc806bae9c452c85d35b59 to your computer and use it in GitHub Desktop.
Homebrew formula for installing the official Rust nightly binary build. Useful because: (1) the `rust.rb` formula in Homebrew does not currently install Crate, and (2) the official binary `.pkg` pollutes `/usr/local`. This formula respects Homebrew's installation directory.
class RustNightly < Formula
url "https://static.rust-lang.org/dist/rust-nightly-x86_64-apple-darwin.pkg", using: :nounzip
homepage "http://www.rust-lang.org"
sha1 ""
version Date.today.to_s
def install
system "pkgutil --expand rust-nightly-x86_64-apple-darwin.pkg rn"
Dir.mkdir "output"
Dir.chdir "output"
system "tar xf ../rn/rust.pkg/Payload"
lib_path_update("bin/rustc")
lib_path_update("bin/rustdoc")
prefix.install Dir["*"]
end
private
def otool(path)
lines = %x[otool -L #{path}].split /\n/
lines[1..-1].map do |line|
line.
strip.
gsub(/ \(compatibility version.*$/, '')
end
end
def install_name_tool(path, old)
pattern = 'x86_64-apple-darwin/stage1/lib/rustlib/x86_64-apple-darwin'
if path.match(pattern)
new = old.gsub(pattern, prefix)
system("install_name_tool -change '#{old}' '#{new}' '#{path}'")
end
end
def lib_path_update(binary)
otool(binary).each do |current_lib_path|
install_name_tool(binary, current_lib_path)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment