-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
buildRustPackage: factor out cargoCheckHook and cargoInstallHook #113193
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
Changes from all commits
9757c71
05e40e7
087ab3d
1df80d2
2df314c
2376921
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| declare -a checkFlags | ||
|
|
||
| cargoCheckHook() { | ||
| echo "Executing cargoCheckHook" | ||
|
|
||
| runHook preCheck | ||
|
|
||
| if [[ -n "${buildAndTestSubdir-}" ]]; then | ||
| pushd "${buildAndTestSubdir}" | ||
| fi | ||
|
|
||
| if [[ -z ${dontUseCargoParallelTests-} ]]; then | ||
| threads=$NIX_BUILD_CORES | ||
| else | ||
| threads=1 | ||
| fi | ||
|
|
||
| argstr="--${cargoBuildType} --target @rustTargetPlatformSpec@ --frozen"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like you changed:
But there are crates out there that on
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an oversight. We should pass
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know how many packages are out there using that, but I added this to work around issues with packages where
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, it's an oversight. I'll do a PR that fixes this.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| ( | ||
| set -x | ||
| cargo test \ | ||
| -j $NIX_BUILD_CORES \ | ||
| ${argstr} -- \ | ||
| --test-threads=${threads} \ | ||
| ${checkFlags} \ | ||
| ${checkFlagsArray+"${checkFlagsArray[@]}"} | ||
| ) | ||
|
|
||
| if [[ -n "${buildAndTestSubdir-}" ]]; then | ||
| popd | ||
| fi | ||
|
|
||
| echo "Finished cargoCheckHook" | ||
|
|
||
| runHook postCheck | ||
| } | ||
|
|
||
| if [ -z "${checkPhase-}" ]; then | ||
| checkPhase=cargoCheckHook | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| cargoInstallPostBuildHook() { | ||
| echo "Executing cargoInstallPostBuildHook" | ||
|
|
||
| releaseDir=target/@shortTarget@/$cargoBuildType | ||
| tmpDir="${releaseDir}-tmp"; | ||
|
|
||
| mkdir -p $tmpDir | ||
| cp -r ${releaseDir}/* $tmpDir/ | ||
| bins=$(find $tmpDir \ | ||
| -maxdepth 1 \ | ||
| -type f \ | ||
| -executable ! \( -regex ".*\.\(so.[0-9.]+\|so\|a\|dylib\)" \)) | ||
|
|
||
| echo "Finished cargoInstallPostBuildHook" | ||
| } | ||
|
|
||
| cargoInstallHook() { | ||
| echo "Executing cargoInstallHook" | ||
|
|
||
| runHook preInstall | ||
|
|
||
| # rename the output dir to a architecture independent one | ||
|
|
||
| releaseDir=target/@shortTarget@/$cargoBuildType | ||
| tmpDir="${releaseDir}-tmp"; | ||
|
|
||
| mapfile -t targets < <(find "$NIX_BUILD_TOP" -type d | grep "${tmpDir}$") | ||
| for target in "${targets[@]}"; do | ||
| rm -rf "$target/../../${cargoBuildType}" | ||
| ln -srf "$target" "$target/../../" | ||
| done | ||
| mkdir -p $out/bin $out/lib | ||
|
|
||
| xargs -r cp -t $out/bin <<< $bins | ||
| find $tmpDir \ | ||
| -maxdepth 1 \ | ||
| -regex ".*\.\(so.[0-9.]+\|so\|a\|dylib\)" \ | ||
| -print0 | xargs -r -0 cp -t $out/lib | ||
| rmdir --ignore-fail-on-non-empty $out/lib $out/bin | ||
| runHook postInstall | ||
|
|
||
| echo "Finished cargoInstallHook" | ||
| } | ||
|
|
||
|
|
||
| if [ -z "${installPhase-}" ]; then | ||
| installPhase=cargoInstallHook | ||
| postBuildHooks+=(cargoInstallPostBuildHook) | ||
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add that to the changelog?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. There was another API change (removal of the
targetargument ofbuildRustPackage). I can do a PR for the release notes after this one that summarizes all the changes.