Skip to content

Commit

Permalink
enable cgo if required by dependency
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Chacin <[email protected]>
  • Loading branch information
pablochacin committed Jan 14, 2025
1 parent 9e086af commit eb7ef14
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,15 @@ func (b *Builder) Build( //nolint:funlen
resolved[k6Dep] = k6Mod.Version

mods := []k6foundry.Module{}
cgoEnabled := false
for _, d := range deps {
m, modErr := b.catalog.Resolve(ctx, catalog.Dependency{Name: d.Name, Constrains: d.Constraints})
if modErr != nil {
return k6build.Artifact{}, k6build.NewWrappedError(ErrInvalidParameters, modErr)
}
mods = append(mods, k6foundry.Module{Path: m.Path, Version: m.Version})
resolved[d.Name] = m.Version
cgoEnabled = cgoEnabled || m.Cgo
}

// generate id form sorted list of dependencies
Expand Down Expand Up @@ -158,9 +160,18 @@ func (b *Builder) Build( //nolint:funlen
return k6build.Artifact{}, k6build.NewWrappedError(ErrAccessingArtifact, err)
}

// set CGO_ENABLED if any of the dependencies require it
env := b.opts.Env
if cgoEnabled {
if env == nil {
env = map[string]string{}
}
env["CGO_ENABLED"] = "1"
}

builderOpts := k6foundry.NativeBuilderOpts{
GoOpts: k6foundry.GoOpts{
Env: b.opts.Env,
Env: env,
CopyGoEnv: b.opts.CopyGoEnv,
},
}
Expand Down

0 comments on commit eb7ef14

Please sign in to comment.