Apple m2-max not being detected as the host CPU?

I have a MacBook with an m2-max CPU:

❯ sysctl -n machdep.cpu.brand_string
Apple M2 Max

But rustc defaults to m1:

❯ rustc +nightly --version
rustc 1.74.0-nightly (58eefc33a 2023-08-24)

❯  rustc +nightly --print target-cpus
Available CPUs for this target:
    native          - Select the CPU of the current host (currently apple-m1).
    a64fx
...
    apple-latest
    apple-m1        - This is the default target CPU for the current build target (currently arm64-apple-macosx11.0.0).
    apple-m2
    apple-s4

Is there a reason for this that I am missing, or is it worth me trying to dig into this and create a PR to default to m2 when running an m2-max?

LLVM is responsible for detecting the native cpu. Looks like LLVM doesn't yet know how to detect cpu's newer than m1:

2 Likes

Thanks for that!

I've submitted this patch ⚙ D158840 Detect apple M2 processor targets to try and fix that. It's not a very friendly contribution experience if you are new, so I'm unclear as to if it's in the right place or who to add as a reviewer.

Let's see!

3 Likes