2017-06-21 18:22:32 +02:00
# This file contains logic to ease porting of Rust packages or
# binaries using the `cargo` command.
#
# Feature: cargo
# Usage: USES=cargo
# Valid ARGS: none
#
2019-04-17 09:33:34 +02:00
# MAINTAINER: rust@FreeBSD.org
2017-06-21 18:22:32 +02:00
. i f ! d e f i n e d ( _ I N C L U D E _ U S E S _ C A R G O _ M K )
_INCLUDE_USES_CARGO_MK = yes
2022-04-24 12:00:20 +02:00
. i f ! e m p t y ( c a r g o _ A R G S )
2017-06-21 18:22:32 +02:00
IGNORE += USES = cargo takes no arguments
2022-04-24 12:00:20 +02:00
. e n d i f
2017-06-21 18:22:32 +02:00
2021-09-07 09:26:05 +02:00
. s i n c l u d e "${MASTERDIR}/Makefile.crates"
2017-06-21 18:22:32 +02:00
# List of static dependencies. The format is cratename-version.
2021-04-14 13:53:37 +02:00
# CARGO_CRATES will be downloaded from MASTER_SITE_CRATESIO.
2017-06-21 18:22:32 +02:00
CARGO_CRATES ?=
# List of features to build (space separated list).
2020-03-04 16:00:17 +01:00
# Use special token --no-default-features to disable default
# features by passing it to cargo build/install/test.
2017-06-21 18:22:32 +02:00
CARGO_FEATURES ?=
# Name of the local directory for vendoring crates.
CARGO_VENDOR_DIR ?= ${ WRKSRC } /cargo-crates
# Default path for cargo manifest.
CARGO_CARGOTOML ?= ${ WRKSRC } /Cargo.toml
CARGO_CARGOLOCK ?= ${ WRKSRC } /Cargo.lock
# Save crates inside ${DISTDIR}/rust/crates by default.
CARGO_DIST_SUBDIR ?= rust/crates
# Generate list of DISTFILES.
2021-04-17 07:27:24 +02:00
# Prefer canonical file extension .crate going forward
2022-04-24 12:00:20 +02:00
. i f m a k e ( m a k e s u m )
2021-04-17 07:27:24 +02:00
CARGO_CRATE_EXT = .crate
2022-04-24 12:00:20 +02:00
. e l s e
2021-04-17 07:27:24 +02:00
# 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
# DISTINFO_FILE. We cache the command output to avoid multiple
# 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 } }
2022-04-24 12:00:20 +02:00
. e n d i f
2021-09-07 16:08:46 +02:00
_CARGO_CRATES := ${ CARGO_CRATES : N *@git+* }
_CARGO_GIT_SOURCES := ${ CARGO_CRATES : M *@git+* }
2021-04-29 11:48:10 +02:00
# enumerate crates for unqiue and sane distfile group names
2021-09-07 16:08:46 +02:00
_CARGO_CRATES := ${ empty (_CARGO_CRATES) : ? : ${ _CARGO_CRATES : range : @i@ $i ${ _CARGO_CRATES : [ $i ] } @ } }
2021-04-29 11:48:10 +02:00
# split up crates into (index, crate, name, version) 4-tuples
2021-09-07 16:08:46 +02:00
_CARGO_CRATES := ${ _CARGO_CRATES : C /^([-_a-zA-Z0-9]+)-([0-9].*)/ \0 \1 \2 / }
2022-04-24 12:00:20 +02:00
. f o r _ i n d e x _ c r a t e _ n a m e _ v e r s i o n i n $ { _ C A R G O _ C R A T E S }
2021-04-14 13:53:37 +02:00
# Resolving CRATESIO alias is very inefficient with many MASTER_SITES, consume MASTER_SITE_CRATESIO directly
2021-04-29 11:48:10 +02:00
MASTER_SITES += ${ MASTER_SITE_CRATESIO : S ,%SUBDIR%, ${ _name } / ${ _version } , : S , $, : _cargo_ ${ _index } , }
DISTFILES += ${ CARGO_DIST_SUBDIR } /${ _crate } ${ CARGO_CRATE_EXT } :_cargo_${ _index }
2021-09-07 16:08:46 +02:00
# 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 }
2022-04-24 12:00:20 +02:00
. e n d f o r
2017-06-21 18:22:32 +02:00
2021-09-07 16:08:46 +02:00
_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
2022-04-24 12:00:20 +02:00
. i f ! e m p t y ( _ C A R G O _ G I T _ S O U R C E S )
. for _index _site _filename _wrksrc _crates in ${ : !${_CARGO_AWK } ${SCRIPTSDIR }/cargo -crates -git -fetch .awk /dev /null !}
2021-09-07 16:08:46 +02:00
MASTER_SITES += ${ _site } :_cargo_git${ _index }
DISTFILES += ${ _filename } :_cargo_git${ _index }
2022-04-24 12:00:20 +02:00
. for _crate in ${_crates : S /, / /g }
2021-09-07 16:08:46 +02:00
# 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 }
2022-04-24 12:00:20 +02:00
. e n d f o r
2021-09-07 16:08:46 +02:00
. e n d f o r
2022-04-24 12:00:20 +02:00
. e n d i f
2021-09-07 16:08:46 +02:00
2017-06-21 18:22:32 +02:00
# Build dependencies.
CARGO_BUILDDEP ?= yes
2022-04-24 12:00:20 +02:00
. if ${CARGO_BUILDDEP : tl } == "yes "
2022-06-29 14:21:31 +02:00
BUILD_DEPENDS += ${ RUST_DEFAULT } >= 1.62.0:lang/${ RUST_DEFAULT }
2022-04-24 12:00:20 +02:00
. e n d i f
2017-06-21 18:22:32 +02:00
2021-11-07 15:08:57 +01:00
# Location of toolchain (default to lang/rust's toolchain)
CARGO ?= ${ LOCALBASE } /bin/cargo
RUSTC ?= ${ LOCALBASE } /bin/rustc
RUSTDOC ?= ${ LOCALBASE } /bin/rustdoc
2017-06-21 18:22:32 +02:00
# Location of the cargo output directory.
CARGO_TARGET_DIR ?= ${ WRKDIR } /target
2021-09-07 11:14:10 +02:00
# Default target platform (affects some RUSTFLAGS if passed)
2021-11-07 15:15:07 +01:00
CARGO_BUILD_TARGET ?= ${ _CARGO_RUST_ARCH_ ${ ARCH } : U ${ ARCH } } -unknown-${ OPSYS : tl }
_CARGO_RUST_ARCH_amd64 = x86_64
_CARGO_RUST_ARCH_i386 = i686
2021-11-05 11:25:23 +01:00
_CARGO_RUST_ARCH_riscv64 = riscv64gc
2021-09-07 11:14:10 +02:00
2017-06-21 18:22:32 +02:00
# Environment for cargo
# - CARGO_HOME: local cache of the registry index
# - CARGO_BUILD_JOBS: configure number of jobs to run
# - CARGO_TARGET_DIR: location of where to place all generated artifacts
2020-01-30 21:00:06 +01:00
# - RUST_BACKTRACE: produce backtraces when something in the build panics
2017-06-21 18:22:32 +02:00
# - RUSTC: path of rustc binary (default to lang/rust)
# - RUSTDOC: path of rustdoc binary (default to lang/rust)
# - RUSTFLAGS: custom flags to pass to all compiler invocations that Cargo performs
CARGO_ENV += \
CARGO_HOME = ${ WRKDIR } /cargo-home \
CARGO_BUILD_JOBS = ${ MAKE_JOBS_NUMBER } \
2021-09-07 11:14:10 +02:00
CARGO_BUILD_TARGET = ${ CARGO_BUILD_TARGET } \
2017-06-21 18:22:32 +02:00
CARGO_TARGET_DIR = ${ CARGO_TARGET_DIR } \
2021-09-07 11:14:10 +02:00
CARGO_TARGET_${ CARGO_BUILD_TARGET : S /-/_/g : tu } _LINKER = " ${ CC } " \
2021-11-07 15:08:57 +01:00
RUSTC = ${ RUSTC } \
RUSTDOC = ${ RUSTDOC } \
2021-09-07 11:14:10 +02:00
RUSTFLAGS = " ${ RUSTFLAGS } ${ LDFLAGS : C /.+/-C link-arg=&/ } "
2017-06-21 18:22:32 +02:00
2022-04-24 12:00:20 +02:00
. i f ${ARCH} != powerpc
2022-03-29 20:24:27 +02:00
CARGO_ENV += RUST_BACKTRACE = 1
2022-04-24 12:00:20 +02:00
. e n d i f
2022-03-29 20:24:27 +02:00
2017-11-29 12:06:11 +01:00
# Adjust -C target-cpu if -march/-mcpu is set by bsd.cpu.mk
2022-04-24 12:00:20 +02:00
. i f ${ARCH} = = amd64 || ${ ARCH } = = i386
2017-11-29 12:06:11 +01:00
RUSTFLAGS += ${ CFLAGS : M -march=* : S /-march=/-C target-cpu=/ }
2022-04-24 12:00:20 +02:00
. elif ${ARCH : Mpowerpc *}
2020-09-19 15:01:35 +02:00
RUSTFLAGS += ${ CFLAGS : M -mcpu=* : S /-mcpu=/-C target-cpu=/ : S /power/pwr/ }
2022-04-24 12:00:20 +02:00
. e l s e
2017-11-29 12:06:11 +01:00
RUSTFLAGS += ${ CFLAGS : M -mcpu=* : S /-mcpu=/-C target-cpu=/ }
2022-04-24 12:00:20 +02:00
. e n d i f
2017-11-29 12:06:11 +01:00
2022-04-24 12:00:20 +02:00
. i f d e f i n e d ( P P C _ A B I ) & & ${PPC_ABI} = = ELFv1
2019-03-02 01:35:33 +01:00
USE_GCC ?= yes
2021-05-04 08:05:04 +02:00
STRIP_CMD = ${ LOCALBASE } /bin/strip # unsupported e_type with base strip
2022-04-24 12:00:20 +02:00
. e n d i f
2019-03-02 01:35:33 +01:00
2017-06-21 18:22:32 +02:00
# Helper to shorten cargo calls.
2021-11-07 15:08:57 +01:00
_CARGO_RUN = ${ SETENV } ${ MAKE_ENV } ${ CARGO_ENV } ${ CARGO }
2021-09-07 16:08:46 +02:00
CARGO_CARGO_RUN = cd ${ WRKSRC } ; ${ SETENV } CARGO_FREEBSD_PORTS_SKIP_GIT_UPDATE = 1 ${ _CARGO_RUN }
2017-06-21 18:22:32 +02:00
# User arguments for cargo targets.
CARGO_BUILD_ARGS ?=
CARGO_INSTALL_ARGS ?=
2019-06-10 12:56:04 +02:00
CARGO_INSTALL_PATH ?= .
2017-06-21 18:22:32 +02:00
CARGO_TEST_ARGS ?=
CARGO_UPDATE_ARGS ?=
# Use module targets ?
CARGO_BUILD ?= yes
CARGO_CONFIGURE ?= yes
CARGO_INSTALL ?= yes
CARGO_TEST ?= yes
2021-09-06 19:16:38 +02:00
# rustc stashes intermediary files in TMPDIR (default /tmp) which
# might cause issues for users that for some reason space limit
# their /tmp. WRKDIR should have plenty of space.
# Allow users and ports to still overwrite it.
2022-04-24 12:00:20 +02:00
. if ${TMPDIR : U /tmp } == /tmp
2021-09-06 19:16:38 +02:00
TMPDIR = ${ WRKDIR }
2022-04-24 12:00:20 +02:00
. e n d i f
2021-09-06 19:16:38 +02:00
2017-06-21 18:22:32 +02:00
# Manage crate features.
2022-04-24 12:00:20 +02:00
. if !empty(CARGO_FEATURES : M --no -default -features )
2020-03-04 16:00:17 +01:00
CARGO_BUILD_ARGS += --no-default-features
CARGO_INSTALL_ARGS += --no-default-features
CARGO_TEST_ARGS += --no-default-features
2022-04-24 12:00:20 +02:00
. e n d i f
. if !empty(CARGO_FEATURES : N --no -default -features )
2020-03-04 16:00:17 +01:00
CARGO_BUILD_ARGS += --features= '${CARGO_FEATURES:N--no-default-features}'
CARGO_INSTALL_ARGS += --features= '${CARGO_FEATURES:N--no-default-features}'
CARGO_TEST_ARGS += --features= '${CARGO_FEATURES:N--no-default-features}'
2022-04-24 12:00:20 +02:00
. e n d i f
2017-06-21 18:22:32 +02:00
2022-04-24 12:00:20 +02:00
. i f ! d e f i n e d ( W I T H _ D E B U G )
2017-06-21 18:22:32 +02:00
CARGO_BUILD_ARGS += --release
CARGO_TEST_ARGS += --release
2022-04-24 12:00:20 +02:00
. e l s e
2017-06-21 18:22:32 +02:00
CARGO_INSTALL_ARGS += --debug
2022-04-24 12:00:20 +02:00
. e n d i f
2017-06-21 18:22:32 +02:00
2022-04-24 12:00:20 +02:00
. if ${_CARGO_CRATES : Mcmake }
2018-06-14 11:56:02 +02:00
BUILD_DEPENDS += cmake:devel/cmake
2022-04-24 12:00:20 +02:00
. e n d i f
2018-06-14 11:56:02 +02:00
2022-04-24 12:00:20 +02:00
. if ${_CARGO_CRATES : Mgettext -sys }
2018-06-14 11:56:02 +02:00
CARGO_ENV += GETTEXT_BIN_DIR = ${ LOCALBASE } /bin \
GETTEXT_INCLUDE_DIR = ${ LOCALBASE } /include \
GETTEXT_LIB_DIR = ${ LOCALBASE } /lib
2022-04-24 12:00:20 +02:00
. e n d i f
2018-06-14 11:56:02 +02:00
2022-04-24 12:00:20 +02:00
. if ${_CARGO_CRATES : Mjemalloc -sys }
2019-09-16 14:39:57 +02:00
BUILD_DEPENDS += gmake:devel/gmake
2022-04-24 12:00:20 +02:00
. e n d i f
2019-09-16 14:39:57 +02:00
2022-04-24 12:00:20 +02:00
. if ${_CARGO_CRATES : Mlibgit 2-sys }
2017-06-21 18:22:32 +02:00
# Use the system's libgit2 instead of building the bundled version
CARGO_ENV += LIBGIT2_SYS_USE_PKG_CONFIG = 1
2022-04-24 12:00:20 +02:00
. e n d i f
2017-06-21 18:22:32 +02:00
2022-04-24 12:00:20 +02:00
. if ${_CARGO_CRATES : Mlibssh 2-sys }
2018-09-21 13:16:08 +02:00
# Use the system's libssh2 instead of building the bundled version
CARGO_ENV += LIBSSH2_SYS_USE_PKG_CONFIG = 1
2022-04-24 12:00:20 +02:00
. e n d i f
2018-09-21 13:16:08 +02:00
2022-04-24 12:00:20 +02:00
. if ${_CARGO_CRATES : Monig_sys }
2018-06-14 11:56:02 +02:00
# onig_sys always prefers the system library but will try to link
# statically with it. Since devel/oniguruma doesn't provide a static
# library it'll link to libonig.so instead. Strictly speaking setting
# RUSTONIG_SYSTEM_LIBONIG is not necessary, but will force onig_sys to
# always use the system's libonig as returned by `pkg-config oniguruma`.
CARGO_ENV += RUSTONIG_SYSTEM_LIBONIG = 1
2022-04-24 12:00:20 +02:00
. e n d i f
2018-06-14 11:56:02 +02:00
2022-04-24 12:00:20 +02:00
. if ${_CARGO_CRATES : Mopenssl -src }
2020-04-04 09:40:38 +02:00
DEV_WARNING += " Please make sure this port uses the system OpenSSL and consider removing CARGO_CRATES= ${ CARGO_CRATES : Mopenssl -src-[0-9]* } (a vendored copy of OpenSSL) from the build, e.g., by patching Cargo.toml appropriately. "
2022-04-24 12:00:20 +02:00
. e n d i f
2020-04-04 09:40:38 +02:00
2022-04-24 12:00:20 +02:00
. if ${_CARGO_CRATES : Mopenssl -sys }
2017-06-21 18:22:32 +02:00
# Make sure that openssl-sys can find the correct version of OpenSSL
CARGO_ENV += OPENSSL_LIB_DIR = ${ OPENSSLLIB } \
OPENSSL_INCLUDE_DIR = ${ OPENSSLINC }
2022-04-24 12:00:20 +02:00
. e n d i f
2017-06-21 18:22:32 +02:00
2022-04-24 12:00:20 +02:00
. if ${_CARGO_CRATES : Mpkg -config }
2017-06-21 18:22:32 +02:00
. i n c l u d e "${USESDIR}/pkgconfig.mk"
2022-04-24 12:00:20 +02:00
. e n d i f
2017-06-21 18:22:32 +02:00
2022-04-24 12:00:20 +02:00
. f o r _ i n d e x _ c r a t e _ n a m e _ v e r s i o n i n $ { _ C A R G O _ C R A T E S }
2021-04-29 11:48:10 +02:00
# Split up semantic version and try to sanitize it by removing
# pre-release identifier (-) or build metadata (+)
2022-04-24 12:00:20 +02:00
. if ${_version : S /./ /:S /./ /:C /[-+].*//:_ :[#]} == 3
. f o r _ m a j o r _ m i n o r _ p a t c h i n $ _
2021-04-29 11:48:10 +02:00
# FreeBSD 12.0 changed ABI: r318736 and r320043
# https://github.com/rust-lang/libc/commit/78f93220d70e
# https://github.com/rust-lang/libc/commit/969ad2b73cdc
2022-04-24 12:00:20 +02:00
. i f ${_name} = = libc && ${ _major } = = 0 && ( ${ _minor } < 2 || ( ${ _minor } = = 2 && ${ _patch } < 38) )
2021-04-29 11:48:10 +02:00
DEV_ERROR += " CARGO_CRATES= ${ _crate } may be unstable on FreeBSD 12.0. Consider updating to the latest version \(higher than 0.2.37\). "
2022-04-24 12:00:20 +02:00
. e n d i f
. i f ${_name} = = libc && ${ _major } = = 0 && ( ${ _minor } < 2 || ( ${ _minor } = = 2 && ${ _patch } < 49) )
2021-04-29 11:48:10 +02:00
DEV_ERROR += " CARGO_CRATES= ${ _crate } may be unstable on aarch64 or not build on armv6, armv7, powerpc64. Consider updating to the latest version \(higher than 0.2.49\). "
2022-04-24 12:00:20 +02:00
. e n d i f
2021-04-29 11:48:10 +02:00
# FreeBSD 12.0 updated base OpenSSL in r339270:
# https://github.com/sfackler/rust-openssl/commit/276577553501
2022-04-24 12:00:20 +02:00
. i f ${_name} = = openssl && !exists( ${ PATCHDIR } /patch-openssl-1.1.1) && ${ _major } = = 0 && ( ${ _minor } < 10 || ( ${ _minor } = = 10 && ${ _patch } < 4) )
2021-04-29 11:48:10 +02:00
DEV_WARNING += " CARGO_CRATES= ${ _crate } does not support OpenSSL 1.1.1. Consider updating to the latest version \(higher than 0.10.3\). "
2022-04-24 12:00:20 +02:00
. e n d i f
. e n d f o r
. e n d i f
. e n d f o r
2021-04-29 11:48:10 +02:00
2017-06-21 18:22:32 +02:00
_USES_extract += 600:cargo-extract
cargo-extract :
# target for preparing crates directory. It will put all crates in
# the local crates directory.
@${ ECHO_MSG } " ===> Moving crates to ${ CARGO_VENDOR_DIR } "
@${ MKDIR } ${ CARGO_VENDOR_DIR }
2022-04-24 12:00:20 +02:00
. f o r _ i n d e x _ c r a t e _ n a m e _ v e r s i o n i n $ { _ C A R G O _ C R A T E S }
. i f ${_index} != @git
2017-06-21 18:22:32 +02:00
@${ MV } ${ WRKDIR } /${ _crate } ${ CARGO_VENDOR_DIR } /${ _crate }
@${ PRINTF } '{"package":"%s","files":{}}' \
2021-04-17 07:27:24 +02:00
$$ ( ${ SHA256 } -q ${ DISTDIR } /${ CARGO_DIST_SUBDIR } /${ _crate } ${ CARGO_CRATE_EXT } ) \
2017-06-21 18:22:32 +02:00
> ${ CARGO_VENDOR_DIR } /${ _crate } /.cargo-checksum.json
2019-05-24 09:57:11 +02:00
@if [ -r ${ CARGO_VENDOR_DIR } /${ _crate } /Cargo.toml.orig ] ; then \
${ MV } ${ CARGO_VENDOR_DIR } /${ _crate } /Cargo.toml.orig \
${ CARGO_VENDOR_DIR } /${ _crate } /Cargo.toml.orig-cargo; \
fi
2022-04-24 12:00:20 +02:00
. e n d i f
. e n d f o r
2017-06-21 18:22:32 +02:00
2022-04-24 12:00:20 +02:00
. if ${CARGO_CONFIGURE : tl } == "yes "
2019-12-01 09:43:43 +01:00
_USES_configure += 250:cargo-configure
2017-06-21 18:22:32 +02:00
# configure hook. Place a config file for overriding crates-io index
# by local source directory.
2019-12-01 09:43:43 +01:00
cargo-configure :
2020-01-13 19:36:04 +01:00
# Check that the running kernel has COMPAT_FREEBSD11 required by lang/rust post-ino64
@${ SETENV } CC = " ${ CC } " OPSYS = " ${ OPSYS } " OSVERSION = " ${ OSVERSION } " WRKDIR = " ${ WRKDIR } " \
${ SH } ${ SCRIPTSDIR } /rust-compat11-canary.sh
2021-09-07 16:08:46 +02:00
@${ ECHO_MSG } "===> Cargo config:"
2017-06-21 18:22:32 +02:00
@${ MKDIR } ${ WRKDIR } /.cargo
2021-09-07 16:08:46 +02:00
@: > ${ WRKDIR } /.cargo/config.toml
@${ ECHO_CMD } "[source.cargo]" >> ${ WRKDIR } /.cargo/config.toml
@${ ECHO_CMD } " directory = ' ${ CARGO_VENDOR_DIR } ' " >> ${ WRKDIR } /.cargo/config.toml
@${ ECHO_CMD } "[source.crates-io]" >> ${ WRKDIR } /.cargo/config.toml
@${ ECHO_CMD } "replace-with = 'cargo'" >> ${ WRKDIR } /.cargo/config.toml
2022-04-24 12:00:20 +02:00
. i f ! e m p t y ( _ C A R G O _ G I T _ S O U R C E S )
2021-09-07 16:08:46 +02:00
@${ _CARGO_AWK } ${ SCRIPTSDIR } /cargo-crates-git-configure.awk \
/dev/null >> ${ WRKDIR } /.cargo/config.toml
2022-04-24 12:00:20 +02:00
. e n d i f
2021-09-07 16:08:46 +02:00
@${ CAT } ${ WRKDIR } /.cargo/config.toml
2017-06-21 18:22:32 +02:00
@if ! ${ GREP } -qF '[profile.release]' ${ CARGO_CARGOTOML } ; then \
${ ECHO_CMD } "" >> ${ CARGO_CARGOTOML } ; \
${ ECHO_CMD } "[profile.release]" >> ${ CARGO_CARGOTOML } ; \
${ ECHO_CMD } "opt-level = 2" >> ${ CARGO_CARGOTOML } ; \
${ ECHO_CMD } "debug = false" >> ${ CARGO_CARGOTOML } ; \
fi
2021-09-07 16:08:46 +02:00
@${ ECHO_MSG } "===> Updating Cargo.lock"
2017-06-21 18:22:32 +02:00
@${ CARGO_CARGO_RUN } update \
--manifest-path ${ CARGO_CARGOTOML } \
--verbose \
2021-04-13 09:01:20 +02:00
--verbose \
2017-06-21 18:22:32 +02:00
${ CARGO_UPDATE_ARGS }
2022-04-24 12:00:20 +02:00
. e n d i f
2017-06-21 18:22:32 +02:00
2022-04-24 12:00:20 +02:00
. if !target(do-build) && ${CARGO_BUILD : tl } == "yes "
2017-06-21 18:22:32 +02:00
do-build :
@${ CARGO_CARGO_RUN } build \
--manifest-path ${ CARGO_CARGOTOML } \
--verbose \
2021-04-13 09:01:20 +02:00
--verbose \
2017-06-21 18:22:32 +02:00
${ CARGO_BUILD_ARGS }
2022-04-24 12:00:20 +02:00
. e n d i f
2017-06-21 18:22:32 +02:00
2022-04-24 12:00:20 +02:00
. if !target(do-install) && ${CARGO_INSTALL : tl } == "yes "
2017-06-21 18:22:32 +02:00
do-install :
2022-04-24 12:00:20 +02:00
. f o r p a t h i n $ { C A R G O _ I N S T A L L _ P A T H }
2017-06-21 18:22:32 +02:00
@${ CARGO_CARGO_RUN } install \
2020-01-30 21:00:06 +01:00
--no-track \
2019-06-10 12:56:04 +02:00
--path " ${ path } " \
2017-06-21 18:22:32 +02:00
--root " ${ STAGEDIR } ${ PREFIX } " \
--verbose \
2021-04-13 09:01:20 +02:00
--verbose \
2017-06-21 18:22:32 +02:00
${ CARGO_INSTALL_ARGS }
2022-04-24 12:00:20 +02:00
. e n d f o r
. e n d i f
2017-06-21 18:22:32 +02:00
2022-04-24 12:00:20 +02:00
. if !target(do-test) && ${CARGO_TEST : tl } == "yes "
2017-06-21 18:22:32 +02:00
do-test :
@${ CARGO_CARGO_RUN } test \
--manifest-path ${ CARGO_CARGOTOML } \
--verbose \
2021-04-13 09:01:20 +02:00
--verbose \
2017-06-21 18:22:32 +02:00
${ CARGO_TEST_ARGS }
2022-04-24 12:00:20 +02:00
. e n d i f
2017-06-21 18:22:32 +02:00
#
# Helper targets for port maintainers
#
2022-04-15 13:51:18 +02:00
# cargo-audit generates a vulnerability report using
# security/cargo-audit based on the crates in Cargo.lock.
cargo-audit : configure
@if ! type cargo-audit > /dev/null 2>& 1; then \
${ ECHO_MSG } "===> Please install \"security/cargo-audit\"" ; exit 1; \
fi
@${ ECHO_MSG } "===> Checking for vulnerable crates"
@${ CARGO } audit --file ${ CARGO_CARGOLOCK }
2018-09-04 09:26:02 +02:00
# cargo-crates will output the crates list from Cargo.lock. If there
# is no Cargo.lock for some reason, try and generate it first.
2021-10-26 13:01:27 +02:00
cargo-crates : cargo -crates -generate -lockfile
@${ _CARGO_AWK } ${ SCRIPTSDIR } /cargo-crates.awk ${ CARGO_CARGOLOCK }
# cargo-crates-generate-lockfile will try to generate a Cargo.lock file
# if it does not exist.
cargo-crates-generate-lockfile : extract
2018-09-04 09:26:02 +02:00
@if [ ! -r " ${ CARGO_CARGOLOCK } " ] ; then \
${ ECHO_MSG } " ===> ${ CARGO_CARGOLOCK } not found. Trying to generate it... " ; \
2021-09-07 16:08:46 +02:00
cd ${ WRKSRC } ; ${ _CARGO_RUN } generate-lockfile \
2018-09-04 09:26:02 +02:00
--manifest-path ${ CARGO_CARGOTOML } \
--verbose; \
fi
2017-06-21 18:22:32 +02:00
# cargo-crates-licenses will try to grab license information from
# all downloaded crates.
cargo-crates-licenses : configure
@${ FIND } ${ CARGO_VENDOR_DIR } -name 'Cargo.toml' -maxdepth 2 \
-exec ${ GREP } -H '^license' { } \; \
| ${ SED } \
-e 's@^${CARGO_VENDOR_DIR}/@@' \
-e 's@/Cargo.toml:license.*= *"@|@' \
2018-06-14 11:56:02 +02:00
-e 's@"$$@@g' | sort | /usr/bin/column -t -s '|'
2021-10-26 13:01:27 +02:00
# cargo-crates-merge will in-place update CARGO_CRATES in the port
# based on the crates list from Cargo.lock. If there is no Cargo.lock
# for some reason, try and generate it first.
2022-04-15 10:45:54 +02:00
cargo-crates-merge :
2021-10-26 13:01:27 +02:00
@if ! type portedit > /dev/null 2>& 1; then \
${ ECHO_MSG } "===> Please install \"ports-mgmt/portfmt\"" ; exit 1; \
fi
2022-04-15 10:45:54 +02:00
@${ MAKE } clean cargo-crates-generate-lockfile
2021-10-26 13:01:27 +02:00
@f= " ${ MASTERDIR } /Makefile " ; [ -r " ${ MASTERDIR } /Makefile.crates " ] && f = " ${ MASTERDIR } /Makefile.crates " ; \
${ _CARGO_AWK } ${ SCRIPTSDIR } /cargo-crates.awk ${ CARGO_CARGOLOCK } | \
portedit merge -i $$ f; \
2022-04-15 10:45:54 +02:00
${ MAKE } clean makesum; \
${ ECHO_MSG } " ${ DISTINFO_FILE } and CARGO_CRATES in $$ f were updated " ;
2021-10-26 13:01:27 +02:00
2017-06-21 18:22:32 +02:00
. e n d i f