How to access the build directory in a build tool plugin?

I'm trying to write a build tool plugin to automate copying libraries into the build directory (for windows and linux builds, since they have to rely on .sytemLibrary targets for 3rd party libs, and these do not get copied.

I don't see in the API a way to get the path to the build products directory. What am I missing?

Check l273-298 how build a target and check the artifact result which has a path:

So you can build library targets “manually” that way if you want and copy them.

Unless I'm reading this wrong, this technique only works from a commandPlugin (can't access packageManager property to build anything from a buildToolPlugin)

Ah, yes - sorry - still get disoriented by the different capabilities at time.

I see the executable path is I retrieved from context.tool(named:) is: /${BUILD_DIR}/${CONFIGURATION}/Tool (at least on Mac)

Do all platforms expand ${BUILD_DIR} in paths, or is this Xcode specific? Is this even going to be in my sandbox If I do so?

This seems like a pretty std thing to need from tooling scripts... but I've blown a day getting this far, and I've noticed other windows projects like the stuff form thebrowsercompany are resorting to make scripts (called after SPM) to do this... so maybe I'm wasting my time?

To answer my own question it appears ${BUILD_DIR} does work as a path on windows (as in it's allowed as a returned path), but the path sent to the executable is actually pointing to a resource folder within the build dir. I assume this is some logic for resource copying that I'm triggering by mistake?