From 1d916198d81efdd6f01d52620eed7759381858ae Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Wed, 15 Apr 2015 13:59:43 +0200 Subject: [PATCH] rust with cargo This follows discussion on #33322, where it has been hypothesized that the best course of action may very well be to include cargo in the rust formula. Reasons include: - upstream packages releases with cargo - cargo has no formal versioning rules, merely binding a particular cargo nightly to a given rust release - cargo needs a non feature-gated rust to build - cargo needs to fetch cargo to bootstrap itself (at the make stage) The most practical way to get the cargo version bound to a rust release is to download a binary rust release and run cargo -V, which shows the SHA1 it was built from. This is what has been done for the beta. Alternatively, building with --HEAD relaxes all version constrains and builds both from their respective master HEADs. Curl is a dependency of .travis.install.deps.sh while both curl and python are a dependency of make (via src/etc/dl-snapshot.py) to download a cargo snapshot. Each one makes respective use of a src/rustversion.txt and a src/snapshots.txt file, combined with some very lighteight processing, to find the required downloads. Thus it is be possible to include fetched downloads as resources to improve cacheability and reduce the dependency profile as long as one maintains consistency between each build component. --- Library/Formula/rust.rb | 78 +++++++++++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 11 deletions(-) diff --git a/Library/Formula/rust.rb b/Library/Formula/rust.rb index db0c16d9162f..990c966814d6 100644 --- a/Library/Formula/rust.rb +++ b/Library/Formula/rust.rb @@ -1,20 +1,43 @@ -require 'formula' - class Rust < Formula - homepage 'http://www.rust-lang.org/' - url 'https://static.rust-lang.org/dist/rustc-1.0.0-beta-src.tar.gz' + homepage "http://www.rust-lang.org/" version "1.0.0-beta" - sha256 '94248e30487723ac6f6c34a0db5a21085c0b1338e6a32bd12b159e1d2cd80451' - head 'https://github.com/rust-lang/rust.git' + stable do + url "https://static.rust-lang.org/dist/rustc-1.0.0-beta-src.tar.gz" + sha256 "94248e30487723ac6f6c34a0db5a21085c0b1338e6a32bd12b159e1d2cd80451" + + resource "cargo" do + url "https://github.com/rust-lang/cargo.git", :revision => "84d6d2c" + end - bottle do - revision 1 - sha256 "30c575c4b5f6580b9fa623b4cd49b7560290da7e0271650767e3d7f87099e6d4" => :yosemite - sha256 "b86ff5452e4cce0cb93b601aec283cd47e06bd8336dbc3eece1e94f634c7e7ac" => :mavericks - sha256 "5194f3ae7512d842ac8085628c31b1c36ceae0fb15382f3a1982bc9e80609ae3" => :mountain_lion + # name includes date to satisfy cache + resource "cargo-nightly-2015-03-26" do + url "https://static-rust-lang-org.s3.amazonaws.com/cargo-dist/2015-03-26/cargo-nightly-x86_64-apple-darwin.tar.gz" + sha1 "394afa61b945717bca18412c3c93a428db7d6d5d" + end + + # name includes date to satisfy cache + resource "rustc-nightly-2015-03-30" do + url "https://static-rust-lang-org.s3.amazonaws.com/dist/2015-03-30/rustc-nightly-x86_64-apple-darwin.tar.gz" + sha256 "bb369a86c90900b577be155c1f7e5bec598777311893092527cf82baad619f7d" + end end + head do + url "https://github.com/rust-lang/rust.git" + resource "cargo" do + url "https://github.com/rust-lang/cargo.git" + end + end + + option "with-brewed-llvm", "Use Homebrew's LLVM to build rust (less optimized, more fixes)" + option "with-brewed-rust", "Use Homebrew's rust to build cargo" + + depends_on "openssl" + depends_on "cmake" => :build + depends_on "pkg-config" => :build + depends_on "llvm" => :build if build.with? "brewed-llvm" + def install args = ["--prefix=#{prefix}"] args << "--disable-rpath" if build.head? @@ -23,6 +46,36 @@ def install system "./configure", *args system "make" system "make install" + + resource("cargo").stage do + cargo_stage_path = pwd + + resource("rustc-nightly-2015-03-30").stage do + system "./install.sh", "--prefix=#{cargo_stage_path}/rustc" + end if build.stable? && build.without?("brewed-rust") + + resource("cargo-nightly-2015-03-26").stage do + system "./install.sh", "--prefix=#{cargo_stage_path}/target/snapshot/cargo" + # satisfy make target to skip download + touch ("#{cargo_stage_path}/target/snapshot/cargo/bin/cargo") + end if build.stable? + + args = ["--prefix=#{prefix}"] + args << "--llvm-root=#{Formula["llvm"].opt_prefix}" if build.with? "brewed-llvm" + + if build.head? || build.with?("brewed-rust") + args << "--local-rust-root=\"#{prefix}\"" + else + args << "--local-rust-root=#{cargo_stage_path}/rustc" + end + + system "./configure", *args + system "make" + system "make", "install" + end + + rm_rf prefix/"lib/rustlib/uninstall.sh" + rm_rf prefix/"lib/rustlib/install.log" end test do @@ -34,5 +87,8 @@ def install 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