January 30, 2012
On 01/30/2012 04:18 PM, Adam D. Ruppe wrote:
> On Monday, 30 January 2012 at 14:24:32 UTC, Manu wrote:
>> I want to know if a library is present, and automatically disable
>> non-vital features if it isn't.
>
> I'd like it too... here's what I tried. It doesn't
> work, though.
>
> ===
> void libraryTest(string lib)() { mixin("import " ~ lib ~ ";"); }
>
> template libraryExists(string lib) {
> enum libraryExists = __traits(compiles, libraryTest!lib());
> }
>
> void main() {
> static if(libraryExists!"arsd.cgi") {
> import arsd.cgi;
> auto cgi = new Cgi();
> cgi.write("hello w/ cgi");
> } else {
> import std.stdio;
> writeln("hello w/ stdio");
> }
> }
> ===
>
>
> That's the idea, but I couldn't get it to actually work.
> Imports are apparently done by the compiler before
> anything else (which makes sense, really) and that breaks
> the if compiles thing; it fails before it gets there. If
> you move the libraryTest inline to the compiles thing, it
> never uses the lib, so that's no good either.
>
>
> Alas.

The fact that this does not work is a compiler bug:

static if(is(typeof({import asdf;}))){}

it fails with exit code 1 without spitting out an error message.
Once that is fixed, it could be used to detect presence or absence of a library.

http://d.puremagic.com/issues/show_bug.cgi?id=7399

January 30, 2012
Am 30.01.2012, 15:24 Uhr, schrieb Manu <turkeyman@gmail.com>:

> Here's another one I'm endlessly wishing I had in C.
> I want to know if a library is present, and automatically disable non-vital
> features if it isn't.
> It shits me to tears when I can't build something because a non-vital
> dependant lib is not available for a given platform or just not wanted.

A library is some .dll/.so in this case ?
If you know it exists only on a certain platform: use version(Platform)
If it _may_ be there, then compile the feature in, but load and check the library at runtime like you would do with a plugin.

This sounds like what has been solved with configure scripts long ago. If you ever built e.g. GDC or most other Linux programs, they come with a little script that allows you to preconfigure your build process and takes care of linking to the different available libraries.

	./configure --disable-libDontUseMe

I never wrote one myself though...
January 30, 2012
On 30 January 2012 19:30, Marco Leise <Marco.Leise@gmx.de> wrote:

> Am 30.01.2012, 15:24 Uhr, schrieb Manu <turkeyman@gmail.com>:
>
>  Here's another one I'm endlessly wishing I had in C.
>> I want to know if a library is present, and automatically disable
>> non-vital
>> features if it isn't.
>> It shits me to tears when I can't build something because a non-vital
>> dependant lib is not available for a given platform or just not wanted.
>>
>
> A library is some .dll/.so in this case ?
> If you know it exists only on a certain platform: use version(Platform)
> If it _may_ be there, then compile the feature in, but load and check the
> library at runtime like you would do with a plugin.
>

I'm talking about static libs, since you need to link the supporting code for DLL's anyway.

This sounds like what has been solved with configure scripts long ago. If
> you ever built e.g. GDC or most other Linux programs, they come with a little script that allows you to preconfigure your build process and takes care of linking to the different available libraries.
>

Configure scripts certainly don't 'solve' the problem, they make it worse... now my buildscript has twice as many steps, nobody can understand it, and it only works on linux.

       ./configure --disable-libDontUseMe
>
> I never wrote one myself though...
>

Exactly, and nobody I've ever met has either. They just seem to exist, magically appeared out of nowhere in all major linux projects that have existed for 20 years or so. As far as I can tell, nobody ACTUALLY wrote them, they've just always been there... ;)


January 30, 2012
On 30 January 2012 17:48, Manu <turkeyman@gmail.com> wrote:
> On 30 January 2012 19:30, Marco Leise <Marco.Leise@gmx.de> wrote:
>>
>> Am 30.01.2012, 15:24 Uhr, schrieb Manu <turkeyman@gmail.com>:
>>
>>> Here's another one I'm endlessly wishing I had in C.
>>> I want to know if a library is present, and automatically disable
>>> non-vital
>>> features if it isn't.
>>> It shits me to tears when I can't build something because a non-vital
>>> dependant lib is not available for a given platform or just not wanted.
>>
>>
>> A library is some .dll/.so in this case ?
>> If you know it exists only on a certain platform: use version(Platform)
>> If it _may_ be there, then compile the feature in, but load and check the
>> library at runtime like you would do with a plugin.
>
>
> I'm talking about static libs, since you need to link the supporting code for DLL's anyway.
>
>> This sounds like what has been solved with configure scripts long ago. If you ever built e.g. GDC or most other Linux programs, they come with a little script that allows you to preconfigure your build process and takes care of linking to the different available libraries.
>
>
> Configure scripts certainly don't 'solve' the problem, they make it worse... now my buildscript has twice as many steps, nobody can understand it, and it only works on linux.
>
>>        ./configure --disable-libDontUseMe
>>
>> I never wrote one myself though...
>
>
> Exactly, and nobody I've ever met has either. They just seem to exist, magically appeared out of nowhere in all major linux projects that have existed for 20 years or so. As far as I can tell, nobody ACTUALLY wrote them, they've just always been there... ;)

Much like my book about the paranormal...  I didn't buy, it just appeared in my room one night.

-- 
Iain Buclaw

*(p < e ? p++ : p) = (c & 0x0f) + '0';
January 30, 2012
On 30 January 2012 20:03, Iain Buclaw <ibuclaw@ubuntu.com> wrote:

> On 30 January 2012 17:48, Manu <turkeyman@gmail.com> wrote:
> > Exactly, and nobody I've ever met has either. They just seem to exist, magically appeared out of nowhere in all major linux projects that have existed for 20 years or so. As far as I can tell, nobody ACTUALLY wrote them, they've just always been there... ;)
>
> Much like my book about the paranormal...  I didn't buy, it just appeared in my room one night.
>

Precisely! :P


January 30, 2012
On 2012-01-30 18:48, Manu wrote:
> On 30 January 2012 19:30, Marco Leise <Marco.Leise@gmx.de
> <mailto:Marco.Leise@gmx.de>> wrote:
>
>     Am 30.01.2012, 15:24 Uhr, schrieb Manu <turkeyman@gmail.com
>     <mailto:turkeyman@gmail.com>>:
>
>         Here's another one I'm endlessly wishing I had in C.
>         I want to know if a library is present, and automatically
>         disable non-vital
>         features if it isn't.
>         It shits me to tears when I can't build something because a
>         non-vital
>         dependant lib is not available for a given platform or just not
>         wanted.
>
>
>     A library is some .dll/.so in this case ?
>     If you know it exists only on a certain platform: use version(Platform)
>     If it _may_ be there, then compile the feature in, but load and
>     check the library at runtime like you would do with a plugin.
>
>
> I'm talking about static libs, since you need to link the supporting
> code for DLL's anyway.
>
>     This sounds like what has been solved with configure scripts long
>     ago. If you ever built e.g. GDC or most other Linux programs, they
>     come with a little script that allows you to preconfigure your build
>     process and takes care of linking to the different available libraries.
>
>
> Configure scripts certainly don't 'solve' the problem, they make it
> worse... now my buildscript has twice as many steps, nobody can
> understand it, and it only works on linux.
>
>             ./configure --disable-libDontUseMe
>
>     I never wrote one myself though...
>
>
> Exactly, and nobody I've ever met has either. They just seem to exist,
> magically appeared out of nowhere in all major linux projects that have
> existed for 20 years or so. As far as I can tell, nobody ACTUALLY wrote
> them, they've just always been there... ;)

Aren't those configure scripts generate by some other tool :)

-- 
/Jacob Carlborg
January 30, 2012
> Aren't those configure scripts generate by some other tool :)

Maybe. I never digged that deep into build processes. After some time I got myself to write Makefiles, but that's about it. I see names like automake, m4, configure etc. pop up now and then and have no idea what role each plays. They just get the job done somehow and check which C standard library is used, what compiler and other useful traits to cover the differences between systems.
January 30, 2012
configure scripts are usually part of the automake build system which used to be the standard on linux maybe 5 years ago I think it went out of favour roughly the same time as cvs.

On Tue, Jan 31, 2012 at 5:29 AM, Marco Leise <Marco.Leise@gmx.de> wrote:

> Aren't those configure scripts generate by some other tool :)
>>
>
> Maybe. I never digged that deep into build processes. After some time I got myself to write Makefiles, but that's about it. I see names like automake, m4, configure etc. pop up now and then and have no idea what role each plays. They just get the job done somehow and check which C standard library is used, what compiler and other useful traits to cover the differences between systems.
>


January 30, 2012
On Monday, 30 January 2012 at 13:23:19 UTC, Manu wrote:
> Is D capable of accessing the filesystem at compile time, for instance, to
> load and parse an XML DOM, or some other structural metadata, which may be
> used to generate the associative struct and its members?
> I can think of many other uses for the technology too. It seems extremely
> powerful, and I'm sure it's been discussed :)

As interesting as that would be, I wouldn't recommend it.

Just generate a .d file from the XML before compiling. It will be faster, and more flexible than trying to hit everything with the D hammer.
1 2
Next ›   Last »