rbeconfigsgen

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package rbeconfigsgen contains utilities to generate C++ & Java Toolchain configs for Bazel to be used to run RBE builds

Index

Constants

View Source
const (
	// OSLinux represents Linux when selecting platforms.
	OSLinux = "linux"
	// OSWindows represents Windows when selecting platforms.
	OSWindows = "windows"
)

Variables

View Source
var (

	// DefaultExecOptions is a map from the ExecOS to default values for certain fields in Options
	// that vary based on the execution environment.
	DefaultExecOptions = map[string]DefaultOptions{
		OSLinux: {
			PlatformParams: PlatformToolchainsTemplateParams{
				ExecConstraints: []string{
					"@bazel_tools//platforms:linux",
					"@bazel_tools//platforms:x86_64",
					"@bazel_tools//tools/cpp:clang",
				},
				TargetConstraints: []string{
					"@bazel_tools//platforms:linux",
					"@bazel_tools//platforms:x86_64",
				},
				OSFamily: "Linux",
			},
			CPPConfigTargets: []string{"@local_config_cc//..."},
			CPPConfigRepo:    "local_config_cc",
			CppBazelCmd:      "build",
			CppGenEnv: map[string]string{
				"ABI_LIBC_VERSION":    "glibc_2.19",
				"ABI_VERSION":         "clang",
				"BAZEL_COMPILER":      "clang",
				"BAZEL_HOST_SYSTEM":   "i686-unknown-linux-gnu",
				"BAZEL_TARGET_CPU":    "k8",
				"BAZEL_TARGET_LIBC":   "glibc_2.19",
				"BAZEL_TARGET_SYSTEM": "x86_64-unknown-linux-gnu",
				"CC":                  "clang",
				"CC_TOOLCHAIN_NAME":   "linux_gnu_x86",
			},
		},
		OSWindows: {
			PlatformParams: PlatformToolchainsTemplateParams{
				ExecConstraints: []string{
					"@bazel_tools//platforms:windows",
					"@bazel_tools//platforms:x86_64",
				},
				TargetConstraints: []string{
					"@bazel_tools//platforms:windows",
					"@bazel_tools//platforms:x86_64",
				},
				OSFamily: "Windows",
			},
			CPPConfigTargets: []string{"@local_config_cc//..."},
			CPPConfigRepo:    "local_config_cc",
			CppBazelCmd:      "query",
		},
	}
)

Functions

func Run

func Run(o Options) error

Run is the main entrypoint to generate Bazel toolchain configs according to the options specified in the given command line arguments. The file structure of the generated configs will be as follows: <config root> |

  • cc- C++ configs as generated by Bazel's internal C++ toolchain detection logic.
  • config- Toolchain entrypoint target for cc_crosstool_top & the auto-generated platform target.
  • java- Java toolchain definition.

Types

type DefaultOptions

type DefaultOptions struct {
	PlatformParams   PlatformToolchainsTemplateParams
	CPPConfigTargets []string
	CPPConfigRepo    string
	CppBazelCmd      string
	CppGenEnv        map[string]string
}

DefaultOptions are some option values that are populated as default values for certain fields of "Options". See "Options" for explanation on what the fields mean.

type Options

type Options struct {
	// BazelVersion is the version of Bazel to generate configs for. If unset, the latest Bazel
	// version is automatically populated into this field when Validate() is called.
	BazelVersion string
	// ToolchainContainer is the docker image of the toolchain container to generate configs for.
	ToolchainContainer string
	// ExecOS is the OS of the toolchain container image or the OS in which the build actions will
	// execute.
	ExecOS string
	// TargetOS is the OS to be used as the target platform in the generated platform rule. This
	// is the OS that artifacts built by Bazel will be executed on.
	TargetOS string
	// OutputTarball is the path at with a tarball will be generated containing the C++/Java
	// configs.
	OutputTarball string
	// OutputSourceRoot is the path where the root of the source repository where generated configs
	// should be copied to. This directory is expected to have a Bazel WORKSPACE file.
	OutputSourceRoot string
	// OutputConfigPath is the path relative to OutputSourceRoot where the generated configs will
	// be copied to.
	OutputConfigPath string
	// OutputManifest is a path where a text file containing details about the generated configs.
	// The manifest aims to be easily parseable by shell utilities like grep/sed.
	OutputManifest string
	// PlatformParams specify platform specific constraints used to generate a BUILD file with the
	// toolchain & platform targets in the generated configs. It's recommended to use the defaults
	// corresponding to the ExecOS.
	PlatformParams *PlatformToolchainsTemplateParams

	// C++ Config generation options.
	// GenCPPConfigs determines whether C++ configs are generated.
	GenCPPConfigs bool
	// CPPConfigTargets are the Bazel targets that will be used to make Bazel auto-generated C++
	// configs.
	// This field can be auto-populated with a default value. See DefaultExecOptions below.
	CPPConfigTargets []string
	// CPPConfigRepo is the name of the Bazel external repo (i.e., the repo name without the '@')
	// whose Bazel build output directory will be used to extract generated C++ config files.
	// This field can be auto-populated with a default value. See DefaultExecOptions below.
	CPPConfigRepo string
	// CppBazelCmd is the Bazel command that'll be executed (build|query) on CppConfigTargets to
	// generate CppConfigTargets. So if CppConfigTargets is @foo//:blah & CppBazelCmd is build,
	// this tool will run bazel build @foo//:blah.
	// This field can be auto-populated with a default value. See DefaultExecOptions below.
	CppBazelCmd string
	// CppGenEnv are the environment variables that'll be set when running the Bazel command to
	// generate C++ configs inside the toolchain container. Only one of CppGenEnv or CppGenEnvJSON
	// can be specified.
	CppGenEnv map[string]string
	// CppGenEnvJSON is a JSON file with environment variables that'll be set when running the Bazel
	// command to generate C++ configs inside the toolchain container. Only one of CppGenEnv or
	// CppGenEnvJSON can be specified.
	CppGenEnvJSON string

	// Java config generation options.
	// GenJavaConfigs determines whether Java configs are generated.
	GenJavaConfigs bool
	// TempWorkDir is a temporary directory that will be used by this tool to store intermediate
	// files. If unspecified, a temporary directory will be requested from the OS.
	TempWorkDir string
	// Cleanup determines whether the running container & intermediate files will be deleted once
	// config generation is done. Setting it to false is useful for debugging intermediate state.
	Cleanup bool
}

Options are the options to tweak Bazel C++/Java Toolchain config generation.

func (*Options) ApplyDefaults

func (o *Options) ApplyDefaults(os string) error

ApplyDefaults applies platform specific default values to the given options for the given OS.

func (*Options) Validate

func (o *Options) Validate() error

Validate verifies that mandatory arguments were provided and argument values don't conflict in certain cases.

type PlatformToolchainsTemplateParams

type PlatformToolchainsTemplateParams struct {
	ExecConstraints    []string
	TargetConstraints  []string
	CppToolchainTarget string
	ToolchainContainer string
	OSFamily           string
}

PlatformToolchainsTemplateParams is used as the input to the toolchains & platform BUILD file template 'platformsToolchainBuildTemplate'.

func (PlatformToolchainsTemplateParams) String

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL