rust: support structuredAttrs in setup hooks (#340862)
This commit is contained in:
commit
bf5f0b6e70
@ -1,4 +1,4 @@
|
||||
declare -a cargoBuildFlags
|
||||
# shellcheck shell=bash disable=SC2154,SC2164
|
||||
|
||||
cargoBuildHook() {
|
||||
echo "Executing cargoBuildHook"
|
||||
@ -9,44 +9,38 @@ cargoBuildHook() {
|
||||
# separateDebugInfo.
|
||||
export "CARGO_PROFILE_${cargoBuildType@U}_STRIP"=false
|
||||
|
||||
if [ ! -z "${buildAndTestSubdir-}" ]; then
|
||||
if [ -n "${buildAndTestSubdir-}" ]; then
|
||||
# ensure the output doesn't end up in the subdirectory
|
||||
export CARGO_TARGET_DIR="$(pwd)/target"
|
||||
CARGO_TARGET_DIR="$(pwd)/target"
|
||||
export CARGO_TARGET_DIR
|
||||
|
||||
pushd "${buildAndTestSubdir}"
|
||||
fi
|
||||
|
||||
local flagsArray=(
|
||||
"-j" "$NIX_BUILD_CORES"
|
||||
"--target" "@rustHostPlatformSpec@"
|
||||
"--offline"
|
||||
)
|
||||
|
||||
if [ "${cargoBuildType}" != "debug" ]; then
|
||||
cargoBuildProfileFlag="--profile ${cargoBuildType}"
|
||||
flagsArray+=("--profile" "${cargoBuildType}")
|
||||
fi
|
||||
|
||||
if [ -n "${cargoBuildNoDefaultFeatures-}" ]; then
|
||||
cargoBuildNoDefaultFeaturesFlag=--no-default-features
|
||||
flagsArray+=("--no-default-features")
|
||||
fi
|
||||
|
||||
if [ -n "${cargoBuildFeatures-}" ]; then
|
||||
if [ -n "$__structuredAttrs" ]; then
|
||||
OLDIFS="$IFS"
|
||||
IFS=','; cargoBuildFeaturesFlag="--features=${cargoBuildFeatures[*]}"
|
||||
IFS="$OLDIFS"
|
||||
unset OLDIFS
|
||||
else
|
||||
cargoBuildFeaturesFlag="--features=${cargoBuildFeatures// /,}"
|
||||
fi
|
||||
flagsArray+=("--features=$(concatStringsSep "," cargoBuildFeatures)")
|
||||
fi
|
||||
|
||||
(
|
||||
set -x
|
||||
@setEnv@ cargo build -j $NIX_BUILD_CORES \
|
||||
--target @rustHostPlatformSpec@ \
|
||||
--offline \
|
||||
${cargoBuildProfileFlag} \
|
||||
${cargoBuildNoDefaultFeaturesFlag} \
|
||||
${cargoBuildFeaturesFlag} \
|
||||
${cargoBuildFlags}
|
||||
)
|
||||
concatTo flagsArray cargoBuildFlags
|
||||
|
||||
if [ ! -z "${buildAndTestSubdir-}" ]; then
|
||||
echoCmd 'cargoBuildHook flags' "${flagsArray[@]}"
|
||||
@setEnv@ cargo build "${flagsArray[@]}"
|
||||
|
||||
if [ -n "${buildAndTestSubdir-}" ]; then
|
||||
popd
|
||||
fi
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
declare -a checkFlags
|
||||
declare -a cargoTestFlags
|
||||
# shellcheck shell=bash disable=SC2154,SC2164
|
||||
|
||||
cargoCheckHook() {
|
||||
echo "Executing cargoCheckHook"
|
||||
@ -10,37 +9,37 @@ cargoCheckHook() {
|
||||
pushd "${buildAndTestSubdir}"
|
||||
fi
|
||||
|
||||
local flagsArray=("-j" "$NIX_BUILD_CORES")
|
||||
|
||||
if [[ -z ${dontUseCargoParallelTests-} ]]; then
|
||||
threads=$NIX_BUILD_CORES
|
||||
prependToVar checkFlags "--test-threads=$NIX_BUILD_CORES"
|
||||
else
|
||||
threads=1
|
||||
prependToVar checkFlags "--test-threads=1"
|
||||
fi
|
||||
|
||||
if [ "${cargoCheckType}" != "debug" ]; then
|
||||
cargoCheckProfileFlag="--profile ${cargoCheckType}"
|
||||
flagsArray+=("--profile" "${cargoCheckType}")
|
||||
fi
|
||||
|
||||
if [ -n "${cargoCheckNoDefaultFeatures-}" ]; then
|
||||
cargoCheckNoDefaultFeaturesFlag=--no-default-features
|
||||
flagsArray+=("--no-default-features")
|
||||
fi
|
||||
|
||||
if [ -n "${cargoCheckFeatures-}" ]; then
|
||||
cargoCheckFeaturesFlag="--features=${cargoCheckFeatures// /,}"
|
||||
flagsArray+=("--features=$(concatStringsSep "," cargoCheckFeatures)")
|
||||
fi
|
||||
|
||||
argstr="${cargoCheckProfileFlag} ${cargoCheckNoDefaultFeaturesFlag} ${cargoCheckFeaturesFlag}
|
||||
--target @rustHostPlatformSpec@ --offline ${cargoTestFlags}"
|
||||
|
||||
(
|
||||
set -x
|
||||
cargo test \
|
||||
-j $NIX_BUILD_CORES \
|
||||
${argstr} -- \
|
||||
--test-threads=${threads} \
|
||||
${checkFlags} \
|
||||
${checkFlagsArray+"${checkFlagsArray[@]}"}
|
||||
flagsArray+=(
|
||||
"--target" "@rustHostPlatformSpec@"
|
||||
"--offline"
|
||||
)
|
||||
|
||||
prependToVar checkFlags "--"
|
||||
concatTo flagsArray cargoTestFlags checkFlags checkFlagsArray
|
||||
|
||||
echoCmd 'cargoCheckHook flags' "${flagsArray[@]}"
|
||||
cargo test "${flagsArray[@]}"
|
||||
|
||||
if [[ -n "${buildAndTestSubdir-}" ]]; then
|
||||
popd
|
||||
fi
|
||||
|
@ -1,5 +1,4 @@
|
||||
declare -a checkFlags
|
||||
declare -a cargoTestFlags
|
||||
# shellcheck shell=bash disable=SC2154,SC2164
|
||||
|
||||
cargoNextestHook() {
|
||||
echo "Executing cargoNextestHook"
|
||||
@ -10,35 +9,34 @@ cargoNextestHook() {
|
||||
pushd "${buildAndTestSubdir}"
|
||||
fi
|
||||
|
||||
local flagsArray=(
|
||||
"--target" "@rustHostPlatformSpec@"
|
||||
"--offline"
|
||||
)
|
||||
|
||||
if [[ -z ${dontUseCargoParallelTests-} ]]; then
|
||||
threads=$NIX_BUILD_CORES
|
||||
flagsArray+=("-j" "$NIX_BUILD_CORES")
|
||||
else
|
||||
threads=1
|
||||
flagsArray+=("-j" "1")
|
||||
fi
|
||||
|
||||
if [ "${cargoCheckType}" != "debug" ]; then
|
||||
cargoCheckProfileFlag="--cargo-profile ${cargoCheckType}"
|
||||
flagsArray+=("--cargo-profile" "${cargoCheckType}")
|
||||
fi
|
||||
|
||||
if [ -n "${cargoCheckNoDefaultFeatures-}" ]; then
|
||||
cargoCheckNoDefaultFeaturesFlag=--no-default-features
|
||||
flagsArray+=("--no-default-features")
|
||||
fi
|
||||
|
||||
if [ -n "${cargoCheckFeatures-}" ]; then
|
||||
cargoCheckFeaturesFlag="--features=${cargoCheckFeatures// /,}"
|
||||
flagsArray+=("--features=$(concatStringsSep "," cargoCheckFeatures)")
|
||||
fi
|
||||
|
||||
argstr="${cargoCheckProfileFlag} ${cargoCheckNoDefaultFeaturesFlag} ${cargoCheckFeaturesFlag}
|
||||
--target @rustHostPlatformSpec@ --offline ${cargoTestFlags}"
|
||||
prependToVar checkFlags "--"
|
||||
concatTo flagsArray cargoTestFlags checkFlags checkFlagsArray
|
||||
|
||||
(
|
||||
set -x
|
||||
cargo nextest run \
|
||||
-j ${threads} \
|
||||
${argstr} -- \
|
||||
${checkFlags} \
|
||||
${checkFlagsArray+"${checkFlagsArray[@]}"}
|
||||
)
|
||||
echoCmd 'cargoNextestHook flags' "${flagsArray[@]}"
|
||||
cargo nextest run "${flagsArray[@]}"
|
||||
|
||||
if [[ -n "${buildAndTestSubdir-}" ]]; then
|
||||
popd
|
||||
|
@ -1,3 +1,5 @@
|
||||
# shellcheck shell=bash disable=SC2154,SC2164
|
||||
|
||||
maturinBuildHook() {
|
||||
echo "Executing maturinBuildHook"
|
||||
|
||||
@ -6,24 +8,26 @@ maturinBuildHook() {
|
||||
# Put the wheel to dist/ so that regular Python tooling can find it.
|
||||
local dist="$PWD/dist"
|
||||
|
||||
if [ ! -z "${buildAndTestSubdir-}" ]; then
|
||||
if [ -n "${buildAndTestSubdir-}" ]; then
|
||||
pushd "${buildAndTestSubdir}"
|
||||
fi
|
||||
|
||||
(
|
||||
set -x
|
||||
@setEnv@ maturin build \
|
||||
--jobs=$NIX_BUILD_CORES \
|
||||
--offline \
|
||||
--target @rustTargetPlatformSpec@ \
|
||||
--manylinux off \
|
||||
--strip \
|
||||
--release \
|
||||
--out "$dist" \
|
||||
${maturinBuildFlags-}
|
||||
local flagsArray=(
|
||||
"--jobs=$NIX_BUILD_CORES"
|
||||
"--offline"
|
||||
"--target" "@rustTargetPlatformSpec@"
|
||||
"--manylinux" "off"
|
||||
"--strip"
|
||||
"--release"
|
||||
"--out" "$dist"
|
||||
)
|
||||
|
||||
if [ ! -z "${buildAndTestSubdir-}" ]; then
|
||||
concatTo flagsArray maturinBuildFlags
|
||||
|
||||
echoCmd 'maturinBuildHook flags' "${flagsArray[@]}"
|
||||
@setEnv@ maturin build "${flagsArray[@]}"
|
||||
|
||||
if [ -n "${buildAndTestSubdir-}" ]; then
|
||||
popd
|
||||
fi
|
||||
|
||||
|
@ -39,7 +39,7 @@ rustPlatform.buildRustPackage rec {
|
||||
|
||||
buildFeatures = lib.optional useMimalloc "mimalloc";
|
||||
|
||||
CFG_RELEASE = version;
|
||||
env.CFG_RELEASE = version;
|
||||
|
||||
inherit doCheck;
|
||||
preCheck = lib.optionalString doCheck ''
|
||||
|
Loading…
Reference in New Issue
Block a user