Changeset View
Standalone View
Mk/Uses/cargo.mk
- This file was added.
Property | Old Value | New Value |
---|---|---|
svn:eol-style | null | native \ No newline at end of property |
svn:keywords | null | FreeBSD=%H \ No newline at end of property |
svn:mime-type | null | text/plain \ No newline at end of property |
# $FreeBSD$ | |||||
# | |||||
# This file contains logic to ease porting of Rust packages or binaries using | |||||
# the `cargo` command. | |||||
# | |||||
# Feature: cargo | |||||
# Usage: USES=cargo | |||||
# Valid ARGS: none | |||||
# | |||||
mat: You should add a check to make sure no args are passed. | |||||
# MAINTAINER: ports@FreeBSD.org | |||||
.if !defined(_INCLUDE_USES_CARGO_MK) | |||||
_INCLUDE_USES_CARGO_MK= yes | |||||
.if !empty(cargo_ARGS) | |||||
IGNORE+= USES=cargo takes no arguments | |||||
.endif | |||||
CARGO_CMD?= ${LOCALBASE}/bin/cargo | |||||
# List of static dependencies. The format is cratename-version. | |||||
# CARGO_CRATES will be downloaded from MASTER_SITES_CRATESIO. | |||||
CARGO_CRATES?= | |||||
# List of features to build (space separated list). | |||||
CARGO_FEATURES?= | |||||
# List of crates to update (no version). | |||||
# Used to override a dependency with newer version. | |||||
CARGO_CRATES_UPDATE?= | |||||
# Name of the local directory for vendoring crates. | |||||
CARGO_VENDOR_DIR?= ${WRKSRC}/cargo-crates | |||||
# Default path for cargo manifest. | |||||
CARGO_CARGOTOML?= ${WRKSRC}/Cargo.toml | |||||
# Define MASTER_SITES_CRATESIO for crates.io | |||||
MASTER_SITES_CRATESIO= https://crates.io/api/v1/crates | |||||
Done Inline ActionsShould probably be something along the lines of: CARGO_DIST_SUBDIR?= ${DIST_SUBDIR:Ucargo} mat: Should probably be something along the lines of:
```
CARGO_DIST_SUBDIR?= ${DIST_SUBDIR… | |||||
# Save crates inside ${DISTDIR}/rust/crates by default. | |||||
CARGO_DIST_SUBDIR?= rust/crates | |||||
Done Inline ActionsCould we use a subdirectory of ${DISTDIR}/rust? We already use this to put Rust and Cargo source archives & bootstraps. Also, the name doesn't reflect the content: we would store crate archives, not Cargo itself. I suggest: CARGO_DIST_SUBDIR?= rust/crates dumbbell: Could we use a subdirectory of `${DISTDIR}/rust`? We already use this to put Rust and Cargo… | |||||
# Generate list of DISTFILES. | |||||
.for _crate in ${CARGO_CRATES} | |||||
MASTER_SITES+= ${MASTER_SITES_CRATESIO}/${_crate:C/-[^-]*$//}/${_crate:C/^.*-//}/download?dummy=/:cargo_${_crate:S/-//g:S/.//g} | |||||
Done Inline ActionsVariables starting with an _ are supposed to be private, but nothing uses this one here. mat: Variables starting with an _ are supposed to be private, but nothing uses this one here. | |||||
DISTFILES+= ${CARGO_DIST_SUBDIR}/${_crate}.tar.gz:cargo_${_crate:S/-//g:S/.//g} | |||||
.endfor | |||||
# Build dependencies. | |||||
Done Inline ActionsMASTER_SITES+= CRATESIO:cargo (I spent a lot of time going over all the ports tree for this, please don't add more :-) mat: ```
MASTER_SITES+= CRATESIO:cargo
```
(I spent a lot of time going over all the ports tree… | |||||
PATCH_DEPENDS+= cargo-generate-vendor:devel/cargo-generate-vendor | |||||
BUILD_DEPENDS+= cargo-generate-vendor:devel/cargo-generate-vendor | |||||
CARGO_BUILDDEP?= yes | |||||
.if ${CARGO_BUILDDEP:tl} == "yes" | |||||
BUILD_DEPENDS+= cargo:devel/cargo rustc:lang/rust | |||||
.endif | |||||
# Location of cargo binary (default to devel/cargo binary) | |||||
CARGO_CARGO_BIN?= ${LOCALBASE}/bin/cargo | |||||
# Location of the cargo output directory. | |||||
CARGO_TARGET_DIR?= ${WRKDIR}/target | |||||
# Environment for cargo | |||||
Done Inline ActionsInstead of putting all the shell code in a variable that you then use later in the target, could you put all the code in the target directly ? (same for patch and confirgure.) mat: Instead of putting all the shell code in a variable that you then use later in the target… | |||||
Done Inline ActionsMoved everything to the relevant targets. I also removed the cargo-metadata target since this is basically the same now as post-patch. tobik: Moved everything to the relevant targets. I also removed the `cargo-metadata` target since this… | |||||
# - 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 | |||||
# - 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 | |||||
# | |||||
# XXX LDFLAGS => -C link-arg=$1 (via RUSTFLAGS) | |||||
CARGO_ENV+= \ | |||||
CARGO_HOME=${WRKDIR}/cargo-home \ | |||||
CARGO_BUILD_JOBS=${MAKE_JOBS_NUMBER} \ | |||||
CARGO_TARGET_DIR=${CARGO_TARGET_DIR} \ | |||||
RUSTC=${LOCALBASE}/bin/rustc \ | |||||
RUSTDOC=${LOCALBASE}/bin/rustdoc \ | |||||
RUSTFLAGS="${RUSTFLAGS}" | |||||
# Helper to shorten cargo calls. | |||||
CARGO_CARGO_RUN= \ | |||||
cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} ${CARGO_ENV} \ | |||||
${CARGO_CARGO_BIN} | |||||
# User arguments for cargo targets. | |||||
CARGO_BUILD_ARGS?= | |||||
CARGO_INSTALL_ARGS?= | |||||
CARGO_TEST_ARGS?= | |||||
# Manage crate features. | |||||
.if !empty(CARGO_FEATURES) | |||||
CARGO_BUILD_ARGS+= --features='${CARGO_FEATURES}' | |||||
CARGO_TEST_ARGS+= --features='${CARGO_FEATURES}' | |||||
.endif | |||||
# Helper for updating a crate. | |||||
CARGO_CARGO_UPDATE= \ | |||||
${CARGO_CARGO_RUN} update \ | |||||
--manifest-path ${CARGO_CARGOTOML} \ | |||||
--verbose | |||||
# Use module targets ? | |||||
CARGO_BUILD?= yes | |||||
Done Inline ActionsI'm not sure creating a variable for this is interesting, it is only used once, and is not overridable. mat: I'm not sure creating a variable for this is interesting, it is only used once, and is not… | |||||
CARGO_INSTALL?= yes | |||||
CARGO_TEST?= yes | |||||
CARGO_CONFIGURE?= yes | |||||
_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} | |||||
.for _crate in ${CARGO_CRATES} | |||||
@${MV} ${WRKDIR}/${_crate} ${CARGO_VENDOR_DIR}/${_crate} | |||||
.endfor | |||||
_USES_patch+= 600:cargo-patch | |||||
cargo-patch: | |||||
# target for generating crate metadata. | |||||
.for _crate in ${CARGO_CRATES} | |||||
@${ECHO_MSG} "===> Generating metadata for ${_crate}" | |||||
@${LOCALBASE}/bin/cargo-generate-vendor \ | |||||
${DISTDIR}/${CARGO_DIST_SUBDIR}/${_crate}.tar.gz \ | |||||
Not Done Inline ActionsTo make this easier to read, you might want to either pre-parse _tuple in local variables, or use the ${GH_(ACCOUNT|PROJET)_${_tagname}} variables that are created by the framework. Also, this might not work if the port does not use the GH_TUPLE but the regular GH_* variables. You might want to iterate over something else like GH_ACCOUNT. (But it may not be ready at that time. mat: To make this easier to read, you might want to either pre-parse _tuple in local variables, or… | |||||
Not Done Inline ActionsI'd nice if I was able to iterate over ${_GITHUB_GROUPS:NDEFAULT} but that of course doesn't work. :-( tobik: I'd nice if I was able to iterate over `${_GITHUB_GROUPS:NDEFAULT}` but that of course doesn't… | |||||
Not Done Inline ActionsYou cannot iterate over it because the variable starts with an _ and is local to the github code from bsd.site.mk. mat: You cannot iterate over it because the variable starts with an _ and is local to the github… | |||||
${CARGO_VENDOR_DIR}/${_crate} | |||||
.endfor | |||||
.if !target(do-configure) && ${CARGO_CONFIGURE:tl} == "yes" | |||||
# configure hook. Place a config file for overriding crates-io index | |||||
# by local source directory. | |||||
do-configure: | |||||
@${MKDIR} ${WRKDIR}/.cargo | |||||
Done Inline ActionsShould have thought about this earlier. USES usually do not override pre-/post-, they create their own targets and hook them up with _USES_xxx, see other USES (say, perl5.mk, there is a fixup thing near the end). It allows ports to have their own pre-/post- targets in case they also need to do something else. mat: Should have thought about this earlier.
USES usually do not override pre-/post-, they create… | |||||
@${ECHO_CMD} "[source.cargo]" > ${WRKDIR}/.cargo/config | |||||
@${ECHO_CMD} "directory = '${CARGO_VENDOR_DIR}'" >> ${WRKDIR}/.cargo/config | |||||
@${ECHO_CMD} "[source.crates-io]" >> ${WRKDIR}/.cargo/config | |||||
@${ECHO_CMD} "replace-with = 'cargo'" >> ${WRKDIR}/.cargo/config | |||||
@if ! ${GREP} -qF '[profile.release]' ${CARGO_CARGOTOML}; then \ | |||||
${ECHO_CMD} "" >>${CARGO_CARGOTOML}; \ | |||||
Done Inline ActionsI don't really like this. It would be better as being part of the do-configure. Something like: ${CARGO_CARGO_UPDATE} ${CARGO_CRATES_UPDATE:S/^/--package /}; or something. mat: I don't really like this. It would be better as being part of the do-configure. Something like… | |||||
${ECHO_CMD} "[profile.release]" >>${CARGO_CARGOTOML}; \ | |||||
${ECHO_CMD} "opt-level = 2" >>${CARGO_CARGOTOML}; \ | |||||
${ECHO_CMD} "debug = false" >>${CARGO_CARGOTOML}; \ | |||||
fi | |||||
# Update crates: place all crates on the same command line. | |||||
.if !empty(CARGO_CRATES_UPDATE) | |||||
@${CARGO_CARGO_UPDATE} ${CARGO_CRATES_UPDATE:S/^/--package /} | |||||
.endif | |||||
.endif | |||||
.if !target(do-build) && ${CARGO_BUILD:tl} == "yes" | |||||
do-build: | |||||
@${CARGO_CARGO_RUN} build \ | |||||
--manifest-path ${CARGO_CARGOTOML} \ | |||||
--release \ | |||||
--verbose \ | |||||
${CARGO_BUILD_ARGS} | |||||
.endif | |||||
.if !target(do-install) && ${CARGO_INSTALL:tl} == "yes" | |||||
do-install: | |||||
@${CARGO_CARGO_RUN} install \ | |||||
--root="${STAGEDIR}${PREFIX}" \ | |||||
--verbose \ | |||||
${CARGO_INSTALL_ARGS} | |||||
@${RM} -- "${STAGEDIR}${PREFIX}/.crates.toml" | |||||
.endif | |||||
.if !target(do-test) && ${CARGO_TEST:tl} == "yes" | |||||
do-test: | |||||
@${CARGO_CARGO_RUN} test \ | |||||
--manifest-path ${CARGO_CARGOTOML} \ | |||||
--release \ | |||||
--verbose \ | |||||
${CARGO_TEST_ARGS} | |||||
.endif | |||||
# | |||||
# Helper targets for port maintainers | |||||
# | |||||
# cargo-crates will output the crates list from Cargo.lock file. | |||||
cargo-crates: extract | |||||
@${ECHO_CMD} -n "CARGO_CRATES=" | |||||
@${AWK} 'BEGIN { i = 0 } /"checksum / { \ | |||||
if (i == 0) { \ | |||||
Done Inline ActionsSame here, put everything in the target. mat: Same here, put everything in the target. | |||||
print " " $$2 "-" $$3 " \\"; \ | |||||
i = 1 \ | |||||
} else { \ | |||||
print " " $$2 "-" $$3 " \\" \ | |||||
} \ | |||||
}' ${WRKSRC}/Cargo.lock | |||||
# cargo-crates-licenses will try to grab license information from | |||||
# downloaded crates. | |||||
cargo-crates-licenses: configure | |||||
@${FIND} ${CARGO_VENDOR_DIR} -name 'Cargo.toml' -maxdepth 2 \ | |||||
-exec ${GREP} -H '^license' {} \; \ | |||||
| ${SED} \ | |||||
Done Inline Actionssame. mat: same. | |||||
-e 's@^${CARGO_VENDOR_DIR}/@@' \ | |||||
-e 's@/Cargo.toml:license.*= *"@|@' \ | |||||
-e 's@"$$@@g' | /usr/bin/column -t -s '|' | |||||
.endif | |||||
Done Inline ActionsKeep the targets sorted. # make -V _TARGETS_STAGES SANITY PKG FETCH EXTRACT PATCH CONFIGURE BUILD INSTALL TEST PACKAGE STAGE mat: Keep the targets sorted.
```
# make -V _TARGETS_STAGES
SANITY PKG FETCH EXTRACT PATCH… |
You should add a check to make sure no args are passed.