Changeset View
Changeset View
Standalone View
Standalone View
Mk/Uses/cargo.mk
Show All 40 Lines | |||||
CARGO_CRATE_EXT= .crate | CARGO_CRATE_EXT= .crate | ||||
.else | .else | ||||
# If there is a rust/crates/*.tar.gz in distinfo keep using the old | # If there is a rust/crates/*.tar.gz in distinfo keep using the old | ||||
# extension. We need to delay eval until the last moment for | # extension. We need to delay eval until the last moment for | ||||
# DISTINFO_FILE. We cache the command output to avoid multiple | # DISTINFO_FILE. We cache the command output to avoid multiple | ||||
# slow grep runs for every CARGO_CRATE_EXT access. | # slow grep runs for every CARGO_CRATE_EXT access. | ||||
CARGO_CRATE_EXT= ${defined(_CARGO_CRATE_EXT_CACHE):?${_CARGO_CRATE_EXT_CACHE}:${:!if ${GREP} -q '\(${CARGO_DIST_SUBDIR}/.*\.tar\.gz\)' "${DISTINFO_FILE}" 2>/dev/null; then ${ECHO_CMD} .tar.gz; else ${ECHO_CMD} .crate; fi!:_=_CARGO_CRATE_EXT_CACHE}} | CARGO_CRATE_EXT= ${defined(_CARGO_CRATE_EXT_CACHE):?${_CARGO_CRATE_EXT_CACHE}:${:!if ${GREP} -q '\(${CARGO_DIST_SUBDIR}/.*\.tar\.gz\)' "${DISTINFO_FILE}" 2>/dev/null; then ${ECHO_CMD} .tar.gz; else ${ECHO_CMD} .crate; fi!:_=_CARGO_CRATE_EXT_CACHE}} | ||||
.endif | .endif | ||||
_CARGO_CRATES:= ${CARGO_CRATES:N*@git+*} | |||||
_CARGO_GIT_SOURCES:= ${CARGO_CRATES:M*@git+*} | |||||
# enumerate crates for unqiue and sane distfile group names | # enumerate crates for unqiue and sane distfile group names | ||||
_CARGO_CRATES:= ${empty(CARGO_CRATES):?:${CARGO_CRATES:range:@i@$i ${CARGO_CRATES:[$i]}@}} | _CARGO_CRATES:= ${empty(_CARGO_CRATES):?:${_CARGO_CRATES:range:@i@$i ${_CARGO_CRATES:[$i]}@}} | ||||
# split up crates into (index, crate, name, version) 4-tuples | # split up crates into (index, crate, name, version) 4-tuples | ||||
_CARGO_CRATES:= ${_CARGO_CRATES:C/^([-_a-zA-Z0-9]+)-([0-9].*)/\0 \1 \2/} | _CARGO_CRATES:= ${_CARGO_CRATES:C/^([-_a-zA-Z0-9]+)-([0-9].*)/\0 \1 \2/} | ||||
.for _index _crate _name _version in ${_CARGO_CRATES} | .for _index _crate _name _version in ${_CARGO_CRATES} | ||||
# Resolving CRATESIO alias is very inefficient with many MASTER_SITES, consume MASTER_SITE_CRATESIO directly | # Resolving CRATESIO alias is very inefficient with many MASTER_SITES, consume MASTER_SITE_CRATESIO directly | ||||
MASTER_SITES+= ${MASTER_SITE_CRATESIO:S,%SUBDIR%,${_name}/${_version},:S,$,:_cargo_${_index},} | MASTER_SITES+= ${MASTER_SITE_CRATESIO:S,%SUBDIR%,${_name}/${_version},:S,$,:_cargo_${_index},} | ||||
DISTFILES+= ${CARGO_DIST_SUBDIR}/${_crate}${CARGO_CRATE_EXT}:_cargo_${_index} | DISTFILES+= ${CARGO_DIST_SUBDIR}/${_crate}${CARGO_CRATE_EXT}:_cargo_${_index} | ||||
# Provide pointer to the crate's extraction dir | |||||
WRKSRC_crate_${_name}= ${CARGO_VENDOR_DIR}/${_crate} | |||||
# ... also with version suffix in case of multiple versions of the | |||||
# same crate | |||||
WRKSRC_crate_${_crate}= ${CARGO_VENDOR_DIR}/${_crate} | |||||
.endfor | .endfor | ||||
_CARGO_AWK= ${AWK} -vCP="${CP}" -vFIND="${FIND}" -vGREP="${GREP}" \ | |||||
-vCARGO_VENDOR_DIR="${CARGO_VENDOR_DIR}" \ | |||||
-vGIT_SOURCES="${_CARGO_GIT_SOURCES}" \ | |||||
-vWRKDIR="${WRKDIR}" -vWRKSRC="${WRKSRC}" \ | |||||
-f${SCRIPTSDIR}/split-url.awk \ | |||||
-f${SCRIPTSDIR}/cargo-crates-git-common.awk -f | |||||
.if !empty(_CARGO_GIT_SOURCES) | |||||
. for _index _site _filename _wrksrc _crates in ${:!${_CARGO_AWK} ${SCRIPTSDIR}/cargo-crates-git-fetch.awk /dev/null!} | |||||
MASTER_SITES+= ${_site}:_cargo_git${_index} | |||||
DISTFILES+= ${_filename}:_cargo_git${_index} | |||||
. for _crate in ${_crates:S/,/ /g} | |||||
# Make sure the build dependencies checks below can work for git sourced crates too | |||||
_CARGO_CRATES+= @git ${_crate} ${_crate} @git | |||||
# Provide pointer to the crate's extraction dir | |||||
# | |||||
# This might not point to the actual crate's sources since a | |||||
# single git source can contain multiple crates. We cannot collect | |||||
# subdir information until after the full extraction is done and we | |||||
# cannot set make variables at that point. This is better than | |||||
# nothing. | |||||
WRKSRC_crate_${_crate}= ${WRKDIR}/${_wrksrc} | |||||
. endfor | |||||
. endfor | |||||
.endif | |||||
# Build dependencies. | # Build dependencies. | ||||
CARGO_BUILDDEP?= yes | CARGO_BUILDDEP?= yes | ||||
.if ${CARGO_BUILDDEP:tl} == "yes" | .if ${CARGO_BUILDDEP:tl} == "yes" | ||||
BUILD_DEPENDS+= ${RUST_DEFAULT}>=1.55.0:lang/${RUST_DEFAULT} | BUILD_DEPENDS+= ${RUST_DEFAULT}>=1.56.0:lang/${RUST_DEFAULT} | ||||
.endif | .endif | ||||
# Location of cargo binary (default to lang/rust's Cargo binary) | # Location of cargo binary (default to lang/rust's Cargo binary) | ||||
CARGO_CARGO_BIN?= ${LOCALBASE}/bin/cargo | CARGO_CARGO_BIN?= ${LOCALBASE}/bin/cargo | ||||
# Location of the cargo output directory. | # Location of the cargo output directory. | ||||
CARGO_TARGET_DIR?= ${WRKDIR}/target | CARGO_TARGET_DIR?= ${WRKDIR}/target | ||||
Show All 29 Lines | |||||
.endif | .endif | ||||
.if defined(PPC_ABI) && ${PPC_ABI} == ELFv1 | .if defined(PPC_ABI) && ${PPC_ABI} == ELFv1 | ||||
USE_GCC?= yes | USE_GCC?= yes | ||||
STRIP_CMD= ${LOCALBASE}/bin/strip # unsupported e_type with base strip | STRIP_CMD= ${LOCALBASE}/bin/strip # unsupported e_type with base strip | ||||
.endif | .endif | ||||
# Helper to shorten cargo calls. | # Helper to shorten cargo calls. | ||||
CARGO_CARGO_RUN= \ | _CARGO_RUN= ${SETENV} ${MAKE_ENV} ${CARGO_ENV} ${CARGO_CARGO_BIN} | ||||
cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} ${CARGO_ENV} \ | CARGO_CARGO_RUN= cd ${WRKSRC}; ${SETENV} CARGO_FREEBSD_PORTS_SKIP_GIT_UPDATE=1 ${_CARGO_RUN} | ||||
${CARGO_CARGO_BIN} | |||||
# User arguments for cargo targets. | # User arguments for cargo targets. | ||||
CARGO_BUILD_ARGS?= | CARGO_BUILD_ARGS?= | ||||
CARGO_INSTALL_ARGS?= | CARGO_INSTALL_ARGS?= | ||||
CARGO_INSTALL_PATH?= . | CARGO_INSTALL_PATH?= . | ||||
CARGO_TEST_ARGS?= | CARGO_TEST_ARGS?= | ||||
CARGO_UPDATE_ARGS?= | CARGO_UPDATE_ARGS?= | ||||
# Use module targets ? | # Use module targets ? | ||||
CARGO_BUILD?= yes | CARGO_BUILD?= yes | ||||
CARGO_CONFIGURE?= yes | CARGO_CONFIGURE?= yes | ||||
CARGO_INSTALL?= yes | CARGO_INSTALL?= yes | ||||
CARGO_TEST?= yes | CARGO_TEST?= yes | ||||
# Set CARGO_USE_GIT{HUB,LAB} to yes if your application requires | |||||
# some dependencies from git repositories hosted on GitHub or | |||||
# GitLab instances. All Cargo.toml files will be patched to point | |||||
# to the right offline sources based on what is defined in | |||||
# {GH,GL}_TUPLE. This makes sure that cargo does not attempt to | |||||
# access the network during the build. | |||||
CARGO_USE_GITHUB?= no | |||||
CARGO_USE_GITLAB?= no | |||||
# rustc stashes intermediary files in TMPDIR (default /tmp) which | # rustc stashes intermediary files in TMPDIR (default /tmp) which | ||||
# might cause issues for users that for some reason space limit | # might cause issues for users that for some reason space limit | ||||
# their /tmp. WRKDIR should have plenty of space. | # their /tmp. WRKDIR should have plenty of space. | ||||
# Allow users and ports to still overwrite it. | # Allow users and ports to still overwrite it. | ||||
.if ${TMPDIR:U/tmp} == /tmp | .if ${TMPDIR:U/tmp} == /tmp | ||||
TMPDIR= ${WRKDIR} | TMPDIR= ${WRKDIR} | ||||
.endif | .endif | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | |||||
.endfor | .endfor | ||||
_USES_extract+= 600:cargo-extract | _USES_extract+= 600:cargo-extract | ||||
cargo-extract: | cargo-extract: | ||||
# target for preparing crates directory. It will put all crates in | # target for preparing crates directory. It will put all crates in | ||||
# the local crates directory. | # the local crates directory. | ||||
@${ECHO_MSG} "===> Moving crates to ${CARGO_VENDOR_DIR}" | @${ECHO_MSG} "===> Moving crates to ${CARGO_VENDOR_DIR}" | ||||
@${MKDIR} ${CARGO_VENDOR_DIR} | @${MKDIR} ${CARGO_VENDOR_DIR} | ||||
.for _crate in ${CARGO_CRATES} | .for _index _crate _name _version in ${_CARGO_CRATES} | ||||
. if ${_index} != @git | |||||
@${MV} ${WRKDIR}/${_crate} ${CARGO_VENDOR_DIR}/${_crate} | @${MV} ${WRKDIR}/${_crate} ${CARGO_VENDOR_DIR}/${_crate} | ||||
@${PRINTF} '{"package":"%s","files":{}}' \ | @${PRINTF} '{"package":"%s","files":{}}' \ | ||||
$$(${SHA256} -q ${DISTDIR}/${CARGO_DIST_SUBDIR}/${_crate}${CARGO_CRATE_EXT}) \ | $$(${SHA256} -q ${DISTDIR}/${CARGO_DIST_SUBDIR}/${_crate}${CARGO_CRATE_EXT}) \ | ||||
> ${CARGO_VENDOR_DIR}/${_crate}/.cargo-checksum.json | > ${CARGO_VENDOR_DIR}/${_crate}/.cargo-checksum.json | ||||
@if [ -r ${CARGO_VENDOR_DIR}/${_crate}/Cargo.toml.orig ]; then \ | @if [ -r ${CARGO_VENDOR_DIR}/${_crate}/Cargo.toml.orig ]; then \ | ||||
${MV} ${CARGO_VENDOR_DIR}/${_crate}/Cargo.toml.orig \ | ${MV} ${CARGO_VENDOR_DIR}/${_crate}/Cargo.toml.orig \ | ||||
${CARGO_VENDOR_DIR}/${_crate}/Cargo.toml.orig-cargo; \ | ${CARGO_VENDOR_DIR}/${_crate}/Cargo.toml.orig-cargo; \ | ||||
fi | fi | ||||
.endfor | |||||
_CARGO_GIT_PATCH_CARGOTOML= | |||||
.if ${CARGO_USE_GITHUB:tl} == "yes" | |||||
. for _group in ${GH_TUPLE:C@^[^:]*:[^:]*:[^:]*:(([^:/]*)?)((/.*)?)@\2@} | |||||
. if empty(CARGO_GIT_SUBDIR:M${_group}\:*) | |||||
_CARGO_GIT_PATCH_CARGOTOML:= ${_CARGO_GIT_PATCH_CARGOTOML} \ | |||||
-e "s@git *= *['\"](https|http|git)://github.com/${GH_ACCOUNT_${_group}}/${GH_PROJECT_${_group}}(\.git)?/?[\"']@path = \"${WRKSRC_${_group}}\"@" | |||||
. else | |||||
. for _group2 _crate _subdir in ${CARGO_GIT_SUBDIR:M${_group}\:*:S,:, ,g} | |||||
_CARGO_GIT_PATCH_CARGOTOML:= ${_CARGO_GIT_PATCH_CARGOTOML} \ | |||||
-e "/^${_crate} =/ s@git *= *['\"](https|http|git)://github.com/${GH_ACCOUNT_${_group}}/${GH_PROJECT_${_group}}(\.git)?/?[\"']@path = \"${WRKSRC_${_group}}/${_subdir}\"@" | |||||
. endfor | |||||
. endif | . endif | ||||
. endfor | .endfor | ||||
.endif | |||||
.if ${CARGO_USE_GITLAB:tl} == "yes" | |||||
. for _group in ${GL_TUPLE:C@^(([^:]*://[^:/]*(:[0-9]{1,5})?(/[^:]*[^/])?:)?)([^:]*):([^:]*):([^:]*)(:[^:/]*)((/.*)?)@\8@:S/^://} | |||||
. if empty(CARGO_GIT_SUBDIR:M${_group}\:*) | |||||
_CARGO_GIT_PATCH_CARGOTOML:= ${_CARGO_GIT_PATCH_CARGOTOML} \ | |||||
-e "s@git *= *['\"]${GL_SITE_${_group}}/${GL_ACCOUNT_${_group}}/${GL_PROJECT_${_group}}(\.git)?/?['\"]@path = \"${WRKSRC_${_group}}\"@" | |||||
. else | |||||
. for _group2 _crate _subdir in ${CARGO_GIT_SUBDIR:M${_group}\:*:S,:, ,g} | |||||
_CARGO_GIT_PATCH_CARGOTOML:= ${_CARGO_GIT_PATCH_CARGOTOML} \ | |||||
-e "/^${_crate} = / s@git *= *['\"]${GL_SITE_${_group}}/${GL_ACCOUNT_${_group}}/${GL_PROJECT_${_group}}(\.git)?/?['\"]@path = \"${WRKSRC_${_group}}/${_subdir}\"@" | |||||
. endfor | |||||
. endif | |||||
. endfor | |||||
.endif | |||||
.if !empty(_CARGO_GIT_PATCH_CARGOTOML) | |||||
_USES_patch+= 600:cargo-patch-git | |||||
cargo-patch-git: | |||||
@${FIND} ${WRKDIR} -name Cargo.toml -type f -exec \ | |||||
${SED} -i.dist -E ${_CARGO_GIT_PATCH_CARGOTOML} {} + | |||||
.endif | |||||
.if ${CARGO_CONFIGURE:tl} == "yes" | .if ${CARGO_CONFIGURE:tl} == "yes" | ||||
_USES_configure+= 250:cargo-configure | _USES_configure+= 250:cargo-configure | ||||
# configure hook. Place a config file for overriding crates-io index | # configure hook. Place a config file for overriding crates-io index | ||||
# by local source directory. | # by local source directory. | ||||
cargo-configure: | cargo-configure: | ||||
# Check that the running kernel has COMPAT_FREEBSD11 required by lang/rust post-ino64 | # Check that the running kernel has COMPAT_FREEBSD11 required by lang/rust post-ino64 | ||||
@${SETENV} CC="${CC}" OPSYS="${OPSYS}" OSVERSION="${OSVERSION}" WRKDIR="${WRKDIR}" \ | @${SETENV} CC="${CC}" OPSYS="${OPSYS}" OSVERSION="${OSVERSION}" WRKDIR="${WRKDIR}" \ | ||||
${SH} ${SCRIPTSDIR}/rust-compat11-canary.sh | ${SH} ${SCRIPTSDIR}/rust-compat11-canary.sh | ||||
@${ECHO_MSG} "===> Cargo config:" | |||||
@${MKDIR} ${WRKDIR}/.cargo | @${MKDIR} ${WRKDIR}/.cargo | ||||
@${ECHO_CMD} "[source.cargo]" > ${WRKDIR}/.cargo/config | @: > ${WRKDIR}/.cargo/config.toml | ||||
@${ECHO_CMD} "directory = '${CARGO_VENDOR_DIR}'" >> ${WRKDIR}/.cargo/config | @${ECHO_CMD} "[source.cargo]" >> ${WRKDIR}/.cargo/config.toml | ||||
@${ECHO_CMD} "[source.crates-io]" >> ${WRKDIR}/.cargo/config | @${ECHO_CMD} "directory = '${CARGO_VENDOR_DIR}'" >> ${WRKDIR}/.cargo/config.toml | ||||
@${ECHO_CMD} "replace-with = 'cargo'" >> ${WRKDIR}/.cargo/config | @${ECHO_CMD} "[source.crates-io]" >> ${WRKDIR}/.cargo/config.toml | ||||
@${ECHO_CMD} "replace-with = 'cargo'" >> ${WRKDIR}/.cargo/config.toml | |||||
.if !empty(_CARGO_GIT_SOURCES) | |||||
@${_CARGO_AWK} ${SCRIPTSDIR}/cargo-crates-git-configure.awk \ | |||||
/dev/null >> ${WRKDIR}/.cargo/config.toml | |||||
.endif | |||||
@${CAT} ${WRKDIR}/.cargo/config.toml | |||||
@if ! ${GREP} -qF '[profile.release]' ${CARGO_CARGOTOML}; then \ | @if ! ${GREP} -qF '[profile.release]' ${CARGO_CARGOTOML}; then \ | ||||
${ECHO_CMD} "" >> ${CARGO_CARGOTOML}; \ | ${ECHO_CMD} "" >> ${CARGO_CARGOTOML}; \ | ||||
${ECHO_CMD} "[profile.release]" >> ${CARGO_CARGOTOML}; \ | ${ECHO_CMD} "[profile.release]" >> ${CARGO_CARGOTOML}; \ | ||||
${ECHO_CMD} "opt-level = 2" >> ${CARGO_CARGOTOML}; \ | ${ECHO_CMD} "opt-level = 2" >> ${CARGO_CARGOTOML}; \ | ||||
${ECHO_CMD} "debug = false" >> ${CARGO_CARGOTOML}; \ | ${ECHO_CMD} "debug = false" >> ${CARGO_CARGOTOML}; \ | ||||
fi | fi | ||||
@${ECHO_MSG} "===> Updating Cargo.lock" | |||||
@${CARGO_CARGO_RUN} update \ | @${CARGO_CARGO_RUN} update \ | ||||
--manifest-path ${CARGO_CARGOTOML} \ | --manifest-path ${CARGO_CARGOTOML} \ | ||||
--verbose \ | --verbose \ | ||||
--verbose \ | --verbose \ | ||||
${CARGO_UPDATE_ARGS} | ${CARGO_UPDATE_ARGS} | ||||
.endif | .endif | ||||
.if !target(do-build) && ${CARGO_BUILD:tl} == "yes" | .if !target(do-build) && ${CARGO_BUILD:tl} == "yes" | ||||
Show All 31 Lines | |||||
# Helper targets for port maintainers | # Helper targets for port maintainers | ||||
# | # | ||||
# cargo-crates will output the crates list from Cargo.lock. If there | # cargo-crates will output the crates list from Cargo.lock. If there | ||||
# is no Cargo.lock for some reason, try and generate it first. | # is no Cargo.lock for some reason, try and generate it first. | ||||
cargo-crates: extract | cargo-crates: extract | ||||
@if [ ! -r "${CARGO_CARGOLOCK}" ]; then \ | @if [ ! -r "${CARGO_CARGOLOCK}" ]; then \ | ||||
${ECHO_MSG} "===> ${CARGO_CARGOLOCK} not found. Trying to generate it..."; \ | ${ECHO_MSG} "===> ${CARGO_CARGOLOCK} not found. Trying to generate it..."; \ | ||||
${CARGO_CARGO_RUN} generate-lockfile \ | cd ${WRKSRC}; ${_CARGO_RUN} generate-lockfile \ | ||||
--manifest-path ${CARGO_CARGOTOML} \ | --manifest-path ${CARGO_CARGOTOML} \ | ||||
--verbose; \ | --verbose; \ | ||||
fi | fi | ||||
@${SETENV} USE_GITHUB=${USE_GITHUB} USE_GITLAB=${USE_GITLAB} GL_SITE=${GL_SITE} \ | @${_CARGO_AWK} ${SCRIPTSDIR}/cargo-crates.awk ${CARGO_CARGOLOCK} | ||||
${AWK} -f ${SCRIPTSDIR}/split-url.awk -f ${SCRIPTSDIR}/cargo-crates.awk ${CARGO_CARGOLOCK} | |||||
# cargo-crates-licenses will try to grab license information from | # cargo-crates-licenses will try to grab license information from | ||||
# all downloaded crates. | # all downloaded crates. | ||||
cargo-crates-licenses: configure | cargo-crates-licenses: configure | ||||
@${FIND} ${CARGO_VENDOR_DIR} -name 'Cargo.toml' -maxdepth 2 \ | @${FIND} ${CARGO_VENDOR_DIR} -name 'Cargo.toml' -maxdepth 2 \ | ||||
-exec ${GREP} -H '^license' {} \; \ | -exec ${GREP} -H '^license' {} \; \ | ||||
| ${SED} \ | | ${SED} \ | ||||
-e 's@^${CARGO_VENDOR_DIR}/@@' \ | -e 's@^${CARGO_VENDOR_DIR}/@@' \ | ||||
-e 's@/Cargo.toml:license.*= *"@|@' \ | -e 's@/Cargo.toml:license.*= *"@|@' \ | ||||
-e 's@"$$@@g' | sort | /usr/bin/column -t -s '|' | -e 's@"$$@@g' | sort | /usr/bin/column -t -s '|' | ||||
.endif | .endif |