-
Notifications
You must be signed in to change notification settings - Fork 144
Support for injecting custom toolchain features (approach injecting rule-based features with example) #524
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
Draft
limdor
wants to merge
1
commit into
bazelbuild:main
Choose a base branch
from
limdor:inject_rules_based_features
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.
Draft
Changes from all commits
Commits
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,6 @@ | ||
| load("@rules_cc//cc:cc_binary.bzl", "cc_binary") | ||
|
|
||
| cc_binary( | ||
| name = "main", | ||
| srcs = ["main.cpp"], | ||
| ) | ||
This file contains hidden or 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,4 @@ | ||
| int main() | ||
| { | ||
| return 32; | ||
| } |
This file contains hidden or 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,185 @@ | ||
| # Copyright 2016 The Bazel Authors. All rights reserved. | ||
| # | ||
| # 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. | ||
|
|
||
| # This becomes the BUILD file for @local_config_cc// under non-BSD unixes. | ||
|
|
||
| load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES") | ||
| load("@rules_cc//cc/toolchains:cc_toolchain.bzl", "cc_toolchain") | ||
| load(":cc_toolchain_config.bzl", "cc_toolchain_config") | ||
|
|
||
| package(default_visibility = ["//visibility:public"]) | ||
|
|
||
| licenses(["notice"]) # Apache 2.0 | ||
|
|
||
| filegroup( | ||
| name = "empty", | ||
| srcs = [], | ||
| ) | ||
|
|
||
| filegroup( | ||
| name = "cc_wrapper", | ||
| srcs = ["cc_wrapper.sh"], | ||
| ) | ||
|
|
||
| filegroup( | ||
| name = "validate_static_library", | ||
| srcs = ["validate_static_library.sh"], | ||
| ) | ||
|
|
||
| filegroup( | ||
| name = "deps_scanner_wrapper", | ||
| srcs = ["deps_scanner_wrapper.sh"], | ||
| ) | ||
|
|
||
| filegroup( | ||
| name = "compiler_deps", | ||
| srcs = glob( | ||
| ["extra_tools/**"], | ||
| allow_empty = True, | ||
| ) + [ | ||
| ":builtin_include_directory_paths", | ||
| ":cc_wrapper", | ||
| ":deps_scanner_wrapper", | ||
| ":validate_static_library", | ||
| ], | ||
| ) | ||
|
|
||
| load("@rules_cc//cc/toolchains:args.bzl", "cc_args") | ||
| load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") | ||
|
|
||
| cc_feature( | ||
| name = "foo", | ||
| args = [":flags"], | ||
| feature_name = "foo", | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| cc_args( | ||
| name = "flags", | ||
| actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], | ||
| args = ["-foo"], | ||
| ) | ||
|
|
||
| toolchain( | ||
| name = "my_linux_toolchain", | ||
| exec_compatible_with = [ | ||
| "@platforms//os:linux", | ||
| "@platforms//cpu:x86_64", | ||
| ], | ||
| target_compatible_with = [ | ||
| "@platforms//os:linux", | ||
| "@platforms//cpu:x86_64", | ||
| ], | ||
| toolchain = ":cc-compiler-k8", | ||
| toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", | ||
| ) | ||
|
|
||
| cc_toolchain( | ||
| name = "cc-compiler-k8", | ||
| all_files = ":compiler_deps", | ||
| ar_files = ":compiler_deps", | ||
| as_files = ":compiler_deps", | ||
| compiler_files = ":compiler_deps", | ||
| dwp_files = ":empty", | ||
| linker_files = ":compiler_deps", | ||
| module_map = None, | ||
| objcopy_files = ":empty", | ||
| strip_files = ":empty", | ||
| supports_header_parsing = 1, | ||
| supports_param_files = 1, | ||
| toolchain_config = ":local", | ||
| toolchain_identifier = "local", | ||
| ) | ||
|
|
||
| cc_toolchain_config( | ||
| name = "local", | ||
| abi_libc_version = "local", | ||
| abi_version = "local", | ||
| compile_flags = [ | ||
| "-fstack-protector", | ||
| "-Wall", | ||
| "-Wunused-but-set-parameter", | ||
| "-Wno-free-nonheap-object", | ||
| "-fno-omit-frame-pointer", | ||
| ], | ||
| compiler = "gcc", | ||
| conly_flags = [], | ||
| coverage_compile_flags = ["--coverage"], | ||
| coverage_link_flags = ["--coverage"], | ||
| cpu = "k8", | ||
| cxx_builtin_include_directories = [ | ||
| "/usr/lib/gcc/x86_64-linux-gnu/10/include", | ||
| "/usr/local/include", | ||
| "/usr/include/x86_64-linux-gnu", | ||
| "/usr/include", | ||
| "/usr/include/c++/10", | ||
| "/usr/include/x86_64-linux-gnu/c++/10", | ||
| "/usr/include/c++/10/backward", | ||
| ], | ||
| cxx_flags = ["-std=c++17"], | ||
| dbg_compile_flags = ["-g"], | ||
| extra_features = [":foo"], | ||
| host_system_name = "local", | ||
| link_flags = [ | ||
| "-fuse-ld=gold", | ||
| "-B/usr/bin", | ||
| "-Wl,-no-as-needed", | ||
| "-Wl,-z,relro,-z,now", | ||
| "-pass-exit-codes", | ||
| ], | ||
| link_libs = [ | ||
| "-Wl,--push-state,-as-needed", | ||
| "-lstdc++", | ||
| "-Wl,--pop-state", | ||
| "-Wl,--push-state,-as-needed", | ||
| "-lm", | ||
| "-Wl,--pop-state", | ||
| ], | ||
| opt_compile_flags = [ | ||
| "-g0", | ||
| "-O2", | ||
| "-D_FORTIFY_SOURCE=1", | ||
| "-DNDEBUG", | ||
| "-ffunction-sections", | ||
| "-fdata-sections", | ||
| ], | ||
| opt_link_flags = ["-Wl,--gc-sections"], | ||
| supports_start_end_lib = True, | ||
| target_libc = "local", | ||
| target_system_name = "local", | ||
| tool_paths = { | ||
| "ar": "/usr/bin/ar", | ||
| "ld": "/usr/bin/ld", | ||
| "cpp": "/usr/bin/cpp-10", | ||
| "gcc": "/usr/bin/gcc-10", | ||
| "dwp": "/usr/bin/dwp", | ||
| "gcov": "/usr/bin/gcov-10", | ||
| "nm": "/usr/bin/nm", | ||
| "objcopy": "/usr/bin/objcopy", | ||
| "objdump": "/usr/bin/objdump", | ||
| "strip": "/usr/bin/strip", | ||
| "c++filt": "/usr/bin/c++filt", | ||
| "cpp-module-deps-scanner": "deps_scanner_wrapper.sh", | ||
| "parse_headers": "cc_wrapper.sh", | ||
| "validate_static_library": "validate_static_library.sh", | ||
| }, | ||
| toolchain_identifier = "local", | ||
| unfiltered_compile_flags = [ | ||
| "-fno-canonical-system-headers", | ||
| "-Wno-builtin-macro-redefined", | ||
| "-D__DATE__=\"redacted\"", | ||
| "-D__TIMESTAMP__=\"redacted\"", | ||
| "-D__TIME__=\"redacted\"", | ||
| ], | ||
| ) |
13 changes: 13 additions & 0 deletions
13
examples/inject_extra_features/toolchain/builtin_include_directory_paths
This file contains hidden or 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,13 @@ | ||
| This file is generated by cc_configure and contains builtin include directories | ||
| that /usr/bin/gcc reported. This file is a dependency of every compilation action and | ||
| changes to it will be reflected in the action cache key. When some of these | ||
| paths change, Bazel will make sure to rerun the action, even though none of | ||
| declared action inputs or the action commandline changes. | ||
|
|
||
| /usr/lib/gcc/x86_64-linux-gnu/10/include | ||
| /usr/local/include | ||
| /usr/include/x86_64-linux-gnu | ||
| /usr/include | ||
| /usr/include/c++/10 | ||
| /usr/include/x86_64-linux-gnu/c++/10 | ||
| /usr/include/c++/10/backward |
61 changes: 61 additions & 0 deletions
61
examples/inject_extra_features/toolchain/cc_toolchain_config.bzl
This file contains hidden or 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,61 @@ | ||
| # buildifier: disable=bzl-visibility | ||
| load( | ||
| "@rules_cc//cc/private/toolchain:unix_cc_toolchain_config.bzl", | ||
| unix_cc_toolchain_config = "cc_toolchain_config", | ||
| ) | ||
|
|
||
| # Macro for calling cc_toolchain_config from @bazel_tools with setting the | ||
| # right paths and flags for the tools. | ||
| def cc_toolchain_config( | ||
| name, | ||
| abi_libc_version, | ||
| abi_version, | ||
| compile_flags, | ||
| compiler, | ||
| conly_flags, | ||
| coverage_compile_flags, | ||
| coverage_link_flags, | ||
| cpu, | ||
| cxx_builtin_include_directories, | ||
| cxx_flags, | ||
| dbg_compile_flags, | ||
| host_system_name, | ||
| link_flags, | ||
| link_libs, | ||
| opt_compile_flags, | ||
| opt_link_flags, | ||
| supports_start_end_lib, | ||
| target_libc, | ||
| target_system_name, | ||
| tool_paths, | ||
| toolchain_identifier, | ||
| unfiltered_compile_flags, | ||
| extra_features = []): | ||
| unix_cc_toolchain_config( | ||
| name = name, | ||
| abi_libc_version = abi_libc_version, | ||
| abi_version = abi_version, | ||
| archive_flags = [], | ||
| compile_flags = compile_flags, | ||
| compiler = compiler, | ||
| conly_flags = conly_flags, | ||
| coverage_compile_flags = coverage_compile_flags, | ||
| coverage_link_flags = coverage_link_flags, | ||
| cpu = cpu, | ||
| cxx_builtin_include_directories = cxx_builtin_include_directories, | ||
| cxx_flags = cxx_flags, | ||
| dbg_compile_flags = dbg_compile_flags, | ||
| fastbuild_compile_flags = [], | ||
| host_system_name = host_system_name, | ||
| link_flags = link_flags, | ||
| link_libs = link_libs, | ||
| extra_features = extra_features, | ||
| opt_compile_flags = opt_compile_flags, | ||
| opt_link_flags = opt_link_flags, | ||
| supports_start_end_lib = supports_start_end_lib, | ||
| target_libc = target_libc, | ||
| target_system_name = target_system_name, | ||
| tool_paths = tool_paths, | ||
| toolchain_identifier = toolchain_identifier, | ||
| unfiltered_compile_flags = unfiltered_compile_flags, | ||
| ) |
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.
Was this intended to be built with the toolchain in
//examples/inject_extra_features/toolchain? The toolchain isn't registered.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.
@armandomontanez it was intended that it is not register. For the moment I just wanted to add an example in the draft in this way people could play around with the command line that I mentioned in the PR description.
If between #523 and #524 you also agree that #524 is the preferred approach, then I would just close both of them and we can continue the discussion in #525. You will see that in #525 I did not add any example, I believe that it is quite simple as to need an example, but if you want one let me know.