[proposal] Conditional flags based on the consumer compiler
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 40/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- cpp
- Domain
- build-system, tooling
Research direction
Start with the CPS schema sections for compile_flags, link_flags, and definitions, including their language-based mappings. Compare the proposed consumer-compiler mapping with those rules and document the expected behavior for MSVC and GCC/Clang consumers; the work is done when the specification resolves these conditional flags without making compatible binaries unusable.
Written by the indexing model from the issue text.
Description
There are many cases of open source third party libraries that require to activate certain flags, like C++ flags, in order to let the consumers to correctly use and link with them.
A common use case is the definition of /Zc:__cplusplus flag, because some conditionals in headers use the __cplusplus value to enable, disable certain features or APIs.
In ConanCenter, I can find around 40 different recipes that have the idiom if msvc => Define /Zc:__cplusplus, with some notorious libraries like llvm-openmp, ffmpeg, libgettext, mlpack, ncurses and swig.
The main problem here is compatible binaries. A given binary can be compiled for example with clang, and then it might be consumed and linked both by different end users, some using msvc compiler and some using clang compiler (with msvc binary-compatible backend).
Consequently, it is not possible to unconditionally define those compiler flags for a given package .cps file.
The current CPS compile_flags are discouraged because of this fact, but it defines that a mapping can be defined for different languages:
A map may be used instead to give different values depending on the language of the consuming source file.
Handling of such shall be the same as for [definitions](https://cps-org.github.io/cps/schema.html#definitions).
Same happens for CPS link_flags.
The situation is similar to the CPS definitions, that also allows a possible mapping based on the language.
I think this scenario is not so niche to not be supported by the spec, and then I'd suggest to define a mapping that allows to conditionally define flags depending on the consumer compiler, something like:
{
"compile_flags": {
"msvc": ["/Zc:__cplusplus", ...]
"gcc": [...]
}
}
Otherwise, we will have a bunch of massively popular C and C++ open source libraries that will fail to be consumed via CPS out of the box, as they will fail due to the lack of correct __cplusplus.
I am happy with actively discouraging the definition of compile_flags and link_flags for most cases, I totally agree on that, but there might be situations that will be quite painful if not allowed and supported by the spec, with major library maintainers not willing to adopt CPS because their users will complain because it doesn't work seamlessly in MSVC, for example.
- Dominant language
- Python
- Stars
- 191
- Forks
- 14
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cps-org/cps
-
Spec: `c-runtime-vendor` field also should document the "musl" typical value and "bionic"Possibly taken @leha-bot claimed this 2 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 3/5 Half a day Newbie friendliness 45/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ok-oldking/ok-wuthering-waves#1785 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
healthchecks/healthchecks#1349 ·
-
deployment release-lag
Difficulty 1/5 Under an hour Newbie friendliness 68/100
nolte/kamerplanter#2374 ·
Maintainers usually reply within 1 day
-
bug v1 v2
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
modelcontextprotocol/python-sdk#3725 ·
Maintainers usually reply within 1 day
-
batchterms() drops queries without a similar() clause, misaligning results with inputsPossibly taken @MohammadHijjawi97 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day