diff --git a/changelog/actual-dynamiclibrary.dd b/changelog/actual-dynamiclibrary.dd new file mode 100644 index 0000000..15757e0 --- /dev/null +++ b/changelog/actual-dynamiclibrary.dd @@ -0,0 +1,7 @@ +Builds dynamicLibrary targets as dynamic libraries instead of static libraries. + +Dub will no longer build dynamicLibrary targetType's as staticLibrary. + +Except for x86_omf. This has been disabled due to numerous issues that will lead this to not doing what is expected of it. + +No compiler or linker flags have been added at this time, you will need to specify the relevant flag to get the compiler to link dynamically against Phobos. diff --git a/source/dub/generators/generator.d b/source/dub/generators/generator.d index 2c87ee9..2b4a7da 100644 --- a/source/dub/generators/generator.d +++ b/source/dub/generators/generator.d @@ -252,15 +252,21 @@ auto roottarget = &targets[rootPackage.name]; // 0. do shallow configuration (not including dependencies) of all packages - TargetType determineTargetType(const ref TargetInfo ti) + TargetType determineTargetType(const ref TargetInfo ti, const ref GeneratorSettings genSettings) { TargetType tt = ti.buildSettings.targetType; if (ti.pack is rootPackage) { if (tt == TargetType.autodetect || tt == TargetType.library) tt = TargetType.staticLibrary; } else { if (tt == TargetType.autodetect || tt == TargetType.library) tt = genSettings.combined ? TargetType.sourceLibrary : TargetType.staticLibrary; - else if (tt == TargetType.dynamicLibrary) { - logWarn("Dynamic libraries are not yet supported as dependencies - building as static library."); + else if (genSettings.platform.architecture.canFind("x86_omf") && tt == TargetType.dynamicLibrary) { + // Unfortunately we cannot remove this check for OMF targets, + // due to Optlink not producing shared libraries without a lot of user intervention. + // For other targets, say MSVC it'll do the right thing for the most part, + // export is still a problem as of this writing, which means static libraries cannot have linking to them removed. + // But that is for the most part up to the developer, to get it working correctly. + + logWarn("Dynamic libraries are not yet supported as dependencies for Windows target OMF - building as static library."); tt = TargetType.staticLibrary; } } @@ -279,7 +285,7 @@ { auto bs = &ti.buildSettings; // determine the actual target type - bs.targetType = determineTargetType(ti); + bs.targetType = determineTargetType(ti, genSettings); switch (bs.targetType) { diff --git a/test/1-dynLib-simple/dub.json b/test/1-dynLib-simple/dub.json index c7747c3..71da415 100644 --- a/test/1-dynLib-simple/dub.json +++ b/test/1-dynLib-simple/dub.json @@ -1,4 +1,5 @@ { "name": "dynlib-simple", - "targetType": "dynamicLibrary" + "targetType": "dynamicLibrary", + "dflags-ldc": ["-link-defaultlib-shared"] } diff --git a/test/1-dynLib-simple/source/dynlib/app.d b/test/1-dynLib-simple/source/dynlib/app.d index 78fbd42..6676219 100644 --- a/test/1-dynLib-simple/source/dynlib/app.d +++ b/test/1-dynLib-simple/source/dynlib/app.d @@ -1,7 +1,7 @@ module dynlib.app; import std.stdio; -void entry() +export void entry() { writeln(__FUNCTION__); } diff --git a/test/2-dynLib-dep/dub.json b/test/2-dynLib-dep/dub.json index 393810d..1d3d5cf 100644 --- a/test/2-dynLib-dep/dub.json +++ b/test/2-dynLib-dep/dub.json @@ -2,5 +2,6 @@ "name": "dynlib-dep", "dependencies": { "dynlib-simple": { "path": "../1-dynLib-simple/" } - } + }, + "dflags-ldc": ["-link-defaultlib-shared"] }