RejectedSoftware Forums

Sign up

Only use a library for a specific compiler

I am using the Economic Modeling containers library, and because it uses std.experimental.allocator, it can't be used with LDC through dub. I have coded in such a way with static if's that LDC will still compile without it, but dub will try to compile it anyway because it's in the dependencies JSON dictionary.

So, I changed my configurations to the following, which somewhat works:

    "configurations": [
        {
            "name": "unittest",
            "mainSourceFile": "bench.d",
            "targetType": "executable",
            "dependencies": {
                "containers": "~>0.2.2"
            },
            "platforms": ["dmd"]
        },
        {
            "name": "unittest",
            "mainSourceFile": "bench.d",
            "targetType": "executable",
            "platforms": ["ldc2", "ldmd2"]
        },
        {
            "name": "library",
            "targetType": "library",
            "dependencies": {
                "containers": "~>0.2.2"
            },
            "platforms": ["dmd"]
        },
        {
            "name": "library",
            "targetType": "library",
            "platforms": ["ldc2", "ldmd2"]
        }
    ]

I can do dub --compiler=ldc2, but dub test --compiler=ldc2 results in

Could not resolve configuration for package containers

Re: Only use a library for a specific compiler

Am 24.03.2016 um 16:16 schrieb Jack Stouffer:

I am using the Economic Modeling containers library, and because it uses std.experimental.allocator, it can't be used with LDC through dub. I have coded in such a way with static if's that LDC will still compile without it, but dub will try to compile it anyway because it's in the dependencies JSON dictionary.

So, I changed my configurations to the following, which somewhat works:

     "configurations": [
         {
             "name": "unittest",
             "mainSourceFile": "bench.d",
             "targetType": "executable",
             "dependencies": {
                 "containers": "~>0.2.2"
             },
             "platforms": ["dmd"]
         },
         {
             "name": "unittest",
             "mainSourceFile": "bench.d",
             "targetType": "executable",
             "platforms": ["ldc2", "ldmd2"]
         },
         {
             "name": "library",
             "targetType": "library",
             "dependencies": {
                 "containers": "~>0.2.2"
             },
             "platforms": ["dmd"]
         },
         {
             "name": "library",
             "targetType": "library",
             "platforms": ["ldc2", "ldmd2"]
         }
     ]

I can do dub --compiler=ldc2, but dub test --compiler=ldc2 results in

Could not resolve configuration for package containers

I think there are two issues: It should be just "ldc" instead of "ldc2"
or "ldmd2" for the platforms field (it uses the constants from here:
http://dlang.org/spec/version.html#predefined-versions, and the name
of each configuration must be unique*, so naming the second one
"unittest-ldc" should make dub test --compiler=ldc2 work (I didn't
verify this so far, though).

* This should really result in an error message...