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

Add Apple M4 host detection #117530

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

madsmtm
Copy link
Contributor

@madsmtm madsmtm commented Nov 25, 2024

Add Apple M4 host detection, which fixes rust-lang/rust#133414.

Also add support for older ARM families (this is likely never going to get used, since only macOS is officially supported as host OS, but nice to have for completeness sake). Error handling (checking CPUFAMILY_UNKNOWN) is also included here.

Finally, add links to extra documentation to make it easier for others to update this in the future.

NOTE: These values are taken from the Xcode 16.2 Beta 3 SDK, and has been confirmed on an M4 Max in rust-lang/rust#133414 (comment).

Comment on lines +1508 to +1511
case CPUFAMILY_UNKNOWN:
return "invalid";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unsure if I should return "generic" or "invalid" when the host CPU cannot be detected?

Copy link
Contributor

Choose a reason for hiding this comment

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

should be "generic", or perhaps change sys::getHostCPUName() to return a std::optional<StringRef>

@madsmtm
Copy link
Contributor Author

madsmtm commented Nov 25, 2024

CC @jroelofs who reviewed #82100 (I don't know the procedures for who to ask, sorry if you're the wrong person to tag).

Copy link

github-actions bot commented Nov 25, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Also add support for older ARM families (this is likely never going to
get used, since only macOS is officially supported as host OS, but nice
to have for completeness sake). Error handling (checking
CPUFAMILY_UNKNOWN) is also included here.

Finally, add links to extra documentation to make it easier for others
to update this in the future.

These values should be up to date with Xcode 16.2 beta 3.
//
// NOTE: We choose to return `apple-mX` instead of `apple-aX`, since the M1,
// M2, M3 etc. aliases are more widely known to users than A14, A15, A16 etc.
// (and this code is basically only used on host macOS anyways).
Copy link
Contributor

Choose a reason for hiding this comment

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

From that perspective, I think it only makes sense to include the ones that shipped in a Mac. All the others are effectively dead code.

case CPUFAMILY_ARM_TAHITI:
return "apple-m4"; // A18 Pro
case CPUFAMILY_ARM_TUPAI:
return "apple-m4"; // A18
Copy link
Contributor

Choose a reason for hiding this comment

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

Mind combining these with fallthroughs?

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.

apple-m3 detected as the native CPU for nightly rustc on apple-m4
2 participants