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

swift: Pass C base compile options to swiftc #14296

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

Conversation

2xsaiko
Copy link
Contributor

@2xsaiko 2xsaiko commented Feb 25, 2025

If the C/Obj-C source code needs a particular standard version, swiftc should know about it so it can parse imported headers correctly.

(This makes more sense with C++ support (commit 2xsaiko@push-nmuxysxxokuy), since setting the standard version is more common there, and was pulled out of #14261, but still applies for C as well)

@2xsaiko 2xsaiko requested a review from dcbaker as a code owner February 25, 2025 23:27
@2xsaiko 2xsaiko mentioned this pull request Feb 25, 2025
4 tasks
@2xsaiko 2xsaiko force-pushed the push-uxoqqoqywmwu branch 2 times, most recently from c5af688 to e79331a Compare February 26, 2025 16:49
# Pass C compiler args to swiftc, notably -std=...
try:
c_langs = ['objc', 'c']
c_lang = next(lang for lang in c_langs if lang in target.compilers)
Copy link
Member

Choose a reason for hiding this comment

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

We have a mesonlib.first() helper that I think would simplify this:

lang = mesonlib.first(target.compilers, lambda x: x in {'objc', 'c'})
if lang is not None:
    cc = target.compilers[lang]
    args.extend(...)

with no need for a try/except block

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The order is important here though, it should generally prefer objc/c++ when available, so kept the iteration the other way around.

@2xsaiko 2xsaiko force-pushed the push-uxoqqoqywmwu branch 2 times, most recently from a3461bb to d5df540 Compare March 7, 2025 19:39
@2xsaiko 2xsaiko force-pushed the push-uxoqqoqywmwu branch from d5df540 to be6623a Compare March 25, 2025 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants