Skip to content

Instantly share code, notes, and snippets.

@gcv
Created January 26, 2015 18:10
Show Gist options
  • Save gcv/20a71053ae416ca24bcc to your computer and use it in GitHub Desktop.
Save gcv/20a71053ae416ca24bcc 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
@Byron
Copy link

Byron commented Jan 27, 2015

Thank you !
Do you think it makes sense to make it create symlinks to make rustc/cargo available from the commandline ?
How do you solve running nightlies on your system, maybe I am missing something. After all it seems it keeps previous versions around in the respective date directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment