Skip to content

Commit 76ab22f

Browse files
authored
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
1 parent adba421 commit 76ab22f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

coderd/database/no_slim.go

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package database
2+
3+
const (
4+
// This declaration protects against imports in slim builds, see
5+
// no_slim_slim.go.
6+
//nolint:revive,unused
7+
_DO_NOT_IMPORT_THIS_PACKAGE_IN_SLIM_BUILDS = "DO_NOT_IMPORT_THIS_PACKAGE_IN_SLIM_BUILDS"
8+
)

coderd/database/no_slim_slim.go

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

0 commit comments

Comments
 (0)