Files
tailscale/ipn/ipnlocal/appconnector.go
Brad Fitzpatrick 2a61a720e5 ipn/ipnlocal: drop the appc import from ts_omit_appconnectors builds
LocalBackend named appc.AppConnector in its appConnector field, in the
field's constructor call, and in the AppConnector accessor, so even
builds with ts_omit_appconnectors linked the appc package and its
dependencies. The buildfeatures.HasAppConnectors checks let the linker
drop the code but could not remove the import.

Add a build-tag-gated type for the field: appcAppConnector is an alias
for appc.AppConnector by default, and in ts_omit_appconnectors builds it
is an empty struct with no-op versions of the methods local.go calls, so
the shared code still type checks. The constructor call moves behind a
newAppConnector helper in the same gated file, and the AppConnector
accessor keeps its *appc.AppConnector signature there, with a nil-
returning version in the omitted build.

This takes tailscale.com/appc out of depaware-min.txt and
depaware-minbox.txt. Add a DepChecker test to keep it out; it also sets
ts_omit_conn25, since conn25 uses appc as well.

Updates #12614

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: Ia7e2d9c4f1b8e6a3d5c0f2b7e9a1c4d6f8b0e2a5
2026-10-06 13:12:00 -07:00

40 lines
1.3 KiB
Go

// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
//go:build !ts_omit_appconnectors
package ipnlocal
import (
"tailscale.com/appc"
"tailscale.com/types/appctype"
"tailscale.com/types/logger"
"tailscale.com/util/eventbus"
)
// appcAppConnector is [appc.AppConnector] in builds that include app
// connectors. Builds with ts_omit_appconnectors substitute a stub type
// (see appconnector_omit.go) so that this package does not import appc
// at all, which keeps appc and its dependencies out of those binaries.
type appcAppConnector = appc.AppConnector
// newAppConnector returns a new [appc.AppConnector] publishing to bus,
// seeded with the previously stored routes in ri (which may be nil).
func newAppConnector(logf logger.Logf, bus *eventbus.Bus, ri *appctype.RouteInfo, storeRoutes bool) *appcAppConnector {
return appc.NewAppConnector(appc.Config{
Logf: logf,
EventBus: bus,
RouteInfo: ri,
HasStoredRoutes: storeRoutes,
})
}
// AppConnector returns the current AppConnector, or nil if not configured.
//
// TODO(nickkhyl): move app connectors to [nodeBackend], or perhaps a feature package?
func (b *LocalBackend) AppConnector() *appc.AppConnector {
b.mu.Lock()
defer b.mu.Unlock()
return b.appConnector
}