Artifact 1683ac8baaa0ab53c6bddb73fd7da5f1a5142885ea8256ed418dc72a60cbc7f2:
- File
nohttp_dependency_test.go
— part of check-in
[9594cf3bae]
at
2026-10-29 03:06:23
on branch main
— perf(wasm): add a libfossil_nohttp build tag that leaves out net/http
Under TinyGo, importing net/http at all links its TLS and X.509 code (crypto/x509, encoding/asn1, math/big's integers, AES-GCM, SHA-3, netip) whether or not a request is ever made: a five-line program that calls only http.StatusText grows by about 430 KB raw. The library imports it for its HTTP client transport and its HTTP server, which a program that serves sync through HandleSyncWithOpts and supplies its own transport never calls.
Built with -tags libfossil_nohttp, the library leaves out NewHTTPTransport, WithHTTPClient, Repo.Pull, Repo.XferHandler and Repo.ServeHTTP, and the internal/sync client, server, redirect handling and peer-address trace they use. HandleSync, HandleSyncWithOpts, Sync over a host Transport and everything else are unchanged. Without the tag nothing changes. The retry classifier keeps the two statuses it read from net/http as constants, and DNS fault classification moves to its own file so it stays in the tagged build.
For the html-artifact-publisher engine (TinyGo 0.43.0, Go 1.26.0) the tag takes the gzipped binary from 1,100,251 to 1,003,279 bytes. A test builds the library, db and simio with the tag for the host and js/wasm and checks none links net/http, net/http/httptrace or crypto/tls, and that the untagged library still does. (user: [email protected], size: 1396) [annotate] [blame] [check-ins using] [more...]
package libfossil import ( "slices" "strings" "testing" ) // noHTTPTag builds the library without its net/http transport and server. const noHTTPTag = "libfossil_nohttp" // TestNoHTTPTagLeavesOutNetHTTP: built with the libfossil_nohttp tag, the // packages an embedder links compile and carry no net/http, whose TLS and // X.509 dependencies are about 97 KB of a gzipped TinyGo binary that serves // sync through HandleSyncWithOpts and its host's own transport. Without the // tag the HTTP transport and server are linked as before. func TestNoHTTPTagLeavesOutNetHTTP(t *testing.T) { if testing.Short() { t.Skip("runs the go tool") } banned := []string{"net/http", "net/http/httptrace", "crypto/tls"} for _, target := range [][2]string{{"", ""}, {"js", "wasm"}} { goos, goarch := target[0], target[1] goTool(t, goos, goarch, "build", "-tags", noHTTPTag, ".", "./db", "./simio") for _, pkg := range []string{".", "./db", "./simio"} { deps := strings.Fields(goTool(t, goos, goarch, "list", "-deps", "-tags", noHTTPTag, "-f={{.ImportPath}}", pkg)) for _, b := range banned { if slices.Contains(deps, b) { t.Errorf("%s (GOOS=%q, -tags %s) links %s", pkg, goos, noHTTPTag, b) } } } if !slices.Contains(goListDeps(t, goos, goarch, "."), "net/http") { t.Errorf("the library (GOOS=%q) without -tags %s does not link net/http", goos, noHTTPTag) } } }