dlang / dub

Package and build management system for D
MIT License
673 stars 230 forks source link

The compiler is not setting options for the C preprocessor even though "cImportPaths" is set in dub.json. #2698

Open takinutani opened 1 year ago

takinutani commented 1 year ago

This is related to the following post in the forum. Dub option for specifying importC include paths

System information

Bug Description

The compiler is not setting options for the C preprocessor even though "cImportPaths" is set in dub.json. In the following code, Lack of append -P when editing DFlag.

settings.addDFlags(settings.cImportPaths.map!(s => "-I"~s)().array());

at

dub/1.34.0/dub/source/dub/compilers/dmd.d(255,32):          settings.addDFlags(settings.cImportPaths.map!(s => "-I"~s)().array());
dub/1.34.0/dub/source/dub/compilers/gdc.d(114,32):          settings.addDFlags(settings.cImportPaths.map!(s => "-I"~s)().array());
dub/1.34.0/dub/source/dub/compilers/ldc.d(135,32):          settings.addDFlags(settings.cImportPaths.map!(s => "-I"~s)().array());

How to reproduce?

dub.json

{
        "name": "test",
        "cImportPaths": ["include_path"]
}
(base) PS D:\labo\dlang\work\test> D:\scoop\user\apps\dmd\2.105.1\windows\bin\dub.exe build -v --compiler=dmd

    Building test ~master: building configuration [application]
[cwd=D:/labo/dlang/work/test] dmd -m64 -c -ofC:\Users\kinut\AppData\Local\dub\cache\test\~master\build\application-debug-wwJttrcyM7Ir6TFENv5q2A\test.obj -debug -g -w -version=Have_test -Isource -Iinclude_path source\app.d -vcolumns
(base) PS D:\labo\dlang\work\test> D:\scoop\user\apps\ldc\1.34.0\bin\dub.exe build -v --compiler=ldc2

    Building test ~master: building configuration [application]
ldc2 -c -ofC:\Users\kinut\AppData\Local\dub\cache\test\~master\build\application-debug-GclWdmZTTjBXFPnUBK5wPg\test.obj -d-debug -g -w --oq -od=C:\Users\kinut\AppData\Local\dub\cache\test\~master\build\application-debug-GclWdmZTTjBXFPnUBK5wPg/obj -d-version=Have_test -Isource -Iinclude_path source\app.d -vcolumns

Expected Behavior

dmd --help

(base) PS D:\labo\dlang\work\test> dmd --help
  -P=<preprocessorflag>
                    pass preprocessorflag to C preprocessor

In dmd, -Iinclude_path should be -P=-Iinclude_path

ldc2 --help

(base) PS D:\labo\dlang\work\test> ldc2 --help
  -P <cppflag>                                 - Pass <cppflag> to C preprocessor

In ldc, -Iinclude_path should be -P-Iinclude_path

apbryan commented 8 months ago

In gdc, it appears -Iinclude_path works, though it is undocumented