diff --git a/source/dub/compilers/dmd.d b/source/dub/compilers/dmd.d index 78fd9d4..5b59d2b 100644 --- a/source/dub/compilers/dmd.d +++ b/source/dub/compilers/dmd.d @@ -230,6 +230,11 @@ { enforceBuildRequirements(settings); + // Keep the current dflags at the end of the array so that they will overwrite other flags. + // This allows user $DFLAGS to modify flags added by us. + const dflagsTail = settings.dflags; + settings.dflags = []; + if (!(fields & BuildSetting.options)) { foreach (t; s_options) if (settings.options & t[0]) @@ -282,6 +287,8 @@ if (platform.platform.canFind("posix") && (settings.options & BuildOption.pic)) settings.addDFlags("-fPIC"); + settings.addDFlags(dflagsTail); + assert(fields & BuildSetting.dflags); assert(fields & BuildSetting.copyFiles); } diff --git a/source/dub/compilers/gdc.d b/source/dub/compilers/gdc.d index 0d34446..3df8eda 100644 --- a/source/dub/compilers/gdc.d +++ b/source/dub/compilers/gdc.d @@ -89,6 +89,11 @@ { enforceBuildRequirements(settings); + // Keep the current dflags at the end of the array so that they will overwrite other flags. + // This allows user $DFLAGS to modify flags added by us. + const dflagsTail = settings.dflags; + settings.dflags = []; + if (!(fields & BuildSetting.options)) { foreach (t; s_options) if (settings.options & t[0]) @@ -138,6 +143,8 @@ if (settings.options & BuildOption.pic) settings.addDFlags("-fPIC"); + settings.addDFlags(dflagsTail); + assert(fields & BuildSetting.dflags); assert(fields & BuildSetting.copyFiles); } diff --git a/source/dub/compilers/ldc.d b/source/dub/compilers/ldc.d index 3cb90e5..3959df6 100644 --- a/source/dub/compilers/ldc.d +++ b/source/dub/compilers/ldc.d @@ -107,6 +107,11 @@ import std.format : format; enforceBuildRequirements(settings); + // Keep the current dflags at the end of the array so that they will overwrite other flags. + // This allows user $DFLAGS to modify flags added by us. + const dflagsTail = settings.dflags; + settings.dflags = []; + if (!(fields & BuildSetting.options)) { foreach (t; s_options) if (settings.options & t[0]) @@ -170,6 +175,8 @@ } } + settings.addDFlags(dflagsTail); + assert(fields & BuildSetting.dflags); assert(fields & BuildSetting.copyFiles); } diff --git a/source/dub/package_.d b/source/dub/package_.d index 307ad78..79be1ed 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -422,10 +422,6 @@ */ void addBuildTypeSettings(ref BuildSettings settings, in BuildPlatform platform, string build_type) const { - import std.process : environment; - string dflags = environment.get("DFLAGS", ""); - settings.addDFlags(dflags.split()); - if (auto pbt = build_type in m_info.buildTypes) { logDiagnostic("Using custom build type '%s'.", build_type); pbt.getPlatformSettings(settings, platform, this.path); @@ -450,6 +446,11 @@ case "syntax": settings.addOptions(syntaxOnly); break; } } + + // Add environment DFLAGS last so that user specified values are not overriden by us. + import std.process : environment; + string dflags = environment.get("DFLAGS", ""); + settings.addDFlags(dflags.split()); } /** Returns the selected configuration for a certain dependency.