Skip to content
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

force CGO_ENABLED=0 #41

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,27 @@ import (
const (
long = `
starts a k6build server

Note: The build server does not support CGO_ENABLE when building binaries
due to this issue: https://github.com/grafana/k6build/issues/37
use --enable-cgo=true to enable CGO support
`

example = `
# start the build server using a custom catalog
# start the build server using a custom local catalog
k6build server -c /path/to/catalog.json

# start the server the build server using a custom GOPROXY
k6build server -e GOPROXY=http://localhost:80`
)

// New creates new cobra command for the server command.
func New() *cobra.Command {
func New() *cobra.Command { //nolint:funlen
var (
config local.BuildServiceConfig
logLevel string
port int
config local.BuildServiceConfig
logLevel string
port int
enableCgo bool
)

cmd := &cobra.Command{
Expand Down Expand Up @@ -61,6 +66,15 @@ func New() *cobra.Command {
),
)

if enableCgo {
log.Warn("enabling CGO for build service")
} else {
if config.BuildEnv == nil {
config.BuildEnv = make(map[string]string)
}
config.BuildEnv["CGO_ENABLED"] = "0"
}

buildSrv, err := local.NewBuildService(cmd.Context(), config)
if err != nil {
return fmt.Errorf("creating local build service %w", err)
Expand Down Expand Up @@ -100,6 +114,7 @@ func New() *cobra.Command {
cmd.Flags().StringToStringVarP(&config.BuildEnv, "env", "e", nil, "build environment variables")
cmd.Flags().IntVarP(&port, "port", "p", 8000, "port server will listen")
cmd.Flags().StringVarP(&logLevel, "log-level", "l", "INFO", "log level")
cmd.Flags().BoolVar(&enableCgo, "enable-cgo", false, "enable CGO for building binaries.")

return cmd
}
Loading