How to retrieve dependancy library component

I’m attempting to write a plugin that generates packages for native components. One feature I’d like to add is to automatically add dependency meta-information to the packages based on the declared dependencies. For example, given a multi-project build with two sub-projects: ‘myLib’ and ‘myExe’, and with the following myExe/build.gradle:

model {
    components {
        myExe(NativeExecutableSpec) {
            sources {
                c {
                    lib project: ':myLib', library: 'myLib'
                }
            }
        }
    }
}

The ‘myExe’ package file would have the meta-information saying that it depends on ‘myLib’.

My problem is: how can I obtain the myLib component from the myExe component in a plugin rule? I can obtain a NativeDependencySet from myExe’s binaries, but I can’t obtain any component information from that interface. I can also obtain the libs collection from the C source set of myExe, but they’re not resolved into libraries.

My guess is that I will need to manually resolve the library information obtained from the source sets, but that doesn’t look like an optimal path. Is there an alternative?

I’ve been studying the Gradle source code to find ideas for a solution, and I’ve stumbled into the service registry. Now, I know it’s internal and isn’t exposed through a public API, but if I accept possible incompatibility with other Gradle versions, would I be able to create a custom LibraryComponentResolver to find the libraries? If so, would it even be helpful for implementing transitive dependencies for native components? (I’d wager yes, because it would be a first step towards obtaining “dependencies of a dependency”, but I’d like to know how far I am from reality).

Thanks in advance for any guidance.