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 21, 2015
1 parent e31bf9c commit 4c8c629
Showing 1 changed file with 66 additions and 6 deletions.
72 changes: 66 additions & 6 deletions Library/Formula/rust.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
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 => "83a6d0e", :tag => "0.2.0"
end

# name includes date to satisfy cache
resource "cargo-nightly-2015-04-02" do
url "https://static-rust-lang-org.s3.amazonaws.com/cargo-dist/2015-04-02/cargo-nightly-x86_64-apple-darwin.tar.gz"
sha256 "18647dccb34acb6085a04b0ea1bfb9d150dc9c17f7829932ddf7e62d518df2fe"
end

# name includes date to satisfy cache
resource "rustc-nightly-2015-04-04" do
url "https://static-rust-lang-org.s3.amazonaws.com/dist/2015-04-04/rustc-nightly-x86_64-apple-darwin.tar.gz"
sha256 "87068b325802fee65a388d249b98a184aff7670140133de78560ef375bae70a5"
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

bottle do
revision 1
Expand All @@ -15,6 +37,10 @@ class Rust < Formula
sha256 "5194f3ae7512d842ac8085628c31b1c36ceae0fb15382f3a1982bc9e80609ae3" => :mountain_lion
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 +49,37 @@ def install
system "./configure", *args
system "make"
system "make install"

resource("cargo").stage do
cargo_stage_path = pwd

if build.stable?
resource("rustc-nightly-2015-04-04").stage do
system "./install.sh", "--prefix=#{cargo_stage_path}/rustc"
end

resource("cargo-nightly-2015-04-02").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
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 +91,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 4c8c629

Please sign in to comment.