manually revert recent rust+cargo changes
[dports.git] / lang / rust / Makefile
1 # Created by: Jyun-Yan You <jyyou@cs.nctu.edu.tw>
2 # $FreeBSD$
3
4 PORTNAME=       rust
5 PORTVERSION?=   1.18.0
6 CATEGORIES=     lang
7 MASTER_SITES=   http://static.rust-lang.org/dist/:src \
8                 https://static.rust-lang.org/dist/:rust_bootstrap \
9                 LOCAL/dumbbell/rust:rust_bootstrap \
10                 https://static.rust-lang.org/dist/:cargo_bootstrap \
11                 https://s3.amazonaws.com/rust-lang-ci/cargo-builds/:cargo_bootstrap \
12                 LOCAL/dumbbell/rust:cargo_bootstrap \
13                 LOCAL/marino:bootstrap
14 DISTNAME?=      ${PORTNAME}c-${PORTVERSION}-src
15 BOOTSTRAP_FILES=${RUSTC_BOOTSTRAP}:rust_bootstrap \
16                 ${RUST_STD_BOOTSTRAP}:rust_bootstrap \
17                 ${CARGO_BOOTSTRAP}:cargo_bootstrap
18 DISTFILES?=     ${DISTNAME}${EXTRACT_SUFX}:src \
19                 ${BOOTSTRAP_FILES}
20 .if !defined(SKIP_CARGO_REGISTRY)
21 MASTER_SITES+=  LOCAL/riggs/rust:registry \
22                 LOCAL/dumbbell/rust:registry
23 DISTFILES+=     ${CARGO_REGISTRY}:registry
24 .endif
25 DIST_SUBDIR?=   rust
26 EXTRACT_ONLY?=  ${DISTFILES:N*\:*bootstrap:C/:.*//}
27
28 MAINTAINER?=    rust@FreeBSD.org
29 COMMENT=        Language with a focus on memory safety and concurrency
30
31 LICENSE=        APACHE20 \
32                 MIT
33 LICENSE_COMB=   dual
34 # APACHE20 license is standard, see Templates/Licenses/APACHE20
35 LICENSE_FILE_MIT=       ${WRKSRC}/LICENSE-MIT
36
37 BUILD_DEPENDS=          cmake:devel/cmake
38
39 ONLY_FOR_ARCHS?=        aarch64 amd64 i386
40 ONLY_FOR_ARCHS_REASON=  requires prebuilt bootstrap compiler
41
42 # FIXME: The bootstrapped rustc adds -L/usr/local/lib in front of
43 # the LDFLAGS. When stage0's rustc is linked, it picks the installed
44 # librust*so and fails.
45 CONFLICTS_BUILD?=       rust-nightly
46 CONFLICTS_BUILD+=       ${PKGBASE}
47 CONFLICTS_INSTALL?=     rust-nightly
48
49 RUST_BOOTSTRAP_DIR?=            2017-04-27
50 RUST_BOOTSTRAP_DIR_aarch64?=    2017-04-24
51 RUST_BOOTSTRAP_VERSION?=        1.17.0
52 RUST_BOOTSTRAP_VERSION_aarch64?=1.17.0
53 RUSTC_BOOTSTRAP=                ${RUST_BOOTSTRAP_DIR_${ARCH}:U${RUST_BOOTSTRAP_DIR}}/rustc-${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}-${RUST_TARGET}.tar.gz
54 RUST_STD_BOOTSTRAP=             ${RUST_BOOTSTRAP_DIR_${ARCH}:U${RUST_BOOTSTRAP_DIR}}/rust-std-${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}-${RUST_TARGET}.tar.gz
55
56 CARGO_BOOTSTRAP_DIR?=           ${RUST_BOOTSTRAP_DIR}
57 CARGO_BOOTSTRAP_DIR_aarch64?=   ${RUST_BOOTSTRAP_DIR_aarch64}
58 CARGO_BOOTSTRAP_VERSION?=       0.18.0
59 CARGO_BOOTSTRAP_VERSION_aarch64?=0.18.0
60 CARGO_BOOTSTRAP=                ${CARGO_BOOTSTRAP_DIR_${ARCH}:U${CARGO_BOOTSTRAP_DIR}}/cargo-${CARGO_BOOTSTRAP_VERSION_${ARCH}:U${CARGO_BOOTSTRAP_VERSION}}-${RUST_TARGET}${EXTRACT_SUFX}
61 CARGO_REGISTRY=                 ${PORTNAME}-registry-${DISTVERSIONFULL}.tar.xz
62
63 RUST_CHANNEL=   ${PKGNAMESUFFIX:Ustable:S/^-//}
64
65 # Rust's target arch string is different from *BSD arch strings
66 RUST_ARCH_aarch64=      aarch64
67 RUST_ARCH_amd64=        x86_64
68 RUST_ARCH_i386=         i686
69 RUST_ARCH_x86_64=       x86_64 # dragonfly
70 RUST_TARGET=            ${RUST_ARCH_${ARCH}}-unknown-${OPSYS:tl}
71 PLIST_SUB+=             RUST_TARGET=${RUST_TARGET}
72
73 USES=           compiler gmake libedit python:2.7,build
74 HAS_CONFIGURE=  yes
75 CONFIGURE_ARGS= --disable-valgrind \
76                 ${CHOSEN_COMPILER_TYPE:Mclang:C/.+/--enable-&/} \
77                 --prefix=${PREFIX}      \
78                 --musl-root=${PREFIX}   \
79                 --local-rust-root=${PREFIX} \
80                 --mandir=${MANPREFIX}/man \
81                 --release-channel=${RUST_CHANNEL} \
82                 --python="${PYTHON_CMD}"
83
84 MAKE_ARGS+=     VERBOSE=1
85
86 OPTIONS_DEFINE=         DOCS GDB LLNEXTGEN PORT_LLVM
87 GDB_DESC=               Install ports gdb (necessary for debugging rust programs)
88 LLNEXTGEN_DESC=         Build with grammar verification
89
90 DOCS_CONFIGURE_ENABLE=  docs
91 GDB_RUN_DEPENDS=                ${LOCALBASE}/bin/gdb:devel/gdb
92 LLNEXTGEN_BUILD_DEPENDS=        LLnextgen:devel/llnextgen
93
94 # Rust may pass more regression tests with bundled LLVM
95 PORT_LLVM_DESC= Build against devel/llvm${LLVM_VER} instead of bundled version
96 PORT_LLVM_BUILD_DEPENDS=        ${LLVM_PREFIX}/bin/FileCheck:devel/llvm${LLVM_VER}
97 PORT_LLVM_CONFIGURE_ON=         --llvm-root=${LLVM_PREFIX}
98 LLVM_VER?=                      40
99 LLVM_PREFIX=                    ${LOCALBASE}/llvm${LLVM_VER}
100
101 # Note that make test does not work when rust is already installed
102 TEST_TARGET=    check
103 TEST_ENV+=      ALLOW_NONZERO_RLIMIT_CORE=1
104
105 # Rust manifests list all files and directories installed by rust-installer.
106 # We use them in:
107 #     - pre-install to cleanup the ${STAGEDIR}
108 #     - post-install to populate the ${TMPPLIST}
109 RUST_MANIFESTS=         lib/rustlib/manifest-rustc \
110                         lib/rustlib/manifest-rust-std-${RUST_TARGET}
111 RUST_DOCS_MANIFESTS=    lib/rustlib/manifest-rust-docs
112 DOCS_VARS=              rust_manifests+=${RUST_DOCS_MANIFESTS}
113
114 PLIST_FILES=            lib/rustlib/components \
115                         lib/rustlib/rust-installer-version
116
117 .include <bsd.port.pre.mk>
118 .if ${OPSYS} == FreeBSD && ${OSVERSION} >= 1200031
119 EXTRA_PATCHES+=        ${PATCHDIR}/extra-patch-ino64
120 .endif
121
122 pre-fetch:
123         # FIXME: This is the same check for CONFLICTS as the standard
124         # one, except port origins are not compared. This allows
125         # the port to conflict with itself, because Rust would pick
126         # installed Rust libraries instead of freshly built ones.
127         @conflicts_with=$$( \
128         { ${PKG_QUERY} -g "%n-%v %p %o" ${CONFLICTS:C/.+/'&'/} ${CONFLICTS_BUILD:C/.+/'&'/} 2>/dev/null || : ; } \
129                 | while read pkgname prfx orgn; do \
130                 if [ "/${PREFIX}" = "/$${prfx}" ]; then \
131                         ${ECHO_CMD} -n " $${pkgname}"; \
132                 fi; \
133         done); \
134         if [ -n "$${conflicts_with}" ]; then \
135                 ${ECHO_MSG}; \
136                 ${ECHO_MSG} "===>  ${PKGNAME} conflicts with installed package(s): "; \
137                 for entry in $${conflicts_with}; do \
138                         ${ECHO_MSG} "      $${entry}"; \
139                 done; \
140                 ${ECHO_MSG}; \
141                 ${ECHO_MSG} "      They will not build together."; \
142                 ${ECHO_MSG} "      Please remove them first with pkg delete."; \
143                 exit 1;\
144         fi
145
146 RUST_STD_DIR=           ${RUST_STD_BOOTSTRAP:T:R:R}
147 LIBSTD_SUFFIX=          f4594d3e53dcb114
148 LIBSTD_SUFFIX_aarch64=  b41e0ffe8c1bd541
149 LIBSTD=                 ${RUST_STD_DIR}/rust-std-${RUST_TARGET}/lib/rustlib/${RUST_TARGET}/lib/libstd-${LIBSTD_SUFFIX_${ARCH}:U${LIBSTD_SUFFIX}}.rlib
150 STDF=                   ${LIBSTD:T:R:S/lib//}.0.o
151
152 post-extract:
153         @${MKDIR} \
154                 ${WRKSRC}/build/cache/${RUST_BOOTSTRAP_DIR_${ARCH}:U${RUST_BOOTSTRAP_DIR}} \
155                 ${WRKSRC}/build/cache/${CARGO_BOOTSTRAP_DIR_${ARCH}:U${CARGO_BOOTSTRAP_DIR}}
156         ${LN} -sf ${DISTDIR}/${DIST_SUBDIR}/${RUSTC_BOOTSTRAP} \
157                 ${WRKSRC}/build/cache/${RUST_BOOTSTRAP_DIR_${ARCH}:U${RUST_BOOTSTRAP_DIR}}
158 .if ${OPSYS} != FreeBSD || ${OSVERSION} < 1200031
159         ${LN} -sf ${DISTDIR}/${DIST_SUBDIR}/${RUST_STD_BOOTSTRAP} \
160                 ${WRKSRC}/build/cache/${RUST_BOOTSTRAP_DIR_${ARCH}:U${RUST_BOOTSTRAP_DIR}}
161 .endif
162         ${LN} -sf ${DISTDIR}/${DIST_SUBDIR}/${CARGO_BOOTSTRAP} \
163                 ${WRKSRC}/build/cache/${CARGO_BOOTSTRAP_DIR_${ARCH}:U${CARGO_BOOTSTRAP_DIR}}
164 .if ${OPSYS} == FreeBSD && ${OSVERSION} >= 1200031
165         ${TAR} -x -C ${WRKSRC} -f ${DISTDIR}/${DIST_SUBDIR}/${RUST_STD_BOOTSTRAP}
166         ${CC} ${CFLAGS} -fPIC -c -o ${WRKSRC}/old_fstat.o ${FILESDIR}/old_fstat.c
167         (cd ${WRKSRC} && ${AR} x ${WRKSRC}/${LIBSTD} ${STDF})
168         ${LD} -r -o ${WRKSRC}/std.xx.o ${WRKSRC}/${STDF} ${WRKSRC}/old_fstat.o
169         ${MV} ${WRKSRC}/std.xx.o ${WRKSRC}/${STDF}
170         (cd ${WRKSRC} && ${AR} r ${WRKSRC}/${LIBSTD} ${STDF})
171         ${TAR} -cy --format=ustar -C ${WRKSRC} -f ${WRKSRC}/rustc.tbz ${RUST_STD_DIR}
172         ${MV} ${WRKSRC}/rustc.tbz ${WRKSRC}/build/cache/${RUST_STD_BOOTSTRAP}
173 .endif
174
175 post-patch:
176         @test ! -f ${WRKSRC}/mk/main.mk || \
177         ${REINPLACE_CMD} -e 's|%%LOCALBASE%%|${LOCALBASE}|' \
178                 ${WRKSRC}/mk/main.mk
179         @${REINPLACE_CMD} -e 's|gdb|${LOCALBASE}/bin/gdb|' \
180                 ${WRKSRC}/src/etc/rust-gdb
181         @if test "${RUST_BOOTSTRAP_DIR_${ARCH}}" -o "${RUST_BOOTSTRAP_VERSION_${ARCH}}"; then \
182                 ${REINPLACE_CMD} -e \
183                 's|^rustc:.*|rustc: ${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}-${RUST_BOOTSTRAP_DIR_${ARCH}:U${RUST_BOOTSTRAP_DIR}}|' \
184                 ${WRKSRC}/src/stage0.txt; \
185         fi
186         @if test "${CARGO_BOOTSTRAP_DIR_${ARCH}}"; then \
187                 ${REINPLACE_CMD} -e \
188                 's|^cargo:.*|cargo: ${RUST_BOOTSTRAP_DIR_${ARCH}:U${RUST_BOOTSTRAP_DIR}}|' \
189                 ${WRKSRC}/src/stage0.txt; \
190         fi
191         @if test "${CARGO_BOOTSTRAP_VERSION_${ARCH}}"; then \
192                 ${REINPLACE_CMD} -e \
193                 's|cargo-nightly-|cargo-${CARGO_BOOTSTRAP_VERSION_${ARCH}:U${CARGO_BOOTSTRAP_VERSION}}-|' \
194                 ${WRKSRC}/src/bootstrap/bootstrap.py; \
195         fi
196
197 # In case the previous "make stage" failed, this ensures rust's
198 # install.sh won't backup previously staged files before reinstalling
199 # new ones. Otherwise, the staging directory is polluted with unneeded
200 # files.
201 pre-install:
202         @for f in ${RUST_MANIFESTS} ${RUST_DOCS_MANIFESTS}; do \
203             if test -f "${STAGEDIR}${PREFIX}/$$f"; then \
204                 ${SED} -E -e 's,^(file|dir):,${STAGEDIR},' \
205                     < "${STAGEDIR}${PREFIX}/$$f" \
206                     | ${XARGS} ${RM} -r; \
207                 ${RM} "${STAGEDIR}${PREFIX}/$$f"; \
208             fi; \
209         done
210         @for f in ${PLIST_FILES}; do \
211             ${RM} "${STAGEDIR}${PREFIX}/$$f"; \
212         done
213
214 # In post-install, we use the manifests generated during Rust install
215 # to in turn generate the PLIST. We do that, instead of the regular
216 # `pkg-plist`, because several libraries have a computed filename based
217 # on the absolute path of the source files. As it is user-specific, we
218 # can't know their filename in advance.
219 #
220 # We fix manpage entries in the generated manifests because Rust
221 # installs them uncompressed but the Ports framework compresses them.
222 post-install:
223         for f in ${RUST_MANIFESTS}; do \
224             ${REINPLACE_CMD} -E \
225                 -e 's|:${STAGEDIR}|:|' \
226                 -e 's|(man/man[1-9]/.*\.[0-9])|\1.gz|' \
227                 ${STAGEDIR}${PREFIX}/$$f; \
228             ${RM} ${STAGEDIR}${PREFIX}/$$f.bak; \
229             ${ECHO} "${PREFIX}/$$f" >> ${TMPPLIST}; \
230             ${AWK} '\
231                 /^file:/ { \
232                     file=$$0; \
233                     sub(/^file:/, "", file); \
234                     print file; \
235                 } \
236                 /^dir:/ { \
237                     dir=$$0; \
238                     sub(/^dir:/, "", dir); \
239                     system("find ${STAGEDIR}" dir " -type f | ${SED} -E -e \"s|${STAGEDIR}||\""); \
240                 }' \
241                 ${STAGEDIR}${PREFIX}/$$f >> ${TMPPLIST}; \
242         done
243         @${RM} \
244             ${STAGEDIR}${PREFIX}/lib/rustlib/install.log \
245             ${STAGEDIR}${PREFIX}/lib/rustlib/uninstall.sh
246 # FIXME: Static libraries in lib/rustlib/*/lib/*.rlib are not stripped,
247 # but they contain non-object files which make strip(1) unhappy.
248         @${STRIP_CMD} \
249                 ${STAGEDIR}${PREFIX}/bin/rustc \
250                 ${STAGEDIR}${PREFIX}/bin/rustdoc \
251                 ${STAGEDIR}${PREFIX}/lib/*.so \
252                 ${STAGEDIR}${PREFIX}/lib/rustlib/*/lib/*.so
253
254 .include <bsd.port.post.mk>
255
256 # "make gen-registry" is a special target to ease this port update.
257 #
258 # After changing the version number and the Git revision, you can run
259 # "make gen-registry" to update the distinfo and create a new snapshot of
260 # the registry. The new registry is written to ${DISTDIR} and can be
261 # uploaded.
262
263 gen-registry:
264         ${MAKE} -C${.CURDIR} -DSKIP_CARGO_REGISTRY makesum
265         ${MAKE} -C${.CURDIR} -DSKIP_CARGO_REGISTRY
266         ${TAR} cJvf ${DISTDIR}/${DIST_SUBDIR}/${CARGO_REGISTRY} -C${WRKDIR} \
267                 --uid 0 --gid 0 \
268                 --exclude 'src/*/benches/' \
269                 --exclude 'src/*/ci/' \
270                 --exclude 'src/*/examples/' \
271                 --exclude 'src/*/tests/' \
272                 --exclude 'index/github.com-*/.git/' \
273                 .cargo
274         ${MAKE} -C${.CURDIR} makesum