Skip to content

[8.6.0] Add a target_type argument to ctx.actions.symlink.#28538

Merged
iancha1992 merged 1 commit intobazelbuild:release-8.6.0from
tjgq:8.6.0-symlink-target-type
Feb 5, 2026
Merged

[8.6.0] Add a target_type argument to ctx.actions.symlink.#28538
iancha1992 merged 1 commit intobazelbuild:release-8.6.0from
tjgq:8.6.0-symlink-target-type

Conversation

@tjgq
Copy link
Copy Markdown
Contributor

@tjgq tjgq commented Feb 5, 2026

This is necessary to create the right kind of filesystem object on Windows (junction for directories, symlink for files) when the target does not yet exist.

This argument is only allowed in conjunction with target_path. For target_file, I have a different plan (infer the type from the artifact) which will be implemented separately.

Fixes #26701.

Progress on #21747.

RELNOTES: ctx.actions.symlink now accepts a target_type argument.
PiperOrigin-RevId: 820670309
Change-Id: I2f29adfd074c404a0b15be369a97fcdfb84fbdad

@tjgq tjgq requested a review from a team as a code owner February 5, 2026 10:51
@github-actions github-actions bot added team-Configurability platforms, toolchains, cquery, select(), config transitions team-Remote-Exec Issues and PRs for the Execution (Remote) team awaiting-review PR is awaiting review from an assigned reviewer labels Feb 5, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a target_type argument to ctx.actions.symlink. This is useful on Windows for creating the correct type of filesystem object (junction or symlink) when the target does not yet exist. The changes correctly plumb this new argument through to the VFS layer and update the action key for caching. I've found a minor issue in one of the new tests that could cause it to fail.

ctx.actions.symlink(
output = link,
target_path = ctx.attr.target_path,
target_type = ctx.attr.target_type or None,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The expression ctx.attr.target_type or None will evaluate to "" if ctx.attr.target_type is an empty string. Since target_type is a string attribute, its default value if not specified is "". This will cause ctx.actions.symlink to receive "" for the targetType parameter, which is not a valid value ("file" or "directory"), leading to an error.

To correctly handle the case where target_type is unspecified or empty and should be treated as None, please change the expression to ctx.attr.target_type if ctx.attr.target_type else None. This will ensure that None is passed to ctx.actions.symlink, which is correctly handled as SymlinkTargetType.UNSPECIFIED.

Suggested change
target_type = ctx.attr.target_type or None,
target_type = ctx.attr.target_type if ctx.attr.target_type else None,

This is necessary to create the right kind of filesystem object on Windows (junction for directories, symlink for files) when the target does not yet exist.

This argument is only allowed in conjunction with `target_path`. For `target_file`, I have a different plan (infer the type from the artifact) which will be implemented separately.

Fixes bazelbuild#26701.

Progress on bazelbuild#21747.

RELNOTES: `ctx.actions.symlink` now accepts a `target_type` argument.
PiperOrigin-RevId: 820670309
Change-Id: I2f29adfd074c404a0b15be369a97fcdfb84fbdad
@iancha1992 iancha1992 added this pull request to the merge queue Feb 5, 2026
Merged via the queue into bazelbuild:release-8.6.0 with commit d31747f Feb 5, 2026
46 checks passed
@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Feb 5, 2026
Mivr added a commit to Mivr/bazel_features that referenced this pull request Feb 7, 2026
The `target_type` argument for `ctx.actions.symlink` has been
cherry-picked into the Bazel 8.6.0 release branch via
bazelbuild/bazel#28538.

Ref: bazelbuild/bazel#27949

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
rdesgroppes added a commit to DataDog/datadog-agent that referenced this pull request Feb 27, 2026
### What does this PR do?
Bump `.bazelversion` from 8.5.1 to 8.6.0.

### Motivation
Selected changes between 8.5.1 and 8.6.0:
- Fix visibility for implicit deps of parent rules (bazelbuild/bazel#28722)
- Force rctx.{download_and,}extract to create user-readable files (bazelbuild/bazel#28551)
- Fix disk cache failures on concurrent read-write access on Windows (bazelbuild/bazel#28529)
- Add a target_type argument to ctx.actions.symlink (bazelbuild/bazel#28538)
- Compensate for Windows filesystems lacking junction support (bazelbuild/bazel#28367)
  (our fix)
- Add short_uncached and detailed_uncached options to --test_summary (bazelbuild/bazel#28343)
- Add --experimental_strict_repo_env option (bazelbuild/bazel#28189)
- Make overlaid files executable in http_archive (bazelbuild/bazel#28277)
- Add bazel mod show_repo --all_repos and --all_visible_repos (bazelbuild/bazel#28012)
- Enable --experimental_retain_test_configuration_across_testonly (bazelbuild/bazel#28115)
- Add option to continue with local execution if remote cache is unavailable (bazelbuild/bazel#28001)
rdesgroppes added a commit to DataDog/datadog-agent that referenced this pull request Feb 27, 2026
### What does this PR do?
Bump `.bazelversion` from 8.5.1 to 8.6.0.

### Motivation
Selected changes between 8.5.1 and 8.6.0:
- Fix visibility for implicit deps of parent rules (bazelbuild/bazel#28722)
- Force rctx.{download_and,}extract to create user-readable files (bazelbuild/bazel#28551)
- Fix disk cache failures on concurrent read-write access on Windows (bazelbuild/bazel#28529)
- Add a target_type argument to ctx.actions.symlink (bazelbuild/bazel#28538)
- Compensate for Windows filesystems lacking junction support (bazelbuild/bazel#28367)
  (our fix)
- Add short_uncached and detailed_uncached options to --test_summary (bazelbuild/bazel#28343)
- Add --experimental_strict_repo_env option (bazelbuild/bazel#28189)
- Make overlaid files executable in http_archive (bazelbuild/bazel#28277)
- Add bazel mod show_repo --all_repos and --all_visible_repos (bazelbuild/bazel#28012)
- Enable --experimental_retain_test_configuration_across_testonly (bazelbuild/bazel#28115)
- Add option to continue with local execution if remote cache is unavailable (bazelbuild/bazel#28001)
gh-worker-dd-mergequeue-cf854d bot pushed a commit to DataDog/datadog-agent that referenced this pull request Feb 27, 2026
### What does this PR do?
Bump `bazel` version from 8.5.1 to 8.6.0 to benefit from a series of improvements and fixes.
Ours (bazelbuild/bazel#28367) allows to re-enable "convenience symlinks" for Windows users and makes [`path.realpath`](https://bazel.build/rules/lib/builtins/path#realpath) succeed when sharing a folder between a Linux host and a Windows VM.

### Motivation
Selected changes between 8.5.1 and 8.6.0:
- 💡 bazelbuild/bazel#28001
- bazelbuild/bazel#28012
- 💡 bazelbuild/bazel#28189
- bazelbuild/bazel#28277
- bazelbuild/bazel#28343
- 🐕 bazelbuild/bazel#28367
- bazelbuild/bazel#28529
- bazelbuild/bazel#28538
- bazelbuild/bazel#28551
- bazelbuild/bazel#28722

Co-authored-by: regis.desgroppes <regis.desgroppes@datadoghq.com>
fmeum added a commit to bazel-contrib/bazel_features that referenced this pull request Mar 9, 2026
The `target_type` argument for `ctx.actions.symlink` has been
cherry-picked into the Bazel 8.6.0 release branch via
bazelbuild/bazel#28538.

Bazel 8.6.0 milestone: bazelbuild/bazel#27949

Follow-up to #124.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-Configurability platforms, toolchains, cquery, select(), config transitions team-Remote-Exec Issues and PRs for the Execution (Remote) team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants