From 2bedb2dc397a372ea97329e8675c87a9000ad63c Mon Sep 17 00:00:00 2001 From: Kevin Krakauer Date: Mon, 22 Nov 2021 14:23:18 -0800 Subject: [PATCH] mark platforms as Linux-only Related to #1270. PiperOrigin-RevId: 411648212 --- runsc/boot/platforms/BUILD | 29 +++++++++++++++---- runsc/boot/platforms/nonstandard/BUILD | 11 +++++++ .../boot/platforms/nonstandard/nonstandard.go | 16 ++++++++++ runsc/boot/platforms/platforms.go | 4 +++ runsc/boot/platforms/platforms_darwin.go | 20 +++++++++++++ tools/bazeldefs/defs.bzl | 7 +++-- tools/bazeldefs/go.bzl | 5 +++- 7 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 runsc/boot/platforms/nonstandard/BUILD create mode 100644 runsc/boot/platforms/nonstandard/nonstandard.go create mode 100644 runsc/boot/platforms/platforms_darwin.go diff --git a/runsc/boot/platforms/BUILD b/runsc/boot/platforms/BUILD index 77774f43c..687e95beb 100644 --- a/runsc/boot/platforms/BUILD +++ b/runsc/boot/platforms/BUILD @@ -1,15 +1,32 @@ -load("//tools:defs.bzl", "go_library") +load("//tools:defs.bzl", "go_library", "select_system") package(licenses = ["notice"]) +# Don't rewrite the deps attribute of :platforms. +# @unused +glaze_ignore = [ + "platforms.go", + "platforms_darwin.go", +] + go_library( name = "platforms", - srcs = ["platforms.go"], + srcs = [ + "platforms.go", + "platforms_darwin.go", + ], + # Nothing needs to be stateified, and stateify has trouble when select is + # used to choose deps. + stateify = False, visibility = [ "//runsc:__subpackages__", ], - deps = [ - "//pkg/sentry/platform/kvm", - "//pkg/sentry/platform/ptrace", - ], + deps = select_system( + darwin = [], + linux = [ + "//pkg/sentry/platform/kvm", + "//pkg/sentry/platform/ptrace", + "//runsc/boot/platforms/nonstandard", + ], + ), ) diff --git a/runsc/boot/platforms/nonstandard/BUILD b/runsc/boot/platforms/nonstandard/BUILD new file mode 100644 index 000000000..f896902d8 --- /dev/null +++ b/runsc/boot/platforms/nonstandard/BUILD @@ -0,0 +1,11 @@ +load("//tools:defs.bzl", "go_library") + +package(licenses = ["notice"]) + +go_library( + name = "nonstandard", + srcs = ["nonstandard.go"], + visibility = [ + "//runsc:__subpackages__", + ], +) diff --git a/runsc/boot/platforms/nonstandard/nonstandard.go b/runsc/boot/platforms/nonstandard/nonstandard.go new file mode 100644 index 000000000..2133c84b5 --- /dev/null +++ b/runsc/boot/platforms/nonstandard/nonstandard.go @@ -0,0 +1,16 @@ +// Copyright 2021 The gVisor Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package nonstandard provides a place for nonstandard platforms. +package nonstandard diff --git a/runsc/boot/platforms/platforms.go b/runsc/boot/platforms/platforms.go index 056b46ad5..7c1ed4a91 100644 --- a/runsc/boot/platforms/platforms.go +++ b/runsc/boot/platforms/platforms.go @@ -12,6 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build linux +// +build linux + // Package platforms imports all available platform packages. package platforms @@ -19,6 +22,7 @@ import ( // Import platforms that runsc might use. _ "gvisor.dev/gvisor/pkg/sentry/platform/kvm" _ "gvisor.dev/gvisor/pkg/sentry/platform/ptrace" + _ "gvisor.dev/gvisor/runsc/boot/platforms/nonstandard" ) const ( diff --git a/runsc/boot/platforms/platforms_darwin.go b/runsc/boot/platforms/platforms_darwin.go new file mode 100644 index 000000000..9863fd51d --- /dev/null +++ b/runsc/boot/platforms/platforms_darwin.go @@ -0,0 +1,20 @@ +// Copyright 2021 The gVisor Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build darwin +// +build darwin + +package platforms + +// This file makes the platforms package buildable on Darwin. diff --git a/tools/bazeldefs/defs.bzl b/tools/bazeldefs/defs.bzl index 7875bbaea..b1cb4796d 100644 --- a/tools/bazeldefs/defs.bzl +++ b/tools/bazeldefs/defs.bzl @@ -27,8 +27,11 @@ def select_arch(amd64 = "amd64", arm64 = "arm64", default = None, **kwargs): values["//conditions:default"] = default return select(values, **kwargs) -def select_system(linux = ["__linux__"], **kwargs): - return linux # Only Linux supported. +def select_system(linux = ["__linux__"], darwin = [], **kwargs): + return select({ + "@bazel_tools//src/conditions:darwin": darwin, + "//conditions:default": linux, + }) def default_installer(): return None diff --git a/tools/bazeldefs/go.bzl b/tools/bazeldefs/go.bzl index af3a1c3ee..af8694626 100644 --- a/tools/bazeldefs/go.bzl +++ b/tools/bazeldefs/go.bzl @@ -156,4 +156,7 @@ def select_goarch(): return select_arch(amd64 = "amd64", arm64 = "arm64") def select_goos(): - return select_system(linux = "linux") + return select_system( + linux = "linux", + darwin = "darwin", + )