-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add a fully working toolchain #13
Open
nathaniel-brough
wants to merge
2
commits into
bazelembedded:main
Choose a base branch
from
nathaniel-brough:minimal_toolchain
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
build --incompatible_enable_cc_toolchain_resolution | ||
build --incompatible_strict_action_env | ||
build --cxxopt=-std=c++17 | ||
build:bzlmod --experimental_enable_bzlmod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
load("@rules_cc//cc:cc_toolchain_config_lib.bzl", "FeatureSetInfo", "feature") | ||
load("//cc:actions.bzl", "ActionConfigSetInfo") | ||
|
||
# TODO(#12): This probably shouldn't exist. | ||
# There are some quirks in how some features are enabled/disabled based on tool_paths. | ||
# As we don't use tool_paths, we need to reimplement some of these quirks? | ||
_QUIRKY_FEATURES = [ | ||
feature( | ||
name = "quirk_enable_archiver_flags", | ||
enabled = True, | ||
implies = ["archiver_flags"], | ||
) | ||
] | ||
|
||
def _cc_toolchain_config_impl(ctx): | ||
runfiles = ctx.runfiles() | ||
transitive_files = [] | ||
|
||
# Flatten action_configs | ||
action_configs = [] | ||
for action_config_set in ctx.attr.action_configs: | ||
action_configs += action_config_set[ActionConfigSetInfo].configs | ||
runfiles = runfiles.merge_all([action_config_set[DefaultInfo].default_runfiles]) | ||
transitive_files.append(action_config_set[DefaultInfo].files) | ||
|
||
# Deduplicate features | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Deduplicate action_configs |
||
action_configs = depset(action_configs).to_list() | ||
|
||
# Flatten features | ||
features = [] | ||
for feature_set in ctx.attr.cc_features: | ||
features += feature_set[FeatureSetInfo].features | ||
runfiles = runfiles.merge_all([feature_set[DefaultInfo].default_runfiles]) | ||
transitive_files.append(feature_set[DefaultInfo].files) | ||
|
||
# Deduplicate features | ||
features = depset(features).to_list() | ||
|
||
return cc_common.create_cc_toolchain_config_info( | ||
ctx = ctx, | ||
toolchain_identifier = "local", | ||
host_system_name = "local", | ||
target_system_name = "local", | ||
target_cpu = "k8", | ||
target_libc = "unknown", | ||
compiler = "clang", | ||
abi_version = "unknown", | ||
abi_libc_version = "unknown", | ||
action_configs = action_configs, | ||
features = features + _QUIRKY_FEATURES, | ||
cxx_builtin_include_directories = ctx.attr.cxx_builtin_include_directories, | ||
) | ||
|
||
cc_toolchain_config = rule( | ||
_cc_toolchain_config_impl, | ||
attrs = { | ||
"cc_features": attr.label_list( | ||
doc = "A list of features to include in the toolchain", | ||
providers = [FeatureSetInfo], | ||
), | ||
"action_configs": attr.label_list( | ||
doc = "A list of action_configs to include in the toolchain", | ||
providers = [ActionConfigSetInfo], | ||
mandatory = True, | ||
), | ||
# TODO(#11): We shouldn't allow this, hard coded system libs make it | ||
# harder to create hermetic toolchains. This should be removed | ||
# before we release the modular toolchains api. | ||
"cxx_builtin_include_directories": attr.string_list( | ||
doc = "A list of system libraries to include", | ||
), | ||
}, | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these include paths listed both here (in this default-enabled feature) and in
cxx_builtin_include_directories
?I guess it's just not clear to me what this feature achieves: you first exclude built-in include paths, but then add them right back in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's mostly a convenience thing to make sure I have consistent includes. Sometimes clang/gcc will change/add include directories depending on other flags. This is usually true for sanitizers. But it gets rather annoying having the compiler "autodetect" different include paths and having them not matching in bazel, not to mention the error messages when this happens are rather cryptic. You end up with a lot of blackbox inconsistencies between environments. But you are probably right, it's probably not 100% necessary here and adds unnecessary indirection.
It's also an intermediate precursor to having fully hermetic libraries as well. But we aren't quite there yet with the modular toolchains.