Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: support structuredAttrs in setup hooks #340862

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 18 additions & 24 deletions pkgs/build-support/rust/hooks/cargo-build-hook.sh
Original file line number Diff line number Diff line change
@@ -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

echoCmd 'cargoBuildHook flags' "${flagsArray[@]}"
@setEnv@ cargo build "${flagsArray[@]}"

if [ ! -z "${buildAndTestSubdir-}" ]; then
if [ -n "${buildAndTestSubdir-}" ]; then
popd
fi

35 changes: 17 additions & 18 deletions pkgs/build-support/rust/hooks/cargo-check-hook.sh
Original file line number Diff line number Diff line change
@@ -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
32 changes: 15 additions & 17 deletions pkgs/build-support/rust/hooks/cargo-nextest-hook.sh
Original file line number Diff line number Diff line change
@@ -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
30 changes: 17 additions & 13 deletions pkgs/build-support/rust/hooks/maturin-build-hook.sh
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion pkgs/development/tools/rust/rust-analyzer/default.nix
Original file line number Diff line number Diff line change
@@ -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 ''