1 # Created by: Jyun-Yan You <jyyou@cs.nctu.edu.tw>
8 MASTER_SITES= http://static.rust-lang.org/dist/:src \
9 LOCAL/dumbbell/rust:rust_bootstrap \
10 https://static.rust-lang.org/dist/:rust_bootstrap \
11 LOCAL/dumbbell/rust:cargo_bootstrap \
12 https://static.rust-lang.org/dist/:cargo_bootstrap \
13 https://s3.amazonaws.com/rust-lang-ci/cargo-builds/:cargo_bootstrap \
14 LOCAL/marino:bootstrap
15 DISTNAME?= ${PORTNAME}c-${PORTVERSION}-src
16 DISTFILES?= ${NIGHTLY_SUBDIR}${DISTNAME}${EXTRACT_SUFX}:src \
17 ${RUSTC_BOOTSTRAP}:rust_bootstrap \
18 ${RUST_STD_BOOTSTRAP}:rust_bootstrap \
19 ${CARGO_BOOTSTRAP}:cargo_bootstrap
21 EXTRACT_ONLY?= ${DISTFILES:N*\:*bootstrap:C/:.*//}
23 MAINTAINER= rust@FreeBSD.org
24 COMMENT= Language with a focus on memory safety and concurrency
29 # APACHE20 license is standard, see Templates/Licenses/APACHE20
30 LICENSE_FILE_MIT= ${WRKSRC}/LICENSE-MIT
32 BUILD_DEPENDS= cmake:devel/cmake
33 LIB_DEPENDS= libcurl.so:ftp/curl \
34 libssh2.so:security/libssh2
36 ONLY_FOR_ARCHS?= aarch64 amd64 i386
37 ONLY_FOR_ARCHS_REASON= requires prebuilt bootstrap compiler
39 # FIXME: The bootstrapped rustc adds -L/usr/local/lib in front of
40 # the LDFLAGS. When stage0's rustc is linked, it picks the installed
41 # librust*so and fails.
42 #CONFLICTS_BUILD?= rust-nightly
43 #CONFLICTS_BUILD+= ${PKGBASE}
44 CONFLICTS_INSTALL?= rust-nightly
46 # See WRKSRC/src/stage0.txt for this date and version values.
47 BOOTSTRAPS_DATE?= 2018-02-15
49 RUST_BOOTSTRAP_VERSION?= 1.24.0
50 RUSTC_BOOTSTRAP= ${BOOTSTRAPS_DATE_${ARCH}:U${BOOTSTRAPS_DATE}}/rustc-${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}-${RUST_TARGET}.tar.gz
51 RUST_STD_BOOTSTRAP= ${BOOTSTRAPS_DATE_${ARCH}:U${BOOTSTRAPS_DATE}}/rust-std-${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}-${RUST_TARGET}.tar.gz
53 CARGO_BOOTSTRAP_VERSION?= 0.25.0
54 CARGO_BOOTSTRAP= ${BOOTSTRAPS_DATE_${ARCH}:U${BOOTSTRAPS_DATE}}/cargo-${CARGO_BOOTSTRAP_VERSION_${ARCH}:U${CARGO_BOOTSTRAP_VERSION}}-${RUST_TARGET}.tar.gz
56 RUST_CHANNEL= ${PKGNAMESUFFIX:Ustable:S/^-//}
58 # Rust's target arch string is different from *BSD arch strings
59 RUST_ARCH_aarch64= aarch64
60 RUST_ARCH_x86_64= x86_64
62 RUST_ARCH_x86_64= x86_64 # dragonfly
63 RUST_TARGET= ${RUST_ARCH_${ARCH}}-unknown-${OPSYS:tl}
64 PLIST_SUB+= RUST_TARGET=${RUST_TARGET}
66 USES= compiler gmake libedit pkgconfig python:2.7,build ssl tar:xz
68 OPTIONS_DEFINE= DOCS GDB LLNEXTGEN SOURCES
69 GDB_DESC= Install ports gdb (necessary for debugging rust programs)
70 LLNEXTGEN_DESC= Build with grammar verification
71 SOURCES_DESC= Install source files
73 GDB_RUN_DEPENDS= ${LOCALBASE}/bin/gdb:devel/gdb
74 LLNEXTGEN_BUILD_DEPENDS= LLnextgen:devel/llnextgen
76 # Rust manifests list all files and directories installed by rust-installer.
78 # - pre-install to cleanup the ${STAGEDIR}
79 # - post-install to populate the ${TMPPLIST}
80 RUST_MANIFESTS= lib/rustlib/manifest-cargo \
81 lib/rustlib/manifest-rls-preview \
82 lib/rustlib/manifest-rustc \
83 lib/rustlib/manifest-rustfmt-preview \
84 lib/rustlib/manifest-rust-analysis-${RUST_TARGET} \
85 lib/rustlib/manifest-rust-std-${RUST_TARGET}
86 RUST_DOCS_MANIFEST= lib/rustlib/manifest-rust-docs
87 RUST_SRC_MANIFEST= lib/rustlib/manifest-rust-src
88 DOCS_VARS= rust_manifests+=${RUST_DOCS_MANIFEST}
89 SOURCES_VARS= rust_manifests+=${RUST_SRC_MANIFEST}
91 PLIST_FILES= lib/rustlib/components \
92 lib/rustlib/rust-installer-version
94 .include <bsd.port.pre.mk>
95 # ABI patch needed to address ino64 before fixes upstreamed.
96 # https://github.com/rust-lang/rust/issues/42681
97 .if ${OPSYS} == FreeBSD && ${OSVERSION} >= 1200031 && !defined(NIGHTLY_DATE)
103 X_PY_ENV+= HOME="${WRKDIR}" \
104 OPENSSL_DIR="${OPENSSLBASE}"
105 X_PY_CMD= ${PYTHON_CMD} ${WRKSRC}/x.py
107 CRATES_PATCHED_BY_FBSD10_FIX= src/vendor/libssh2-sys \
111 # FIXME: This is the same check for CONFLICTS as the standard
112 # one, except port origins are not compared. This allows
113 # the port to conflict with itself, because Rust would pick
114 # installed Rust libraries instead of freshly built ones.
115 @conflicts_with=$$( \
116 { ${PKG_QUERY} -g "%n-%v %p %o" ${CONFLICTS:C/.+/'&'/} ${CONFLICTS_BUILD:C/.+/'&'/} 2>/dev/null || : ; } \
117 | while read pkgname prfx orgn; do \
118 if [ "/${PREFIX}" = "/$${prfx}" ]; then \
119 ${ECHO_CMD} -n " $${pkgname}"; \
122 if [ -n "$${conflicts_with}" ]; then \
124 ${ECHO_MSG} "===> ${PKGNAME} conflicts with installed package(s): "; \
125 for entry in $${conflicts_with}; do \
126 ${ECHO_MSG} " $${entry}"; \
129 ${ECHO_MSG} " They will not build together."; \
130 ${ECHO_MSG} " Please remove them first with pkg delete."; \
134 RUST_STD_DIR= ${RUST_STD_BOOTSTRAP:T:R:R}
138 ${WRKSRC}/build/cache/${BOOTSTRAPS_DATE_${ARCH}:U${BOOTSTRAPS_DATE}}
139 ${LN} -sf ${DISTDIR}/${DIST_SUBDIR}/${RUSTC_BOOTSTRAP} \
140 ${WRKSRC}/build/cache/${BOOTSTRAPS_DATE_${ARCH}:U${BOOTSTRAPS_DATE}}
141 .if ${NEED_ABI_PATCH} == 0
142 ${LN} -sf ${DISTDIR}/${DIST_SUBDIR}/${RUST_STD_BOOTSTRAP} \
143 ${WRKSRC}/build/cache/${BOOTSTRAPS_DATE_${ARCH}:U${BOOTSTRAPS_DATE}}
145 ${LN} -sf ${DISTDIR}/${DIST_SUBDIR}/${CARGO_BOOTSTRAP} \
146 ${WRKSRC}/build/cache/${BOOTSTRAPS_DATE_${ARCH}:U${BOOTSTRAPS_DATE}}
147 .if ${NEED_ABI_PATCH} == 1
148 ${TAR} -x -C ${WRKSRC} -f ${DISTDIR}/${DIST_SUBDIR}/${RUST_STD_BOOTSTRAP}
149 ${CC} ${CFLAGS} -fPIC -c -o ${WRKSRC}/old_fstat.o ${FILESDIR}/old_fstat.c
150 (set -ex; cd ${WRKSRC}; \
151 libstd="$$(echo "${RUST_STD_DIR}/rust-std-${RUST_TARGET}/lib/rustlib/${RUST_TARGET}/lib/"libstd-*.rlib)"; \
152 hash="$$(basename "$$libstd" .rlib | ${SED} 's/^libstd-//')"; \
153 std_o="$$(${AR} t "$$libstd" | ${GREP} -E "^std-$$hash.*\.o$$" | ${HEAD} -n 1)"; \
154 ${AR} x "$$libstd" "$$std_o"; \
155 ${LD} -r -o std.xx.o "$$std_o" old_fstat.o; \
156 ${MV} std.xx.o "$$std_o"; \
157 ${AR} r "$$libstd" "$$std_o")
158 ${TAR} -c --format=ustar -C ${WRKSRC} -f ${WRKSRC}/rust-std.tar.gz ${RUST_STD_DIR}
159 ${MV} ${WRKSRC}/rust-std.tar.gz ${WRKSRC}/build/cache/${RUST_STD_BOOTSTRAP}
163 @${REINPLACE_CMD} -e 's|gdb|${LOCALBASE}/bin/gdb|' \
164 ${WRKSRC}/src/etc/rust-gdb
165 # If we override the versions and date of the bootstraps (for instance
166 # on aarch64 where we provide our own bootstraps), we need to update
167 # places where they are recorded.
168 @${REINPLACE_CMD} -e \
169 's|^date:.*|date: ${BOOTSTRAPS_DATE_${ARCH}:U${BOOTSTRAPS_DATE}}|' \
170 ${WRKSRC}/src/stage0.txt
171 @${REINPLACE_CMD} -e \
172 's|^rustc:.*|rustc: ${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}|' \
173 ${WRKSRC}/src/stage0.txt
174 @${REINPLACE_CMD} -e \
175 's|^cargo:.*|cargo: ${CARGO_BOOTSTRAP_VERSION_${ARCH}:U${CARGO_BOOTSTRAP_VERSION}}|' \
176 ${WRKSRC}/src/stage0.txt
177 # After patching crates, we need to update their corresponding
178 # `.cargo-checksum.json` to reflect the new checksums verified by Cargo.
179 @for dir in "${WRKSRC}/src/vendor/libc" "${WRKSRC}/src/vendor/openssl" "${WRKSRC}/src/vendor/openssl-sys"; do \
180 if ! test -d "$$dir"; then \
184 for file in $$(${FIND} * -name "*.orig"); do \
185 old_checksum=$$(${SHA256} -q "$$file"); \
186 new_checksum=$$(${SHA256} -q "$${file%%.orig}"); \
187 regex="$$regex -e s|\"$${file%%.orig}\":\"$$old_checksum\"|\"$${file%%.orig}\":\"$$new_checksum\"|"; \
189 if test "$$regex"; then \
190 ${REINPLACE_CMD} -E $$regex .cargo-checksum.json; \
193 # We make a backup of a few files before the FreeBSD 10 autotools
194 # fix is applied. We'll need them in `do-configure` to update the
195 # `.cargo-checksum.json` files.
196 @for crate in ${CRATES_PATCHED_BY_FBSD10_FIX}; do \
197 if ! test -d "${WRKSRC}/$$crate"; then \
200 for file in $$(${FIND} "${WRKSRC}/$$crate" -name "config.rpath"); do \
201 ${CP} "$$file" "$$file.orig"; \
205 .if defined(WITH_CCACHE_BUILD) && !defined(NO_CCACHE)
206 CCACHE_VALUE= "${CCACHE_WRAPPER_PATH:C,/libexec/ccache$,,}/bin/ccache"
213 -e 's,%PREFIX%,${PREFIX},' \
214 -e 's,%SYSCONFDIR%,${PREFIX}/etc,' \
215 -e 's,%MANDIR%,${MANPREFIX}/man,' \
216 -e 's,%PYTHON_CMD%,${PYTHON_CMD},' \
217 -e 's,%CHANNEL%,${RUST_CHANNEL},' \
218 -e 's,%TARGET%,${RUST_TARGET},' \
219 -e 's,%CCACHE%,${CCACHE_VALUE},' \
220 < ${FILESDIR}/config.toml \
221 > ${WRKSRC}/config.toml
222 # The FreeBSD 10 autotools fix may modify some files just before
223 # `do-configure`. Like after `extra-path-ino64`, we need to update
224 # `.cargo-checksum.json`.
225 @for crate in ${CRATES_PATCHED_BY_FBSD10_FIX}; do \
226 if ! test -d "${WRKSRC}/$$crate"; then \
229 cd "${WRKSRC}/$$crate"; \
230 for file in $$(${FIND} * -name "*.orig"); do \
231 old_checksum=$$(${SHA256} -q "$$file"); \
232 new_checksum=$$(${SHA256} -q "$${file%%.orig}"); \
233 regex="$$regex -e s|\"$${file%%.orig}\":\"$$old_checksum\"|\"$${file%%.orig}\":\"$$new_checksum\"|"; \
235 if test "$$regex"; then \
236 ${REINPLACE_CMD} -E $$regex .cargo-checksum.json; \
240 post-configure-DOCS-on:
241 ${REINPLACE_CMD} -e 's,%DOCS%,true,' ${WRKSRC}/config.toml
243 post-configure-DOCS-off:
244 ${REINPLACE_CMD} -e 's,%DOCS%,false,' ${WRKSRC}/config.toml
248 ${SETENV} ${X_PY_ENV} \
251 --config ./config.toml \
252 --jobs ${MAKE_JOBS_NUMBER}
254 # In case the previous "make stage" failed, this ensures rust's
255 # install.sh won't backup previously staged files before reinstalling
256 # new ones. Otherwise, the staging directory is polluted with unneeded
259 @for f in ${RUST_MANIFESTS} ${RUST_DOCS_MANIFEST} ${RUST_SRC_MANIFEST}; do \
260 if test -f "${STAGEDIR}${PREFIX}/$$f"; then \
261 ${SED} -E -e 's,^(file|dir):,${STAGEDIR},' \
262 < "${STAGEDIR}${PREFIX}/$$f" \
263 | ${XARGS} ${RM} -r; \
264 ${RM} "${STAGEDIR}${PREFIX}/$$f"; \
267 @for f in ${PLIST_FILES}; do \
268 ${RM} "${STAGEDIR}${PREFIX}/$$f"; \
273 ${SETENV} ${X_PY_ENV} \
274 DESTDIR=${STAGEDIR} \
275 ${X_PY_CMD} install \
277 --config ./config.toml \
278 --jobs ${MAKE_JOBS_NUMBER}
280 # In post-install, we use the manifests generated during Rust install
281 # to in turn generate the PLIST. We do that, instead of the regular
282 # `pkg-plist`, because several libraries have a computed filename based
283 # on the absolute path of the source files. As it is user-specific, we
284 # can't know their filename in advance.
286 # Both rustc and Cargo components install the same README.md and LICENSE
287 # files. The install process backs up the first copy to install the
288 # second. Thus here, we need to remove those backups. We also need to
289 # dedup the entries in the generated PLIST, because both components'
290 # manifests list them.
292 # We fix manpage entries in the generated manifests because Rust
293 # installs them uncompressed but the Ports framework compresses them.
295 for f in ${RUST_MANIFESTS}; do \
296 ${REINPLACE_CMD} -E \
297 -e 's|:${STAGEDIR}|:|' \
298 -e 's|(man/man[1-9]/.*\.[0-9])|\1.gz|' \
299 ${STAGEDIR}${PREFIX}/$$f; \
300 ${RM} ${STAGEDIR}${PREFIX}/$$f.bak; \
301 ${ECHO} "${PREFIX}/$$f" >> ${TMPPLIST}; \
305 sub(/^file:/, "", file); \
310 sub(/^dir:/, "", dir); \
311 system("find ${STAGEDIR}" dir " -type f | ${SED} -E -e \"s|${STAGEDIR}||\""); \
313 ${STAGEDIR}${PREFIX}/$$f >> ${TMPPLIST}; \
315 ${RM} ${STAGEDIR}${PREFIX}/share/doc/rust/*.old
316 ${SORT} -u < ${TMPPLIST} > ${TMPPLIST}.uniq
317 ${MV} ${TMPPLIST}.uniq ${TMPPLIST}
319 ${STAGEDIR}${PREFIX}/lib/rustlib/install.log \
320 ${STAGEDIR}${PREFIX}/lib/rustlib/uninstall.sh
321 # FIXME: Static libraries in lib/rustlib/*/lib/*.rlib are not stripped,
322 # but they contain non-object files which make strip(1) unhappy.
324 ${STAGEDIR}${PREFIX}/bin/cargo \
325 ${STAGEDIR}${PREFIX}/bin/cargo-fmt \
326 ${STAGEDIR}${PREFIX}/bin/rls \
327 ${STAGEDIR}${PREFIX}/bin/rustc \
328 ${STAGEDIR}${PREFIX}/bin/rustdoc \
329 ${STAGEDIR}${PREFIX}/bin/rustfmt \
330 ${STAGEDIR}${PREFIX}/lib/*.so \
331 ${STAGEDIR}${PREFIX}/lib/rustlib/*/lib/*.so
333 # We set `extended = true` in config.toml because we want to build
334 # Cargo at the same time. However, this installs the rust-src component
335 # as well. If the user doesn't want that, I don't know how to prevent
336 # its install. So for now, use the rust-src manifest to remove it from
338 post-install-SOURCES-off:
339 if test -f "${STAGEDIR}${PREFIX}/${RUST_SRC_MANIFEST}"; then \
340 ${SED} -E -e 's,^(file|dir):,,' \
341 < "${STAGEDIR}${PREFIX}/${RUST_SRC_MANIFEST}" \
342 | ${XARGS} ${RM} -r; \
343 ${RM} "${STAGEDIR}${PREFIX}/${RUST_SRC_MANIFEST}"; \
344 ${RM} -r "${STAGEDIR}${PREFIX}/lib/rustlib/src"; \
347 # Note that make test does not work when rust is already installed.
350 ${SETENV} ${X_PY_ENV} \
351 ALLOW_NONZERO_RLIMIT_CORE=1 \
354 --config ./config.toml \
355 --jobs ${MAKE_JOBS_NUMBER}
357 BOOTSTRAPS_SOURCE_PKG_FBSDVER= 10
358 BOOTSTRAPS_SOURCE_PKG_FBSDVER_aarch64= 11
359 BOOTSTRAPS_SOURCE_PKG_REV=
360 BOOTSTRAPS_SOURCE_PKG_URL= https://pkg.freebsd.org/FreeBSD:${BOOTSTRAPS_SOURCE_PKG_FBSDVER_${ARCH}:U${BOOTSTRAPS_SOURCE_PKG_FBSDVER}}:${ARCH}/latest/All/rust-${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}${BOOTSTRAPS_SOURCE_PKG_REV}.txz
361 BOOTSTRAPS_SOURCE_PKG= ${_DISTDIR}/${BOOTSTRAPS_DATE_${ARCH}:U${BOOTSTRAPS_DATE}}/rust-${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}-${ARCH}.txz
363 package-to-bootstraps: ${BOOTSTRAPS_SOURCE_PKG}
364 ${MKDIR} ${WRKDIR}/bootstraps
365 ${RM} -r ${WRKDIR}/bootstraps/usr
367 -C ${WRKDIR}/bootstraps \
368 --strip-components 3 \
369 ${EXTRACT_BEFORE_ARGS} ${BOOTSTRAPS_SOURCE_PKG} ${LOCALBASE}
371 ${RM} -r ${WRKDIR}/bootstraps/rustc-${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}-${RUST_TARGET}
372 ${MKDIR} ${WRKDIR}/bootstraps/rustc-${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}-${RUST_TARGET}
373 cd ${WRKDIR}/bootstraps/rustc-${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}-${RUST_TARGET} && \
374 ${MKDIR} rustc/bin rustc/lib && \
375 ${MV} ${WRKDIR}/bootstraps/bin/rust* rustc/bin && \
376 ${MV} ${WRKDIR}/bootstraps/lib/*.so rustc/lib
377 ${TAR} -cz --format=ustar -C ${WRKDIR}/bootstraps \
378 -f ${_DISTDIR}/${RUSTC_BOOTSTRAP} \
379 rustc-${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}-${RUST_TARGET}
380 # `rust-std` bootstrap.
381 ${RM} -r ${WRKDIR}/bootstraps/rust-std-${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}-${RUST_TARGET}
382 ${MKDIR} ${WRKDIR}/bootstraps/rust-std-${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}-${RUST_TARGET}
383 cd ${WRKDIR}/bootstraps/rust-std-${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}-${RUST_TARGET} && \
384 ${MKDIR} rust-std-${RUST_TARGET}/lib/rustlib/${RUST_TARGET} && \
385 ${MV} ${WRKDIR}/bootstraps/lib/rustlib/${RUST_TARGET}/lib rust-std-${RUST_TARGET}/lib/rustlib/${RUST_TARGET}
386 ${TAR} -cz --format=ustar -C ${WRKDIR}/bootstraps \
387 -f ${_DISTDIR}/${RUST_STD_BOOTSTRAP} \
388 rust-std-${RUST_BOOTSTRAP_VERSION_${ARCH}:U${RUST_BOOTSTRAP_VERSION}}-${RUST_TARGET}
390 ${BOOTSTRAPS_SOURCE_PKG}:
392 ${FETCH_CMD} -o $@ ${BOOTSTRAPS_SOURCE_PKG_URL}
394 .include <bsd.port.post.mk>