providers: add opt-out build tags to reduce binary size#222
Conversation
Add opt-out build tags so users can exclude providers they don't use. All providers compile by default (no breaking change). Pass -tags to exclude heavy dependency trees: go build -tags "nogoogle,noaws,noazure,novercel,noopenrouter,nokronk" Tags: nogoogle — google provider + anthropic vertex support noaws — bedrock provider + anthropic bedrock support noazure — azure provider novercel — vercel provider noopenrouter — openrouter provider nokronk — kronk provider Anthropic's bedrock.go and google.go are gated behind !noaws and !nogoogle respectively. Bedrock/Vertex configuration is extracted from anthropic.go into build-tagged files with error-returning stubs. Binary size impact (stripped, anthropic+openai+openaicompat only): Before: 32 MB After: 12 MB (63% reduction)
e01f1ec to
32c5d69
Compare
|
@andreynering Opening this as a draft PR because I'm not sure if this is a direction that you want to go with the library. Feel free to reject and close if not aligned with project goals. I'm building and maintaining an internal toolset that uses Fantasy and I'd like to keep the dependencies as clean as possible. Currently, my plan is to internally support only |
|
Hey @ljuti, The Go module system is smart enough to only add the dependencies used by the packages your project import. So, for example, if you don't import the I know there are still a couple extra dependencies because of things like, for example, AWS package being imported by the I would be nice to solve that if possible, but that's not a priority for us now, and I think I would do that differently: instead of build tags I would try to reorganize packages in a way that would prevent these extra dependencies. |
Add opt-out build tags so users can exclude providers they don't use, reducing binary size significantly.
All providers compile by default — no breaking change. Pass
-tagsto exclude heavy dependency trees:go build -tags "nogoogle,noaws,noazure,novercel,noopenrouter,nokronk" ./...Tags
nogoogleproviders/google+ anthropic vertex supportnoawsproviders/bedrock+ anthropic bedrock supportnoazureproviders/azurenovercelproviders/vercelnoopenrouterproviders/openrouternokronkproviders/kronkImplementation
.gofile in each optional provider package gets//go:build !no<name>providertests/files that import optional providers get matching tagsbedrock.go/google.gogated behind!noaws/!nogoogleLanguageModelconfiguration extracted into build-tagged files (bedrock_lm.go,vertex_lm.go) with error-returning stubs for when excludedanthropic.goheavy imports (AWS SDK, Google OAuth) removed from main fileBinary size impact
Stripped
-ldflags="-s -w"binary with anthropic + openai + openaicompat: