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
Enables C preprocessing for .i files #16386
base: master
Are you sure you want to change the base?
Conversation
Thanks for your pull request and interest in making D better, @denizzzka! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
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 referencesYour 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 locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#16386" |
Can't you rename those back to .c? If .i gets preprocessed as well, what's the difference between .i and .c? |
.i can be preprocessed as non-standard C17 sources, for example: __extension__ typedef long long _off64_t;
static __inline int _putchar_unlocked(int _c); Such preprocessed file causes ImportC "Error: illegal combination of type specifiers" for both lines. Also, renaming to .c can't be used here, because .i files can contain such # 0 "/home/denizzz/Dev/Aeth/Espressif_IDE/esp-idf-v5.2.1/components/driver/gpio/gpio.c"
# 1 "/home/denizzz/Dev/БЦИ-1/mcu_software/build//"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/home/denizzz/Dev/Aeth/Espressif_IDE/esp-idf-v5.2.1/components/driver/gpio/gpio.c"
# 41 "/home/denizzz/.espressif/tools/riscv32-esp-elf/esp-13.2.0_20230928/riscv32-esp-elf/riscv32-esp-elf/sys-include/machine/_default_types.h" 3 4
typedef signed char __int8_t; In fact, for now this patch just applies preprocessor (with onboard I think there is no need to differentiate between .i and .h/.c files - all of them need to be preprocessed by a preprocessor with same |
Perhaps here is also needed compiler flag like: “Strict compliance with the C11 standard” which disables |
cb6a245
to
23a28ee
Compare
In other words, the file is preprocessed, but gcc/clang support parsing all the alternative names for C keywords (before they got standardised). |
@ibuclaw yes I do not like name Another question: should this option be hidden from |
Looks like MS preprocessor can't preprocess already preprocessed files :-( |
ImportC runs the preprocessor when compiling .c files. This relies on the file Therefore, if one is using a C build system to cache generated .i files, add the |
More precisely, before compilation. And .h files #included in .c files are preprocessed too. This is important, see below
As I understand you, my PR is about another thing: it eliminates the unfair difference between importing "non-standard" .c (which automatically preprocessed with mentioned above |
Doesn't every C build system have a means to add switches to the preprocessor? |
This is what I meant by "manually" But we don’t preprocess regular .c files in this manner - preprocessor for us called by D compiler. I think for .i files should be same behaviour |
Also, in case of separate run of preprocessor we should know where is |
4e74374
to
9b2ae36
Compare
New option removed, replaced by |
9b2ae36
to
de416fe
Compare
1548cd2
to
a89e96f
Compare
It has nothing to do with fairness. I don't understand why the user cannot add a switch to their build to add in the necessary .h file. |
(I meant what .c files is 1-st class passengers, but .i isn't for some unknown reason) .c files can be processed by an external preprocessor too, but D compiler invokes preprocessor by itself. But not for .i files.
It's just pointless extra work that could very easily be avoided. (For hypotetical rare cases when importc.h incompartible with used C code this PR allows to disable preprocessor at all) |
58430af
to
509bb61
Compare
509bb61
to
2e7ebab
Compare
The reason is .i is for preprocessed files, so no preprocessor should be run on them. |
Why not? By default no one knows (from outside of the D compiler, I mean) that actually .i file implictly preprocessed again. Compiler pretends what it just understands all theese C dialects. After all, that was the idea of calling preprocessor with importc.h internally? |
I tried, and dmd compiles that snippet just fine. |
Oh, it's only a problem on Windows version (Windows) enum canPreprocessTwice = false; |
@dkorpel yes, and I left this line instead of |
Use case: Almost any C build system provides way to create *.i files during compilation (
-save-temps
flag). But usually C sources do not meet to the strict requirements of C11 standard needed by importC.Ability to preprocess already preprocessed C files is useful in this case.
We can just pass preprocessor over all *.i files recursively and it will convert files to a suitable for importC C version (replaces__inline__
toinline
and so)upd: This PR enables implicit preprocessing of .i files (same as works preprocessing .c files and included .h files)
This way we are spared from the need of enter/search/maintain/fetch of sets of definition flags for .c code used by D compiler - external C preprocessor does this job for us, just use generated .i files as bindings!