How to import from indirect dependency to package extension

I’m writing a package extension, say ABExt.jl, where A and B are package names. B depends on C, fc is a method defined by C and not imported by B. I’d like to import fc to ABExt. I have two attempts so far:

  • import B: fc throws WARNING: could not import B.fc into ABExt
  • import C: fc throws ArgumentError: Package ABExt does not have C in its dependencies

You should make the extension depend on both B and C:

[extensions]
ABExt = ["B", "C"]

Thanks for your help. Now I’m getting LoadError: KeyError: key "C" not found. Do you have a working example?

In my package DifferentiationInterface.jl, the Zygote extension also depends explicitly on ForwardDiff, even though ForwardDiff is a dependency of Zygote too:

This allows me to do import ForwardDiff in the extension instead of import Zygote.ForwardDiff

Very helpful. It turns out that I also have to add C to weakdeps.