130 lines
4.5 KiB
Ruby
130 lines
4.5 KiB
Ruby
class Rust < Formula
|
|
desc "Safe, concurrent, practical language"
|
|
homepage "https://www.rust-lang.org/"
|
|
revision 1
|
|
|
|
stable do
|
|
url "https://static.rust-lang.org/dist/rustc-1.37.0-src.tar.gz"
|
|
sha256 "120e7020d065499cc6b28759ff04153bfdc2ac9b5adeb252331a4eb87cbe38c3"
|
|
|
|
resource "cargo" do
|
|
url "https://github.com/rust-lang/cargo.git",
|
|
:tag => "0.38.0",
|
|
:revision => "9edd089168f8795b3890bc3daf5b99f03e9f8765"
|
|
end
|
|
|
|
resource "racer" do
|
|
# Racer should stay < 2.1 for now as 2.1 needs the nightly build of rust
|
|
# See https://github.com/racer-rust/racer/tree/v2.1.2#installation
|
|
url "https://github.com/racer-rust/racer/archive/2.0.14.tar.gz"
|
|
sha256 "0442721c01ae4465843cb73b24f6caa0127c3308d72b944ad75736164756e522"
|
|
end
|
|
end
|
|
|
|
bottle do
|
|
cellar :any
|
|
sha256 "0ec319b1c076fbfbfc0448952bcf3775b8854e6182c0c3fa886ae7c0e56cdb45" => :catalina
|
|
sha256 "2ad99aa268bf571c91105da674810e0680a3e76d418e10c03b54584b0be8de58" => :mojave
|
|
sha256 "4d6789db13ac445ed199666aed1fda37fc9f4aa9b82aa7ee2015a05a17b48552" => :high_sierra
|
|
sha256 "a377119eb42735fe2654d0be3ff931a4df487762be927ae9e68894522166128d" => :sierra
|
|
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
|
|
|
|
depends_on "cmake" => :build
|
|
depends_on "libssh2"
|
|
depends_on "openssl@1.1"
|
|
depends_on "pkg-config"
|
|
|
|
resource "cargobootstrap" do
|
|
# From https://github.com/rust-lang/rust/blob/#{version}/src/stage0.txt
|
|
url "https://static.rust-lang.org/dist/2019-07-04/cargo-0.37.0-x86_64-apple-darwin.tar.gz"
|
|
sha256 "1378e7a0fba0b66dd4d7b621313c149a0d7a76a526ee24c7c1249390e82f9dda"
|
|
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
|
|
|
|
# Ensure that the `openssl` crate picks up the intended library.
|
|
# https://crates.io/crates/openssl#manual-configuration
|
|
ENV["OPENSSL_DIR"] = Formula["openssl@1.1"].opt_prefix
|
|
|
|
# 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?
|
|
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, "--path", ".", "--features", "curl-sys/force-system-lib-on-osx"
|
|
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, "--path", "."
|
|
(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-project,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
|