Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Windows] fix psutil installation on arm64 #81071

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

charles-zablit
Copy link

@charles-zablit charles-zablit commented Apr 24, 2025

Currently, the build.ps1 script will try to install a psutil wheel for amd64, regardless of the platform. The script fails on windows if psutil was not installed manually before running the script.

Instead of manually downloading wheels and installing them via pip, we directly invoke pip install with the correct version of the package and let pip figure out if there is an available wheel or not.

This should not be an issue for building the wheel locally as the VisualStudio toolchain should already be installed before running the script.

@charles-zablit charles-zablit changed the title [windows] fix psutil installation on arm64 [Windows] replace wheels with automatic pip install Apr 24, 2025
Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d like to see the arm64 fix, but the approach here makes me wonder if this is a good idea. This removes the control from our hands and relies on pip managing that properly. I think that there is some value to the additional complexity for controlling the supply chain more aggressively.

@charles-zablit
Copy link
Author

charles-zablit commented Apr 25, 2025

I think that there is some value to the additional complexity for controlling the supply chain more aggressively.

I see, would you be more favorable to have a try/catch strategy, sort of like 345452c?

We can:

  1. try to install the wheel.
  2. if it fails, fallback to a regular pip install.
  3. block the regular pip install if an env variable is set in the case we want extra control over the supply chain.

Another option would be to vendor our own wheel for arm64-windows.

What do you think?

@compnerd
Copy link
Member

Would it be possible to just add a wheel and specify the locations for ARM64 like we do other tools?

@charles-zablit
Copy link
Author

Unfortunately psutil does not build a wheel for arm64 windows: https://pypi.org/project/psutil/#files.

@compnerd
Copy link
Member

Ugh, that is unfortunate. There are separate projects (e.g. https://github.com/cgohlke/win_arm64-wheels) to create wheels for Windows ARM64. The psutil wheel particularly is only needed for testing LLDB, which would be good to do.

I'd love to get @shahmishal's take on this.

@adrian-prantl
Copy link
Contributor

@compnerd @shahmishal Would using pip install but constraining it to a known version be a reasonable compromise to provide some control about what we install?

@compnerd
Copy link
Member

I think that we should absolutely constrain the version. I also wondering if we should be doing more to ensure that something else isn't being injected. If you note the existing implementation, we have a specific URL and expected SHA256 that we compare against.

@adrian-prantl
Copy link
Contributor

A quick web search seems to indicate that this might be possible with pip: https://pip.pypa.io/en/stable/topics/secure-installs/

@weliveindetail
Copy link
Member

pip install with versions (and hashes if you wish) sounds great! Thanks for working on this.

@compnerd
Copy link
Member

Oh, nice, I didn't know about that feature! Versions, Hash Checking Mode, and binary only combined would be great.

@charles-zablit
Copy link
Author

This approach combines the best of both worlds:

  • If a wheel exists, use it and check its hash.
  • Otherwise, install from source and check the hash through pip using --requires-hashes.

We have to use a temporary requirements.txt file to pass the hash as the cli does not support it already. There is a tracking issue but it appears to be stale: pypa/pip#3257.

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the source distribution - this will add additional CI time and we are working to reduce that. If you want to use the from source distributions, it will require that we find some way to reduce the build times first.

utils/build.ps1 Outdated
@@ -1008,27 +1032,47 @@ function Get-Dependencies {
}
}

function Install-PythonWheel([string] $ModuleName) {
function Is-Python-Module-Installed([string] $ModuleName) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functions are not named using kebab case, there is a dictated nomenclature for PowerShell functions. https://learn.microsoft.com/en-us/powershell/scripting/learn/ps101/09-functions?view=powershell-7.5

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know about that convention, fixed, thanks!

@charles-zablit
Copy link
Author

I'm not sure about the source distribution - this will add additional CI time and we are working to reduce that. If you want to use the from source distributions, it will require that we find some way to reduce the build times first.

The source distributions are only used as a fallback. All the modules should be installed from the wheel (no build time), except for psutil on Windows arm64, because there are no wheels for it.

The only way I see to not use a source distribution for psutil on Windows arm64 would be to build a wheel ourselves and host is somewhere or vendor it inside of the repository.

@charles-zablit charles-zablit changed the title [Windows] replace wheels with automatic pip install [Windows] fix psutil installation on arm64 Apr 29, 2025
@charles-zablit
Copy link
Author

I think there are 3 approaches to fix this script failure on Windows ARM64:

1. Build psutil from source

We use pip install instead of downloading the wheel manually. We use --requires-hashes to make sure the source has not been tempered with.

Pros: Simple to implement, no need to host a file for win-arm64.
Cons: Could slow down the CI, although it takes only 4s to install on my machine (MacBook Pro M2 running Parallels), see below:

(venv) PS C:\Users\charleszablit> Measure-Command { pip install psutil==6.1.0 --no-cache-dir }

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 3
Milliseconds      : 740
Ticks             : 37405082
TotalDays         : 4.32929189814815E-05
TotalHours        : 0.00103903005555556
TotalMinutes      : 0.0623418033333333
TotalSeconds      : 3.7405082
TotalMilliseconds : 3740.5082

2. Use a pre-built wheel online

We use the v2024.11.3 release of https://github.com/cgohlke/win_arm64-wheels/, which has a win-arm64 wheel for psutil==6.1.0.

Pros: We don't have to build/host a wheel.
Cons: The release is a zip of all the wheels and has a size of ~350MB, which has to be downloaded then extracted to then be able to install the wheel. This might be slower than building from source.

3. Vendor our own wheel

I was able to build a wheel for psutil==6.1.0 on Windows ARM64. We can host it somewhere or include it in the repo.

Pros: The wheel is available without the need to download.
Cons: We either have to host the file somewhere or include it in the repo (~250KB).

Conclusion

All 3 approaches ensure that we maintain control of the supply chain through checksum checking.
Approach 2 seems to be the slowest due to the 350MB download.
I have a slight preference for 1 over 3 because it does not require shipping a binary/wheel, and the CI time gains are not substantial.

@compnerd
Copy link
Member

I think that a build taking 4s is reasonable enough to then consider. I agree with your assessment - it avoids the hosting problem and has a negligible impact on the build.

@adrian-prantl
Copy link
Contributor

@compnerd If you're okay with the patch, can you merge it? (I can do it, too, but I think it's better if you review it)

@adrian-prantl
Copy link
Contributor

ping @compnerd

@compnerd
Copy link
Member

compnerd commented May 2, 2025

Yeah, I'll take a look soon, at an offsite this week.

@compnerd
Copy link
Member

compnerd commented May 3, 2025

@charles-zablit would you mind just using the same process for all architectures? That is, lets completely ignore the wheel and just build the dependencies. This makes the ARM64 and X64 paths identical and therefore less likely to be an issue when working on one architecture.

@charles-zablit
Copy link
Author

Done, this revision of the code uses pip install with the --with-hashes parameter and a pinned version to install the packages, whatever the platform is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants