Thread overview
dub can build library for dependencies
July 30
I want to rely on a library, but I don't want to compile it on my computer. I hope dub can help us with this function.

Just as I rely on a docker mirror, this docker mirror is not built on my computer. This will increase my compilation time.

Thanks.
July 30
On Thursday, 30 July 2020 at 12:04:18 UTC, zoujiaqing wrote:
> I want to rely on a library, but I don't want to compile it on my computer. I hope dub can help us with this function.
>
> Just as I rely on a docker mirror, this docker mirror is not built on my computer. This will increase my compilation time.
>
> Thanks.

Python solves this with the many-linux libraries. The dub package author has to package the libraries and all the dependencies + d header files. The libraries needs to be build to be runnable on many linux systems (+ libraries for windows, + libraries for osx).
As far as I see, from dub side everything is there, just the dub package author needs to provide a complete dub package.

Kind regards
Andre
July 30
On Thursday, 30 July 2020 at 12:23:29 UTC, Andre Pany wrote:
> On Thursday, 30 July 2020 at 12:04:18 UTC, zoujiaqing wrote:
>> I want to rely on a library, but I don't want to compile it on my computer. I hope dub can help us with this function.
>>
>> Just as I rely on a docker mirror, this docker mirror is not built on my computer. This will increase my compilation time.
>>
>> Thanks.
>
> Python solves this with the many-linux libraries. The dub package author has to package the libraries and all the dependencies + d header files. The libraries needs to be build to be runnable on many linux systems (+ libraries for windows, + libraries for osx).
> As far as I see, from dub side everything is there, just the dub package author needs to provide a complete dub package.
>
> Kind regards
> Andre

Andre, Thanks for the response.

dub services should support corresponding support. Compile if some platforms are not supported. similar brew on macOS.
July 30
Java can use gradle manager depends on compiled *.jar to Maven server.
July 30
On Thursday, 30 July 2020 at 18:50:54 UTC, zoujiaqing wrote:
> Java can use gradle manager depends on compiled *.jar to Maven server.

In dub the same thing is already possible like it is done for Python Wheels
or Node packages.

Have a look at this python wheel:
https://files.pythonhosted.org/packages/5e/89/fa556c4f9ac56d466e229dceaa5cbc3993308c5c9574f739964f853415bb/FMPy-0.2.21-py2.py3-none-any.whl

Rename the extension to zip and extract it.
It contains the *.so files for linux / *.dylib for macos / *.dll for windows.
The python code makes use of the functionality using wrapper code.

You could just create a new dub package, copy the *.so/*.dll/*.dylib files into
it, write the wrapper code in D and upload it to dub registry.

This is almost your scenario except the dynamic libraries are written in C and
in your case in D.

(Java is a different thing, as the jar files contains byte code...)

Kind regards
André
July 30
On Thursday, 30 July 2020 at 18:50:54 UTC, zoujiaqing wrote:
> Java can use gradle manager depends on compiled *.jar to Maven server.

What you may do is commit the .lib/.a and add them to the source files.

Example here:
https://github.com/Devisualization/window/blob/master/dub.json#L39


Or you can find out why dub recompiles your stuff. --combined breaks caching
July 30
On 7/30/20 8:04 AM, zoujiaqing wrote:
> I want to rely on a library, but I don't want to compile it on my computer. I hope dub can help us with this function.

No it cannot.

Every build of a library for a project has a unique set of version definitions (e.g. has_vibe_d)

So a library built for your project may possibly be different than one built for another project.

-Steve
July 31
On Thursday, 30 July 2020 at 12:04:18 UTC, zoujiaqing wrote:
> I want to rely on a library, but I don't want to compile it on my computer. I hope dub can help us with this function.
>
> Just as I rely on a docker mirror, this docker mirror is not built on my computer. This will increase my compilation time.
>
> Thanks.

I think the best way to address this problem is via something along the lines of https://cachix.org/.

The idea is that you create a Nix package (which declaratively describes the complete dependency graph of the thing you want to build) and then the first time the package is built it would be placed in a shared cache, which can be securely access by other developers. I am a Nix user and I haven't tried cachix yet, but from what I've seen many people use it successfully speed up both their local and CI builds. I think the Dub registry should host cachix-like server.
The first step in this direction would be to add the nix store as an alternative registry provider to dub.
July 31
On Friday, 31 July 2020 at 03:09:03 UTC, Steven Schveighoffer wrote:
> On 7/30/20 8:04 AM, zoujiaqing wrote:
>> I want to rely on a library, but I don't want to compile it on my computer. I hope dub can help us with this function.
>
> No it cannot.
>
> Every build of a library for a project has a unique set of version definitions (e.g. has_vibe_d)
>
> So a library built for your project may possibly be different than one built for another project.
>
> -Steve

Thanks Steve! But about libphobos?

I can't compile phobos library! easy! fast!
3 days ago
On 7/31/20 2:07 PM, zoujiaqing wrote:
> On Friday, 31 July 2020 at 03:09:03 UTC, Steven Schveighoffer wrote:
>> On 7/30/20 8:04 AM, zoujiaqing wrote:
>>> I want to rely on a library, but I don't want to compile it on my computer. I hope dub can help us with this function.
>>
>> No it cannot.
>>
>> Every build of a library for a project has a unique set of version definitions (e.g. has_vibe_d)
>>
>> So a library built for your project may possibly be different than one built for another project.
>>
> 
> Thanks Steve! But about libphobos?
> 
> I can't compile phobos library! easy! fast!

If you compile against phobos with different versions than what it was compiled with, then you will have potential problems.

But Phobos also isn't meant to have dependencies on vibe or the like.

An example:

https://github.com/mysql-d/mysql-native/blob/master/source/mysql/connection.d#L446-L471

If you have a pre-compiled mysql-native app without vibe-core support (i.e. wasn't compiled with vibe-core also as a dependency), but then you compile an app and include vibe-core, your app will build, run, and promptly crash.

So yes, technically, you can have a library that has no other dependencies (because you know it doesn't), and one could compile it once and use it wherever.

But dub cannot be the one that decides how to do this. You have to do it manually.

-Steve