diff --git a/source/dub/compilers/utils.d b/source/dub/compilers/utils.d index 2961001..20de0de 100644 --- a/source/dub/compilers/utils.d +++ b/source/dub/compilers/utils.d @@ -74,50 +74,6 @@ /** - Determines if a specific file name has the extension related to dynamic libraries. - - This includes dynamic libraries and for Windows pdb, export and import library files. -*/ -bool isDynamicLibraryFile(const scope ref BuildPlatform platform, string f) -{ - import std.path; - switch (extension(f)) { - default: - return false; - case ".lib", ".pdb", ".dll", ".exp": - return platform.isWindows(); - case ".so", ".dylib": - return !platform.isWindows(); - } -} - -unittest { - BuildPlatform p; - - p.platform = ["windows"]; - assert(!isDynamicLibraryFile(p, "test.obj")); - assert(isDynamicLibraryFile(p, "test.lib")); - assert(isDynamicLibraryFile(p, "test.dll")); - assert(isDynamicLibraryFile(p, "test.pdb")); - assert(!isDynamicLibraryFile(p, "test.res")); - assert(!isDynamicLibraryFile(p, "test.o")); - assert(!isDynamicLibraryFile(p, "test.d")); - assert(!isDynamicLibraryFile(p, "test.dylib")); - - p.platform = ["something else"]; - assert(!isDynamicLibraryFile(p, "test.o")); - assert(!isDynamicLibraryFile(p, "test.a")); - assert(isDynamicLibraryFile(p, "test.so")); - assert(isDynamicLibraryFile(p, "test.dylib")); - assert(!isDynamicLibraryFile(p, "test.obj")); - assert(!isDynamicLibraryFile(p, "test.d")); - assert(!isDynamicLibraryFile(p, "test.lib")); - assert(!isDynamicLibraryFile(p, "test.dll")); - assert(!isDynamicLibraryFile(p, "test.pdb")); -} - - -/** Adds a default DT_SONAME (ELF) / 'install name' (Mach-O) when linking a dynamic library. This makes dependees reference their dynamic-lib deps by filename only (DT_NEEDED etc.) instead of by the path used in the dependee linker cmdline, and enables loading the diff --git a/source/dub/generators/build.d b/source/dub/generators/build.d index dfe26fe..8d431f6 100644 --- a/source/dub/generators/build.d +++ b/source/dub/generators/build.d @@ -103,41 +103,48 @@ NativePath[] additional_dep_files, dependencyBinariesToCopy; auto bs = ti.buildSettings.dup; + const dependeeTT = bs.targetType; foreach (ldep; ti.linkDependencies) { - auto location = target_paths[ldep].toNativeString(); + const ldepPath = target_paths[ldep].toNativeString(); + const doLink = dependeeTT != TargetType.staticLibrary && !(bs.options & BuildOption.syntaxOnly); - if (bs.targetType != TargetType.staticLibrary && !(bs.options & BuildOption.syntaxOnly) && isLinkerFile(settings.platform, location)) { - bs.addSourceFiles(location); - } else if (settings.platform.isWindows() && location.endsWith(".dll")) { - // switch from linking against the dll to against the import library, - // and copy any dependent build artifacts if found too + if (doLink && isLinkerFile(settings.platform, ldepPath)) + bs.addSourceFiles(ldepPath); + else + additional_dep_files ~= target_paths[ldep]; - const pdbFilename = location.setExtension(".pdb"); - if (existsFile(pdbFilename)) - dependencyBinariesToCopy ~= NativePath(pdbFilename); + if (targets[ldep].buildSettings.targetType == TargetType.dynamicLibrary) { + // copy the .{dll,so,dylib} if the dependee is an executable or dynamic lib + if (dependeeTT == TargetType.executable || dependeeTT == TargetType.dynamicLibrary) + dependencyBinariesToCopy ~= NativePath(ldepPath); - const importLibraryLocation = location.setExtension(".lib"); - if (existsFile(importLibraryLocation)) { - bs.addSourceFiles(importLibraryLocation); - dependencyBinariesToCopy ~= NativePath(importLibraryLocation); + if (settings.platform.isWindows()) { + if (dependeeTT == TargetType.executable || dependeeTT == TargetType.dynamicLibrary) { + // copy the accompanying .pdb if found + const pdb = ldepPath.setExtension(".pdb"); + if (existsFile(pdb)) + dependencyBinariesToCopy ~= NativePath(pdb); + } + + const importLib = ldepPath.setExtension(".lib"); + if (existsFile(importLib)) { + // link dependee against the import lib + if (doLink) + bs.addSourceFiles(importLib); + // and copy if the dependee is a DLL too + if (dependeeTT == TargetType.dynamicLibrary) + dependencyBinariesToCopy ~= NativePath(importLib); + } + + // copy the .exp file if the dependee is a DLL (just like the import lib) + const exp = ldepPath.setExtension(".exp"); + if (dependeeTT == TargetType.dynamicLibrary && existsFile(exp)) + dependencyBinariesToCopy ~= NativePath(exp); } - - const exportFilesLocation = location.setExtension(".exp"); - if (existsFile(exportFilesLocation)) - dependencyBinariesToCopy ~= NativePath(exportFilesLocation); - - additional_dep_files ~= target_paths[ldep]; - } else { - additional_dep_files ~= target_paths[ldep]; - } - - // copy any dynamic library dependencies to our target directory - if (isDynamicLibraryFile(settings.platform, location)) { - dependencyBinariesToCopy ~= target_paths[ldep]; } } NativePath tpath; - if (bs.targetType != TargetType.none) + if (dependeeTT != TargetType.none) if (buildTarget(settings, bs, ti.pack, ti.config, ti.packages, additional_dep_files, dependencyBinariesToCopy, tpath)) any_cached = true; target_paths[target] = tpath;