Skip to content

Allow changing the CPP Toolchain. - #955

Merged
smukherj1 merged 1 commit into
bazelbuild:masterfrom
rubensf:winfix2
Mar 3, 2021
Merged

smukherj1 merged 1 commit into
bazelbuild:masterfrom
rubensf:winfix2

Conversation

@rubensf

@rubensf rubensf commented Mar 2, 2021

Copy link
Copy Markdown
Contributor

The cpp default toolchain on windows was hardset to cc-compiler-k8, which
is linux exclusive. Additionally it's quite common to need to change the
compiler being used.

The drawback of this approach is that it potentially creates many repetitive
equal cc_toolchains if you use the same container with multiple toolings installed.

Long term we could add multiple cpp toolchains to configs/, but so far the limited
amount of repetition isn't harmful.

Comment thread cmd/rbe_configs_gen/rbe_configs_gen.go Outdated
genJavaConfigs = flag.Bool("generate_java_configs", true, "(Optional) Generate Java configs. Defaults to true.")
genCppConfigs = flag.Bool("generate_cpp_configs", true, "(Optional) Generate C++ configs. Defaults to true.")
cppEnvJSON = flag.String("cpp_env_json", "", "(Optional) JSON file containing a str -> str dict of environment variables to be set when generating C++ configs inside the toolchain container. This replaces any exec OS specific defaults that would usually be applied.")
cppToolchainTarget = flag.String("cpp_target_toolchain", "", "(Optional) Set the target CPP toolchain. On linux, the default is cc-compiler-k8, on windows is cc-compiler-x64_windows.")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Change to cpp_target_toolchain -> cpp_toolchain_target to be consistent with variable name.

Also for help Set the CPP toolchain target
Also When exec_os is linux instead of On linux, ..., ditto for windows

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad on target_toolchain, forgot to clean that up :)
Done.

Comment thread pkg/rbeconfigsgen/options.go Outdated
// command to generate C++ configs inside the toolchain container. Only one of CppGenEnv or
// CppGenEnvJSON can be specified.
CppGenEnvJSON string
// CPPToolchainTarget is the toolchain to be used by the cpp configs. It overrides the default

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove It overrides the default equally named field in PlatformParams. because it's application to every other field in this struct

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread pkg/rbeconfigsgen/options.go Outdated
// command to generate C++ configs inside the toolchain container. Only one of CppGenEnv or
// CppGenEnvJSON can be specified.
CppGenEnvJSON string
// CPPToolchainTarget is the toolchain to be used by the cpp configs. It overrides the default

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I suggest creating a new variable called CPPToolchainTarget at the top level in the Options struct to align with the fact that all command line variables translate to Option fields.

This way, CppToolchainTarget inside PlatformParams is only populated once we know the full target path based on the config dir (if specified)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread pkg/rbeconfigsgen/rbeconfigsgen.go Outdated
if o.OutputConfigPath != "" {
o.PlatformParams.CppToolchainTarget = fmt.Sprintf("//%s/cc:cc-compiler-k8", path.Clean(o.OutputConfigPath))
// The Toolchain target should always start with `//`.
o.PlatformParams.CppToolchainTarget = strings.TrimPrefix(o.PlatformParams.CppToolchainTarget, "/")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This trimming should be unnecessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread pkg/rbeconfigsgen/rbeconfigsgen.go Outdated
Comment on lines +656 to +668
if o.CPPToolchainTarget != "" {
o.PlatformParams.CppToolchainTarget = fmt.Sprintf("//cc:%s", o.CPPToolchainTarget)
}
if o.OutputConfigPath != "" {
o.PlatformParams.CppToolchainTarget = fmt.Sprintf("//%s/cc:cc-compiler-k8", path.Clean(o.OutputConfigPath))
// The Toolchain target should always start with `//`.
o.PlatformParams.CppToolchainTarget = strings.TrimPrefix(o.PlatformParams.CppToolchainTarget, "/")
o.PlatformParams.CppToolchainTarget = fmt.Sprintf("//%s%s", path.Clean(o.OutputConfigPath), o.PlatformParams.CppToolchainTarget)
}
} else {
o.PlatformParams.CppToolchainTarget = ""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the cpp toolchain target path construction logic has become complicated enough that we should refactor it into its own function and add unit tests. Specifically I'm interested in making sure the target path is constructed correctly for various values of o.OutputConfigPath

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines -654 to -656
if o.PlatformParams.CppToolchainTarget != "" {
return generatedFile{}, fmt.Errorf("<internal error> C++ toolchain target was already set")
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to add this error back now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread pkg/rbeconfigsgen/options.go Outdated
// CppGenEnvJSON can be specified.
CppGenEnvJSON string
// CPPToolchainTarget is the toolchain to be used by the cpp configs.
CPPToolchainTargetBasename string

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest calling this CPPToolchainTarget for simplicity. It's not immediately apparent what "basename" exactly means because it's not a standard term used to refer to Bazel labels/targets.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid that it's confusing with the CppToolchainTarget inside of PlatformParams. They technically represent the entire thing, while this only has the "name".

Should I call it CppToolchainName? ...TargetName? Wdyt?

Comment thread pkg/rbeconfigsgen/rbeconfigsgen.go Outdated

func genCppToolchainTarget(o *Options) string {
if o.OutputConfigPath != "" {
return fmt.Sprintf("//%s/cc:%s", path.Clean(o.OutputConfigPath), o.CPPToolchainTargetBasename)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a string replace for "\" -> "/" in o.OutputConfigPath and unit test for this case. I don't think Bazel allows "\" in labels. Also, ensure you don't mutate o.OutputConfigPath, so something like:

configPath := string.Replace(o.OutputConfigPath, "\\", "/")
if configPath != "" {
...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Also added some checks taht OutputConfigPath isn't an absolute path on Validation.

The cpp default toolchain on windows was hardset to cc-compiler-k8, which
is linux exclusive. Additionally it's quite common to need to change the
compiler being used.

The drawback of this approach is that it potentially creates many repetitive
equal cc_toolchains if you use the same container with multiple toolings installed.

Long term we could add multiple cpp toolchains to configs/, but so far the limited
amount of repetition isn't harmful.
@smukherj1
smukherj1 merged commit 27f2db2 into bazelbuild:master Mar 3, 2021
@rubensf
rubensf deleted the winfix2 branch March 3, 2021 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants