Skip to content

Revive Generate C++ header files from public extern (C++) declarations #9971

Closed
edi33416 wants to merge 44 commits intodlang:masterfrom
edi33416:pr/8591
Closed

Revive Generate C++ header files from public extern (C++) declarations #9971
edi33416 wants to merge 44 commits intodlang:masterfrom
edi33416:pr/8591

Conversation

@edi33416
Copy link
Contributor

@edi33416 edi33416 commented Jun 4, 2019

This PR takes #8591, rebases with master and converts it into a compiler switch.
This is a separate PR as I don't have the rights to push to existing dmd PRs.

Credit to @ibuclaw for the actual work.

@dlang-bot dlang-bot added the Review:WIP Work In Progress - not ready for review or pulling label Jun 4, 2019
@dlang-bot
Copy link
Contributor

dlang-bot commented Jun 4, 2019

Thanks for your pull request and interest in making D better, @edi33416! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + dmd#9971"

@andralex
Copy link
Member

andralex commented Jun 4, 2019

This is for GSoC - @edi33416 please reach out to @ibuclaw about what's still to be done.

@andralex
Copy link
Member

andralex commented Jun 4, 2019

Bootstrapping is an issue now - we need to compile the compiler before using it to generate the headers. @edi33416 please make sure the compiler does not need the headers.

@jacob-carlborg
Copy link
Contributor

I guess the same comments that were made in the original PR apply here as well.

@wilzbach
Copy link
Contributor

wilzbach commented Jun 4, 2019

Bootstrapping is an issue now - we need to compile the compiler before using it to generate the headers.

That is no concern. D already requires a host D compiler (>= 2.079) to be built and has no dependence on C++ anymore.

@ibuclaw
Copy link
Member

ibuclaw commented Jun 10, 2019

As far as I'm aware, no testing of this has been done beyond the cxxfrontend unittests, which only covers a small amount of the actual use of the c++ api. So integration with gdc and ldc - as well as bootstrapping - would also be required as a preliminary requirement.

Secondly, we should have a way to red flag any prs that modify the output of the c++ headers, so that extra checking can be done to verify its correctness.


diff -pu --strip-trailing-cr ${EXTRA_FILES}/${TEST_NAME}.out ${OUTPUT_BASE}.out

rm -f ${OUTPUT_BASE}.out
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there really a need for removing this file? Might be useful for debugging when the test failed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test suite will complain if any files are left over with the shell tests (which I despise). Also this should be made in to a D test rather than a shell one. The less shell tests the better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it won't. It will only complain if the files aren't placed in the test_results directory.

//}

/****************************************************
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actual description

@wilzbach
Copy link
Contributor

Secondly, we should have a way to red flag any prs that modify the output of the c++ headers, so that extra checking can be done to verify its correctness.

This could be done by simply checking in the generated DMD frontend C++ headers into the source code and in one CI checking whether the output has been changed. This way all future changes to the C++ headers will be visible and I'm sure we can either make the test work with AUTO_UPDATE=1 or probably a simple update command, s.t. it's no big hassle for people when they touch the headers.
Additionally, this would make bootstrapping for LDC/GDC even easier.

@wilzbach wilzbach changed the title [WIP] Revive Generate C++ header files from public extern (C++) declarations Revive Generate C++ header files from public extern (C++) declarations Oct 19, 2019
@wilzbach wilzbach removed the Review:WIP Work In Progress - not ready for review or pulling label Oct 19, 2019
@TurkeyMan
Copy link
Contributor

Let's make this PR happen people!
Needs a rebase... are we happy to merge it in prototype form, then it can be improved incrementally going forward? I would contribute to this if it were merged.

@MoonlightSentinel
Copy link
Contributor

The initial version could be limited to the test suite without the changes to existing C++ headers/Tests. That would yield a much smaller change and avoid breaking stuff while being WIP.

MoonlightSentinel added a commit to MoonlightSentinel/dmd that referenced this pull request Feb 18, 2020
The -HC switch let's dmd output header files from existing extern(C++)
files to ease C++ interoperation. Use -HCd=<directory> / -HCf=<file>
to select the directory/file where the header should be generated.

The following commits were squashed from dlang#9971 without the changes
to the existing C++ interface/test suite:

Testing D to H tool

Remove unused and redundant dmd headers

Improve dtoh

Factor out compiler specific parts
Attempt to make cross platform

Fix stuff

Add dtoh as a compiler switch

Update code after rebase

Compile frontend srcs and write to flie

Add dtoh enum test

Add free functions dtoh test

Add unittest block dtoh test

Add VarDeclaration dtoh test

Add AliasDeclaration dtoh test

Add AnonDeclaration dtoh test

Add StructDeclaration dtoh test

Add ClassDeclaration dtoh test

Add TemplateDeclaration dtoh test

Add debug prints

Fix struct field void initializer

Add ignoredModule tmp helper

Add tmp workaround for alias forward decl and >> template issue

Add support for enum base type

Add support for alignment of pow2

Fix alignment issues

Generate enums based on -extern-std version

Update tool auto-gen message

Update tests

Code cleanup

CPP does not support covariant const methods

Correctly write ctor declarations

Generate default args for literals

Generate dtor and copy ctor declarations

Rebase with master

Add compiler switch to cli.d

Update tests

Add support for @disable

Improve default ctor generation

Update struct decl test

Use member initializer list for default ctor definition

Co-Authored-By: Eduard Staniloiu <edi33416@gmail.com>

(Rebase + Fixup)
Co-Authored-By: MoonlightSentinel <moonlightsentinel@disroot.org>
MoonlightSentinel added a commit to MoonlightSentinel/dmd that referenced this pull request Feb 19, 2020
The -HC switch let's dmd output header files from existing extern(C++)
files to ease C++ interoperation. Use -HCd=<directory> / -HCf=<file>
to select the directory/file where the header should be generated.

The following commits were squashed from dlang#9971 without the changes
to the existing C++ interface/test suite:

Testing D to H tool

Remove unused and redundant dmd headers

Improve dtoh

Factor out compiler specific parts
Attempt to make cross platform

Fix stuff

Add dtoh as a compiler switch

Update code after rebase

Compile frontend srcs and write to flie

Add dtoh enum test

Add free functions dtoh test

Add unittest block dtoh test

Add VarDeclaration dtoh test

Add AliasDeclaration dtoh test

Add AnonDeclaration dtoh test

Add StructDeclaration dtoh test

Add ClassDeclaration dtoh test

Add TemplateDeclaration dtoh test

Add debug prints

Fix struct field void initializer

Add ignoredModule tmp helper

Add tmp workaround for alias forward decl and >> template issue

Add support for enum base type

Add support for alignment of pow2

Fix alignment issues

Generate enums based on -extern-std version

Update tool auto-gen message

Update tests

Code cleanup

CPP does not support covariant const methods

Correctly write ctor declarations

Generate default args for literals

Generate dtor and copy ctor declarations

Rebase with master

Add compiler switch to cli.d

Update tests

Add support for @disable

Improve default ctor generation

Update struct decl test

Use member initializer list for default ctor definition

Co-Authored-By: Eduard Staniloiu <edi33416@gmail.com>

(Rebase + Fixup)
Co-Authored-By: MoonlightSentinel <moonlightsentinel@disroot.org>
MoonlightSentinel added a commit to MoonlightSentinel/dmd that referenced this pull request Feb 20, 2020
The -HC switch let's dmd output header files from existing extern(C++)
files to ease C++ interoperation. Use -HCd=<directory> / -HCf=<file>
to select the directory/file where the header should be generated.

The following commits were squashed from dlang#9971 without the changes
to the existing C++ interface/test suite:

Testing D to H tool

Remove unused and redundant dmd headers

Improve dtoh

Factor out compiler specific parts
Attempt to make cross platform

Fix stuff

Add dtoh as a compiler switch

Update code after rebase

Compile frontend srcs and write to flie

Add dtoh enum test

Add free functions dtoh test

Add unittest block dtoh test

Add VarDeclaration dtoh test

Add AliasDeclaration dtoh test

Add AnonDeclaration dtoh test

Add StructDeclaration dtoh test

Add ClassDeclaration dtoh test

Add TemplateDeclaration dtoh test

Add debug prints

Fix struct field void initializer

Add ignoredModule tmp helper

Add tmp workaround for alias forward decl and >> template issue

Add support for enum base type

Add support for alignment of pow2

Fix alignment issues

Generate enums based on -extern-std version

Update tool auto-gen message

Update tests

Code cleanup

CPP does not support covariant const methods

Correctly write ctor declarations

Generate default args for literals

Generate dtor and copy ctor declarations

Rebase with master

Add compiler switch to cli.d

Update tests

Add support for @disable

Improve default ctor generation

Update struct decl test

Use member initializer list for default ctor definition

Co-Authored-By: Eduard Staniloiu <edi33416@gmail.com>

(Rebase + Fixup)
Co-Authored-By: MoonlightSentinel <moonlightsentinel@disroot.org>
MoonlightSentinel added a commit to MoonlightSentinel/dmd that referenced this pull request Feb 20, 2020
The -HC switch let's dmd output header files from existing extern(C++)
files to ease C++ interoperation. Use -HCd=<directory> / -HCf=<file>
to select the directory/file where the header should be generated.

The following commits were squashed from dlang#9971 without the changes
to the existing C++ interface/test suite:

Testing D to H tool

Remove unused and redundant dmd headers

Improve dtoh

Factor out compiler specific parts
Attempt to make cross platform

Fix stuff

Add dtoh as a compiler switch

Update code after rebase

Compile frontend srcs and write to flie

Add dtoh enum test

Add free functions dtoh test

Add unittest block dtoh test

Add VarDeclaration dtoh test

Add AliasDeclaration dtoh test

Add AnonDeclaration dtoh test

Add StructDeclaration dtoh test

Add ClassDeclaration dtoh test

Add TemplateDeclaration dtoh test

Add debug prints

Fix struct field void initializer

Add ignoredModule tmp helper

Add tmp workaround for alias forward decl and >> template issue

Add support for enum base type

Add support for alignment of pow2

Fix alignment issues

Generate enums based on -extern-std version

Update tool auto-gen message

Update tests

Code cleanup

CPP does not support covariant const methods

Correctly write ctor declarations

Generate default args for literals

Generate dtor and copy ctor declarations

Rebase with master

Add compiler switch to cli.d

Update tests

Add support for @disable

Improve default ctor generation

Update struct decl test

Use member initializer list for default ctor definition

Co-Authored-By: Eduard Staniloiu <edi33416@gmail.com>

(Rebase + Fixup)
Co-Authored-By: MoonlightSentinel <moonlightsentinel@disroot.org>
@moon-chilled
Copy link

Superseded by #10801, so this should probably be closed.

CC @edi33416 @wilzbach

@wilzbach
Copy link
Contributor

Yes, though I will let Edi close or update his PR as it contains a few more things. Most importantly the setup to emit the header files for DMD itself

@ibuclaw ibuclaw added the Feature:dtoh C++ header generation label Sep 28, 2020
@RazvanN7
Copy link
Contributor

I'm gonna close this since the superseded #10801 got merged and since then it was continuously improved. If any of the features in this PR are needed, the PR is already linked to the one that got in.

@RazvanN7 RazvanN7 closed this Jan 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:dtoh C++ header generation

Projects

None yet

Development

Successfully merging this pull request may close these issues.