Using dub and rdmd together?

Seb seb at wilzba.ch
Wed Jul 11 16:43:24 UTC 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.


More information about the Digitalmars-d-learn mailing list