Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented Sep 4, 2023

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 is a bit of a hack, perhaps we want to lint this in the future, but for now a compile-time check should protect against the immediate danger of importing coderd/database.

The error is (IMO) clear enough:

❯ make build/coder-slim_linux_amd64
# github.com/coder/coder/v2/coderd/database
coderd/database/no_slim_slim.go:12:2: _DO_NOT_IMPORT_THIS_PACKAGE_IN_SLIM_BUILDS redeclared in this block
	coderd/database/no_slim.go:6:2: other declaration of _DO_NOT_IMPORT_THIS_PACKAGE_IN_SLIM_BUILDS
make: *** [Makefile:205: build/coder-slim_2.1.4-devel+72655331a_linux_amd64] Error 1

… build

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
@mafredri mafredri self-assigned this Sep 4, 2023
Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A very clever way to do this. Very simple, I like it.

@mafredri mafredri changed the title chore(coderd/database): add compile-time guard against import in slim build chore(coderd/database): introduce compile-time guard against import in slim build Sep 4, 2023
@mafredri mafredri enabled auto-merge (squash) September 4, 2023 18:46
@mafredri mafredri merged commit 76ab22f into main Sep 4, 2023
@mafredri mafredri deleted the mafredri/chore-prevent-database-import-in-slim-builds branch September 4, 2023 19:01
@github-actions github-actions bot locked and limited conversation to collaborators Sep 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants