Commit Graph

518 Commits

Author SHA1 Message Date
Copybara-Service b1bea517b7 Merge pull request #240 from bazelbuild:comius-patch-1
PiperOrigin-RevId: 682269919
Change-Id: Iae32802a2d92a79f9791708dceeafc8b1fb51f10
2024-10-04 04:41:30 -07:00
Ivo List b6db47b84b Add bazel version 2024-10-04 13:28:28 +02:00
Ivo List 6a6e870a20 Fix url 2024-10-04 13:28:28 +02:00
Ivo List 85e02e42b3 Adding maintainers 2024-10-04 13:28:28 +02:00
Googler c2549f6eb0 Sync cc toolchain from Bazel's tools/cpp
- @bazel_tools//tools/cpp:toolchain_type is not moved.
- Added cc/toolchains/toolchain_config_utils.bzl for exposing util functions for cc toolchain configuration.

Closes https://github.com/bazelbuild/rules_cc/pull/247

Working towards https://github.com/bazelbuild/bazel/issues/23809

PiperOrigin-RevId: 681913803
Change-Id: I16ff456a212ab0e579c137bd74344255f4e49bd8
2024-10-03 09:32:38 -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 1af2140e73 Document feature-related toolchain rules
BEGIN_PUBLIC

Document feature-related toolchain rules

Extends the toolchain API documentation to cover all feature-related rules.

END_PUBLIC

PiperOrigin-RevId: 681476538
Change-Id: Icfe35e03937bdb0bc55eae24f57eafe0db7b16eb
2024-10-02 09:10:38 -07:00
Googler b06d2f7d53 Add cc_action_type and cc_tool documentation
BEGIN_PUBLIC

Add cc_action_type and cc_tool documentation

Extends the toolchain API documentation to include docs for cc_action_type, cc_action_type_set, cc_variable, and cc_tool.

Also improves cross-reference links and copybara behavior for docs.

END_PUBLIC

PiperOrigin-RevId: 680601617
Change-Id: Idbbdfbcb2c5a1c3598b6a7e7ba985ed14f871099
2024-09-30 09:15:19 -07:00
Googler 9cb80cfc32 Add objcopy_embed_data to rules_cc action_names.bzl.
PiperOrigin-RevId: 680579470
Change-Id: I73600ea8df35aa8a7983ebc4e2e278945d2e65cb
2024-09-30 08:07:27 -07:00
Googler 848d56aa29 Update copybara to improve docs handling
BEGIN_PUBLIC

Add `@rules_cc` to generated docs

Ensures when docs are generated that the `@rules_cc` prefix is used for anything that appears to come from the repo.

END_PUBLIC

PiperOrigin-RevId: 677883741
Change-Id: I82b910b338aea8b14ecb7b192b5f3d3907be30ee
2024-09-23 11:55:00 -07:00
Googler 91f050e461 Release rules_cc 0.0.10
PiperOrigin-RevId: 674308086
Change-Id: I1b673c7b1c04e3d47b826160903357fa1dbb3ba9
2024-09-13 08:30:29 -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 de86823dde Document args-related toolchain rules
BEGIN_PUBLIC

Document args-related toolchain rules

Adds comprehensive documentation for cc_args, cc_nested_args, and cc_args_list.

END_PUBLIC

PiperOrigin-RevId: 673921558
Change-Id: I1c9c0731925a03dedec983083072f52c6d4c270f
2024-09-12 11:09:02 -07:00
Googler 0d5561bcba Consolidate action labels in toolchain args
BEGIN_PUBLIC

Consolidate action labels in toolchain args

Consolidates action labels used by re-implementation of legacy features to use logical groups rather than individually listing every action. This simplifies the rule definitions slightly.

END_PUBLIC

PiperOrigin-RevId: 673920103
Change-Id: If5453dd5b45d5549ff75d656da8a2873232117ae
2024-09-12 11:05:19 -07:00
Googler da1ac71c8e Create group for c compile actions
BEGIN_PUBLIC

Create group for c compile actions

Adds `c_compile_actions` group to provide a logical C equivalent for `cpp_compile_actions`.

END_PUBLIC

PiperOrigin-RevId: 673408772
Change-Id: Ic5ccb57bc1fa7a98999d944316b97a39aac571ac
2024-09-11 08:46:50 -07:00
Ivo List 7a67e9887b Copybara Merge: https://github.com/bazelbuild/rules_cc/pull/238
BEGIN_PUBLIC
Copybara import of the project:

--
2803a12428 by Ivo List <ilist@google.com>:

Prepare for release 0.0.10-rc2

--
3423c73208 by Ivo List <ilist@google.com>:

Format WORKSPACE

--
a99403a6b0 by Ivo List <ilist@google.com>:

Touch module

--
258d8c9f24 by Ivo List <ilist@google.com>:

Revert "Touch module"

This reverts commit a99403a6b0.

END_PUBLIC

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_cc/pull/238 from comius:release-0.0.10-rc2 258d8c9f24
PiperOrigin-RevId: 673358956
Change-Id: Iabc9c29e6f168cfdfd2f0657438b71654f470cc9
2024-09-11 05:56:57 -07:00
Googler 96ac608d34 No public description
PiperOrigin-RevId: 673231375
Change-Id: I61110c5d47898c0ef27af650ad56de6f107d3976
2024-09-10 22:04:14 -07:00
Googler ce4bc8a8de Make `cc_helper.bzl` publicly `load()`-able for `@rules_java`
PiperOrigin-RevId: 672945291
Change-Id: I0c2a32475c1f2fdeffe28239cb0b9bead70295a7
2024-09-10 06:54:08 -07:00
Googler 5c1be25800 Copy a few utilities from `@_builtins` to `@rules_cc`
PiperOrigin-RevId: 672519388
Change-Id: Icb077dd736af10724ffdbfb8330564516b43fb1d
2024-09-09 06:06:10 -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 ca8483971c Automated rollback of commit 0f352c3497.
*** Reason for rollback ***

Rollforward with fix for b/365154741

*** Original change description ***

Automated rollback of commit 0bc1ba56ef.

*** Reason for rollback ***

TAP failures in Bazel/Blaze, see b/365154741 and discussion at https://chat.google.com/room/AAAAXE3XKrY/_e3TpBFJvus

*** Original change description ***

Add user-facing documentation for cc_tool_map

BEGIN_PUBLIC

Add user-facing documentation for cc_tool_map

Adds user-facing documentation for the cc_tool_map toolchain rule, including an example and higher level analogies.

END_PUBLIC

***

***

PiperOrigin-RevId: 672000172
Change-Id: If7ad64e2378a2016d389a3718944aa04bc5e9759
2024-09-06 23:05:56 -07:00
Googler 0f352c3497 Automated rollback of commit 0bc1ba56ef.
*** Reason for rollback ***

TAP failures in Bazel/Blaze, see b/365154741 and discussion at https://chat.google.com/room/AAAAXE3XKrY/_e3TpBFJvus

*** Original change description ***

Add user-facing documentation for cc_tool_map

BEGIN_PUBLIC

Add user-facing documentation for cc_tool_map

Adds user-facing documentation for the cc_tool_map toolchain rule, including an example and higher level analogies.

END_PUBLIC

***

PiperOrigin-RevId: 671898382
Change-Id: Iead81a71adb17dff46b1b442471e595769fb5c2e
2024-09-06 14:50:15 -07:00
Googler 0bc1ba56ef Add user-facing documentation for cc_tool_map
BEGIN_PUBLIC

Add user-facing documentation for cc_tool_map

Adds user-facing documentation for the cc_tool_map toolchain rule, including an example and higher level analogies.

END_PUBLIC

PiperOrigin-RevId: 671777889
Change-Id: Ib53de76f355db43a9530f7cbe11face3c9219675
2024-09-06 09:01:28 -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 9333569bc8 Add support for the `mandatory` param to `find_cc_toolchain` in `@rules_cc`
PiperOrigin-RevId: 671758214
Change-Id: I37d0ca1f9b083513cb5933984153e1ba608313ca
2024-09-06 07:59:59 -07:00
Googler 8b63556334 Fix buildifier finding in rules_cc
BEGIN_PUBLIC

Fix buildifier finding in rules_cc

Fixes an out-of-order dictionary entry identified by the rules_cc Bazel CI.

END_PUBLIC

PiperOrigin-RevId: 671626223
Change-Id: Ib33fa36db879a5cd89cb2d01bb5b671e706de77b
2024-09-05 22:08:07 -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 391170f339 Export a few utility functions from `@builtins` to `rules_cc`
PiperOrigin-RevId: 670979420
Change-Id: I37ce050f747a0dbc5ab0039fd32a84d7be7e1ed4
2024-09-04 08:25:21 -07:00
Googler a778282a15 Fix action label evaluation in cc_sysroot
BEGIN_PUBLIC

Fix action label evaluation in cc_sysroot

Explicitly converts action labels in cc_sysroot to Label objects to address issues where the labels were being evaluated as relative to the module instantiating cc_sysroot rules.

END_PUBLIC

PiperOrigin-RevId: 667520654
Change-Id: Ia64306cc172dfaa747ef28a92390bcd90296b109
2024-08-26 03:09:37 -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 0d1b084cfa Update toolchain variable definitions to allow static linking
BEGIN_PUBLIC
Update toolchain variable definitions to allow static linking

Updates the rules-based-toolchain variable definitions to reflect the how the variables are used in Bazel's CppActionConfigs.java Java implementation, particularly with respect to static linking.
END_PUBLIC

PiperOrigin-RevId: 647301605
Change-Id: I7ff87a75f9654d70ea160282ba66e99363c79ce5
2024-06-27 06:55:51 -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 9ff1d1b6fd No public description
PiperOrigin-RevId: 646508523
Change-Id: I7f45474a8c0052e3693aceca6ed2436396f13829
2024-06-25 09:37:32 -07:00
Googler 94d34d7954 Restructure rules_cc
BEGIN_PUBLIC
Restructure rules_cc

Design doc: https://docs.google.com/document/d/1L1JFgjpZ7SrBinb24DC_5nTIELeYDacikcme-YcA7xs/edit
END_PUBLIC

PiperOrigin-RevId: 643879458
Change-Id: Id3fd760fde1c1145cb5044fff9020b61652d2f25
2024-06-16 22:40:48 -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 1cf35f02db Make output_file accessible from strip.
BEGIN_PUBLIC
Make output_file accessible from strip.

See https://github.com/bazelbuild/bazel/pull/22638
END_PUBLIC

PiperOrigin-RevId: 640622335
Change-Id: I96fdca9494e5043f546b588490d692d67f94ee2b
2024-06-05 13:03:51 -07:00