-
-
Notifications
You must be signed in to change notification settings - Fork 12.6k
/
Copy pathrust.rb
139 lines (120 loc) · 5.11 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
139
class Rust < Formula
desc "Safe, concurrent, practical language"
homepage "https://www.rust-lang.org/"
license any_of: ["Apache-2.0", "MIT"]
stable do
url "https://static.rust-lang.org/dist/rustc-1.69.0-src.tar.gz"
sha256 "fb05971867ad6ccabbd3720279f5a94b99f61024923187b56bb5c455fa3cf60f"
# From https://github.com/rust-lang/rust/tree/#{version}/src/tools
resource "cargo" do
url "https://github.com/rust-lang/cargo.git",
tag: "0.70.0",
revision: "6e9a83356b70586d4b77613a6b33f9ea067b9cdf"
end
end
bottle do
sha256 cellar: :any, arm64_ventura: "0ca792a1dc62130fce46ebb1fb7cb9adf7d9382eb00a47d444b46f502bd00298"
sha256 cellar: :any, arm64_monterey: "2a682658ec44fb651ea2872b437944f14b361b8e559e301f27f73d501ac75b13"
sha256 cellar: :any, arm64_big_sur: "61db8deb3fc312c4921b4ad84868d5c350f68e107d07037103a5a7c594e95d07"
sha256 cellar: :any, ventura: "f2f65bf433a89cb82ead5bd77ecc83cedc1517fb0ed917fc570126fde6008a24"
sha256 cellar: :any, monterey: "1ba0ae6aaa1319c834c21dfd4f131576c65b696f07a6708c0a28d4f50ec56e21"
sha256 cellar: :any, big_sur: "5fa5a33f0ee9c446f293c46841f2575f07968c679e3180c105b4a57d1c214279"
sha256 cellar: :any_skip_relocation, x86_64_linux: "ca21499b915b29248c23c9720a7cffff27af5c3be0d3c16cad21bb744b7b406f"
end
head do
url "https://github.com/rust-lang/rust.git", branch: "master"
resource "cargo" do
url "https://github.com/rust-lang/cargo.git", branch: "master"
end
end
depends_on "cmake" => :build
depends_on "ninja" => :build
depends_on "[email protected]" => :build
depends_on "openssl@3"
depends_on "pkg-config"
uses_from_macos "curl"
uses_from_macos "zlib"
resource "cargobootstrap" do
on_macos do
# From https://github.com/rust-lang/rust/blob/#{version}/src/stage0.json
on_arm do
url "https://static.rust-lang.org/dist/2023-03-28/cargo-1.68.2-aarch64-apple-darwin.tar.gz"
sha256 "7317f1a2823a78f531f433d55cf76baf8701d16268bded12e0501fc07e74c6f4"
end
on_intel do
url "https://static.rust-lang.org/dist/2023-03-28/cargo-1.68.2-x86_64-apple-darwin.tar.gz"
sha256 "c580e7dbf6bde9bf4246380ac1591682981dc7cbdb7b82a95eac8322d866e4bd"
end
end
on_linux do
# From: https://github.com/rust-lang/rust/blob/#{version}/src/stage0.json
on_arm do
url "https://static.rust-lang.org/dist/2023-03-28/cargo-1.68.2-aarch64-unknown-linux-gnu.tar.gz"
sha256 "09119c8df515f3358dbbb23514a80deb5d9891a5fcd4323667dbc84f32a160da"
end
on_intel do
url "https://static.rust-lang.org/dist/2023-03-28/cargo-1.68.2-x86_64-unknown-linux-gnu.tar.gz"
sha256 "cf4e6c9d1a61c1898ffa21353fc9eb4c1512fc6beb6cad433851fbed777f1ea6"
end
end
end
def install
ENV.prepend_path "PATH", Formula["[email protected]"].opt_libexec/"bin"
# Ensure that the `openssl` crate picks up the intended library.
# https://crates.io/crates/openssl#manual-configuration
ENV["OPENSSL_DIR"] = Formula["openssl@3"].opt_prefix
if OS.mac? && MacOS.version <= :sierra
# Requires the CLT to be the active developer directory if Xcode is installed
ENV["SDKROOT"] = MacOS.sdk_path
# 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
end
args = %W[--prefix=#{prefix} --enable-vendor --set rust.jemalloc]
if build.head?
args << "--disable-rpath"
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"
args = %W[--root #{prefix} --path .]
args += %w[--features curl-sys/force-system-lib-on-osx] if OS.mac?
system "cargo", "install", *args
man1.install Dir["src/etc/man/*.1"]
bash_completion.install "src/etc/cargo.bashcomp.sh"
zsh_completion.install "src/etc/_cargo"
end
(lib/"rustlib/src/rust").install "library"
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)}")
MachO.codesign!(dylib) if Hardware::CPU.arm?
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", shell_output("./hello")
system bin/"cargo", "new", "hello_world", "--bin"
assert_equal "Hello, world!", cd("hello_world") { shell_output("#{bin}/cargo run").split("\n").last }
end
end