Commit Graph

71 Commits

Author SHA1 Message Date
Fabian Meumertzheim 8395ec0172 Copybara Merge: https://github.com/bazelbuild/rules_cc/pull/263
BEGIN_PUBLIC
Copybara import of the project:

--
82e44f3c47 by Fabian Meumertzheim <fabian@meumertzhe.im>:

Copy over runfiles library from Bazel

The runfiles library can be maintained independently of Bazel releases and bazel_tools can refer to it via an alias.

--
885d333d55 by Fabian Meumertzheim <fabian@meumertzhe.im>:

Switch to new include path and namespace

--
b8cd815963 by Fabian Meumertzheim <fabian@meumertzhe.im>:

Fix CI

--
41b7d48ed8 by Fabian Meumertzheim <fabian@meumertzhe.im>:

Silence warnings

--
b97a30e8bb by Fabian Meumertzheim <fabian@meumertzhe.im>:

Remove per_file_copt

END_PUBLIC

PiperOrigin-RevId: 697942902
Change-Id: I10a6c9baf0464722fca026db99cf572acfd159f1
2024-11-19 02:58:45 -08:00
Googler f5044c0097 Fix rules_shell copybara
BEGIN_PUBLIC
Internal change
END_PUBLIC

PiperOrigin-RevId: 693722123
Change-Id: I97ace26fc9275ff7417302a6f39ab90002c733f4
2024-11-06 07:36:04 -08:00
Googler 7e5f6a9391 Remove defs.bzl usages
BEGIN_PUBLIC
Remove defs.bzl usages
END_PUBLIC

PiperOrigin-RevId: 693709660
Change-Id: I1c92999e23c153f865ad68ab802d907abaea74eb
2024-11-06 07:35:53 -08:00
Copybara-Service 76413676fc Merge pull request #265 from comius:rules-shell-in-cc
PiperOrigin-RevId: 693699461
Change-Id: Icd113a5668da50f186836ca79036f6620ad0bfce
2024-11-06 07:35:39 -08:00
Ivo List 2b8d08c910 Use rules_shell 2024-11-06 14:21:54 +01:00
Fabian Meumertzheim 3d51aaa430 Deduplicate tools for `cc_tool_map`
Fixes #235
2024-10-15 14:30:10 +02:00
Googler a2949e206e Fix toolchain argument ordering
BEGIN_PUBLIC

Fix argument ordering

Expected argument ordering should be:

1. Arguments listed in `args`.
2. Legacy/built-in features.
3. User-defined features.

Due to some implementation changes, user-defined arguments were being applied last, reducing the ability for features to properly toggle behaviors dynamically.

This also fixes an issue caught by this change where cc_sysroot was applying flags to actions that had no associated action config.

END_PUBLIC

PiperOrigin-RevId: 683677895
Change-Id: I60e25ca22ffefce717e4e5ce476db0a070ca1993
2024-10-08 10:34:59 -07:00
Googler f364500ba8 Create a concept of a tool capability.
This should make the concept of "sentinel features" work correctly with known_features and enabled_features, rather than enabling them directly in features.

PiperOrigin-RevId: 681688437
Change-Id: I29184a2079ccfd0eb3a275439508a66ca61109af
2024-10-02 19:56:22 -07:00
Googler 58debbffe4 Remove experimental_enable_rule_based_toolchains flag
BEGIN_PUBLIC

Remove experimental_enable_rule_based_toolchains flag

Rule-based toolchains will not be gated by a flag when released with rules_cc v0.0.10. Also, this flag is unfortunately inherently incompatible with --experimental_exclude_starlark_flags_from_exec_config.

END_PUBLIC

PiperOrigin-RevId: 674072362
Change-Id: Iebda45d4daf4cec27c48296d61092dc513442911
2024-09-12 17:31:23 -07:00
Googler b8bb882895 Fix rule-based implementation of runtime_library_search_directories
BEGIN_PUBLIC

Fix rule-based implementation of runtime_library_search_directories

As runtime_library_search_directories was written and reorganized through review, some instances of `$ORIGIN` were unintentionally renamed to `$EXEC_ORIGIN`. This change fixes those instances to correctly mirror CppActionConfigs.java.

END_PUBLIC

BUG: 349427627
PiperOrigin-RevId: 672401255
Change-Id: Ic20f9e77eccca8bc7e7f895aeaeb44f85022df28
2024-09-08 22:14:44 -07:00
Googler 0cd5c640a7 Implement libraries_to_link as cc_args
BEGIN_PUBLIC

Implement libraries_to_link as cc_args

Implements the libraries_to_link feature as libraries_to_link rules.

END_PUBLIC

PiperOrigin-RevId: 671775909
Change-Id: Ie3758e37f3db5c24ed9d757aa7cbeb78aecb153d
2024-09-06 08:56:38 -07:00
Googler 7c2883f3b1 Implement runtime_library_search_directories as cc_args
BEGIN_PUBLIC

Implement runtime_library_search_directories as cc_args

Implements the runtime_library_search_directories feature as cc_args rules.

END_PUBLIC

PiperOrigin-RevId: 671773775
Change-Id: I703824dee8ceb62ac1597e42cc74de0162952386
2024-09-06 08:49:49 -07:00
Googler 4bf8bb1f7d Implement shared_flag as cc_args
BEGIN_PUBLIC

Implement shared_flag as cc_args

Implements the shared_flag feature as cc_args rules.

END_PUBLIC

PiperOrigin-RevId: 671765792
Change-Id: I0c13873ef2b5c19908cbed13c1b88b5fc957c4cd
2024-09-06 08:25:09 -07:00
Googler 98ab8334e7 Implement force_pic_flags as cc_args
BEGIN_PUBLIC

Implement force_pic_flags as cc_args

Implements the force_pic_flags feature as cc_args rules.

END_PUBLIC

PiperOrigin-RevId: 671764316
Change-Id: I7f04bbf46027007fc47d230d49d3334b1a6ddfac
2024-09-06 08:20:51 -07:00
Googler cf6ccb93f4 Implement linker_param_file as cc_args
BEGIN_PUBLIC

Implement linker_param_file as cc_args

Implements the linker_param_file feature as cc_args rules.

END_PUBLIC

PiperOrigin-RevId: 671762576
Change-Id: Ic6bd3ad3b059599c796680cdb4e2b63f6929b8a9
2024-09-06 08:14:11 -07:00
Googler f999a8e23b Implement archiver_flags as cc_args
BEGIN_PUBLIC

Implement archiver_flags as cc_args

This is the first change in a series that will reimplement the legacy
features defined in Bazel's Java code using the new toolchain rules. These implementations are redefined as raw arguments using the new toolchain rules, which allows for the definition shared and reused across different contexts.

This first change implements archiver_flags, which is used to produce the arguments for the archiver tool used by `cc_library`.

This CL also adds a test that compares the feature implementation produced by
the new rules to the feature implementation defined in Bazel's Java
code. This should make it easier to review the final result and ensure it
is functionally equivalent to the Java implementation.

END_PUBLIC

PiperOrigin-RevId: 671403834
Change-Id: I2d4f15b49619a11995a50c86439340ea532e360e
2024-09-05 09:36:58 -07:00
Googler 66613ac5d9 Add support for implicit include directories to rule-based toolchains
BEGIN_PUBLIC

Add support for implicit include directories to rule-based toolchains

Reorients the `cc_toolchain.cxx_builtin_include_directories` attribute so it is expressed as an attribute on `cc_args` and `cc_tool` to signify that the tools or arguments imply include directories that Bazel's include path checker should allowlist. This moves the allowlist to the source of truth that implies these directories.

END_PUBLIC

PiperOrigin-RevId: 671393376
Change-Id: Ide8cae548783726835168adcd3f705028a1f4308
2024-09-05 09:06:15 -07:00
Googler 2480c90525 Replace sysroot with a cc_sysroot macro.
BEGIN_PUBLIC
Replace sysroot with a cc_sysroot macro.

This is part of what amontanez@ and I discussed about making C++ toolchains less "magic".
I'd like to do the same for cxx_builtin_include_directories, but that will require significantly more effort.

END_PUBLIC

PiperOrigin-RevId: 666607531
Change-Id: Ic9cfb157e892c05a9c875f240c0ed9a1048dea19
2024-08-22 20:36:02 -07:00
Googler f5eb3c0c4a Integrate cc_tool_map into rule-based toolchains
BEGIN_PUBLIC

Integrate cc_tool_map into rule-based toolchains

Integrates cc_tool_map as a new attribute of cc_toolchain, completely replacing cc_action_type_config.

END_PUBLIC

PiperOrigin-RevId: 666365739
Change-Id: Iac74a31736dad66ac3dc75b4478ab4d4d2412181
2024-08-22 08:46:18 -07:00
Googler 3a62fd3f5b Make enabled_features functionally equivalent to cc_feature(..., enabled=True)
BEGIN_PUBLIC
Make enabled_features functionally equivalent to cc_feature(..., enabled=True)

This should allow you to disable an enabled feature elsewhere in the toolchain.

Fixes #233
END_PUBLIC

PiperOrigin-RevId: 666318466
Change-Id: I0b820cb2033d4ce8b141ff74dcd6516b8157c2b4
2024-08-22 06:06:56 -07:00
Googler 84fceed887 Disallow features from specifying whether they are enabled by default or not.
BEGIN_PUBLIC
Disallow features from specifying whether they are enabled by default or not.

Such a decision shouldn't be made by the feature, but instead by the toolchain author.
END_PUBLIC

PiperOrigin-RevId: 658621275
Change-Id: I4dae8ee1acc349a0ff6f09e6cf68e15fdc481a48
2024-08-01 19:19:51 -07:00
Googler af926372c5 Replace toolchain_features with known_features and enabled_features.
BEGIN_PUBLIC
Replace toolchain_features with known_features and enabled_features.

This should allow for the deprecation of action_type_config, as `implies` there is no longer required.
END_PUBLIC

PiperOrigin-RevId: 658620044
Change-Id: Idda9bd77edad1be1fd26d5a655e3b9084d38bca8
2024-08-01 19:14:33 -07:00
Googler dcf1dc1680 Create a new cc_tool_config rule which will, in the future, replace cc_action_type_config.
PiperOrigin-RevId: 658426046
Change-Id: Ie90cec7049b3bddf7f022d188a0765ffeb1dcf1d
2024-08-01 09:20:43 -07:00
Googler dde7ad4094 Replace execution_requirements with the standardized field "tags".
PiperOrigin-RevId: 657777523
Change-Id: If803f20aebba7126b70bcc9c483b9d03989104bc
2024-07-30 16:57:06 -07:00
Googler f97190f039 Remove feature requirements from tools.
BEGIN_PUBLIC
Remove feature requirements from tools.

It's such a niche use case, adds a fair amount of complexity, and there are multiple alternatives available:
* Now that we're using rule based things, you should just be able to add a bazel flag and select on it in your tool definition.
* If you really want precisely that behaviour, you can make your feature add "--use-foo-tool" to the args, and make your tool a wrapper tool that reads the command-line argument, and if provided, invokes a different tool.
END_PUBLIC

PiperOrigin-RevId: 657383729
Change-Id: Idb4f3ad66dc92d48ef81a1e8875bf6d3ba215aa4
2024-07-29 17:37:10 -07:00
Googler e1c7ebb858 Add support for select'ing on cc_args(args=...).
This CL is an alternative to unknown commit. I left the other CL seperately, because I wasn't 100% sure that we'd agree to this, since this is an API change.
I did it this way because I believe it's much less hacky, and it also allows us to format things that aren't variables.

BEGIN_PUBLIC
Add support for select'ing on cc_args(args=...).

This is quite tricky because the one parameter was being split into two in a macro, one of type label and the other of type string.

For example, `args = ["--foo", format_arg("--bar=%s", "//path/to:bar")]` was rewritten by the macro to `args = [json.encode(struct(format_type="raw", format="foo")), json.encode(struct(format_type="format_arg", format="--bar=%s", value=0))], variables = ["//path/to:bar"]`.
To allow it to work with selects, we need to ensure that we don't perform post-processing on the inside of the select. To solve this, we:
* Ensure that args only take strings
* Provide a seperate parameter for substitutions.

This new mechanism also has the useful property that we can now format things that are not variables. For example, I can do the following:

```
directory(name = "sysroot", ...)
cc_args(
    name = "sysroot_arg",
    args = ["--sysroot={sysroot}"],
    format = {
        ":sysroot": "sysroot"
    }
)
```

END_PUBLIC

PiperOrigin-RevId: 656211278
Change-Id: If83f1ea5a99090c18f2a561c51ec6d39ce9fe419
2024-07-25 20:13:42 -07:00
Googler 280d3ad603 Allow creation of sentinel features in rule-based toolchains
BEGIN_PUBLIC
Makes the `args` attribute of `cc_feature` optional so that users may declare sentinel features that do not have any inherent arguments.
END_PUBLIC

PiperOrigin-RevId: 646545838
Change-Id: I470a496aec951608f21cc8ea693387c5b551c8a9
2024-06-25 11:23:34 -07:00
Googler 5e848c1434 Remove the "data" attribute from cc_action_type_config.
BEGIN_PUBLIC
Remove the "data" attribute from cc_action_type_config.

Technically speaking, data shouldn't be associated with action types. Instead, data should be associated with either a tool or a set of flags.

For example, instead of the cc_compile action having the header files as a data dependency, the "include_paths" cc_arg should instead declare `data = <header files>`.

This will allow us to, once we have a fully starlark-ified c++ toolchain, do much finer-grained dependencies. This will allow us to, for example, not provide header files to the action when the user enables the feature "nostdlib".
END_PUBLIC

PiperOrigin-RevId: 642434412
Change-Id: Id16fe05a1c86bbaf4718cd36a15f8a9d6afb0163
2024-06-11 16:44:42 -07:00
Googler ac3f19bac7 Remove support for args from action_type_config.
BEGIN_PUBLIC
Remove support for args from action_type_config.

Args in individual action type configs result in redundant configuration, where both the cc_args and the cc_action_type_config control which actions they're enabled for. Instead of:
```
cc_args(name = "compile_args", action_types = [":c_compile", ":cpp_compile])
cc_action_type_config(name = "c_compile_config", actions = [":c_compile"], args = [":compile_args"])
cc_action_type_config(name = "cpp_compile_config", actions = [":cpp_compile"], args = [":compile_args"])
cc_toolchain(action_type_configs = [":c_compile_config", ":cpp_compile_config"])
```

We should force users to write the following:
```
cc_args(name = "compile_args", action_types = [":c_compile", ":cpp_compile])
cc_action_type_config(name = "c_compile_config", actions = [":c_compile"])
cc_action_type_config(name = "cpp_compile_config", actions = [":cpp_compile"])
cc_toolchain(action_type_configs = [":c_compile_config", ":cpp_compile_config"], args = [":compile_args"])
```
END_PUBLIC

PiperOrigin-RevId: 642432029
Change-Id: I1aa7c1752f4d915d8c84c17a06314ae9ad2c69f0
2024-06-11 16:35:03 -07:00
Googler 531c9951a8 Remove legacy toolchain flags.
BEGIN_PUBLIC
Remove legacy toolchain flags.

This will allow us to enforce that users of the rule based toolchain are not using legacy toolchain resolution, and simplify toolchain creation.
END_PUBLIC

PiperOrigin-RevId: 640017209
Change-Id: I6ea4fad8ddf1a06ad17d706d82e54eb7f05aa6c6
2024-06-03 21:59:53 -07:00
Googler 0069837ab5 Create a cc_directory_tool rule.
BEGIN_PUBLIC
Create a cc_directory_tool rule.

This should allow for easy definition of tools from the sysroot. For example:
cc_directory_tool(
  name = "clang",
  directory = "@sysroot//:sysroot",
  executable = "usr/bin/clang",
)
END_PUBLIC

PiperOrigin-RevId: 639947945
Change-Id: I4c211eb9c0b5fdc6457d9d32ef9250b5384a4ef3
2024-06-03 16:24:27 -07:00
Googler 2351aa42b1 Make toolchains use directory markers instead of strings.
BEGIN_PUBLIC
Make toolchains use directory markers instead of strings.

You now refer to this instead of a string containing the repo mapped path.
END_PUBLIC

PiperOrigin-RevId: 639946886
Change-Id: I409be7b7002252b06562a2982a2568e79811877d
2024-06-03 16:20:34 -07:00
Googler f88663dc50 Provide a default toolchain_identifier.
BEGIN_PUBLIC
Provide a default toolchain_identifier.

END_PUBLIC

PiperOrigin-RevId: 626172528
Change-Id: I2d23d79b82f4268b462dac79edc4f69a7f865e00
2024-04-18 15:47:16 -07:00
Googler 6e490f79ee Implement flag_group in the new rule-based toolchain.
BEGIN_PUBLIC
Implement flag_group in the new rule-based toolchain.
END_PUBLIC

PiperOrigin-RevId: 622107179
Change-Id: I9e1971e279f313ce85537c899bcf80860616f8b7
2024-04-05 01:47:45 -07:00
Googler 1361256a68 Gather variable metadata for the new rule-based toolchain.
BEGIN_PUBLIC
Gather variable metadata for the new rule-based toolchain.
END_PUBLIC

PiperOrigin-RevId: 622000877
Change-Id: I5b2ea6c363fc43fd44e60ffc8fa7ae041545337e
2024-04-04 16:13:02 -07:00
Googler 991cdf09a9 Implement provides in rule based toolchain.
BEGIN_PUBLIC
Implement provides in rule based toolchain.
END_PUBLIC

PiperOrigin-RevId: 619082926
Change-Id: I938640981bd10f0e3d41402d211672a45264df1a
2024-03-25 23:44:03 -07:00
Googler 61def7a42c Improve errors in variable definitions by adding labels to the variables.
BEGIN_PUBLIC
Improve errors in variable definitions by adding labels to the variables.
END_PUBLIC

PiperOrigin-RevId: 618984216
Change-Id: I5d6d11ba2b72f426b9f01bcbb528b0914c98c964
2024-03-25 15:53:13 -07:00
Googler 17143d150d Add strictly typed variables toolchain rules.
BEGIN_PUBLIC
Add strictly typed variables to toolchain rules.

This should allow us to implement a proper replacement for flag_group
END_PUBLIC

PiperOrigin-RevId: 617338607
Change-Id: I7f3058578cb5eb17ecc1aa38d2e1459e0742aee9
2024-03-19 17:05:03 -07:00
Googler aa19278bbd Rename ExpandArgs to NestedArgs
After discussion with @amontanez in unknown commit, we decided that NestedArgs was a more appropriate name.

BEGIN_PUBLIC
Rename ExpandArgs to NestedArgs
END_PUBLIC

PiperOrigin-RevId: 617085672
Change-Id: I1d7190cac79f8fa953d23be7d0db3b028a84cf30
2024-03-19 01:09:56 -07:00
Googler bbb0615a87 Refactor AddArgsInfo into ExpandArgsInfo
BEGIN_PUBLIC
Refactor AddArgsInfo into ExpandArgsInfo

This allows us to create a similar mechanism to the current toolchain, while maintaining type safety.
END_PUBLIC

PiperOrigin-RevId: 615939056
Change-Id: I9b6763150194f8a76dfd8da730a3e2d45accbe20
2024-03-14 16:28:07 -07:00
Googler 59cf8ff109 Rename additional_files to data.
BEGIN_PUBLIC
Rename additional_files to data.

This is more consistent with other rules.
END_PUBLIC

PiperOrigin-RevId: 615364332
Change-Id: Ic27ec8c8e72d290e72074034f85a34b38401599b
2024-03-13 04:22:40 -07:00
Googler e658433e23 No public description
PiperOrigin-RevId: 613579953
Change-Id: I4aea8af1b3db8eb532c7c9296fc4dfa0c2ff9481
2024-03-07 07:40:02 -08:00
Googler de4aaa6472 Allow cc_toolchain_info rule to be used as a parameter to pass into native.cc_toolchain(config = ...)
BEGIN_PUBLIC
Allow cc_toolchain_info rule to be used as a parameter to pass into native.cc_toolchain(config = ...)
END_PUBLIC

PiperOrigin-RevId: 613000772
Change-Id: I8348e2cbb4aa7d0a523341dcaf1e2c2bc647f640
2024-03-05 16:04:53 -08:00
Googler 94d4760a89 Implement cc_toolchain_config rule and cc_legacy_file_group rule.
BEGIN_PUBLIC
Implement cc_toolchain_config rule and cc_legacy_file_group rule.

Note that this rule is in the impl/ directory because we require users to use the cc_toolchain_config rule via the cc_toolchain macro that we will define later, to ensure that parameters such as `compile_files` are passed correctly.
END_PUBLIC

PiperOrigin-RevId: 612998387
Change-Id: I986d11775e368c4386a930ab2ce8663956a57f9d
2024-03-05 15:58:06 -08:00
Googler 7250ef4352 BEGIN_PUBLIC
Implement ToolchainConfigInfo.

Add support to create the toolchain from feature, action config, and args targets, and validate it to ensure correctness.
END_PUBLIC

PiperOrigin-RevId: 612985448
Change-Id: I7d9086dd1dde07eb0c2484414c9c28c1b8bfb427
2024-03-05 15:15:39 -08:00
Googler 9befdcd90e Remove macros wrapping rules that take in features.
Based on the comments in unknown commit, I created this CL

BEGIN_PUBLIC
Remove macros wrapping rules that take in features.
END_PUBLIC

PiperOrigin-RevId: 612979047
Change-Id: I5690717b164432c9cecebf87ef9dda41f9fa846f
2024-03-05 14:55:21 -08:00
Googler 4eccbe17c8 BEGIN_PUBLIC
Implement builtin CC toolchain features.

This will allow you to override builtin features
END_PUBLIC

PiperOrigin-RevId: 610887686
Change-Id: I30e928c116386ec703dff24a97f925481c395b06
2024-02-27 15:07:57 -08:00
Googler db087578f7 BEGIN_PUBLIC
Implement cc_feature_set and cc_feature_constraint.
END_PUBLIC

PiperOrigin-RevId: 610713183
Change-Id: Ia009ac536b71cd9aa44578f823f13361c1580e37
2024-02-27 04:49:36 -08:00
Googler 2b6cdcfe88 BEGIN_PUBLIC
Implement cc_feature for the rule based toolchain.
END_PUBLIC

PiperOrigin-RevId: 610712498
Change-Id: I2539825f0f4cf7f234a2310de6af0662aeb0ea2c
2024-02-27 04:45:26 -08:00
Googler c5493f9b2c BEGIN_PUBLIC
Implement cc_action_type_config.

Rename it from cc_action_config, to make it clear that we are not configuring an action, but rather configuring a type of action.
END_PUBLIC

PiperOrigin-RevId: 610518142
Change-Id: Ic10755952ee786d30a3a5564aa09a8dc16499f3a
2024-02-26 13:58:42 -08:00