Skip to content

Commit 70d6d48

Browse files
committed
build/gvisor: use make to build runsc
Signed-off-by: Andrei Vagin <avagin@google.com>
1 parent a6c9c73 commit 70d6d48

File tree

1 file changed

+18
-53
lines changed

1 file changed

+18
-53
lines changed

pkg/build/gvisor.go

Lines changed: 18 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package build
66
import (
77
"fmt"
88
"path/filepath"
9-
"regexp"
109
"strings"
1110
"time"
1211

@@ -17,8 +16,6 @@ import (
1716

1817
type gvisor struct{}
1918

20-
var bazelTargetPath = regexp.MustCompile(`(?sm:.*^)\s*Outputs: \[(.*)\](?sm:$.*)`)
21-
2219
func (gvisor gvisor) build(params Params) (ImageDetails, error) {
2320
if params.Compiler == "" {
2421
params.Compiler = "bazel"
@@ -31,66 +28,34 @@ func (gvisor gvisor) build(params Params) (ImageDetails, error) {
3128
if err != nil {
3229
return ImageDetails{}, fmt.Errorf("cannot parse gVisor configuration: %w", err)
3330
}
34-
args := []string{}
31+
bazelOpts := "--verbose_failures"
3532

3633
target := "//runsc:runsc"
37-
if config.Race {
38-
args = append(args, "--config=race")
39-
target = "//runsc:runsc-race"
40-
}
4134
if config.Coverage {
42-
coverageFiles := "//pkg/..."
43-
exclusions := []string{
44-
"//pkg/sentry/platform", "//pkg/ring0", // Breaks kvm.
45-
"//pkg/coverage:coverage", // Too slow.
46-
}
4735
if config.Race {
48-
// These targets use go:norace, which is not
49-
// respected by coverage instrumentation. Race builds
50-
// will be instrumented with atomic coverage (using
51-
// sync/atomic.AddInt32), which will not work.
52-
exclusions = append(exclusions, []string{
53-
"//pkg/sleep:sleep",
54-
"//pkg/sync:sync",
55-
"//pkg/syncevent:syncevent",
56-
}...)
36+
target = "//runsc:runsc_race_coverage"
37+
} else {
38+
target = "//runsc:runsc_coverage"
5739
}
58-
for _, f := range exclusions {
59-
coverageFiles += ",-" + f
60-
}
61-
args = append(args, []string{
62-
"--collect_code_coverage",
63-
"--instrumentation_filter=" + coverageFiles}...)
64-
}
65-
buildArgs := []string{"build", "--verbose_failures"}
66-
buildArgs = append(buildArgs, args...)
67-
buildArgs = append(buildArgs, target)
68-
log.Logf(0, "bazel: %v", buildArgs)
69-
// The 1 hour timeout is quite high. But we've seen false positives with 20 mins
70-
// on the first build after bazel/deps update. Also other gvisor instances running
71-
// on the same machine contribute to longer build times.
72-
if _, err := osutil.RunCmd(60*time.Minute, params.KernelDir, params.Compiler, buildArgs...); err != nil {
73-
return ImageDetails{}, err
40+
} else if config.Race {
41+
bazelOpts += " --config=race "
42+
target = "//runsc:runsc-race"
7443
}
7544

76-
// Find out a path to the runsc binary.
77-
aqueryArgs := append([]string{"aquery"}, args...)
78-
aqueryArgs = append(aqueryArgs, fmt.Sprintf("mnemonic(\"GoLink\", %s)", target))
79-
log.Logf(0, "bazel: %v", aqueryArgs)
80-
out, err := osutil.RunCmd(10*time.Minute, params.KernelDir, params.Compiler, aqueryArgs...)
81-
if err != nil {
45+
outBinary := filepath.Join(params.OutputDir, "image")
46+
cmd := osutil.Command("make", "copy",
47+
"DOCKER_BUILD=0",
48+
fmt.Sprintf("BAZEL_OPTIONS=%s", bazelOpts),
49+
fmt.Sprintf("TARGETS=%s", target),
50+
fmt.Sprintf("DESTINATION=%s", outBinary),
51+
)
52+
cmd.Dir = params.KernelDir
53+
54+
log.Logf(0, "bazel copy: %v", cmd.Env)
55+
if _, err := osutil.Run(60*time.Minute, cmd); err != nil {
8256
return ImageDetails{}, err
8357
}
8458

85-
match := bazelTargetPath.FindSubmatch(out)
86-
if match == nil {
87-
return ImageDetails{}, fmt.Errorf("failed to find the runsc binary")
88-
}
89-
outBinary := filepath.Join(params.KernelDir, filepath.FromSlash(string(match[1])))
90-
91-
if err := osutil.CopyFile(outBinary, filepath.Join(params.OutputDir, "image")); err != nil {
92-
return ImageDetails{}, err
93-
}
9459
sysTarget := targets.Get(params.TargetOS, params.TargetArch)
9560
return ImageDetails{}, osutil.CopyFile(outBinary, filepath.Join(params.OutputDir, "obj", sysTarget.KernelObject))
9661
}

0 commit comments

Comments
 (0)