HPCC-Platform icon indicating copy to clipboard operation
HPCC-Platform copied to clipboard

HPCC-29808 Enable C++17 features for embedded C++ code

Open dcamper opened this issue 1 year ago • 9 comments

Type of change:

  • [ ] This change is a bug fix (non-breaking change which fixes an issue).
  • [x] This change is a new feature (non-breaking change which adds functionality).
  • [ ] This change improves the code (refactor or other change that does not change the functionality)
  • [ ] This change fixes warnings (the fix does not alter the functionality or the generated code)
  • [ ] This change is a breaking change (fix or feature that will cause existing behavior to change).
  • [ ] This change alters the query API (existing queries will have to be recompiled)

Checklist:

  • [x] My code follows the code style of this project.
    • [x] My code does not create any new warnings from compiler, build system, or lint.
  • [x] The commit message is properly formatted and free of typos.
    • [x] The commit message title makes sense in a changelog, by itself.
    • [x] The commit is signed.
  • [ ] My change requires a change to the documentation.
    • [ ] I have updated the documentation accordingly, or...
    • [ ] I have created a JIRA ticket to update the documentation.
    • [ ] Any new interfaces or exported functions are appropriately commented.
  • [ ] I have read the CONTRIBUTORS document.
  • [ ] The change has been fully tested:
    • [ ] I have added tests to cover my changes.
    • [ ] All new and existing tests passed.
    • [ ] I have checked that this change does not introduce memory leaks.
    • [ ] I have used Valgrind or similar tools to check for potential issues.
  • [ ] I have given due consideration to all of the following potential concerns:
    • [ ] Scalability
    • [ ] Performance
    • [ ] Security
    • [ ] Thread-safety
    • [ ] Cloud-compatibility
    • [ ] Premature optimization
    • [ ] Existing deployed queries will not be broken
    • [ ] This change fixes the problem, not just the symptom
    • [ ] The target branch of this pull request is appropriate for such a change.
  • [ ] There are no similar instances of the same problem that should be addressed
    • [ ] I have addressed them here
    • [ ] I have raised JIRA issues to address them separately
  • [ ] This is a user interface / front-end modification
    • [ ] I have tested my changes in multiple modern browsers
    • [ ] The component(s) render as expected

Smoketest:

  • [ ] Send notifications about my Pull Request position in Smoketest queue.
  • [ ] Test my draft Pull Request.

Testing:

Manual spot-check of regression tests as well as a couple of embedded C++ functions I had that used C++17 features.

dcamper avatar Jun 23 '23 17:06 dcamper

https://track.hpccsystems.com/browse/HPCC-29808 Jira updated

github-actions[bot] avatar Jun 23 '23 19:06 github-actions[bot]

Related to our offline conversation about runtime compatibility of older clusters: From https://gcc.gnu.org/projects/cxx-status.html#cxx17:

C++17 Support in GCC

GCC has almost full support for the previous revision of the C++ standard, which was published in 2017. The status of C++17 library features is described in the library documentation.

C++17 mode is the default since GCC 11; it can be explicitly selected with the -std=c++17 command-line flag, or -std=gnu++17 to enable GNU extensions as well. Some C++17 features are available since GCC 5, but support was experimental and the ABI of C++17 features was not stable until GCC 9.

dcamper avatar Jun 26 '23 15:06 dcamper

Adding runtime environment notes to this PR from offline conversations.

Apparently there are still CentOS 7.9 environments in production, and the default compiler version is 4.8.5. gcc 4.8.5 supports exactly three features in C++17, which is of course a small subset. That version also supports only a subset of C++14, which is a bit surprising.

If we want to remain compatible with those environments then blindly enabling C++17 features will end badly.

It is theoretically possible to determine the std features to enable (c++11, c++14, or c++17) at runtime. Is that a good idea, though? It would mean that, for instance, embedded C++ functions written for platform version 9.0.22 run fine under one OS but fail to compile in another. Is that acceptable behavior, if it is documented?

dcamper avatar Jun 27 '23 14:06 dcamper

On systems where an older compiler is the default, do we not already deploy a newer one in order to support the functionality required by the generated code? I thought we did.

richardkchapman avatar Jun 28 '23 08:06 richardkchapman

We download updated compilers at build time, but I don't think they are pushed to the built package for installation. I just downloaded the CentOS7 .rpm and looked at the contents. I did not find a compiler. @GordonSmith could answer that definitively, though.

dcamper avatar Jun 28 '23 12:06 dcamper

How about a hash option compileflags 'xyz' ? Or some config setting for custom compile flags ??

mckellyln avatar Jun 28 '23 12:06 mckellyln

If a dev added something like #compileflags --std=c++17 to an embedded function then I think the result is really defining the minimum feature set the function requires. The definitions I changed in this PR define the maximum feature set, in essence.

If #compileflags was used and the underlying compiler doesn't support the flag then the code will fail to compile, which is the same result as it would be without using the option. The error message may be more sensible, though (maybe).

That said, the general idea of having a #compileflags feature at all is interesting.

dcamper avatar Jun 28 '23 12:06 dcamper

I don't believe any of the packages have a way to download and update the build tools for the host environment.

GordonSmith avatar Jun 28 '23 13:06 GordonSmith

When we finally drop centos 7 support this should be looked at again.

ghalliday avatar Sep 10 '24 12:09 ghalliday