Skip to content

feat: add runtime_executable adapter for foreign_cc binaries#1539

Draft
jsun-splunk wants to merge 3 commits into
bazel-contrib:mainfrom
jsun-splunk:jsun-executable
Draft

feat: add runtime_executable adapter for foreign_cc binaries#1539
jsun-splunk wants to merge 3 commits into
bazel-contrib:mainfrom
jsun-splunk:jsun-executable

Conversation

@jsun-splunk
Copy link
Copy Markdown
Contributor

Introduce a runtime_executable rule for turning selected foreign_cc binary outputs into executable Bazel targets. This cannot live directly on the existing foreign_cc rules because foreign_cc outputs are not always expected to contain a binary, so those rules cannot always expose an executable.

The adapted executable may require runtime_library_search_directories = "enabled" on the producing foreign_cc target when it depends directly or transitively on foreign_cc-produced shared libraries.

runtime_executable is a more Bazel-native version of runnable_binary because it exposes the executable through DefaultInfo.files_to_run for downstream consumers. The API is intentionally kept similar to runnable_binary. For now, it cannot completely replace runnable_binary because runtime_library_search_directories defaults to "disabled" to minimize blast radius while these features mature.

@jsun-splunk jsun-splunk force-pushed the jsun-executable branch 2 times, most recently from 6d453cb to 981f69e Compare May 19, 2026 08:53
@jsun-splunk jsun-splunk force-pushed the jsun-executable branch 2 times, most recently from 8d2f0ce to 0b389f0 Compare June 5, 2026 03:00
Add opt-in runtime library search directory derivation for foreign_cc
outputs. This lets foreign-built binaries and shared libraries resolve
shared libraries from `deps`, `dynamic_deps`, and this rule's own declared
shared-library outputs without relying on loader environment variables such
as `LD_LIBRARY_PATH`.

Public attrs:

- `runtime_library_search_directories`
- `additional_dynamic_runtime_library_search_origins`
- `additional_executable_runtime_library_search_origins`

Example:

```python
configure_make(
    name = "python",
    out_binaries = ["python3.10"],
    out_shared_libs = ["libpython3.10.so"],
    runtime_library_search_directories = "enabled",
    additional_dynamic_runtime_library_search_origins = [
        "lib/python3.10/lib-dynload",
    ],
    deps = [":openssl"],
)
```

`runtime_library_search_directories` accepts `auto`, `enabled`, and
`disabled`. The global build setting defaults to `disabled`, so existing
targets keep the previous behavior unless a target opts in or the build
setting is enabled.

Default origins are derived from declared output `File.short_path` values.
Shared-library link actions use declared shared-library output directories.
Executable link actions use declared binary output directories. Additional
origins are install-tree-relative paths joined under this rule's INSTALLDIR.

The implementation derives dependency origins from `LibraryToLink` dynamic
libraries and adds Bazel `_solib` sibling search paths for solib symlink
layouts. Runtime search derivation is skipped for Windows C++ toolchains.

Wire the runtime search path flags as common implementation flags.
However, support is limited to `cmake`, `configure_make`, `make` and
`meson`. `Ninja` and `boost` support is currently disabled.

Add unit coverage for enablement, default origins, additional origins,
self-output search paths, `_solib` paths, deduplication, and global
build-setting resolution. Add integration coverage for runtime
dependency chains and self-contained output bundles.
Introduce a `runtime_executable` rule for turning selected foreign_cc
binary outputs into executable Bazel targets. This cannot live directly
on the existing foreign_cc rules because foreign_cc outputs are not
always expected to contain a binary, so those rules cannot always expose
an executable.

The adapted executable may require `runtime_library_search_directories =
"enabled"` on the producing foreign_cc target when it depends directly
or transitively on foreign_cc-produced shared libraries.

`runtime_executable` is a more Bazel-native version of `runnable_binary`
because it exposes the executable through `DefaultInfo.files_to_run` for
downstream consumers. The API is intentionally kept similar to
`runnable_binary`. For now, it cannot completely replace
`runnable_binary` because `runtime_library_search_directories` defaults
to `"disabled"` to minimize blast radius while these features mature.
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.

2 participants