Update lang/rust to version 1.39.0
[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.39.0
6 PORTREVISION?=  0
7 CATEGORIES=     lang
8 MASTER_SITES=   https://static.rust-lang.org/dist/:src \
9                 https://static.rust-lang.org/dist/:rust_bootstrap \
10                 LOCAL/tobik/rust:rust_bootstrap \
11                 https://static.rust-lang.org/dist/:cargo_bootstrap \
12                 LOCAL/tobik/rust:cargo_bootstrap \
13                 https://releases.llvm.org/${COMPILER_RT_VERSION}/:compiler_rt \
14                 https://github.com/llvm/llvm-project/releases/download/llvmorg-${COMPILER_RT_VERSION}/:compiler_rt
15 DISTNAME?=      ${PORTNAME}c-${PORTVERSION}-src
16 DISTFILES?=     ${NIGHTLY_SUBDIR}${DISTNAME}${EXTRACT_SUFX}:src \
17                 ${_RUSTC_BOOTSTRAP}${BOOTSTRAPS_SUFFIX}${EXTRACT_SUFX}:rust_bootstrap \
18                 ${_RUST_STD_BOOTSTRAP}${BOOTSTRAPS_SUFFIX}${EXTRACT_SUFX}:rust_bootstrap \
19                 ${_CARGO_BOOTSTRAP}${BOOTSTRAPS_SUFFIX}${EXTRACT_SUFX}:cargo_bootstrap \
20                 ${DISTFILES_${ARCH}}
21 DISTFILES_armv6=        compiler-rt-${COMPILER_RT_VERSION}.src.tar.xz:compiler_rt
22 DISTFILES_armv7=        compiler-rt-${COMPILER_RT_VERSION}.src.tar.xz:compiler_rt
23 DIST_SUBDIR?=   rust
24 EXTRACT_ONLY?=  ${DISTFILES:N*\:*bootstrap:C/:.*//}
25
26 MAINTAINER=     rust@FreeBSD.org
27 COMMENT=        Language with a focus on memory safety and concurrency
28
29 LICENSE=        APACHE20 MIT
30 LICENSE_COMB=   dual
31 LICENSE_FILE_APACHE20=  ${WRKSRC}/LICENSE-APACHE
32 LICENSE_FILE_MIT=       ${WRKSRC}/LICENSE-MIT
33
34 IGNORE_FreeBSD_11_powerpc64=    is missing a bootstrap for FreeBSD 11.x powerpc64
35 ONLY_FOR_ARCHS?=        aarch64 amd64 armv6 armv7 i386 powerpc64
36 ONLY_FOR_ARCHS_REASON=  requires prebuilt bootstrap compiler
37
38 BUILD_DEPENDS=  cmake:devel/cmake
39 LIB_DEPENDS=    libcurl.so:ftp/curl \
40                 libgit2.so:devel/libgit2 \
41                 libssh2.so:security/libssh2
42
43 USES=           pkgconfig python:3.3+,build ssl tar:xz
44
45 CONFLICTS_INSTALL?=     rust-nightly
46
47 PLIST_FILES=    lib/rustlib/components \
48                 lib/rustlib/rust-installer-version
49
50 OPTIONS_DEFINE= DOCS GDB SOURCES
51 GDB_DESC=       Install ports gdb (necessary for debugging rust programs)
52 SOURCES_DESC=   Install source files
53
54 DOCS_VARS_OFF=          _RUST_BUILD_DOCS=false
55 DOCS_VARS=              _RUST_BUILD_DOCS=true
56 GDB_RUN_DEPENDS=        ${LOCALBASE}/bin/gdb:devel/gdb
57
58 # See WRKSRC/src/stage0.txt for the date and version values.
59 BOOTSTRAPS_DATE?=               2019-09-26
60 RUST_BOOTSTRAP_VERSION?=        1.38.0
61 CARGO_BOOTSTRAP_VERSION?=       0.39.0
62 COMPILER_RT_VERSION?=           9.0.0
63
64 BOOTSTRAPS_SUFFIX?=             ${BOOTSTRAPS_SUFFIX_${ARCH}}
65 BOOTSTRAPS_SUFFIX_powerpc64?=   -${PPC_ABI:tl}
66
67 CARGO_VENDOR_DIR?=              ${WRKSRC}/vendor
68
69 # Rust's target arch string might be different from *BSD arch strings
70 _RUST_ARCH_x86_64=      x86_64
71 _RUST_ARCH_i386=        i686
72 _RUST_TARGET=           ${_RUST_ARCH_${ARCH}:U${ARCH}}-unknown-${OPSYS:tl}
73 _LLVM_TARGET=           ${ARCH:C/armv.*/ARM/:S/aarch64/AArch64/:S/powerpc64/PowerPC/}
74
75 _RUSTC_BOOTSTRAP=       ${BOOTSTRAPS_DATE_${ARCH}:U${BOOTSTRAPS_DATE}}/rustc-${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}-${_RUST_TARGET}
76 _RUST_STD_BOOTSTRAP=    ${BOOTSTRAPS_DATE_${ARCH}:U${BOOTSTRAPS_DATE}}/rust-std-${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}-${_RUST_TARGET}
77 _CARGO_BOOTSTRAP=       ${BOOTSTRAPS_DATE_${ARCH}:U${BOOTSTRAPS_DATE}}/cargo-${CARGO_BOOTSTRAP_VERSION_${ARCH}:U${CARGO_BOOTSTRAP_VERSION}}-${_RUST_TARGET}
78
79 .include <bsd.port.pre.mk>
80
81 .if exists(${PATCHDIR}/${ARCH}${BOOTSTRAPS_SUFFIX})
82 EXTRA_PATCHES+= ${PATCHDIR}/${ARCH}${BOOTSTRAPS_SUFFIX}
83 .endif
84
85 .if ${ARCH} == powerpc64 && ${PPC_ABI} == ELFv1
86 # The bootstrap is hardcoded to use gcc9
87 # but we can build with a newer or older compiler as provided by USE_GCC=yes
88 BUILD_DEPENDS+= gcc9:lang/gcc9
89 USE_GCC=        yes
90 .endif
91
92 .if ${ARCH} == aarch64 && ${OSVERSION} < 1200502
93 IGNORE= fails to run due to a bug in rtld, update to 12-STABLE r342847 or 13-CURRENT r342113
94 .endif
95
96 .ifdef QEMU_EMULATING
97 IGNORE= fails to build with qemu-user-static
98 .endif
99
100 X_PY_ENV+=      HOME="${WRKDIR}" \
101                 LIBGIT2_SYS_USE_PKG_CONFIG=1 \
102                 LIBSSH2_SYS_USE_PKG_CONFIG=1 \
103                 OPENSSL_DIR="${OPENSSLBASE}"
104 X_PY_CMD=       ${PYTHON_CMD} ${WRKSRC}/x.py
105
106 post-extract:
107         @${MKDIR} ${WRKSRC}/build/cache/${BOOTSTRAPS_DATE_${ARCH}:U${BOOTSTRAPS_DATE}}
108         ${LN} -sf ${DISTDIR}/${DIST_SUBDIR}/${_RUSTC_BOOTSTRAP}${BOOTSTRAPS_SUFFIX}${EXTRACT_SUFX} \
109                 ${WRKSRC}/build/cache/${_RUSTC_BOOTSTRAP}${EXTRACT_SUFX}
110         ${LN} -sf ${DISTDIR}/${DIST_SUBDIR}/${_RUST_STD_BOOTSTRAP}${BOOTSTRAPS_SUFFIX}${EXTRACT_SUFX} \
111                 ${WRKSRC}/build/cache/${_RUST_STD_BOOTSTRAP}${EXTRACT_SUFX}
112         ${LN} -sf ${DISTDIR}/${DIST_SUBDIR}/${_CARGO_BOOTSTRAP}${BOOTSTRAPS_SUFFIX}${EXTRACT_SUFX} \
113                 ${WRKSRC}/build/cache/${_CARGO_BOOTSTRAP}${EXTRACT_SUFX}
114 .if ${ARCH} == armv6 || ${ARCH} == armv7
115         ${LN} -sf ${WRKDIR}/compiler-rt-${COMPILER_RT_VERSION}.src ${WRKSRC}/src/llvm-project/compiler-rt
116 .endif
117
118 post-patch:
119         @${REINPLACE_CMD} 's,gdb,${LOCALBASE}/bin/gdb,' ${WRKSRC}/src/etc/rust-gdb
120         @${ECHO_MSG} "Canonical bootstrap date and version before patching:"
121         @${GREP} -E '^(date|rustc|cargo)' ${WRKSRC}/src/stage0.txt
122 # If we override the versions and date of the bootstraps (for instance
123 # on aarch64 where we provide our own bootstraps), we need to update
124 # places where they are recorded.
125         @${REINPLACE_CMD} -e 's,^date:.*,date: ${BOOTSTRAPS_DATE_${ARCH}:U${BOOTSTRAPS_DATE}},' \
126                 -e 's,^rustc:.*,rustc: ${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}},' \
127                 -e 's,^cargo:.*,cargo: ${CARGO_BOOTSTRAP_VERSION_${ARCH}:U${CARGO_BOOTSTRAP_VERSION}},' \
128                 ${WRKSRC}/src/stage0.txt
129         @${ECHO_MSG} "Bootstrap date and version after patching:"
130         @${GREP} -E '^(date|rustc|cargo)' ${WRKSRC}/src/stage0.txt
131 .if ${ARCH} == powerpc64
132         @${REINPLACE_CMD} -e 's,powerpc64-unknown-freebsd,powerpc64-unknown-freebsd${OSREL},' \
133                 ${WRKSRC}/src/librustc_target/spec/powerpc64_unknown_freebsd.rs
134 .endif
135 # Disable vendor checksums
136         @${REINPLACE_CMD} 's,"files":{[^}]*},"files":{},' \
137                 ${CARGO_VENDOR_DIR}/*/.cargo-checksum.json
138
139 post-patch-SOURCES-off:
140 # Mimic tools in config.toml with just src excluded
141         @${REINPLACE_CMD} -e 's/config.tools.*"src".*/false;/' \
142                 ${WRKSRC}/src/bootstrap/install.rs
143
144 .if defined(WITH_CCACHE_BUILD) && !defined(NO_CCACHE)
145 CCACHE_VALUE=   "${CCACHE_BIN}"
146 .else
147 CCACHE_VALUE=   false
148 .endif
149
150 do-configure:
151         ${SED} -E \
152                 -e 's,%PREFIX%,${PREFIX},' \
153                 -e 's,%SYSCONFDIR%,${PREFIX}/etc,' \
154                 -e 's,%MANDIR%,${MANPREFIX}/man,' \
155                 -e 's,%PYTHON_CMD%,${PYTHON_CMD},' \
156                 -e 's,%CHANNEL%,${PKGNAMESUFFIX:Ustable:S/^-//},' \
157                 -e 's,%TARGET%,${_RUST_TARGET},' \
158                 -e 's,%CCACHE%,${CCACHE_VALUE},' \
159                 -e 's,%CC%,${CC},' \
160                 -e 's,%CXX%,${CXX},' \
161                 -e 's,%DOCS%,${_RUST_BUILD_DOCS},' \
162                 < ${FILESDIR}/config.toml \
163                 > ${WRKSRC}/config.toml
164 # no need to build a crosscompiler for these targets
165 .if ${ARCH} == aarch64 || ${ARCH} == armv6 || ${ARCH} == armv7 || ${ARCH} == powerpc64
166         @${REINPLACE_CMD} -e 's,^#targets =.*,targets = "${_LLVM_TARGET}",' \
167                 -e 's,^#experimental-targets =.*,experimental-targets = "",' \
168                 ${WRKSRC}/config.toml
169 .endif
170         @${REINPLACE_CMD} -e 's,%CC%,${CC},g' \
171                 ${WRKSRC}/src/librustc_llvm/build.rs \
172                 ${WRKSRC}/src/bootstrap/native.rs
173
174 do-build:
175         cd ${WRKSRC} && \
176         ${SETENV} ${X_PY_ENV} \
177         ${X_PY_CMD} build \
178                 --verbose \
179                 --config ./config.toml \
180                 --jobs ${MAKE_JOBS_NUMBER}
181
182 do-install:
183         cd ${WRKSRC} && \
184         ${SETENV} ${X_PY_ENV} \
185                 DESTDIR=${STAGEDIR} \
186         ${X_PY_CMD} 'install' \
187                 --verbose \
188                 --config ./config.toml \
189                 --jobs ${MAKE_JOBS_NUMBER}
190
191 # In post-install, we use the manifests generated during Rust install
192 # to in turn generate the PLIST. We do that, instead of the regular
193 # `pkg-plist`, because several libraries have a computed filename based
194 # on the absolute path of the source files. As it is user-specific, we
195 # can't know their filename in advance.
196 #
197 # Both rustc and Cargo components install the same README.md and LICENSE
198 # files. The install process backs up the first copy to install the
199 # second. Thus here, we need to remove those backups. We also need to
200 # dedup the entries in the generated PLIST, because both components'
201 # manifests list them.
202 #
203 # We fix manpage entries in the generated manifests because Rust
204 # installs them uncompressed but the Ports framework compresses them.
205 post-install:
206         for f in ${STAGEDIR}${PREFIX}/lib/rustlib/manifest-*; do \
207             ${REINPLACE_CMD} -i '' -E \
208                 -e 's|:${STAGEDIR}|:|' \
209                 -e 's|(man/man[1-9]/.*\.[0-9])|\1.gz|' \
210                 "$$f"; \
211             ${ECHO_CMD} "$${f#${STAGEDIR}}" >> ${TMPPLIST}; \
212             ${AWK} '\
213                 /^file:/ { \
214                     file=$$0; \
215                     sub(/^file:/, "", file); \
216                     print file; \
217                 } \
218                 /^dir:/ { \
219                     dir=$$0; \
220                     sub(/^dir:/, "", dir); \
221                     system("find ${STAGEDIR}" dir " -type f | ${SED} -E -e \"s|${STAGEDIR}||\""); \
222                 }' \
223                 "$$f" >> ${TMPPLIST}; \
224         done
225         ${RM} -r ${STAGEDIR}${PREFIX}/share/doc/rust/*.old
226         ${SORT} -u < ${TMPPLIST} > ${TMPPLIST}.uniq
227         ${MV} ${TMPPLIST}.uniq ${TMPPLIST}
228         @${RM} \
229             ${STAGEDIR}${PREFIX}/lib/rustlib/install.log \
230             ${STAGEDIR}${PREFIX}/lib/rustlib/uninstall.sh
231 # FIXME: Static libraries in lib/rustlib/*/lib/*.rlib are not stripped,
232 # but they contain non-object files which make strip(1) unhappy.
233         @${FIND} ${STAGEDIR}${PREFIX}/bin -exec ${FILE} -i {} + | ${AWK} -F: \
234                 '/executable|sharedlib/ { print $$1 }' | ${XARGS} ${STRIP_CMD}
235
236 # Note that make test does not work when rust is already installed.
237 do-test:
238         cd ${WRKSRC} && \
239         ${SETENV} ${X_PY_ENV} \
240                 ALLOW_NONZERO_RLIMIT_CORE=1 \
241         ${X_PY_CMD} test \
242                 --verbose \
243                 --config ./config.toml \
244                 --jobs ${MAKE_JOBS_NUMBER}
245
246 .if !defined(_RUST_MAKESUM_GUARD)
247 makesum:
248         ${MAKE} -D_RUST_MAKESUM_GUARD makesum ARCH=${ONLY_FOR_ARCHS:O:[1]} DISTINFO_FILE=${DISTINFO_FILE}.tmp
249 .for arch in ${ONLY_FOR_ARCHS:O:[2..-1]}
250         ${MAKE} -D_RUST_MAKESUM_GUARD makesum PPC_ABI=ELFv1 ARCH=${arch} DISTINFO_FILE=${DISTINFO_FILE}.${arch}
251         ${GREP} ${_RUST_ARCH_${arch}:U${arch}} ${DISTINFO_FILE}.${arch} >> ${DISTINFO_FILE}.tmp
252 .for file in ${DISTFILES_${arch}}
253         ${GREP} ${file:S,:, ,:[1]} ${DISTINFO_FILE}.${arch} >> ${DISTINFO_FILE}.tmp
254 .endfor
255         ${RM} ${DISTINFO_FILE}.${arch}
256 .endfor
257 .if ${ONLY_FOR_ARCHS:Mpowerpc64}
258         ${MAKE} -D_RUST_MAKESUM_GUARD makesum PPC_ABI=ELFv2 ARCH=powerpc64 DISTINFO_FILE=${DISTINFO_FILE}.powerpc64-elfv2
259         ${GREP} ${_RUST_ARCH_powerpc64:Upowerpc64} ${DISTINFO_FILE}.powerpc64-elfv2 >> ${DISTINFO_FILE}.tmp
260         ${RM} ${DISTINFO_FILE}.powerpc64-elfv2
261 .endif
262         ${AWK} '!seen[$$0]++' ${DISTINFO_FILE}.tmp > ${DISTINFO_FILE}
263         ${RM} ${DISTINFO_FILE}.tmp
264 .endif
265
266 .include <bsd.port.post.mk>