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

builder: use cc enum in CcompilerOptions, fix cc detection, enable cc guessing without prod flag #21370

Merged
merged 11 commits into from
Apr 29, 2024

Conversation

ttytm
Copy link
Member

@ttytm ttytm commented Apr 28, 2024

  • The PR utilizes an enum for the CC instead of multiple boolean fields on the CcompilerOptions struct. Since only one CC can be used at a time, structuring things this way can make sense.

    A nice side effect of the change was discovering a bug where the CC is not set when compiling V on macOS. This was fixed by enabling compiler guessing on macOS even when V is not compiled in prod mode

    Example CI after swapping to use an enum and panicking on an unknown compiler:

  • To pass the sanitized workflow, a vpath in a step (which was enabled in a recently made change) was fixed. Additionally, a trigger was added for changes to this sanitized workflow.


Edit:
Refs. for development / review purposes

  • Commit no. 3 9b58466 contains the first full CI run after the initial changes from which further improvements were started.

@ttytm
Copy link
Member Author

ttytm commented Apr 28, 2024

Checking the other fails that I couldn't spot before the PR:
If moving towards using an enum, should all supported compilers be part of the enum, or should there be a other enum field that is used when the cc is an unknown compiler?

@JalonSolov
Copy link
Contributor

other makes more sense. Especially when the cc might be a cross-compiler, zig, or anything else that's C99 compatible.

@JalonSolov
Copy link
Contributor

For example, you can also choose -cc g++, and it usually works fine.

In other words, there is no current way to know all possible compilers.

@ttytm
Copy link
Member Author

ttytm commented Apr 28, 2024

Thanks for the input.

I let the current CI finish to be able to analyze the full run before making an update.

vlib/v/builder/cc.v Outdated Show resolved Hide resolved
cc_file_name.contains('clang') || ccoptions.guessed_compiler == 'clang' { .clang }
cc_file_name.contains('msvc') || ccoptions.guessed_compiler == 'msvc' { .msvc }
cc_file_name.contains('icc') || ccoptions.guessed_compiler == 'icc' { .icc }
else { panic('unknown C compiler `${cc_file_name}`') }
Copy link
Contributor

Choose a reason for hiding this comment

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

Thought you were going to have an other type?

Copy link
Member Author

@ttytm ttytm Apr 29, 2024

Choose a reason for hiding this comment

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

That's why the commit message

improve info on unknown compiler (for now keep panic for CI, add .unknown to enum later)

I forced pushed, but the message was the same.

It helps to work with the errors for now instead of silencing them.

Thought of adding an unknown field rather than other then as it still can be a gcc or clang just not detected. other implies it is something else. Also an error message but not a panic when it's an unknown compiler.

Copy link
Member Author

@ttytm ttytm Apr 29, 2024

Choose a reason for hiding this comment

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

Looks like we can pass now without panicking when keeping the panic. Keeping it would make it immediately clear when there is an unknown compiler and potentially prevent regressions and unknown behaviour. Also increase the likelihood of making us aware through reports when we can add a not yet supported compiler. If keeping the panic is not an option I'd follow through with what was stated in the comment above.

Copy link
Member

Choose a reason for hiding this comment

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

Also increase the likelihood of making us aware through reports when we can add a not yet supported compiler.

The likelyhood is imho that people experimenting with such compilers will just not report anything and skip V.

The only requirement that we do have, is that the C compiler should support C99. Not that it is named in a particular "supported" way. That is good, and it should stay that way.

@ttytm
Copy link
Member Author

ttytm commented Apr 29, 2024

Enabled guessing the compiler outside of prod. The reason that it was done only in prod was performance. Not tested yet but the gain through saving the redundant ccompiler_file_name.contains(...) checks and due to the improved code structure should relativize performance losses.

@ttytm ttytm marked this pull request as draft April 29, 2024 03:10
@ttytm ttytm marked this pull request as ready for review April 29, 2024 03:44
@ttytm ttytm changed the title builder: use enum for cc, enable compiler guessing without prod flag on macos builder: use enum for cc, enable compiler guessing without prod flag Apr 29, 2024
@ttytm ttytm changed the title builder: use enum for cc, enable compiler guessing without prod flag builder: use cc enum in CcompilerOptions, fix cc detection, enable cc guessing without prod flag Apr 29, 2024
vlib/v/builder/cc.v Outdated Show resolved Hide resolved
vlib/v/builder/cc.v Outdated Show resolved Hide resolved
Comment on lines -178 to -181
if ccoptions.guessed_compiler == 'cc' && v.pref.is_prod {
// deliberately guessing only for -prod builds for performance reasons
ccversion := os.execute('cc --version')
if ccversion.exit_code == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

The is_prod check is there for a reason. Restore it.

Copy link
Member

Choose a reason for hiding this comment

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

I do not like how you are doing refactorings (the replacement of the strings and several bool fields -> a single enum is good), mixed with functional changes in behavior (which is questionable) :-| .

Please do keep such PRs separate. One can be merged, and the other closed. Now, you have to do more work to separate them, and I to review it.

Copy link
Member Author

@ttytm ttytm Apr 29, 2024

Choose a reason for hiding this comment

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

The is_prod check is there for a reason. Restore it.

  • If I'm not forbidden to tust the comment. The reason why it's there is performance.
    But there is no performance regression with the update. Instead there is a benefit of several fixes.

Please read:

  • It fixes the compiler being detected. E.g. on macos in general. This was stated in the issue description:

    screenshot macos

    Screenshot_20240429_122657

    So before opening the PR I just enabled guessing outside prod on macos. After opening it, it revealed that there are similar scenarios on other platforms. I classified that detecting a compiler is of priority - even if there would be a performance regression:

    screenshot freestanding

    Screenshot_20240429_122712

    screenshot vsl/vtl test

    Screenshot_20240429_122751

    screenshot freebsd

    Screenshot_20240429_122831

Another fix that was made, unrelated to enabling guessing without prod:

screenshot g++

Screenshot_20240429_122817

So it is mainly a fix, not a refactor.

I know there is a lot of descriptions in the PR, I try to keep them simple and down to what is important to simplify reviewing. But doesn't seem like anyone was read before writing the review comments. The changes pointed out in the reviews were also pointed out in the descriptions / open discussions where joining on would allow to address them better. I see your point but on some code it's hard sometimes impossible to keep changes very simple or would take a lot of time and PRs so I try to find a middlegroud.

Copy link
Member Author

Choose a reason for hiding this comment

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

I do not like how you are doing refactorings (the replacement of the strings and several bool fields -> a single enum is good), mixed with functional changes in behavior (which is questionable) :-| .

As stated above it's more of a fix than a refactor. Using an enum had to be exclusive. And in the first stage a panic was added if the compiler is unknown. If the panic is kept was up for discussion. It helped to detect where a compiler is not known during the work on the fix.

Copy link
Member

Choose a reason for hiding this comment

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

All of those are panics, that I do insist should not be there at all.

Copy link
Member

Choose a reason for hiding this comment

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

The portability of V to new platforms and OSes, will be limited by having a panic for no good reason at all.
The failures that you claim to be fixed, are self inflicted, by the very panics that I do insist should not be there. The check for -prod is also related - without it, the restrictions to cc are practically non existent, and that facilitates bootstrapping on new platforms, where it can be anything.

Again, V requires a C99 compiler, not a specific named one, and that should continue to be so. It should not panic when it can not decide what the compiler is, it should just not add compiler specific flags.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes we don't need to dwell down so much on the panics. I made the experience often enough that it's good to turn something into an error that should be a notice or warning in the result, just to be able to better work with it during development.

I would update the panic like stated here: #21370 (comment). Would that make the PR a merge candidate?

Copy link
Member

Choose a reason for hiding this comment

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

Even an error is not appropriate imho, since it should not prevent the compilation and bootstrapping on a new system.

At best, it can be a notice.

Copy link
Member Author

@ttytm ttytm Apr 29, 2024

Choose a reason for hiding this comment

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

Yes, looks like we agree. It would be just a print to stderr to make note of using an undetected compiler (as it's done with other notices in the builder/cc.v), things would continue as usual.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated. As - with the PRs changes - we didn't panicked with all our currently tested options, the notice should only become visible when there is an unknown compiler.

@spytheman spytheman merged commit ec59760 into vlang:master Apr 29, 2024
66 checks passed
@ttytm ttytm deleted the builder/enum-cc branch April 29, 2024 14:15
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.

None yet

3 participants