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

Support for C++ source compatibility #8055

Closed
wants to merge 29 commits into from

Conversation

k-mack
Copy link
Contributor

@k-mack k-mack commented Dec 17, 2018

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 are Cpp98, Cpp03, Cpp11, Cpp17, and Cpp2a. The CppSourceCompatibility enum will have to be updated with any future compatibilities. In addition, GccVersionCppSourceCompatibility and ClangVersionCppSourceCompatibility encapsulate the logic that translates a CppSourceCompatibility into the correct command-line argument for the compiler. This requires knowledge of the compiler's version.

Contributor Checklist

  • Review Contribution Guidelines
  • Make sure that all commits are signed off to indicate that you agree to the terms of Developer Certificate of Origin.
  • Check "Allow edit from maintainers" option in pull request so that additional changes can be pushed by Gradle team
  • Provide integration tests (under <subproject>/src/integTest) to verify changes from a user perspective
  • Provide unit tests (under <subproject>/src/test) to verify logic
  • Update User Guide, DSL Reference, and Javadoc for public-facing changes
  • Ensure that tests pass locally: ./gradlew <changed-subproject>:check

Gradle Core Team Checklist

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation
  • Recognize contributor in release notes

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>
Copy link
Contributor

@lacasseio lacasseio left a 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 👍

}
}
}
}
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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;
}

Copy link
Contributor

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);
Copy link
Contributor

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>
@k-mack
Copy link
Contributor Author

k-mack commented Feb 3, 2019

@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.

@big-guy big-guy added the @core Issue owned by GBT Core label Jun 19, 2019
@lacasseio lacasseio added the in:native-platform c, cpp, swift and other native languages support, etc label Sep 11, 2019
@big-guy big-guy added this to the 6.2 RC1 milestone Nov 5, 2019
@big-guy big-guy modified the milestones: 6.2 RC1, 6.3 RC1 Jan 27, 2020
@big-guy big-guy modified the milestones: 6.3 RC1, 6.4 RC1 Mar 2, 2020
@big-guy big-guy removed this from the 6.4 RC1 milestone Mar 10, 2020
@stale
Copy link

stale bot commented Aug 5, 2020

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.

@stale stale bot added the stale label Aug 5, 2020
@stale
Copy link

stale bot commented Aug 26, 2020

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 master), all review comments have been addressed and the build is passing.

@stale stale bot closed this Aug 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@core Issue owned by GBT Core in:native-platform c, cpp, swift and other native languages support, etc stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants