Search code examples
packagedependenciesrakusoftware-distribution

How do I declare a dependency that can be fulfilled by one of many differently named packages?


In a Raku distribution how do I depend on either Foo::Bar or Foo::Baz without requiring both?


Solution

  • You can use "any": [$dependency-spec1, $dependency-spec2]. This could look like one of the following (depending on if you use a plain string dependency or a hash):

    "depends" : {
        "runtime" : {
            "any" : [
                "Foo::Bar",
                "Foo::Baz"
            ]
        }
    }
    
    "depends" : {
        "runtime" : {
            "any" : [
                {
                    "name" : "Foo::Bar"
                },
                {
                    "name" : "Foo::Baz"
                }
            ]
        }
    }
    

    This isn't constrained to raku dependencies either. For instance to declare a dependency on either curl or wget one can do:

    "depends" : {
        "runtime" : {
            "any" : [
                "curl:from<bin>",
                "wget:from<bin>"
            ]
        }
    }
    

    which would cause zef install $whatever to inform the user of the missing programs if none are found.