-
-
Notifications
You must be signed in to change notification settings - Fork 12.6k
/
Copy pathrust.rb
138 lines (116 loc) · 4.62 KB
/
rust.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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.29.2-src.tar.gz"
sha256 "5088e796aa2e47478cdf41e7243fc5443fafab0a7c70a11423e57c80c04167c9"
resource "cargo" do
url "https://github.com/rust-lang/cargo.git",
:tag => "0.30.0",
:revision => "524a578d75df2869eedd5fbf51054b1d5909cff7"
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
sha256 "187562ab7645dfd7dce1bef9e43c5c4a82a82d75a43754b68aa38fdf7912a1c6" => :mojave
sha256 "e08c15d3e95f7833b13bda40e5e6c0defb60745399c29786abc68db1ba042a7c" => :high_sierra
sha256 "5002aa07724246f712c3cb0f143f1a850398da15a2ce38c8a258a304c29accae" => :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
option "with-llvm", "Build with brewed LLVM. By default, Rust's LLVM will be used."
depends_on "cmake" => :build
depends_on "libssh2"
depends_on "openssl"
depends_on "pkg-config"
depends_on "llvm" => :optional
# According to the official readme, GCC 4.7+ is required
fails_with :gcc_4_0
fails_with :gcc_4_2
("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-08-02/cargo-0.29.0-x86_64-apple-darwin.tar.gz"
sha256 "24ea65fba1e1c317842c2d554659f483748a6b155cea53204b1126b142de9125"
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"].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?
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, "--path", "."
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,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