golang-plugin/build/go_build_help.go

110 lines
2.8 KiB
Go
Raw Normal View History

2023-08-15 19:46:36 +00:00
package build
import (
2023-09-05 20:07:47 +00:00
commonv1 "code.icb4dc0.de/buildr/api/generated/common/v1"
2023-08-15 19:46:36 +00:00
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",
2023-09-05 20:07:47 +00:00
Container: &commonv1.ContainerSpec{
2023-08-15 19:46:36 +00:00
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",
2023-09-05 20:07:47 +00:00
Container: &commonv1.ContainerSpec{
2023-08-15 19:46:36 +00:00
Image: "golang:alpine",
2023-09-05 20:07:47 +00:00
VolumeMounts: []*commonv1.ContainerVolumeMount{
2023-08-15 19:46:36 +00:00
{
Target: "/go/pkg/mod",
Name: "modcache",
},
},
},
Module: GoBuild{
Binary: "buildr",
Main: ".",
GoOS: "linux",
GoArch: "amd64",
},
},
},
},
}
}