-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
setuptools.msvc: set host_dir correctly on ARM64 hosts #4786
base: main
Are you sure you want to change the base?
Conversation
setuptools/msvc.py
Outdated
host_dir = ( | ||
r'bin\HostX86%s' if self.pi.current_is_x86() else r'bin\HostX64%s' | ||
r'bin\HostX86%s' | ||
if self.pi.current_is_x86() | ||
else ( | ||
r'bin\HostARM64%s' | ||
if self.pi.current_cpu == 'arm64' | ||
else r'bin\HostX64%s' | ||
) | ||
) |
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.
Not a maintainer here, but personally I find if-else chains to be much more readable and concise than nested ternaries:
if self.pi.current_is_x86():
host_dir = r'bin\HostX86%s'
elif self.pi.current_cpu == 'arm64':
host_dir = r'bin\HostARM64%s'
else:
host_dir = r'bin\HostX64%s'
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.
Updated.
5ef90ee
to
cf436b4
Compare
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.
Since this PR isn't linked to any issue, can you update the PR description to elaborate on the issue? In particular, answer questions like: Why does it matter? How did you encounter it? Under what conditions is it relevant (e.g. does it affect all users of Setuptools on ARM, or some subset)?
I see lots of other places in this module where the assumption is that there is x86 and x64. I'm not sure it makes sense to add ARM support here, but not elsewhere. What's the value in fixing just this issue and not other parts in the module that deal with processor architecture?
setuptools/msvc.py
Outdated
if self.pi.current_is_x86(): | ||
host_dir = r'bin\HostX86%s' | ||
elif self.pi.current_cpu == 'arm64': | ||
host_dir = r'bin\HostARM64%s' | ||
else: | ||
host_dir = r'bin\HostX64%s' |
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.
Even better than an if/else statement would be something like:
if self.pi.current_is_x86(): | |
host_dir = r'bin\HostX86%s' | |
elif self.pi.current_cpu == 'arm64': | |
host_dir = r'bin\HostARM64%s' | |
else: | |
host_dir = r'bin\HostX64%s' | |
host_dir = os.path.join('bin', f'Host{self.host_id.upper()}%s') |
And then of course implement the property host_id
to reflect the correct string to insert. In general, it's good practice to DRY - avoid repeating the assignment and prefix and suffix of the value.
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.
Adding a property for something that's only used once seemed a bit of overkill. Let me know if what I did works.
setuptools/msvc.py
Outdated
) | ||
if self.pi.current_is_x86(): | ||
host_dir = r'bin\HostX86%s' | ||
elif self.pi.current_cpu == 'arm64': |
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.
Note that this comparison is no longer symmetrical with the check for 'x86'. Better would be to be consistent. Either use self.pi.current_cpu == 'x86'
inline or implement a new self.pi.current_is_arm64()
method.
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.
Addressed.
I thought the description was pretty clear about what the problem was (it really is just about the This is the only problem that I'm actually aware of with setuptools.msvc on Windows ARM64. I just did another look through the file and while yes, there are a lot of cases where it assumes there is only x86 and x64, I didn't see any cases where it is actually doing the wrong thing on ARM64. The rest of the output of EnvironmentInfo.return_env() looks fine. |
cf436b4
to
b8f9800
Compare
b8f9800
to
e1d81b8
Compare
Summary of changes
This corrects the setting of the host directory name on ARM64 hosts so that
EnvironmentInfo.return_env()['path']
includes the correct path to CL.EXE. Currently, it returns the X64 directory. See below; noteHostX64
in first listed path.Pull Request Checklist
newsfragments/
.(See documentation for details)