www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How about source-level importing the third-party modules for D

reply Heromyth <bitworld qq.com> writes:
In DUB repository, all the projects are avaliable in source. When 
my project depends on some of them, I want to import them in 
source level, instead of using them as some static libraries.

Of course, I can copy all the depended projects into my project 
and build it in source level.

So, is it possible to import the depended projects in source 
level whout copying them? Or, is it necessary for D to support 
this feature?

Thanks!
Dec 12 2018
parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Wednesday, December 12, 2018 6:17:10 PM MST Heromyth via Digitalmars-d 
wrote:
 In DUB repository, all the projects are avaliable in source. When
 my project depends on some of them, I want to import them in
 source level, instead of using them as some static libraries.

 Of course, I can copy all the depended projects into my project
 and build it in source level.

 So, is it possible to import the depended projects in source
 level whout copying them? Or, is it necessary for D to support
 this feature?
This is not a language issue. It's entirely an issue with dub and how projects are set up. If you look at the "target types" section in the dub documentation http://code.dlang.org/package-format?lang=json you'll see that "sourceLibrary" is one of the target types, and if a project is set to be a "sourceLibrary," then the project doesn't generate a library but rather just acts like it's part of your project and gets imported and built as part of your project - which sounds like what you want. However, that's set by the project itself, not by the projects that have it as a dependency. dub is really designed with the idea that how the project is built is under the control of the maintainer of that project, not the projects that use it as a dependency. That being said, looking at the dub command line documentation, it looks like you might be able to use the --data flag to force dependencies to be built with the target type of "sourceLibrary" instead of whatever they're set up to be built as. So, you might try experimenting with it. http://code.dlang.org/docs/commandline That being said, in general, trying to force dependencies to be built in a way other than how the project maintainer set it up is likely asking for trouble. It may work in simple cases, but if the project is doing anything fancy, it likely won't. e.g. all it would take would be for the project to need to link against a C library, and it wouldn't work. And that doesn't take into account any other scripts or code generation that might be involved with more complex projects. So, in general, even if it turns out that you can make it happen with --data, I would advise against trying to force projects to be built in a different manner from how the maintainer set it up. If --data doesn't work for you, and you're determined to treat dependencies as source libraries, another approach would be to set up the dependency as a git submodule of your project so that it gets pulled in that way. However, at that point, you're basically taking it into into your own hands to make sure that it builds correctly, and the odds are much higher that the setup is going to break at some point than if you just used the project via dub in the manner that the project maintainer set it up. So, again, I'd advise against it unless you have a really good reason why it doesn't make sense to just use the dub project normally. BTW, questions about how D works and how to use D or its related tools belong in D.Learn, not the the general D newsgroup/forum/list. This newsgroup is for general discussions on D, not for answering questions about how to use it. - Jonathan M Davis
Dec 12 2018