110 lines
2.8 KiB
Go
110 lines
2.8 KiB
Go
|
package build
|
||
|
|
||
|
import (
|
||
|
sdk "code.icb4dc0.de/buildr/wasi-module-sdk-go"
|
||
|
rpcv1 "code.icb4dc0.de/buildr/wasi-module-sdk-go/protocol/generated/rpc/v1"
|
||
|
)
|
||
|
|
||
|
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: &rpcv1.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: &rpcv1.ContainerSpec{
|
||
|
Image: "golang:alpine",
|
||
|
VolumeMounts: []*rpcv1.ContainerVolumeMount{
|
||
|
{
|
||
|
Target: "/go/pkg/mod",
|
||
|
Name: "modcache",
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
Module: GoBuild{
|
||
|
Binary: "buildr",
|
||
|
Main: ".",
|
||
|
GoOS: "linux",
|
||
|
GoArch: "amd64",
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
}
|