golang-plugin/build/go_build_help.go

109 lines
2.8 KiB
Go

package build
import (
commonv1 "code.icb4dc0.de/buildr/api/generated/common/v1"
sdk "code.icb4dc0.de/buildr/wasi-module-sdk-go"
)
func (g GoBuild) Help() sdk.Help {
return sdk.Help{
Name: "Go build - build Go binaries",
Description: `This module helps to build Go binaries.
It abstracts common build parameters like GOOS and GOARCH.
Less common parameters can be specified e.g. with ` + "`flags`" + ` or ` + "`ldflags`" + `.
Builds - as every other task - are executed in parallel.`,
Examples: []sdk.Example{
{
Name: "Simple build",
Description: "Simplest possible example of a build",
Spec: sdk.TaskSpec[sdk.Module]{
ModuleName: "buildr_linux_amd64",
Module: GoBuild{
Binary: "buildr",
Main: ".",
GoOS: "linux",
GoArch: "amd64",
},
},
},
{
Name: "Build with flags",
Description: `Specify normal build flags as well as ldflags.`,
Spec: sdk.TaskSpec[sdk.Module]{
ModuleName: "buildr_linux_amd64",
Module: GoBuild{
Binary: "buildr",
Main: ".",
GoOS: "linux",
GoArch: "amd64",
Flags: []string{
"-v",
"-trimpath",
"-a",
"-installsuffix=cgo",
},
LdFlags: []string{
"-w -s",
"-X 'code.icb4dc0.de/buildr/buildr/cmd.CurrentVersion=main'",
},
},
},
},
{
Name: "Build with environment variables",
Description: `Specify additional environment variables.`,
Spec: sdk.TaskSpec[sdk.Module]{
ModuleName: "buildr_linux_amd64",
Module: GoBuild{
Binary: "buildr",
Main: ".",
GoOS: "linux",
GoArch: "amd64",
Env: map[string]string{
"CGO_ENABLED": "0",
},
},
},
},
{
Name: "Containerize build process",
Description: `It is also possible to run the build in a container.
Although it is not very effective because the build process always has to download all dependencies if they are not cached.`,
Spec: sdk.TaskSpec[sdk.Module]{
ModuleName: "buildr_linux_amd64",
Container: &commonv1.ContainerSpec{
Image: "golang:alpine",
},
Module: GoBuild{
Binary: "buildr",
Main: ".",
GoOS: "linux",
GoArch: "amd64",
},
},
},
{
Name: "Containerize build process - with module cache volume",
Description: `Specify additional environment variables.`,
Spec: sdk.TaskSpec[sdk.Module]{
ModuleName: "buildr_linux_amd64",
Container: &commonv1.ContainerSpec{
Image: "golang:alpine",
VolumeMounts: []*commonv1.ContainerVolumeMount{
{
Target: "/go/pkg/mod",
Name: "modcache",
},
},
},
Module: GoBuild{
Binary: "buildr",
Main: ".",
GoOS: "linux",
GoArch: "amd64",
},
},
},
},
}
}