@@ -35,6 +35,7 @@ const (
3535 nogoDisableFlag = "--//build/toolchains:nogo_disable_flag"
3636 geosTarget = "//c-deps:libgeos"
3737 devTarget = "//pkg/cmd/dev:dev"
38+ testbuildonly = "test-build-only"
3839)
3940
4041type buildTarget struct {
@@ -68,6 +69,7 @@ func makeBuildCmd(runE func(cmd *cobra.Command, args []string) error) *cobra.Com
6869 buildCmd .Flags ().String (crossFlag , "" , "cross-compiles using the builder image (options: linux, linuxarm, macos, macosarm, windows)" )
6970 buildCmd .Flags ().Lookup (crossFlag ).NoOptDefVal = "linux"
7071 buildCmd .Flags ().StringArray (dockerArgsFlag , []string {}, "additional arguments to pass to Docker (only used for cross builds)" )
72+ buildCmd .Flags ().Bool (testbuildonly , false , "only check test binaries can be built; do not link them" )
7173 addCommonBuildFlags (buildCmd )
7274 return buildCmd
7375}
@@ -147,6 +149,7 @@ func (d *dev) build(cmd *cobra.Command, commandLine []string) error {
147149 targets , additionalBazelArgs := splitArgsAtDash (cmd , commandLine )
148150 ctx := cmd .Context ()
149151 cross := mustGetFlagString (cmd , crossFlag )
152+ testbuildonly := mustGetFlagBool (cmd , testbuildonly )
150153 dockerArgs := mustGetFlagStringArray (cmd , dockerArgsFlag )
151154
152155 // Set up dev cache unless it's disabled via the environment variable or the
@@ -166,7 +169,7 @@ func (d *dev) build(cmd *cobra.Command, commandLine []string) error {
166169 }
167170 }
168171
169- args , buildTargets , err := d .getBasicBuildArgs (ctx , targets )
172+ args , buildTargets , err := d .getBasicBuildArgsInternal (ctx , targets , testbuildonly )
170173 if err != nil {
171174 return err
172175 }
@@ -387,6 +390,12 @@ func targetToBinBasename(target string) string {
387390// (e.g. after translation, so short -> "//pkg/cmd/cockroach-short").
388391func (d * dev ) getBasicBuildArgs (
389392 ctx context.Context , targets []string ,
393+ ) (args []string , buildTargets []buildTarget , _ error ) {
394+ return d .getBasicBuildArgsInternal (ctx , targets , false )
395+ }
396+
397+ func (d * dev ) getBasicBuildArgsInternal (
398+ ctx context.Context , targets []string , testbuildonly bool ,
390399) (args []string , buildTargets []buildTarget , _ error ) {
391400 if len (targets ) == 0 {
392401 // Default to building the cockroach binary.
@@ -457,7 +466,11 @@ func (d *dev) getBasicBuildArgs(
457466 }
458467
459468 if shouldBuildWithTestConfig {
460- args = append (args , "--config=test" )
469+ if testbuildonly {
470+ args = append (args , "--config=testbuildonly" )
471+ } else {
472+ args = append (args , "--config=test" )
473+ }
461474 }
462475 if canDisableNogo {
463476 args = append (args , nogoDisableFlag )
0 commit comments