You can do that through profiles and some clever namespace/symbol existence checking, eg. with https://github.com/borkdude/dynaload