chore(coderd/database): introduce compile-time guard against import in slim build (#9521)

This change introduces a compile-time error when `coderd/database` is
imported into the slim build. This is to guard against accidentally
growing the binary size via import.

Ref: #9380
This commit is contained in:
Mathias Fredriksson 2023-09-04 22:01:11 +03:00 committed by GitHub
parent adba421524
commit 76ab22f539
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,8 @@
package database
const (
// This declaration protects against imports in slim builds, see
// no_slim_slim.go.
//nolint:revive,unused
_DO_NOT_IMPORT_THIS_PACKAGE_IN_SLIM_BUILDS = "DO_NOT_IMPORT_THIS_PACKAGE_IN_SLIM_BUILDS"
)

View File

@ -0,0 +1,14 @@
//go:build slim
package database
const (
// This re-declaration will result in a compilation error and is present to
// prevent increasing the slim binary size by importing this package,
// directly or indirectly.
//
// no_slim_slim.go:7:2: _DO_NOT_IMPORT_THIS_PACKAGE_IN_SLIM_BUILDS redeclared in this block
// no_slim.go:4:2: other declaration of _DO_NOT_IMPORT_THIS_PACKAGE_IN_SLIM_BUILDS
//nolint:revive,unused
_DO_NOT_IMPORT_THIS_PACKAGE_IN_SLIM_BUILDS = "DO_NOT_IMPORT_THIS_PACKAGE_IN_SLIM_BUILDS"
)