-
-
Save archaelus/d26344e9b93ca32cf84a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
mkdir "output" | |
Dir.chdir "rn/rustc.pkg/Scripts/rustc" do | |
lib_path_update("bin/rustc") | |
lib_path_update("bin/rustdoc") | |
lib_path_update("bin/rust-lldb") | |
end | |
cp_r Dir["rn/rustc.pkg/Scripts/rustc/*"], "output/" | |
Dir.chdir "rn/cargo.pkg/Scripts/cargo" do | |
lib_path_update("bin/cargo") | |
rm "manifest.in" | |
end | |
cp_r Dir["rn/cargo.pkg/Scripts/cargo/*"], "output/" | |
Dir.chdir "rn/rust-docs.pkg/Scripts/rust-docs" do | |
rm "manifest.in" | |
end | |
cp_r Dir["rn/rust-docs.pkg/Scripts/rust-docs/*"], "output/" | |
prefix.install Dir["output/*"] | |
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