Index: Portfile
===================================================================
--- Portfile	(revision 103790)
+++ Portfile	(working copy)
@@ -6,6 +6,7 @@
 name                rust
 version             0.5
 maintainers         g5pw openmaintainer
+license             {MIT Apache-2}
 
 categories          lang devel
 description         Compiler for the Rust programming language
@@ -15,19 +16,89 @@
 platforms           darwin
 
 homepage            http://www.rust-lang.org
-master_sites        http://dl.rust-lang.org/dist
+master_sites        http://static.rust-lang.org/dist:main \
+                    http://static.rust-lang.org/stage0-snapshots:stage0
 
-checksums           rmd160  b4988da7be984aa1337f4076e96e6d0c72e3170d \
-                    sha256  d326d22707f0562d669c11efbc33ae812ddbf76ab78f07087fc5beb095a8928a
+# Rust has not added universal binary support: https://github.com/mozilla/rust/issues/2024
+supported_archs     i386 x86_64
+universal_variant   no
+
+# Download the right bootstrap compiler
+if {${os.platform} == "darwin" && $build_arch == "x86_64"} {
+    set rust-stage0     rust-stage0-2012-12-19-8554d5e-macos-x86_64-e4564933f11b17f7dbd25b61032233693da21dc5.tar.bz2
+} elseif {${os.platform} == "darwin" && $build_arch == "i386"} {
+    set rust-stage0     rust-stage0-2012-12-19-8554d5e-macos-i386-151ff211c01f0b7a1895b93ff0bc021bf1472346.tar.bz2
+}
+
+set rust-local-root ${worksrcpath}/${build_arch}-apple-darwin/stage0
+
+distfiles-append	${rust-stage0}:stage0
+extract.only-delete ${rust-stage0}
+
+checksums           rust-0.5.tar.gz \
+                    rmd160  b4988da7be984aa1337f4076e96e6d0c72e3170d \
+                    rust-stage0-2012-12-19-8554d5e-macos-x86_64-e4564933f11b17f7dbd25b61032233693da21dc5.tar.bz2 \
+                    rmd160  3d966bd2d17e3f2c74ed78f3674439c89d5a16ee \
+                    sha256  a2e287a683128e2e213e11c5b9f92e5e628eb63163591d61523549deb2e21f7d \
+                    rust-stage0-2012-12-19-8554d5e-macos-i386-151ff211c01f0b7a1895b93ff0bc021bf1472346.tar.bz2 \
+                    rmd160  300b17458073a8704817821bd5406189a264f765 \
+                    sha256  5e598d4c45ee2dd8b7f2b69d92f60d16e57991e796d76ca255a612357a5e48e0
+
+# Configure patch needed to accept LLVM backends higher than 3.1
+# Stage0.pk patch nixes download
+patchfiles          configure.patch \
+                    mk-stage0.mk.patch \
+                    mk-platform.mk.patch
 
 configure.universal_args-delete \
                     --disable-dependency-tracking
 
+configure.args-append \
+                    --disable-docs
+                    
+
 # There's a makefile that ignores the configure script CC options, this makes \
 # it behave.
 build.args-append   CC=${configure.cc} \
                     CXX=${configure.cxx} \
                     CPP=${configure.cpp}
 
+post-extract {
+    file mkdir  ${worksrcpath}/${build_arch}-apple-darwin
+    system -W   ${workpath} "gnutar --no-same-owner -xf ${distpath}/${rust-stage0}"
+    move        ${workpath}/rust-stage0 ${rust-local-root}
+}
+
+variant llvm30 description {Use LLVM 3.0 backend} conflicts llvm31 llvm32 llvm33 {
+   depends_lib-append   port:llvm-3.0
+   configure.args-append \
+                        --llvm-root=${prefix}/libexec/llvm-3.0
+}
+
+variant llvm31 description {Use LLVM 3.1 backend} conflicts llvm30 llvm32 llvm33 {
+   depends_lib-append   port:llvm-3.1
+   configure.args-append \
+                        --llvm-root=${prefix}/libexec/llvm-3.1
+}
+
+variant llvm32 description {Use LLVM 3.2 backend} conflicts llvm30 llvm31 llvm33 {
+   depends_lib-append   port:llvm-3.2
+   configure.args-append \
+                        --llvm-root=${prefix}/libexec/llvm-3.2
+}
+
+variant llvm33 description {Use LLVM 3.3 backend} conflicts llvm30 llvm31 llvm32 {
+   depends_lib-append   port:llvm-3.3
+   configure.args-append \
+                        --llvm-root=${prefix}/libexec/llvm-3.3
+}
+
+if { ![variant_isset llvm30] &&
+     ![variant_isset llvm31] &&
+     ![variant_isset llvm32] &&
+     ![variant_isset llvm33] } {
+    default_variants +llvm32
+}
+
 livecheck.url       ${homepage}/
 livecheck.regex     "/release-(\\d\.\\d)/"
Index: files/configure.patch
===================================================================
--- files/configure.patch	(revision 0)
+++ files/configure.patch	(working copy)
@@ -0,0 +1,28 @@
+--- configure.orig	2012-12-19 07:29:12.000000000 +0800
++++ configure	2012-12-24 20:52:33.524922231 +0800
+@@ -363,7 +363,6 @@
+ step_msg "looking for build programs"
+ 
+ probe_need CFG_PERL        perl
+-probe_need CFG_CURL        curl
+ probe_need CFG_PYTHON      python2.7 python2.6 python2 python
+ 
+ python_version=$($CFG_PYTHON -V 2>&1)
+@@ -493,7 +493,7 @@
+     LLVM_VERSION=$($LLVM_CONFIG --version)
+
+     case $LLVM_VERSION in
+-	(3.1svn|3.1|3.0svn|3.0)
++	(3.3svn|3.3|3.2svn|3.2|3.1svn|3.1|3.0svn|3.0)
+ 	    msg "found ok version of LLVM: $LLVM_VERSION"
+ 	    ;;
+ 	(*)
+@@ -516,7 +506,7 @@
+                       | cut -d ' ' -f 2)
+ 
+     case $CFG_CLANG_VERSION in
+-        (3.0svn | 3.0 | 3.1 | 4.0 | 4.1)
++        (3.0svn | 3.0 | 3.1 | 3.2 | 4.0 | 4.1)
+         step_msg "found ok version of CLANG: $CFG_CLANG_VERSION"
+         CFG_C_COMPILER="clang"
+         ;;
Index: files/mk-platform.mk.patch
===================================================================
--- files/mk-platform.mk.patch	(revision 0)
+++ files/mk-platform.mk.patch	(working copy)
@@ -0,0 +1,11 @@
+--- mk/platform.mk	2012-12-19 00:29:12.000000000 +0100
++++ mk/platform.mk.new	2013-03-07 20:56:14.000000000 +0100
+@@ -313,7 +313,7 @@
+ # We're using llvm-mc as our assembler because it supports
+ # .cfi pseudo-ops on mac
+ define CFG_MAKE_ASSEMBLER
+-  CFG_ASSEMBLE_$(1)=$$(CPP) $$(CFG_DEPEND_FLAGS) $$(2) | \
++  CFG_ASSEMBLE_$(1)=$$(CPP) -MMD -MP $$(2) | \
+                     $$(LLVM_MC_$$(CFG_HOST_TRIPLE)) \
+                     -assemble \
+                     -filetype=obj \
Index: files/mk-stage0.mk.patch
===================================================================
--- files/mk-stage0.mk.patch	(revision 0)
+++ files/mk-stage0.mk.patch	(working copy)
@@ -0,0 +1,10 @@
+--- mk/stage0.mk	2012-12-19 00:29:12.000000000 +0100
++++ mk/stage0.mk.new	2013-03-07 00:12:00.000000000 +0100
+@@ -11,7 +11,6 @@
+ ifdef CFG_ENABLE_LOCAL_RUST
+ 	$(Q)$(S)src/etc/local_stage0.sh $(CFG_HOST_TRIPLE) $(CFG_LOCAL_RUST_ROOT)
+ else 
+-	$(Q)$(S)src/etc/get-snapshot.py $(CFG_HOST_TRIPLE) $(SNAPSHOT_FILE)
+ ifdef CFG_ENABLE_PAX_FLAGS
+ 	@$(call E, apply PaX flags: $@)
+ 	@"$(CFG_PAXCTL)" -cm "$@"
