Tweak lang/rust version 1.43.1
[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.43.1
6 PORTREVISION?=  0
7 CATEGORIES=     lang
8 MASTER_SITES=   https://static.rust-lang.org/dist/:src \
9                 LOCAL/tobik/rust:bootstrap \
10                 https://static.rust-lang.org/dist/:bootstrap
11 DISTNAME?=      ${PORTNAME}c-${PORTVERSION}-src
12 DISTFILES?=     ${NIGHTLY_DATE:D${NIGHTLY_DATE}/}${DISTNAME}${EXTRACT_SUFX}:src \
13                 ${_RUSTC_BOOTSTRAP}${BOOTSTRAPS_SUFFIX}${EXTRACT_SUFX}:bootstrap \
14                 ${_RUST_STD_BOOTSTRAP}${BOOTSTRAPS_SUFFIX}${EXTRACT_SUFX}:bootstrap \
15                 ${_CARGO_BOOTSTRAP}${BOOTSTRAPS_SUFFIX}${EXTRACT_SUFX}:bootstrap
16 DIST_SUBDIR?=   rust
17
18 MAINTAINER=     rust@FreeBSD.org
19 COMMENT=        Language with a focus on memory safety and concurrency
20
21 LICENSE=        APACHE20 MIT
22 LICENSE_COMB=   dual
23 LICENSE_FILE_APACHE20=  ${WRKSRC}/LICENSE-APACHE
24 LICENSE_FILE_MIT=       ${WRKSRC}/LICENSE-MIT
25
26 IGNORE_FreeBSD_11_powerpc64=    is missing a bootstrap for FreeBSD 11.x powerpc64
27 ONLY_FOR_ARCHS?=        aarch64 amd64 armv6 armv7 i386 powerpc64
28 ONLY_FOR_ARCHS_REASON?= requires prebuilt bootstrap compiler
29
30 BUILD_DEPENDS=  cmake:devel/cmake \
31                 libgit2>=1.0.0:devel/libgit2
32 LIB_DEPENDS=    libcurl.so:ftp/curl \
33                 libgit2.so:devel/libgit2 \
34                 libssh2.so:security/libssh2
35
36 USES=           pkgconfig python:3.3+,build ssl tar:xz
37
38 MAKE_ENV=       LIBGIT2_SYS_USE_PKG_CONFIG=1 \
39                 LIBSSH2_SYS_USE_PKG_CONFIG=1 \
40                 OPENSSL_DIR="${OPENSSLBASE}" \
41                 RUST_BACKTRACE=1
42 TEST_ENV=       ${MAKE_ENV} \
43                 ALLOW_NONZERO_RLIMIT_CORE=1
44
45 CONFLICTS_INSTALL?=     rust-nightly
46
47 OPTIONS_DEFINE=         DOCS GDB SOURCES WASM
48 OPTIONS_DEFAULT=        SOURCES WASM
49
50 GDB_DESC=       Install ports gdb (necessary for debugging rust programs)
51 SOURCES_DESC=   Install source files
52 WASM_DESC=      Build the WebAssembly target (wasm32-unknown-unknown)
53
54 DOCS_VARS=              _RUST_BUILD_DOCS=true
55 DOCS_VARS_OFF=          _RUST_BUILD_DOCS=false
56 GDB_RUN_DEPENDS=        ${LOCALBASE}/bin/gdb:devel/gdb
57 WASM_VARS=              _RUST_BUILD_WASM=true \
58                         _RUST_TARGETS+=wasm32-unknown-unknown
59 WASM_VARS_OFF=          _RUST_BUILD_WASM=false
60
61 # See WRKSRC/src/stage0.txt for the date and version values.
62 BOOTSTRAPS_DATE?=               2020-03-12
63 RUST_BOOTSTRAP_VERSION?=        1.42.0
64 CARGO_BOOTSTRAP_VERSION?=       0.43.0
65
66 BOOTSTRAPS_SUFFIX?=             ${BOOTSTRAPS_SUFFIX_${ARCH}}
67 BOOTSTRAPS_SUFFIX_powerpc64?=   -${PPC_ABI:tl}
68
69 CARGO_VENDOR_DIR?=              ${WRKSRC}/vendor
70
71 # Rust's target arch string might be different from *BSD arch strings
72 _RUST_ARCH_x86_64=      x86_64
73 _RUST_ARCH_i386=        i686
74 _RUST_TARGET=           ${_RUST_ARCH_${ARCH}:U${ARCH}}-unknown-${OPSYS:tl}
75 _RUST_TARGETS=          ${_RUST_TARGET}
76
77 _RUSTC_BOOTSTRAP=       ${BOOTSTRAPS_DATE_${ARCH}:U${BOOTSTRAPS_DATE}}/rustc-${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}-${_RUST_TARGET}
78 _RUST_STD_BOOTSTRAP=    ${BOOTSTRAPS_DATE_${ARCH}:U${BOOTSTRAPS_DATE}}/rust-std-${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}-${_RUST_TARGET}
79 _CARGO_BOOTSTRAP=       ${BOOTSTRAPS_DATE_${ARCH}:U${BOOTSTRAPS_DATE}}/cargo-${CARGO_BOOTSTRAP_VERSION_${ARCH}:U${CARGO_BOOTSTRAP_VERSION}}-${_RUST_TARGET}
80
81 .include <bsd.port.pre.mk>
82
83 .if exists(${PATCHDIR}/${ARCH}${BOOTSTRAPS_SUFFIX})
84 EXTRA_PATCHES+= ${PATCHDIR}/${ARCH}${BOOTSTRAPS_SUFFIX}
85 .endif
86
87 .if ${ARCH} == powerpc64
88 # The bootstrap is hardcoded to use gcc9
89 # but we can build with a newer or older compiler as provided by USE_GCC=yes
90 BUILD_DEPENDS+= gcc9:lang/gcc9
91 USE_GCC=        yes
92 .endif
93
94 .if ${ARCH} == aarch64 && ${OSVERSION} < 1200502
95 IGNORE= fails to run due to a bug in rtld, update to 12-STABLE r342847 or 13-CURRENT r342113
96 .endif
97
98 .ifdef QEMU_EMULATING
99 IGNORE= fails to build with qemu-user-static
100 .endif
101
102 post-patch:
103         @${REINPLACE_CMD} 's,gdb,${LOCALBASE}/bin/gdb,' ${WRKSRC}/src/etc/rust-gdb
104 .if defined(NIGHTLY_DATE)
105         @${REINPLACE_CMD} '/^rustfmt:/d' ${WRKSRC}/src/stage0.txt
106 .endif
107 .if ${ARCH} == powerpc64
108 # Starting with 13.0 powerpc64 is ELFv2 while 12.0 is ELFv1.  Pass the correct LLVM target triple.
109         @${REINPLACE_CMD} 's,powerpc64-unknown-freebsd,powerpc64-unknown-freebsd${OSREL},' \
110                 ${WRKSRC}/src/librustc_target/spec/powerpc64_unknown_freebsd.rs
111 .endif
112 # Disable vendor checksums
113         @${REINPLACE_CMD} 's,"files":{[^}]*},"files":{},' \
114                 ${CARGO_VENDOR_DIR}/*/.cargo-checksum.json
115
116 post-patch-SOURCES-off:
117 # Mimic tools in config.toml with just src excluded
118         @${REINPLACE_CMD} 's,config.tools.*"src".*,false;,' \
119                 ${WRKSRC}/src/bootstrap/install.rs
120
121 do-configure:
122 # Check that the running kernel has COMPAT_FREEBSD11 required by lang/rust post-ino64
123         @${SETENV} CC="${CC}" OPSYS="${OPSYS}" OSVERSION="${OSVERSION}" WRKDIR="${WRKDIR}" \
124                 ${SH} ${SCRIPTSDIR}/rust-compat11-canary.sh
125 .for _component in cargo rust-std rustc
126         @cd ${WRKDIR}/${_component}-*-${OPSYS:tl} && \
127                 ${SH} install.sh --disable-ldconfig --prefix=${WRKDIR}/bootstrap \
128                 --verbose
129 .endfor
130         @${ECHO_CMD} '[build]' > ${WRKSRC}/config.toml
131         @${ECHO_CMD} 'vendor=true' >> ${WRKSRC}/config.toml
132         @${ECHO_CMD} 'extended=true' >> ${WRKSRC}/config.toml
133         @${ECHO_CMD} 'python="${PYTHON_CMD}"' >> ${WRKSRC}/config.toml
134         @${ECHO_CMD} 'docs=${_RUST_BUILD_DOCS}' >> ${WRKSRC}/config.toml
135         @${ECHO_CMD} 'verbose=2' >> ${WRKSRC}/config.toml
136         @${ECHO_CMD} 'target=[${_RUST_TARGETS:@.target.@"${.target.}"@:ts,}]' >> ${WRKSRC}/config.toml
137         @${ECHO_CMD} 'cargo="${WRKDIR}/bootstrap/bin/cargo"' >> ${WRKSRC}/config.toml
138         @${ECHO_CMD} 'rustc="${WRKDIR}/bootstrap/bin/rustc"' >> ${WRKSRC}/config.toml
139         @${ECHO_CMD} '[install]' >> ${WRKSRC}/config.toml
140         @${ECHO_CMD} 'prefix="${PREFIX}"' >> ${WRKSRC}/config.toml
141         @${ECHO_CMD} 'sysconfdir="${PREFIX}/etc"' >> ${WRKSRC}/config.toml
142         @${ECHO_CMD} '[rust]' >> ${WRKSRC}/config.toml
143         @${ECHO_CMD} 'channel="${PKGNAMESUFFIX:Ustable:S/^-//}"' >> ${WRKSRC}/config.toml
144         @${ECHO_CMD} 'default-linker="${CC}"' >> ${WRKSRC}/config.toml
145         @${ECHO_CMD} 'verbose-tests=true' >> ${WRKSRC}/config.toml
146         @${ECHO_CMD} 'lld=${_RUST_BUILD_WASM}' >> ${WRKSRC}/config.toml
147         @${ECHO_CMD} '[llvm]' >> ${WRKSRC}/config.toml
148 .if defined(WITH_CCACHE_BUILD) && !defined(NO_CCACHE)
149         @${ECHO_CMD} 'ccache="${CCACHE_BIN}"' >> ${WRKSRC}/config.toml
150 .else
151         @${ECHO_CMD} 'ccache=false' >> ${WRKSRC}/config.toml
152 .endif
153 .if ${ARCH} == armv6
154 # fails to link with base ld.bfd: rustc_codegen_llvm.e2557spx-cgu.11:(.text._ZN89_$LT$rustc_target..abi..call..CastTarget$u20$as$u20$rustc_codegen_llvm..abi..LlvmType$GT$9llvm_type17h1296210ab461fc57E+0x54): relocation truncated to fit: R_ARM_CALL against symbol `__aeabi_uldivmod' defined in .text.__aeabi_uldivmod section in /tmp/rustcdnGbao/libcompiler_builtins-ee65b414e4115a8f.rlib(compiler_builtins-ee65b414e4115a8f.compiler_builtins.ay8p39ey-cgu.13.rcgu.o)
155         @${PRINTF} '#!/bin/sh\nexec ${CC} -fuse-ld=lld "$$@"' > ${WRKDIR}/cc-wrapper
156         @${CHMOD} +x ${WRKDIR}/cc-wrapper
157 .endif
158 .for _target in ${_RUST_TARGETS}
159         @${ECHO_CMD} '[target.${_target}]' >> ${WRKSRC}/config.toml
160         @${ECHO_CMD} 'ar="${AR}"' >> ${WRKSRC}/config.toml
161         @${ECHO_CMD} 'cc="${CC}"' >> ${WRKSRC}/config.toml
162         @${ECHO_CMD} 'cxx="${CXX}"' >> ${WRKSRC}/config.toml
163 .if ${ARCH} == armv6
164         @${ECHO_CMD} 'linker="${WRKDIR}/cc-wrapper"' >> ${WRKSRC}/config.toml
165 .else
166         @${ECHO_CMD} 'linker="${CC}"' >> ${WRKSRC}/config.toml
167 .endif
168 .endfor
169         @${ECHO_CMD} '[dist]' >> ${WRKSRC}/config.toml
170         @${ECHO_CMD} 'src-tarball=false' >> ${WRKSRC}/config.toml
171         @${REINPLACE_CMD} 's,%CC%,${CC},g' \
172                 ${WRKSRC}/src/librustc_llvm/build.rs \
173                 ${WRKSRC}/src/bootstrap/native.rs
174
175 do-build:
176         @cd ${WRKSRC} && \
177                 ${SETENV} ${MAKE_ENV} ${PYTHON_CMD} x.py build --jobs=${MAKE_JOBS_NUMBER}
178
179 do-install:
180 # DESTDIR not in MAKE_ENV as it would cause the bundled LLVM to be
181 # staged into it during do-build.
182         @cd ${WRKSRC} && \
183                 ${SETENV} ${MAKE_ENV} DESTDIR=${STAGEDIR} ${PYTHON_CMD} \
184                 x.py install --jobs=${MAKE_JOBS_NUMBER}
185 # We autogenerate the plist file.  We do that, instead of the
186 # regular pkg-plist, because several libraries have a computed
187 # filename based on the absolute path of the source files.  As it
188 # is user-specific, we cannot know their filename in advance.
189         @${RM} -r ${STAGEDIR}${DOCSDIR}/*.old \
190                 ${STAGEDIR}${DOCSDIR}/html/.lock \
191                 ${STAGEDIR}${DOCSDIR}/html/.stamp \
192                 ${STAGEDIR}${PREFIX}/lib/rustlib/install.log \
193                 ${STAGEDIR}${PREFIX}/lib/rustlib/manifest-* \
194                 ${STAGEDIR}${PREFIX}/lib/rustlib/uninstall.sh
195         @${FIND} ${STAGEDIR}${PREFIX}/bin ${STAGEDIR}${PREFIX}/lib -exec ${FILE} -i {} + | \
196                 ${AWK} -F: '/executable|sharedlib/ { print $$1 }' | ${XARGS} ${STRIP_CMD}
197         @${FIND} ${STAGEDIR}${PREFIX} -not -type d | \
198                 ${SED} -E -e 's,^${STAGEDIR}${PREFIX}/,,' \
199                         -e 's,(share/man/man[1-9]/.*\.[0-9]),\1.gz,' >> ${TMPPLIST}
200
201 post-install-SOURCES-on:
202 # Silence stage-qa warnings by sanitizing permissions on sources
203         @${FIND} ${STAGEDIR}${PREFIX}/lib/rustlib/src -type f -exec ${CHMOD} \
204                 ${SHAREMODE} {} +
205
206 # Note that make test does not work when rust is already installed.
207 do-test:
208         @cd ${WRKSRC} && \
209                 ${SETENV} ${TEST_ENV} ${PYTHON_CMD} x.py test --jobs=${MAKE_JOBS_NUMBER}
210
211 .if !defined(_RUST_MAKESUM_GUARD)
212 makesum:
213         ${MAKE} -D_RUST_MAKESUM_GUARD makesum ARCH=${ONLY_FOR_ARCHS:O:[1]} DISTINFO_FILE=${DISTINFO_FILE}.tmp
214 .for arch in ${ONLY_FOR_ARCHS:O:[2..-1]}
215         ${MAKE} -D_RUST_MAKESUM_GUARD makesum PPC_ABI=ELFv1 ARCH=${arch} DISTINFO_FILE=${DISTINFO_FILE}.${arch}
216         ${SED} 1d ${DISTINFO_FILE}.${arch} >> ${DISTINFO_FILE}.tmp
217         ${RM} ${DISTINFO_FILE}.${arch}
218 .endfor
219 .if ${ONLY_FOR_ARCHS:Mpowerpc64}
220         ${MAKE} -D_RUST_MAKESUM_GUARD makesum PPC_ABI=ELFv2 ARCH=powerpc64 DISTINFO_FILE=${DISTINFO_FILE}.powerpc64-elfv2
221         ${SED} 1d ${DISTINFO_FILE}.powerpc64-elfv2 >> ${DISTINFO_FILE}.tmp
222         ${RM} ${DISTINFO_FILE}.powerpc64-elfv2
223 .endif
224         ${AWK} '!seen[$$0]++' ${DISTINFO_FILE}.tmp > ${DISTINFO_FILE}
225         ${RM} ${DISTINFO_FILE}.tmp
226 .endif
227
228 .include <bsd.port.post.mk>