You can use compiled libraries or plugin mechanism for this but your project must be hard modified in this way. For secure acces simply use ssh or vpn connections. Are not to much options to hide source code in the idea of the developers need to use this code
If you want to hide the source code, your best option is to not share it, but only as a service: create an interface and provide the access through some client code (for example gRPC to your well secured server).
Microservice architecture, as Tamas has suggested, is a good way to keep things encapsulated and on a need to know. Since you can then manage its service as it’s own project with its own code branch, tests, and build procedures.