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
Support for C++ source compatibility #8055
Conversation
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
At this point, the selected toolchain should support the selected source compatibility. Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
If source compatibility is not selected by the time a toolchain is selected, then default the source compatibility to the toolchain's default compatibility. This is currently only implemented for GCC and Clang compilers. Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Also makes source compatibility an optional input to the task. Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Unit test caught a bug when testing Cpp17 for clang 3.5. Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
0d59354
to
870036c
Compare
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.
Thanks @k-mack for looking into this. I believe it's a big step in the right direction. The change I request are mostly polishing and to avoid waterfall changes everywhere. Great work so far 👍
...age-native/src/integTest/groovy/org/gradle/language/cpp/CppApplicationIntegrationTest.groovy
Outdated
Show resolved
Hide resolved
...age-native/src/integTest/groovy/org/gradle/language/cpp/CppApplicationIntegrationTest.groovy
Outdated
Show resolved
Hide resolved
...age-native/src/integTest/groovy/org/gradle/language/cpp/CppApplicationIntegrationTest.groovy
Outdated
Show resolved
Hide resolved
...age-native/src/integTest/groovy/org/gradle/language/cpp/CppApplicationIntegrationTest.groovy
Outdated
Show resolved
Hide resolved
...age-native/src/integTest/groovy/org/gradle/language/cpp/CppApplicationIntegrationTest.groovy
Outdated
Show resolved
Hide resolved
} | ||
} | ||
} | ||
} |
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.
❌ Same as above, moving this method to CppCompilerArgsTransformer
simplify it greatly. For starter, the spec
is already typed as CppCompileSpec
. To work around the need for compiler type, I would simply create 2 types just as we did for Visual C++. I would keep the two distinct type for C++ compiler only. This will allow you to avoid passing the compiler type at a constructor argument.
@@ -53,6 +55,7 @@ class CppCompileTest extends AbstractProjectBuilderSpec { | |||
cppCompile.objectFileDir = temporaryFolder.file("outputFile") | |||
cppCompile.source sourceFile | |||
cppCompile.setPreCompiledHeader pch | |||
cppCompile.sourceCompatibility = Cpp11 |
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.
❌ There is a missing coverage when the source compatibility isn't set. It should result in the spec property to be null.
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 added another test to demonstrate this behavior. Let me know what you think.
CppCompiler(BuildOperationExecutor buildOperationExecutor, CompilerOutputFileNamingSchemeFactory compilerOutputFileNamingSchemeFactory, CommandLineToolInvocationWorker commandLineToolInvocationWorker, CommandLineToolContext invocationContext, String objectFileExtension, boolean useCommandFile, WorkerLeaseService workerLeaseService) { | ||
super(buildOperationExecutor, compilerOutputFileNamingSchemeFactory, commandLineToolInvocationWorker, invocationContext, new CppCompileArgsTransformer(), Transformers.<CppCompileSpec>noOpTransformer(), objectFileExtension, useCommandFile, workerLeaseService); | ||
CppCompiler(BuildOperationExecutor buildOperationExecutor, CompilerOutputFileNamingSchemeFactory compilerOutputFileNamingSchemeFactory, CommandLineToolInvocationWorker commandLineToolInvocationWorker, CommandLineToolContext invocationContext, String objectFileExtension, boolean useCommandFile, WorkerLeaseService workerLeaseService, CompilerType compilerType, VersionNumber compilerVersion) { | ||
super(buildOperationExecutor, compilerOutputFileNamingSchemeFactory, commandLineToolInvocationWorker, invocationContext, new CppCompileArgsTransformer(compilerType, compilerVersion), Transformers.<CppCompileSpec>noOpTransformer(), objectFileExtension, useCommandFile, workerLeaseService); |
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.
❌ Instead of passing the version inside the constructor and causing lots of waterfall changes, I think we should simply set the version on the spec
here. You would be required to add CompilerVersion
getter/setter on CompileSpec
. You will need to add test coverage for version aware compiler wrapped vs normal compiler. There isn't any yet, so just add a unit test Specification
as VersionAwareCompilerTest
and mock the wrapped compiler to assert the version is properly set on the CompileSpec
.
The CompilerVersion
most likely contains the String that would identify Clang vs GCC, however, I would still create typed CppCompiler
for both tool chain simply because we want to avoid comparing strings and such.
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.
Should we really be adding this getter/setter on CompileSpec
? It's pretty high-level interface, and it would require changing a number of classes unrelated to this PR (e.g., JavadocSpec
).
this.compilerType = compilerType; | ||
this.compilerVersion = compilerVersion; | ||
} | ||
|
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.
❌ This would go away with the change explained above.
OutputCleaningCompiler<CppCompileSpec> outputCleaningCompiler = new OutputCleaningCompiler<CppCompileSpec>(cppCompiler, compilerOutputFileNamingSchemeFactory, getObjectFileExtension()); | ||
return versionAwareCompiler(outputCleaningCompiler, ToolType.CPP_COMPILER); | ||
return versionAwareCompiler(outputCleaningCompiler, gccMetadata); |
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.
❌ This would also go away with the change explained above.
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Prior to clang 6, the default C++ dialect is GNU C++98. From clang 6 and after, the default dialect is GNU C++14. This change also recognizes that the default dialects use the GNU C++ extensions as state in the clang documentation. Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
After rereading the GCC documentation, the default C++ dialect, if std is not chosen, is GNU C++. Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
Signed-off-by: Kevin Macksamie <kevin.macksamie@gmail.com>
@lacasseio should this be closed and restarted? Since #8222 was merged, I'm assuming source compatibility should be put in the CppPlatform to align with the goals of gradle/gradle-native#963. Either way, let me know how we should proceed. |
This pull request has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be closed if no further activity occurs. If you intend to work on this pull request, please reopen the PR. Thank you for your contributions. |
This pull request has been automatically closed due to inactivity. If you are still interested in contributing this, please ensure that it is rebased against the latest branch (usually |
Context
See gradle/gradle-native#399.
/cc @lacasseio
sourceCompatibility
is added to the new C++ plugins for the GCC and Clang toolchains, enabling users to declare a C++ binary's source compatibility. The introduced source compatibilities areCpp98
,Cpp03
,Cpp11
,Cpp17
, andCpp2a
. TheCppSourceCompatibility
enum will have to be updated with any future compatibilities. In addition,GccVersionCppSourceCompatibility
andClangVersionCppSourceCompatibility
encapsulate the logic that translates aCppSourceCompatibility
into the correct command-line argument for the compiler. This requires knowledge of the compiler's version.Contributor Checklist
<subproject>/src/integTest
) to verify changes from a user perspective<subproject>/src/test
) to verify logic./gradlew <changed-subproject>:check
Gradle Core Team Checklist