139 lines
4.6 KiB
Ruby
139 lines
4.6 KiB
Ruby
class Rust < Formula
|
|
desc "Safe, concurrent, practical language"
|
|
homepage "https://www.rust-lang.org/"
|
|
|
|
stable do
|
|
url "https://static.rust-lang.org/dist/rustc-1.27.0-src.tar.gz"
|
|
sha256 "2cb9803f690349c9fd429564d909ddd4676c68dc48b670b8ddf797c2613e2d21"
|
|
|
|
resource "cargo" do
|
|
url "https://github.com/rust-lang/cargo.git",
|
|
:tag => "0.27.0",
|
|
:revision => "0e7c5a93159076952f609e05760e2458828d0d1f"
|
|
end
|
|
|
|
resource "racer" do
|
|
url "https://github.com/racer-rust/racer/archive/2.0.14.tar.gz"
|
|
sha256 "0442721c01ae4465843cb73b24f6caa0127c3308d72b944ad75736164756e522"
|
|
end
|
|
end
|
|
|
|
bottle do
|
|
sha256 "fc3dd655539149da38e351fd2f8bd5608a55d25c546bd87c8983346ff8b32568" => :high_sierra
|
|
sha256 "9d91681309cce40845d8c20d97ed2fa9ab0f4ecc7d015c33907abab7d5fa8643" => :sierra
|
|
sha256 "eafee2b64ed79f94c04fb46e394ff84e68f60cc89ef6036f81bef5ca041d6aac" => :el_capitan
|
|
end
|
|
|
|
head do
|
|
url "https://github.com/rust-lang/rust.git"
|
|
|
|
resource "cargo" do
|
|
url "https://github.com/rust-lang/cargo.git"
|
|
end
|
|
|
|
resource "racer" do
|
|
url "https://github.com/racer-rust/racer.git"
|
|
end
|
|
end
|
|
|
|
option "with-llvm", "Build with brewed LLVM. By default, Rust's LLVM will be used."
|
|
|
|
depends_on "cmake" => :build
|
|
depends_on "pkg-config"
|
|
depends_on "llvm" => :optional
|
|
depends_on "openssl"
|
|
depends_on "libssh2"
|
|
|
|
conflicts_with "cargo-completion", :because => "both install shell completion for cargo"
|
|
|
|
# According to the official readme, GCC 4.7+ is required
|
|
fails_with :gcc_4_0
|
|
fails_with :gcc
|
|
("4.3".."4.6").each do |n|
|
|
fails_with :gcc => n
|
|
end
|
|
|
|
resource "cargobootstrap" do
|
|
# From https://github.com/rust-lang/rust/blob/#{version}/src/stage0.txt
|
|
url "https://static.rust-lang.org/dist/2018-05-10/cargo-0.27.0-x86_64-apple-darwin.tar.gz"
|
|
sha256 "5a21a7569a67b9d06442063a1b4c2c2e42279e3d67f843ea77df647d87937eb5"
|
|
end
|
|
|
|
def install
|
|
# Fix build failure for compiler_builtins "error: invalid deployment target
|
|
# for -stdlib=libc++ (requires OS X 10.7 or later)"
|
|
ENV["MACOSX_DEPLOYMENT_TARGET"] = MacOS.version
|
|
|
|
# Prevent cargo from linking against a different library (like openssl@1.1)
|
|
# from libssh2 and causing segfaults
|
|
ENV["OPENSSL_INCLUDE_DIR"] = Formula["openssl"].opt_include
|
|
ENV["OPENSSL_LIB_DIR"] = Formula["openssl"].opt_lib
|
|
|
|
# Fix build failure for cmake v0.1.24 "error: internal compiler error:
|
|
# src/librustc/ty/subst.rs:127: impossible case reached" on 10.11, and for
|
|
# libgit2-sys-0.6.12 "fatal error: 'os/availability.h' file not found
|
|
# #include <os/availability.h>" on 10.11 and "SecTrust.h:170:67: error:
|
|
# expected ';' after top level declarator" among other errors on 10.12
|
|
ENV["SDKROOT"] = MacOS.sdk_path
|
|
|
|
args = ["--prefix=#{prefix}"]
|
|
args << "--disable-rpath" if build.head?
|
|
args << "--llvm-root=#{Formula["llvm"].opt_prefix}" if build.with? "llvm"
|
|
if build.head?
|
|
args << "--release-channel=nightly"
|
|
else
|
|
args << "--release-channel=stable"
|
|
end
|
|
system "./configure", *args
|
|
system "make"
|
|
system "make", "install"
|
|
|
|
resource("cargobootstrap").stage do
|
|
system "./install.sh", "--prefix=#{buildpath}/cargobootstrap"
|
|
end
|
|
ENV.prepend_path "PATH", buildpath/"cargobootstrap/bin"
|
|
|
|
resource("cargo").stage do
|
|
ENV["RUSTC"] = bin/"rustc"
|
|
system "cargo", "install", "--root", prefix
|
|
end
|
|
|
|
resource("racer").stage do
|
|
ENV.prepend_path "PATH", bin
|
|
cargo_home = buildpath/"cargo_home"
|
|
cargo_home.mkpath
|
|
ENV["CARGO_HOME"] = cargo_home
|
|
system "cargo", "install", "--root", libexec
|
|
(bin/"racer").write_env_script(libexec/"bin/racer", :RUST_SRC_PATH => pkgshare/"rust_src")
|
|
end
|
|
|
|
# Remove any binary files; as Homebrew will run ranlib on them and barf.
|
|
rm_rf Dir["src/{llvm,llvm-emscripten,test,librustdoc,etc/snapshot.pyc}"]
|
|
(pkgshare/"rust_src").install Dir["src/*"]
|
|
|
|
rm_rf prefix/"lib/rustlib/uninstall.sh"
|
|
rm_rf prefix/"lib/rustlib/install.log"
|
|
end
|
|
|
|
def post_install
|
|
Dir["#{lib}/rustlib/**/*.dylib"].each do |dylib|
|
|
chmod 0664, dylib
|
|
MachO::Tools.change_dylib_id(dylib, "@rpath/#{File.basename(dylib)}")
|
|
chmod 0444, dylib
|
|
end
|
|
end
|
|
|
|
test do
|
|
system "#{bin}/rustdoc", "-h"
|
|
(testpath/"hello.rs").write <<~EOS
|
|
fn main() {
|
|
println!("Hello World!");
|
|
}
|
|
EOS
|
|
system "#{bin}/rustc", "hello.rs"
|
|
assert_equal "Hello World!\n", `./hello`
|
|
system "#{bin}/cargo", "new", "hello_world", "--bin"
|
|
assert_equal "Hello, world!",
|
|
(testpath/"hello_world").cd { `#{bin}/cargo run`.split("\n").last }
|
|
end
|
|
end
|