-
Notifications
You must be signed in to change notification settings - Fork 715
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
Let cc-rs choose the correct optimization flags for MSVC (/O2
instead of /Ox
)
#1596
Merged
briansmith
merged 1 commit into
briansmith:main
from
andoalon:fix-msvc-optimization-flag
Oct 13, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do you agree that cc-rs does the right thing automatically, so that we can just remove both this line and the analogous "/Od" line above? I would prefer to do that, if cc-rs is automatically doing the right thing. (In general, I want to remove as much logic from build.rs that duplicates that cc-rs does as possible; see recent PRs that change build.rs to this effect.)
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.
I haven't previously used cc-rs so I assumed manually specifying optimization flags was somehow necessary 😅
Well, cc-rs can determine the correct flag for each compiler: https://github.com/rust-lang/cc-rs/blob/2447a2ba5f455c00b1563193e125b60eebbd8ebe/src/lib.rs#L1748-L1749
I quickly checked the docs and there's this function that lets you manually specify the optimization level, but it also says that the
OPT_LEVEL
environment variable is used to determine the correct value otherwise (which is what is done manually here).About
"/Od"
, it is the default so no need to specify it: https://learn.microsoft.com/en-us/cpp/build/reference/od-disable-debug?view=msvc-170It's not clear to me whether
"/RTCsu"
is on by default:https://learn.microsoft.com/en-us/cpp/build/reference/rtc-run-time-error-checks?view=msvc-170
The Visual Studio IDE does enable it for debug builds but that might not be true when using the compiler directly. We might need to read a little more, or just keep it to be sure.
tl;dr
Yes, I totally agree, no optimization flags should be manually set unless there's a good reason for doing it. The
"/RTCsu"
situation is not 100% clear to meThere 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.
I took another look, but I couldn't conclusively find anything indicating that
/RTCsu
is enabled by default. Therefore I left that part but removed the rest. If you think you don't need/RTCsu
, then the whole if statement can be removed, otherwise I would say the change is ready to be mergedThere 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.
@andoalon I would be happy to have the /RTCsu removed.