-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
Optimise rust-based formulas by setting target-cpu
#15530
Comments
For C/C++-based formulae, we set It seems reasonable to do something similar for Rust. How do you set the desired |
We will probably add flags at some point for the benefit of GCC. The flags are however different on GCC and Clang so it's trickier than Intel. But yeah for Rust this seems like a good idea. |
FWIW starting with Rust 1.71 (coming out in 5.5 weeks) rust will default to targeting an M1 in macOS arm64 targets: rust-lang/rust#109899 |
Ah excellent - we probably don't need to do anything here for arm64 then. Not sure if there's anything worth doing for x86_64 or not. |
This simplifies deciding which cpu to target.
That's nice to know, thanks.
If the flag can be conditionally added to |
I don't think passing a
Perhaps you need for this to be set in |
Yes, you are right. For cargo, this option can be set in rustflags. |
We used to but intentionally don't any more to reduce the difference (and we don't support local builds anyway). As a result,
sounds perfect. |
|
I think I can self-assign this. I could add a config flag to std_cargo_args based on the target triple (thus sorting out conditionals on cpu arch). A cargo config file will be more ergonomic at this point, but that can be left for a future PR. If anyone has general advice or warnings of any pitfalls, please let me know. |
Off the top of my head, one important thing to note is that we'll want to use the same value returned from here instead of actually hard-coding brew/Library/Homebrew/extend/ENV/shared.rb Lines 273 to 281 in 9d01e1d
|
Sounds good, looking forward to the PR @Tokarak! |
I looked at
Given that Rust already minimaxs the cpu without version context, it may be best to create a function which returns rust flags with version context, similar to brew/Library/Homebrew/extend/ENV/shared.rb Lines 273 to 281 in 9d01e1d
but without oldest_cpu which has a lot of complex logic which is incompatible with rustflags and is already handled by cargo. This allows to use useful default rust cpus (just return an empty string to not change rust flags!) Maintaining 5 lines of code shouldn't be an issue either, even though oldest_cpu and this function will have to be updated in parallel.
|
Closing to keep discussion in #15544.
Seems reasonable 👍🏻 |
Verification
brew install wget
. If they do, open an issue at https://github.com/Homebrew/homebrew-core/issues/new/choose instead.Provide a detailed description of the proposed feature
Rust has optional support for building with certain cpu features enabled. For example, arm-based macs, I would imagine, use only
apple-m1
orapple-m2
cpus.rustc --print cfg | grep target_feature | wc -l
gives me 28 features, while thegeneric
target only has neon.Specific features can also be specified — this can be useful if it's feasible to take the common features of a set of cpus.
If a better union set of cpu features can be found than
generic
, that can be an improvement to the ecosystem.What is the motivation for the feature?
This can increase peformance (sometimes marginally, other times significantly) for binaries built in Rust.
How will the feature be relevant to at least 90% of Homebrew users?
Mac users on official hardware should use only a small set of cpus. This means there is a high potential for improvement.
I'm worried about alienating the small number of hackingtosh and opencore-patcher users. Perphaps if the OS requires specific features, then those can be used. Otherwise, if a Hackingtosh can be built on any hardware, then it would seem that the only way to avoid alienation is to stick to the generic targets, or provide multiple builds (though I'm not looking to inflate the CI minutes).
This is particularly true for silicon based macs. AFAIK, there are no arm-based hackingtoshes, and there are only two, very similar cpu types. This could mean that it's completely safe to add these features cargo_args on silicon builds and distributions.
What alternatives to the feature have been considered?
The text was updated successfully, but these errors were encountered: