3ab9f1147b4e95efe2b28f083e9d614fdefe238f
[gentoo.git] / dev-util / cargo / cargo-0.12.0.ebuild
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=6
6
7 CARGO_SNAPSHOT_DATE="2016-03-21"
8 CARGO_INDEX_COMMIT="64a9f2f594cefc2ca652e0cecf7ce6e41c0279ee"
9 CRATES="advapi32-sys-0.1.2
10 aho-corasick-0.5.1
11 bitflags-0.1.1
12 bufstream-0.1.1
13 cmake-0.1.16
14 crossbeam-0.2.8
15 cfg-if-0.1.0
16 curl-0.3.0
17 curl-sys-0.2.0
18 docopt-0.6.78
19 env_logger-0.3.2
20 filetime-0.1.10
21 flate2-0.2.13
22 fs2-0.2.3
23 gcc-0.3.26
24 gdi32-sys-0.1.1
25 git2-0.4.3
26 git2-curl-0.5.0
27 glob-0.2.11
28 hamcrest-0.1.0
29 idna-0.1.0
30 kernel32-sys-0.2.1
31 libc-0.2.8
32 libgit2-sys-0.4.3
33 libressl-pnacl-sys-2.1.6
34 libssh2-sys-0.1.37
35 libz-sys-1.0.2
36 log-0.3.5
37 matches-0.1.2
38 memchr-0.1.10
39 miniz-sys-0.1.7
40 miow-0.1.2
41 net2-0.2.24
42 nom-1.2.2
43 num-0.1.31
44 num_cpus-0.2.11
45 openssl-sys-0.7.8
46 pkg-config-0.3.8
47 pnacl-build-helper-1.4.10
48 rand-0.3.14
49 regex-0.1.58
50 regex-syntax-0.3.0
51 rustc-serialize-0.3.18
52 semver-0.2.3
53 strsim-0.3.0
54 tar-0.4.5
55 tempdir-0.3.4
56 term-0.4.4
57 toml-0.1.30
58 unicode-bidi-0.2.3
59 unicode-normalization-0.1.2
60 url-1.1.0
61 user32-sys-0.1.2
62 utf8-ranges-0.1.3
63 winapi-0.2.6
64 winapi-build-0.1.1
65 ws2_32-sys-0.2.1
66 "
67
68 inherit cargo bash-completion-r1
69
70 DESCRIPTION="The Rust's package manager"
71 HOMEPAGE="http://crates.io"
72 SRC_URI="https://github.com/rust-lang/cargo/archive/${PV}.tar.gz -> ${P}.tar.gz
73         https://github.com/rust-lang/crates.io-index/archive/${CARGO_INDEX_COMMIT}.tar.gz -> cargo-registry-${CARGO_INDEX_COMMIT}.tar.gz
74         $(cargo_crate_uris ${CRATES})
75         x86?   (
76                 https://static.rust-lang.org/cargo-dist/${CARGO_SNAPSHOT_DATE}/cargo-nightly-i686-unknown-linux-gnu.tar.gz ->
77                 cargo-snapshot-x86-${CARGO_SNAPSHOT_DATE}.tar.gz
78         )
79         amd64? (
80                 https://static.rust-lang.org/cargo-dist/${CARGO_SNAPSHOT_DATE}/cargo-nightly-x86_64-unknown-linux-gnu.tar.gz ->
81                 cargo-snapshot-amd64-${CARGO_SNAPSHOT_DATE}.tar.gz
82         )"
83
84 RESTRICT="mirror"
85 LICENSE="|| ( MIT Apache-2.0 )"
86 SLOT="0"
87 KEYWORDS="~amd64 ~x86"
88
89 IUSE="doc"
90
91 COMMON_DEPEND="sys-libs/zlib
92         dev-libs/openssl:0=
93         net-libs/libssh2
94         net-libs/http-parser"
95 RDEPEND="${COMMON_DEPEND}
96         !dev-util/cargo-bin
97         net-misc/curl[ssl]"
98 DEPEND="${COMMON_DEPEND}
99         >=dev-lang/rust-1.1.0:stable
100         dev-util/cmake
101         sys-apps/coreutils
102         sys-apps/diffutils
103         sys-apps/findutils
104         sys-apps/sed"
105
106 # Until cargo bootstraps itself with a version based on 0.13.0, this needs
107 # to stay (these variables and src_unpack)
108 ECARGO_HOME="${WORKDIR}/cargo_home"
109 ECARGO_REPO="github.com-88ac128001ac3a9a"
110 ECARGO_INDEX="${ECARGO_HOME}/registry/index/${ECARGO_REPO}"
111 ECARGO_SRC="${ECARGO_HOME}/registry/src/${ECARGO_REPO}"
112 ECARGO_CACHE="${ECARGO_HOME}/registry/cache/${ECARGO_REPO}"
113
114 src_unpack() {
115         mkdir -p "${ECARGO_INDEX}" || die
116         mkdir -p "${ECARGO_CACHE}" || die
117         mkdir -p "${ECARGO_SRC}" || die
118         mkdir -p "${S}" || die
119
120         local archive
121         for archive in ${A}; do
122                 case "${archive}" in
123                         *.crate)
124                                 ebegin "Unpacking ${archive}"
125                                 cp "${DISTDIR}"/${archive} "${ECARGO_CACHE}/" || die
126                                 tar -xf "${DISTDIR}"/${archive} -C "${ECARGO_SRC}/" || die
127                                 eend $?
128                                 ;;
129                         cargo-snapshot*)
130                                 ebegin "Unpacking ${archive}"
131                                 mkdir -p "${S}"/target/snapshot
132                                 tar -xzf "${DISTDIR}"/${archive} -C "${S}"/target/snapshot --strip-components 2 || die
133                                 # cargo's makefile needs this otherwise it will try to
134                                 # download it
135                                 touch "${S}"/target/snapshot/bin/cargo || die
136                                 eend $?
137                                 ;;
138                         cargo-registry*)
139                                 ebegin "Unpacking ${archive}"
140                                 tar -xzf "${DISTDIR}"/${archive} -C "${ECARGO_INDEX}" --strip-components 1 || die
141                                 # prevent cargo from attempting to download this again
142                                 touch "${ECARGO_INDEX}"/.cargo-index-lock || die
143                                 eend $?
144                                 ;;
145                         *)
146                                 unpack ${archive}
147                                 ;;
148                 esac
149         done
150 }
151
152 src_configure() {
153         # Cargo only supports these GNU triples:
154         # - Linux: <arch>-unknown-linux-gnu
155         # - MacOS: <arch>-apple-darwin
156         # - Windows: <arch>-pc-windows-gnu
157         # where <arch> could be 'x86_64' (amd64) or 'i686' (x86)
158         use amd64 && CTARGET="x86_64-unknown-linux-gnu"
159         use x86 && CTARGET="i686-unknown-linux-gnu"
160
161         # NOTE: 'disable-nightly' is used by crates (such as 'matches') to entirely
162         # skip their internal libraries that make use of unstable rustc features.
163         # Don't use 'enable-nightly' with a stable release of rustc as DEPEND,
164         # otherwise you could get compilation issues.
165         # see: github.com/gentoo/gentoo-rust/issues/13
166         local myeconfargs=(
167                 --host=${CTARGET}
168                 --build=${CTARGET}
169                 --target=${CTARGET}
170                 --enable-optimize
171                 --disable-nightly
172                 --disable-verify-install
173                 --disable-debug
174                 --disable-cross-tests
175         )
176         econf "${myeconfargs[@]}"
177 }
178
179 src_compile() {
180         # Building sources
181         export CARGO_HOME="${ECARGO_HOME}"
182         emake VERBOSE=1 PKG_CONFIG_PATH=""
183
184         # Building HTML documentation
185         use doc && emake doc
186 }
187
188 src_install() {
189         emake prepare-image-${CTARGET} IMGDIR_${CTARGET}="${ED}/usr"
190
191         # Install HTML documentation
192         use doc && HTML_DOCS=("target/doc")
193         einstalldocs
194
195         dobashcomp "${ED}"/usr/etc/bash_completion.d/cargo
196         rm -rf "${ED}"/usr/etc || die
197 }
198
199 src_test() {
200         # Running unit tests
201         # NOTE: by default 'make test' uses the copy of cargo (v0.0.1-pre-nighyly)
202         # from the installer snapshot instead of the version just built, so the
203         # ebuild needs to override the value of CFG_LOCAL_CARGO to avoid false
204         # positives from unit tests.
205         emake test \
206                 CFG_ENABLE_OPTIMIZE=1 \
207                 VERBOSE=1 \
208                 CFG_LOCAL_CARGO="${WORKDIR}"/${P}/target/${CTARGET}/release/cargo
209 }