From 6c0e3a3272340a0c0cfe44ebad7b9bc39c981b28 Mon Sep 17 00:00:00 2001 From: Alex Bryan Date: Fri, 19 Jan 2024 01:56:11 -0500 Subject: [PATCH] Fix #2698: cImportPaths doesn't work with dmd and ldc --- changelog/fix-cimport-paths.dd | 3 +++ source/dub/compilers/dmd.d | 2 +- source/dub/compilers/ldc.d | 2 +- .../c_headers/foo.h | 6 ++++++ test/issue2698-cimportpaths-broken-with-dmd-ldc/dub.sdl | 5 +++++ .../source/app.d | 7 +++++++ .../source/foo.c | 1 + 7 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 changelog/fix-cimport-paths.dd create mode 100644 test/issue2698-cimportpaths-broken-with-dmd-ldc/c_headers/foo.h create mode 100644 test/issue2698-cimportpaths-broken-with-dmd-ldc/dub.sdl create mode 100644 test/issue2698-cimportpaths-broken-with-dmd-ldc/source/app.d create mode 100644 test/issue2698-cimportpaths-broken-with-dmd-ldc/source/foo.c diff --git a/changelog/fix-cimport-paths.dd b/changelog/fix-cimport-paths.dd new file mode 100644 index 000000000..7bab23dc4 --- /dev/null +++ b/changelog/fix-cimport-paths.dd @@ -0,0 +1,3 @@ +Fix issue where cImportPaths wasn't working with dmd and ldc + +dub was passing -I instead of -P-I as is required by those compilers diff --git a/source/dub/compilers/dmd.d b/source/dub/compilers/dmd.d index 5b59d2b99..8d58f515c 100644 --- a/source/dub/compilers/dmd.d +++ b/source/dub/compilers/dmd.d @@ -257,7 +257,7 @@ config /etc/dmd.conf } if (!(fields & BuildSetting.cImportPaths)) { - settings.addDFlags(settings.cImportPaths.map!(s => "-I"~s)().array()); + settings.addDFlags(settings.cImportPaths.map!(s => "-P-I"~s)().array()); settings.cImportPaths = null; } diff --git a/source/dub/compilers/ldc.d b/source/dub/compilers/ldc.d index 3959df615..bd6193346 100644 --- a/source/dub/compilers/ldc.d +++ b/source/dub/compilers/ldc.d @@ -137,7 +137,7 @@ config /etc/ldc2.conf (x86_64-pc-linux-gnu) } if (!(fields & BuildSetting.cImportPaths)) { - settings.addDFlags(settings.cImportPaths.map!(s => "-I"~s)().array()); + settings.addDFlags(settings.cImportPaths.map!(s => "-P-I"~s)().array()); settings.cImportPaths = null; } diff --git a/test/issue2698-cimportpaths-broken-with-dmd-ldc/c_headers/foo.h b/test/issue2698-cimportpaths-broken-with-dmd-ldc/c_headers/foo.h new file mode 100644 index 000000000..dab60af48 --- /dev/null +++ b/test/issue2698-cimportpaths-broken-with-dmd-ldc/c_headers/foo.h @@ -0,0 +1,6 @@ +#include + +int bar(void) +{ + printf("func bar in foo.h\n"); +} diff --git a/test/issue2698-cimportpaths-broken-with-dmd-ldc/dub.sdl b/test/issue2698-cimportpaths-broken-with-dmd-ldc/dub.sdl new file mode 100644 index 000000000..837f5274d --- /dev/null +++ b/test/issue2698-cimportpaths-broken-with-dmd-ldc/dub.sdl @@ -0,0 +1,5 @@ +name "issue2698-cimportpaths-broken-with-dmd-ldc" +description "test issue 2698" +authors "alexander bryan" +cSourcePaths "source" +cImportPaths "c_headers" diff --git a/test/issue2698-cimportpaths-broken-with-dmd-ldc/source/app.d b/test/issue2698-cimportpaths-broken-with-dmd-ldc/source/app.d new file mode 100644 index 000000000..6413a1cd8 --- /dev/null +++ b/test/issue2698-cimportpaths-broken-with-dmd-ldc/source/app.d @@ -0,0 +1,7 @@ +import std.stdio; +import foo; + +void main() +{ + bar(); +} diff --git a/test/issue2698-cimportpaths-broken-with-dmd-ldc/source/foo.c b/test/issue2698-cimportpaths-broken-with-dmd-ldc/source/foo.c new file mode 100644 index 000000000..f4de601ff --- /dev/null +++ b/test/issue2698-cimportpaths-broken-with-dmd-ldc/source/foo.c @@ -0,0 +1 @@ +#include "foo.h"