Skip to content

Commit

Permalink
rust with cargo
Browse files Browse the repository at this point in the history
This follows discussion on Homebrew#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.
  • Loading branch information
lloeki committed Apr 16, 2015
1 parent e31bf9c commit d444c1e
Showing 1 changed file with 61 additions and 11 deletions.
72 changes: 61 additions & 11 deletions Library/Formula/rust.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
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

# 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

bottle do
revision 1
sha256 "30c575c4b5f6580b9fa623b4cd49b7560290da7e0271650767e3d7f87099e6d4" => :yosemite
sha256 "b86ff5452e4cce0cb93b601aec283cd47e06bd8336dbc3eece1e94f634c7e7ac" => :mavericks
sha256 "5194f3ae7512d842ac8085628c31b1c36ceae0fb15382f3a1982bc9e80609ae3" => :mountain_lion
# 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

depends_on "openssl"
depends_on "cmake" => :build
depends_on "pkg-config" => :build

def install
args = ["--prefix=#{prefix}"]
args << "--disable-rpath" if build.head?
Expand All @@ -23,6 +42,34 @@ 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?

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

args = ["--prefix=#{prefix}"]
if build.head?
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
Expand All @@ -34,5 +81,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

0 comments on commit d444c1e

Please sign in to comment.