Skip to content

Check Starlark contracts in the fork - #1

Draft
tamird wants to merge 88 commits into
mainfrom
type-contracts
Draft

tamird wants to merge 88 commits into
mainfrom
type-contracts

Conversation

@tamird

@tamird tamird commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Run the existing pull-request workflows for the Starlark contracts proposed upstream 1. This fork PR provides CI results while upstream workflows await approval.

Prepared by OpenAI's Codex on behalf of @tamird.

keith and others added 18 commits September 24, 2026 12:39
We don't want to block on env differences from buildkite to github
actions. This makes sure the commit the release being cut from is green.

Closes bazelbuild#898

COPYBARA_INTEGRATE_REVIEW=bazelbuild#898 from keith:ks/remove-release-tests-add-check-for-green-commit 2c6c094
PiperOrigin-RevId: 987685459
Change-Id: I85ab425de0d086b49a8410ad224b079b7859aa13
Renames INTERNAL_VISIBILITY to better clarify the intent of the variable, and communicate to both Bazel and Google-internal users what this variable implies. Also restricts the visibilty of the visibility.bzl file to hopefully prevent hyrum's law from taking too strong a hold on this non-private file.

Closes bazelbuild#910

COPYBARA_INTEGRATE_REVIEW=bazelbuild#910 from armandomontanez:armando/add-visibility-comment 2d87d58
PiperOrigin-RevId: 990112200
Change-Id: I55c5a5acf45634125d2e5e6cede0b6efc8704d7c
…ild#909)

rules_python switched to using --enable_runfiles on windows which
revealed a bug that we weren't copying dependent dylibs for
cc_shared_library as we do for cc_binary.

Closes bazelbuild#909

COPYBARA_INTEGRATE_REVIEW=bazelbuild#909 from keith:ks/fix-cc_shared_library-locations-with-rules_python-on-windows 674b125
PiperOrigin-RevId: 990763525
Change-Id: I8fe763ae5623bf54e0cc90d78a002110c6b2383b
This temporarily works around a bazel bug where windows bwtb produces invalid results bazelbuild/bazel#31423

Closes bazelbuild#915

COPYBARA_INTEGRATE_REVIEW=bazelbuild#915 from keith:ks/use-remote_download_all-on-windows 7606258
PiperOrigin-RevId: 991211475
Change-Id: I27559e370ba55834abd365983375b299780a1ee5
We switched the default toolchain to a rules based one moving forward. This also required
a integration test change since previously the rules based toolchain files weren't in
the integration test inputs, but now they are required.

Closes bazelbuild#903

COPYBARA_INTEGRATE_REVIEW=bazelbuild#903 from keith:ks/bump-apple_support-dep 5541504
PiperOrigin-RevId: 991449012
Change-Id: I54fbdb4a8e726e03186340f4ec27e33a9ac8aad3
Having actions for these is relatively new.

Closes bazelbuild#904

COPYBARA_INTEGRATE_REVIEW=bazelbuild#904 from keith:ks/set-coverage_files-from-rules-based-toolchains 4af2175
PiperOrigin-RevId: 991450972
Change-Id: I18d5c2b4a58822e90893b7539619e42c320b1afc
Replace `_map_to_list` with `dict.items()` in `cc_helper.bzl` and `objc_compilation_support.bzl`. Starlark's `dict.items()` already returns a list of key-value tuples in insertion order, so the helpers unnecessarily iterate over that list and recreate each tuple. Remove both helpers and return `artifact_label_map.items()` at all five call sites.

Closes bazelbuild#900

COPYBARA_INTEGRATE_REVIEW=bazelbuild#900 from dzbarsky:codex/use-dict-items bef7e1e
PiperOrigin-RevId: 991615000
Change-Id: I281e1f5634a85fff7e0a079e79d13a02b3b3f22a
Replace the Java-backed `cc_common.empty_variables()` call with `_cc_internal.cc_toolchain_variables(vars = {})`. Both implementations construct the same empty `CcToolchainVariables` representation, preserving compile, link, FDO, and toolchain feature expansion.

Validation: `buildifier -mode=check cc/private/cc_common.bzl` and 66 passing C++ common, compile-variable, link-variable, and FDO analysis tests.

Closes bazelbuild#806

COPYBARA_INTEGRATE_REVIEW=bazelbuild#806 from dzbarsky:codex/starlarkify-empty-variables 33dcb2f
PiperOrigin-RevId: 991757889
Change-Id: Ifec667bdd7fbd5b7c852258e69d7f0198d2df1bd
Enable cc_copts_policy to enforce disallowed flags on command-line compiler options (--copt, --cxxopt, --conlyopt) via verify_command_line = True.

Taken over from unknown commit by trybka@.

Startblock:
  * // Put other blockers before this line to avoid churning.
  * has lgtm
  * is approved
  * and then
  * all comments are resolved
  * and then
  *[] allows unknown commit
PiperOrigin-RevId: 991964690
Change-Id: I04934ce74c252ad3a4c049ddcc6dad9b4463eb4d
This is the default in the toolchains now, this flag was invalid for
windows so CI warned

Closes bazelbuild#918

COPYBARA_INTEGRATE_REVIEW=bazelbuild#918 from keith:ks/remove-std-c-17-from-bazelrc 0829b78
PiperOrigin-RevId: 992301854
Change-Id: I2364dc05bc0963edd8a23368af0da64ef46baeda
There's references to this from bazel https://github.com/bazelbuild/bazel/blob/5604b553b2a54152e5e4f41ef4b01a416b7bfd44/tools/cpp/BUILD.tools#L44

We should remove both but in the meantime some rulesets reference this

Closes bazelbuild#888

COPYBARA_INTEGRATE_REVIEW=bazelbuild#888 from keith:ks/add-back-grep-includes-alias ebc21b3
PiperOrigin-RevId: 992413533
Change-Id: Iaeaf5a245db5a7a8a5fc891d4c70324a4b57f868
PiperOrigin-RevId: 993739069
Change-Id: I6fd5884126ba600529ff1904d8aac0438ca13e00
Closes bazelbuild#906

COPYBARA_INTEGRATE_REVIEW=bazelbuild#906 from keith:ks/use-named-arguments-instead-of-comments a5169cb
PiperOrigin-RevId: 993754957
Change-Id: I8963cdc410859edd985730f4d5bc1d35316a0acf
Closes bazelbuild#920

COPYBARA_INTEGRATE_REVIEW=bazelbuild#920 from keith:ks/add-docs-for-skip_virtual_includes 0e834a4
PiperOrigin-RevId: 994315342
Change-Id: Iab7ea501f9c35ad434a11cec1ff31c73ce566222
Provide a `dwo_files` output group for debug builds with fission enabled so that separate DWARF (`.dwo`) files can be requested on-demand in build modes where intermediate compilation outputs are not materialized by default.

PiperOrigin-RevId: 996578913
Change-Id: Iea1798051051edf66fa30f25417796d742c8dad2
…zelbuild#901)

`_compute_tool_paths` prefixes every relative tool path with the package of the `cc_toolchain`, which turns exec-cfg paths into non-existent ones. With apple_support 2.8.4, which Bazel@HEAD now bundles and thus selects by default on macOS, `$(CC)` expands to the nonsensical

```
external/apple_support++apple_cc_configure_extension+local_config_apple_cc/bazel-out/darwin_arm64-opt-exec-ST-<hash>/bin/external/apple_support+/crosstool/wrapped_clang
```

instead of

```
bazel-out/darwin_arm64-opt-exec-ST-<hash>/bin/external/apple_support+/crosstool/wrapped_clang
```

This PR keeps tool paths that start with the output directory as they are.

Closes bazelbuild#901

COPYBARA_INTEGRATE_REVIEW=bazelbuild#901 from fmeum:generated-tool-paths 103fab8
PiperOrigin-RevId: 996808000
Change-Id: Ice1f696166553d98f893dd6c430a769f3b9e691e
This just fixes minor incompatibilities

Closes bazelbuild#924

COPYBARA_INTEGRATE_REVIEW=bazelbuild#924 from keith:ks/enable-cc_integration_test-on-macos 3f48e22
PiperOrigin-RevId: 998012310
Change-Id: I41cd53581c97e9455208d5a1c63c585eebfcd843
Startblock:
PiperOrigin-RevId: 1000590878
Change-Id: Iae8805f45f22d773b39697d676886f1b9e1258de
_verify_no_disallowed_copts runs for every C++ target, once per copts, conlyopts and cxxopts attribute. It used to call allowlist.contains(ctx.label) first, for every policy. PackageGroupContents.containsPackage uses a hash set for exact //pkg entries but scans //pkg/... entries one by one, so a large prefix allowlist made the check expensive for every target, including the vast majority that use no disallowed flag.

The flags are now matched first, and the allowlist is consulted only when a flag matched, at most once per policy. Violations and their messages are unchanged.

This is needed before registering the -g0 debug info policy, whose allowlist has about 8k //pkg/... entries.

Startblock:
  * // Put other blockers before this line to avoid churning.
  * has lgtm
  * is approved
  * and then
  * all comments are resolved
  * and then
  *[] allows unknown commit
PiperOrigin-RevId: 1002043792
Change-Id: I68f80519dad93d597669a6aadfc71ef53f297719
fmeum and others added 5 commits October 19, 2026 21:19
`%package(...)%` resolved relative to rules_cc itself, not the location where the `cc_toolchain` was defined. For `cc_shared_library`, the existing initializer did resolve labels correctly, but failed to do so for `select` expressions.

Closes bazelbuild#896

COPYBARA_INTEGRATE_REVIEW=bazelbuild#896 from fmeum:claude/package-paths-bzlmod-toolchain-w8lcdu 0468ba0
PiperOrigin-RevId: 1002808922
Change-Id: Iea958478b558c0a5f80e6edd84bc13f20d6a9b98
…allowed copts policies.

Implement the design changes specified in design_banned_warnings.md and
design_modular_copts_policies.md:
- Update CcDisallowedCoptsInfo to provide package_allowlist, target_allowlist, and policy_label.
- Update cc_copts_policy to accept package_allowlist and target_allowlist.
- Update tools/cpp/policy/banned_warnings/BUILD to use package_allowlist.
- Update third_party/crosstool/v18/stable/crosstool_configuration.bzl and third_party/apple_crosstool/crosstool.bzl to forward package_allowlist, target_allowlist, and policy_label.
- Update cc_helper.bzl to exempt targets matching entries in package_allowlist and target_allowlist, and emit "disallowed by '<policy_label>'" in violation messages.
- Add and update unit tests in tools/cpp/policy/ and third_party/bazel_rules/rules_cc/tests/cc/common/.

Startblock:
  - BTRGuardian allows unknown commit

Startblock:
  * // Put other blockers before this line to avoid churning.
  * has lgtm
  * is approved
  * and then
  * all comments are resolved
  * and then
  *[] allows unknown commit
PiperOrigin-RevId: 1002924230
Change-Id: I35d1aefd0e0ecc47c81fa45c62481d534ca95a3f
This silences noise that encourages us to bump our MVS dep versions
which would affect users and we should only bump if we really need to

Closes bazelbuild#917

COPYBARA_INTEGRATE_REVIEW=bazelbuild#917 from keith:ks/add-check_direct_dependencies-off-to-bazelrc d525a7d
PiperOrigin-RevId: 1003300828
Change-Id: I3f7cce6f2988e426dcd819b797b0a1a731fae4ea
Closes bazelbuild#912

COPYBARA_INTEGRATE_REVIEW=bazelbuild#912 from PikachuHyA:msvc_support b3056e0
PiperOrigin-RevId: 1003457743
Change-Id: Ic6e1b559130a00b43c7b4c770abbc0f17ea2c8bc
Buildifier warns about this now

Closes bazelbuild#891

COPYBARA_INTEGRATE_REVIEW=bazelbuild#891 from keith:ks/update-location-to-execpath e0d7ca9
PiperOrigin-RevId: 1003826865
Change-Id: I8de712ba8d978a26bccb0cc74bc9d8faab78daab
@tamird
tamird force-pushed the type-contracts branch 3 times, most recently from 749ce49 to 1b8a555 Compare October 22, 2026 02:42
Combining `--features=cpp_modules` with either `--features=parse_headers` or `--compilation_mode opt` was broken, this seems to fix it. This adds an early exit copied from `_create_cc_compile_actions` that was missing in `_create_cc_compile_actions_with_cpp20_module_helper`:

https://github.com/bazelbuild/rules_cc/blob/c1ba7a0d5a5f51f6539eb94f32ef8d9fedd0250d/cc/private/compile/compile.bzl#L1249-L1254

I tested the changes in [my personal monorepo](https://github.com/rdong8/monorepo) + added a test for `parse_headers`.

This was found with the help of an LLM

Closes bazelbuild#876

COPYBARA_INTEGRATE_REVIEW=bazelbuild#876 from rdong8:cpp-modules-fixes 77b47b7
PiperOrigin-RevId: 1004479640
Change-Id: I2d1d38ce1c85bf027d3749a78bb4b11eb531b80b
fmeum and others added 8 commits November 17, 2026 14:55
With Bazel 9 and later, rules_cc disables its autodetected C++ toolchain on macOS, which makes the toolchain provided by apple_support the default. Register it from rules_cc, after rules_cc's own toolchains, so that it stays the default when only the module defining a toolchain type may register toolchains for it, as proposed in bazelbuild/bazel#32428.

apple_support already registers the same toolchains, which only match macOS execution platforms. Today, the only effect is that they can take precedence over C++ toolchains registered by modules that come after rules_cc and before apple_support in the dependency graph. Registering them after rules_cc's own toolchains keeps the autodetected toolchain first with Bazel 7 and 8 and with `BAZEL_USE_LEGACY_MACOS_TOOLCHAIN=1`.

Closes bazelbuild#984

COPYBARA_INTEGRATE_REVIEW=bazelbuild#984 from fmeum:register-apple-cc-toolchain 0a636ff
PiperOrigin-RevId: 1024077036
Change-Id: I19f6cdce425f6440acc1e03cdece2251f8ab6e95
…n rules_cc

`USE_STARLARK_SOLIB_SYMLINK` has been unconditionally enabled since July 2026 without interfering with path mapping, so removing the flag and the `_cc_internal.solib_symlink_action` fallback is safe across supported Bazel versions. Keep the `hasattr(_cc_internal, "maybe_hash_preserve_extension")` guards on `dynamic_library_soname`, `dynamic_library_symlink`, and `dynamic_library_symlink2` for Bazel 9 compatibility until Bazel 9 support is dropped, while allowing Bazel HEAD to delete the remaining Java symlink bridges.

Startblock:
  * // Put other blockers before this line to avoid churning.
  * has lgtm
  * is approved
  * and then
  * all comments are resolved
  * and then
  *[] allows unknown commit
PiperOrigin-RevId: 1024445353
Change-Id: Ia51b1e4ea9c13e05c1c0d2e56a41be7dbaf12c37
Roll back commit 05c945a (re-apply legacy Obj-C copts removal).

This CL rolls back commit 05c945a to re-apply the removal of hardcoded copts_for_current_compilation_mode flags in the objc configuration fragment (originally in commit 59cfcfd). These flags are considered technical debt and should instead be provided by the C++ toolchain (Crosstool).

PiperOrigin-RevId: 1024837724
Change-Id: Ia23cb9e6d46bd2f9d8b9f1c19b39b6e0e343cb65
…CATION_ALLOWLIST`.

Adds `rules_swift` (`rules_swift/swift/internal` and `build_bazel_rules_swift/swift/internal`) to `PRIVATE_STARLARKIFICATION_ALLOWLIST` in `cc/private/visibility.bzl`, matching `rules_rust/rust/private`.

This allows `rules_swift` to call `cc_common.create_lto_compilation_context` and pass `lto_compilation_context` to `cc_common.create_compilation_outputs` so Swift ThinLTO bitcode objects participate in Bazel's distributed ThinLTO (`CppLTOIndexing` / `CcLtoBackendCompile`) pipeline.

PiperOrigin-RevId: 1024910985
Change-Id: Ib61c1fd47a37bc2352e4d43561c2fdf61c4870ec
In Bazel downstream CI (`--use_but`), Bazelisk links `USE_BAZEL_VERSION` to a Bazel binary under `/tmp`. On Linux, `--sandbox_tmpfs_path=/tmp` hides `/tmp` inside the test sandbox, which makes the `@local_bazel//:bazel` symlink dangle and causes all integration tests to fail immediately.

Also, OSS integration tests used the default 300s timeout instead of `long`, causing `//tests/integration:cc_integration_test` to time out on Intel macOS workers.

- Copy the resolved Bazel binary (`cp -L`) instead of symlinking it on non-Windows platforms in `local_bazel.bzl`.
- Default `timeout = "long"` in `rules_cc_integration_test.bzl.oss`.

PiperOrigin-RevId: 1025490292
Change-Id: I70351b1e48be3f71f7661b8728b2a877ec78b506
Defines `//cc:toolchain_type`, `:cc_runtimes_toolchain_type` and `:test_runner_toolchain_type` as the actual toolchain types rather than aliases into `@bazel_tools`, conditional on a `bazel_features` feature that is always `False` for now. bazelbuild/bazel#32518 will allow them to be flipped over. Until then and on all older versions they are aliases of the types in `@bazel_tools`, so both labels always refer to the same type.

`//cc:cc_runtimes_toolchain_type` and `//cc:test_runner_toolchain_type` are new, previously these types were only available via `@bazel_tools`. Since `@bazel_tools//tools/cpp:cc_runtimes_toolchain_type` only exists as of Bazel 9, `//cc:cc_runtimes_toolchain_type` is a standalone type on older versions, which don't use the Starlark implementation of the rules that requests it.

Work towards bazelbuild/bazel#32428

Closes bazelbuild#979

COPYBARA_INTEGRATE_REVIEW=bazelbuild#979 from fmeum:cc-toolchain-types 74985eb
PiperOrigin-RevId: 1025616412
Change-Id: Ie847b7569ef75737128f698d93d5dbd5e024eb14
…ncies with interface outputs.

Allow Unix dynamic library link actions created by cc_common.link with interface shared library outputs to pass linker arguments through parameter files when supported by the toolchain. Single-target cc_library dynamic library links continue passing arguments inline on Unix to preserve existing behavior.

Dynamic library links with large input lists can now emit interface shared libraries without exceeding operating system command-line length limits.

Startblock:
 * has lgtm
 * is approved
 * and then
 * all comments are resolved
 * and then
 *[] allows unknown commit
PiperOrigin-RevId: 1026078787
Change-Id: I8223982e4c3f53e4db89a326d1b0a1edb9c07d53
…p_includes`.

Previously, `grep_includes` on `cc_toolchain` used `cfg = "exec"`, which resolved to the default exec group of `cc_toolchain` (`forceExecutionPlatform(parentExecutionPlatformLabel)`), forcing `grep_includes` to use the consuming target's compile execution platform.

Configure `grep_includes` using `cfg = config.exec("grep_includes")` and pass the resolved execution platform (`_cc_internal.exec_group_execution_platform(ctx, "grep_includes")`) to `CcToolchainInfo`.

PiperOrigin-RevId: 1026107994
Change-Id: Idee643aa6e9a095c7da6979176c613ec020dc026
find_cc_toolchain(..., mandatory = True) could return None when Bazel resolved ToolchainInfo(cc_provider_in_toolchain = True, cc = None). The helper checked the wrapper for None before extracting its cc field, so the documented mandatory failure was skipped.

Extract the C++ value first and apply the existing missing-toolchain behavior to it. The analysis test registers the wrapper and checks mandatory and optional lookups separately.

Prepared by Codex for Tamir Duberstein.

Closes bazelbuild#949

COPYBARA_INTEGRATE_REVIEW=bazelbuild#949 from tamird:codex/find-cc-toolchain-required-value a1aaa6a
PiperOrigin-RevId: 1026719389
Change-Id: I7c858855396d9f80f7ab44953863ddd0fe2b6b32
Give toolchain configuration, provider collectors and rule helpers typed
inputs and results. Keep simple signatures in their implementations;
represent provider fields and generic functions in companion interfaces.
Export the interfaces for dependent repositories. Run sty on the
implementations and report findings across the remaining Starlark files.
Move four companion declarations into the implementations they describe.
Keep the same strict sources and let the shared action select the
complete advisory inventory.
Declare each macro's inputs at its definition. Derive the directory
tool's forwarded keywords from cc_tool so both macros share one
contract. Check the repository rule at its implementation.

Remove four companion interfaces and their registrations. Document
which generic binders and cross-module types the others require.
Link the three wrapper signatures to the Bazel proposal for deriving
keyword arguments from a wrapped rule.
Identify the native types each exceptional comment needs. Document
the language boundary beside its use.
Follow the repository’s release-tag convention for external actions.
Use the same checkout and checker revisions as the previous workflow.
Set one severity for the eleven strict diagnostics. Let the pinned
checker define the group so an upgrade can extend it without edits to
the project configuration.
Since 60dc620, the root module replaces Skylib with a fork to get
type information. Bazel also uses that fork for ordinary builds.

Declare the build macro, path helpers and two providers against Skylib
1.9.0. Check their signatures against the installed sources. Report
incomplete types in three files from the release while checking their
contracts and callers as errors.
Use the updated checker and canonical names for the existing diagnostic
ignores. Keep the optional Objective-C artifact access tied to its
union-attribute diagnostic.
Update the checker action to the qualified Ruff rebase and receiver
correction, including finite provided-field descent.
Use the checker with corrected fresh collection inference.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.