Thread overview
Using dub and rdmd together?
Jul 11, 2018
Matthew OConnor
Jul 11, 2018
Seb
Jul 11, 2018
Timoses
July 11, 2018
Hi, I'm new to D and trying to make some command line tools that are run with `#!/usr/bin/env rdmd`. But I would also like to reference external packages from dub. I know I can do this with:


    #!/usr/bin/env dub
    /+ dub.sdl:
      name "get"
      dependency "requests" version="~>0.3.2"
    +/

But when I run it (with `dub get.d` on Windows), it rebuilds every time.

Is there a way to integrate the two so that `rdmd` is used for the builds, but `dub` is used to download the necessary packages?

Thanks,
Matthew
July 11, 2018
On Wednesday, 11 July 2018 at 16:13:56 UTC, Matthew OConnor wrote:
> Hi, I'm new to D and trying to make some command line tools that are run with `#!/usr/bin/env rdmd`. But I would also like to reference external packages from dub. I know I can do this with:
>
>
>     #!/usr/bin/env dub
>     /+ dub.sdl:
>       name "get"
>       dependency "requests" version="~>0.3.2"
>     +/
>
> But when I run it (with `dub get.d` on Windows), it rebuilds every time.
>
> Is there a way to integrate the two so that `rdmd` is used for the builds, but `dub` is used to download the necessary packages?
>
> Thanks,
> Matthew

I don't know of an easy way to do out of the box.
However, with dmd's new -i option, it could be as easy as:

---
dub fetch requests
cat > test.d << EOF
import std.stdio;
import requests;

void main() {
    auto content = postContent("http://httpbin.org/post", queryParams("name", "any name", "age", 42));
    writeln(content);
}
EOF
dub fetch requests
dmd -I~/.dub/packages/requests-0.8.2/requests/source -i -run tests.d
---

However, dmd itself doesn't do any caching (though it would work similarly with rdmd).
But, of course, this won't work for more complex dub packages.
There's `dub describe` (and a backend generator) for which they might be used.
July 11, 2018
On Wednesday, 11 July 2018 at 16:43:24 UTC, Seb wrote:
> I don't know of an easy way to do out of the box.
> However, with dmd's new -i option, it could be as easy as:
>
> ---
> dub fetch requests
> cat > test.d << EOF
> import std.stdio;
> import requests;
>
> void main() {
>     auto content = postContent("http://httpbin.org/post", queryParams("name", "any name", "age", 42));
>     writeln(content);
> }
> EOF
> dub fetch requests
> dmd -I~/.dub/packages/requests-0.8.2/requests/source -i -run tests.d
> ---
>
> However, dmd itself doesn't do any caching (though it would work similarly with rdmd).
> But, of course, this won't work for more complex dub packages.
> There's `dub describe` (and a backend generator) for which they might be used.

So this is kind of similar to what dub does already?
Would be nice if dub could cache such compiled scripts somewhere. I mean dub already caches inside .dub folder in a dub project. Why not also cache compiled scripts somewhere?