bust/pkg/tasks/rust-bin/build.go

32 lines
605 B
Go
Raw Normal View History

2022-11-06 00:39:03 +01:00
package rustbin
import (
"context"
"fmt"
"log"
"dagger.io/dagger"
)
func Build(ctx context.Context, container *dagger.Container, binName string) (dagger.FileID, error) {
log.Printf("building binary: (binName=%s)", binName)
c := container.Exec(dagger.ContainerExecOpts{
Args: []string{
"cargo",
"build",
"--release",
"--target=x86_64-unknown-linux-musl",
},
})
if _, err := c.ExitCode(ctx); err != nil {
return "", err
}
2022-11-06 16:23:04 +01:00
bin, err := c.File(fmt.Sprintf("target/x86_64-unknown-linux-musl/release/%s", binName)).ID(ctx)
2022-11-06 00:39:03 +01:00
if err != nil {
return "", err
}
return bin, nil
}