|
| 1 | +# Package Manager C/C++ Language Standard Support |
| 2 | + |
| 3 | +* Proposal: SE-NNNN |
| 4 | +* Authors: [Ankit Aggarwal](https://github.com/aciidb0mb3r) |
| 5 | +* Review Manager: [Daniel Dunbar](https://github.com/ddunbar) |
| 6 | +* Status: **Discussion** |
| 7 | + |
| 8 | +## Introduction |
| 9 | + |
| 10 | +This proposal adds support for declaring the language standard for C and C++ |
| 11 | +targets in a SwiftPM package. |
| 12 | + |
| 13 | +## Motivation |
| 14 | + |
| 15 | +The C++ language standard is one of the most important build setting needed to |
| 16 | +compile C++ targets. We want to add some mechanism to declare it until we get |
| 17 | +the complete build settings feature, which is deferred from the Swift 4 release. |
| 18 | + |
| 19 | +## Proposed solution |
| 20 | + |
| 21 | +We will add support to the package manifest declaration to specify the C and C++ |
| 22 | +language standards: |
| 23 | + |
| 24 | +```swift |
| 25 | +let package = Package( |
| 26 | + name: "CHTTP", |
| 27 | + ... |
| 28 | + cStandard: .c89, |
| 29 | + cxxStandard: .cxx11 |
| 30 | +) |
| 31 | +``` |
| 32 | + |
| 33 | +These settings will apply to all the C and C++ targets in the package. The |
| 34 | +default value of these properties will be `nil`, i.e. language standard flag |
| 35 | +will not be passed when invoking the C/C++ compiler. |
| 36 | + |
| 37 | +_Once we get the build settings feature, we will deprecate these properties._ |
| 38 | + |
| 39 | +## Detailed design |
| 40 | + |
| 41 | +The C/C++ language standard will be defined by the enums below and |
| 42 | +updated as per the Clang compiler [repository](https://github.com/llvm-mirror/clang/blob/master/include/clang/Frontend/LangStandards.def). |
| 43 | + |
| 44 | +```swift |
| 45 | +public enum CLanguageStandard { |
| 46 | + case c89 |
| 47 | + case c90 |
| 48 | + case iso9899_1990 |
| 49 | + case iso9899_199409 |
| 50 | + case gnu89 |
| 51 | + case gnu90 |
| 52 | + case c99 |
| 53 | + case iso9899_1999 |
| 54 | + case gnu99 |
| 55 | + case c11 |
| 56 | + case iso9899_2011 |
| 57 | + case gnu11 |
| 58 | +} |
| 59 | + |
| 60 | +public enum CXXLanguageStandard { |
| 61 | + case cxx98 |
| 62 | + case cxx03 |
| 63 | + case gnucxx98 |
| 64 | + case gnucxx03 |
| 65 | + case cxx11 |
| 66 | + case gnucxx11 |
| 67 | + case cxx14 |
| 68 | + case gnucxx14 |
| 69 | + case cxx1z |
| 70 | + case gnucxx1z |
| 71 | +} |
| 72 | +``` |
| 73 | +## Impact on existing code |
| 74 | + |
| 75 | +There will be no impact on existing packages because this is a new API and the |
| 76 | +default behaviour remains unchanged. |
| 77 | + |
| 78 | +## Alternatives considered |
| 79 | + |
| 80 | +We considered adding this property at target level but we think that will |
| 81 | +pollute the target namespace. Moreover, this is a temporary measure until we get |
| 82 | +the build settings feature. |
0 commit comments