Add build tag to omit the x/crypto/ssh dependency#645
Add build tag to omit the x/crypto/ssh dependency#645espadolini wants to merge 1 commit intopkg:masterfrom
Conversation
puellanivis
left a comment
There was a problem hiding this comment.
I mean… this doesn’t remove it from the go.mod so it’s going to get pulled in anyways?
Dead-code analysis should let this be removed anyways?
If someone has serious concerns about 900 KiB of binary size, then they’ll probably want to vendor/fork and do significantly more manual dead code removal than add an esoteric, and poorly discoverable build flag option?
DCE can't change the semantics of the code, and there's enough init time code in
Adding a build tag seemed less invasive than moving all code except for I'd happily take that as an option tho, it would work way better.
DCE seems to work quite well for sftp - at least in the case of a full featured server such as the one in server_standalone, I'm not really seeing any client code and 900KiB is not a lot in absolute terms but it's a third of the binary, in the case of server_standalone, so it's just a little unfortunate, that's all. |
|
I mean, the
I understand that it is a third of the binary, but that scaling does not really follow when someone is including pkg/sftp as a dependency. It’s reasonable to presume that it would be about ~900 KiB regardless of how large one’s binary is, it just so happens that
It’s not that I’m fundamentally against improving the package weight when someone doesn’t need an SFTP client, and therefore wouldn’t need to import the whole Perhaps this is something that could be solved with |
That'd be great actually, a different package would even let callers get rid of the indirect dependency in their |
The only use of
golang.org/x/crypto/ssh(and, transitively, of any package incrypto/...) is in theNewClientfunction, which is a small wrapper around running a subsystem request with anssh.Clientto then run a sftp client on the channel.For binaries that don't otherwise depend on
x/crypto/ssh(for example utility binaries that only do sftp through stdio) this can be a somewhat significant chunk of binary size; for example a stripped cgoless build ofserver_standalone(darwin arm64, go 1.26.1) goes from 2.9 to 2.0 MiB, which is (relatively) significant.This PR moves
NewClientto a new file which is omitted from the build if a newpkg_sftp.omit_sshbuild tag is set during the build, so users of the library that don't usex/crypto/sshcan omit that dependency.