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 may be possible to include fetched downloads as resources to
improve cacheability and reduce the dependency profile, but this
requires patching of .travis.install.deps.sh, that currently
unconditionally downloads its stuff. Simply putting the cargo snapshot
in the right place ($(TARGET_ROOT)/snapshot/cargo) will certainly make
the makefile happy, as long as the proper filename unmangling is done
(see src/etc/dl-snapshot.py). Still, configure wants to probe for
python. Staying KISS, no patching has been done here: make it work, make
it right, make it fast.
  • Loading branch information
lloeki committed Apr 15, 2015
1 parent e31bf9c commit acc45ba
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions Library/Formula/rust.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
require 'formula'
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/"
url "https://static.rust-lang.org/dist/rustc-1.0.0-beta-src.tar.gz"
version "1.0.0-beta"
sha256 '94248e30487723ac6f6c34a0db5a21085c0b1338e6a32bd12b159e1d2cd80451'
sha256 "94248e30487723ac6f6c34a0db5a21085c0b1338e6a32bd12b159e1d2cd80451"

head 'https://github.com/rust-lang/rust.git'
head "https://github.com/rust-lang/rust.git"

bottle do
revision 1
sha256 "30c575c4b5f6580b9fa623b4cd49b7560290da7e0271650767e3d7f87099e6d4" => :yosemite
sha256 "b86ff5452e4cce0cb93b601aec283cd47e06bd8336dbc3eece1e94f634c7e7ac" => :mavericks
sha256 "5194f3ae7512d842ac8085628c31b1c36ceae0fb15382f3a1982bc9e80609ae3" => :mountain_lion
end
depends_on "cmake" => :build
depends_on "python" => :build
depends_on "pkg-config" => :build
depends_on "curl" => :build unless build.head?
depends_on "openssl"

resource "cargo" do
url "https://github.com/rust-lang/cargo.git"
end if build.head?

resource "cargo" do
url "https://github.com/rust-lang/cargo.git", :revision => "84d6d2c"
end unless build.head?

def install
args = ["--prefix=#{prefix}"]
Expand All @@ -23,6 +30,23 @@ def install
system "./configure", *args
system "make"
system "make install"

resource("cargo").stage do
# as soon as cargo can be built without gated features,
# running ./travis.install.deps.sh should be useless
# and --local-rust-root should be able to point to `prefix`

args = ["--prefix=#{prefix}"]
if build.head?
args << "--local-rust-root=\"#{prefix}\""
else
system "./.travis.install.deps.sh"
args << "--local-rust-root=\"$PWD\"/rustc"
end
system "./configure", *args
system "make"
system "make", "install"
end
end

test do
Expand All @@ -34,5 +58,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!\n",
(testpath/"hello_world").cd { `#{bin}/cargo run` }
end
end

0 comments on commit acc45ba

Please sign in to comment.