Skip to content

feat(foreign-cc): derive runtime library search directories#1536

Draft
jsun-splunk wants to merge 1 commit into
bazel-contrib:mainfrom
jsun-splunk:jsun-runtime-libs
Draft

feat(foreign-cc): derive runtime library search directories#1536
jsun-splunk wants to merge 1 commit into
bazel-contrib:mainfrom
jsun-splunk:jsun-runtime-libs

Conversation

@jsun-splunk

@jsun-splunk jsun-splunk commented May 4, 2026

Copy link
Copy Markdown
Contributor

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:

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.

Depends on #1401.

@jsun-splunk jsun-splunk force-pushed the jsun-runtime-libs branch 8 times, most recently from b9adfbf to 641ee6a Compare May 11, 2026 04:44
@jsun-splunk jsun-splunk force-pushed the jsun-runtime-libs branch 3 times, most recently from 2ecebfa to 35f722c Compare May 19, 2026 08:52
@jsun-splunk jsun-splunk force-pushed the jsun-runtime-libs branch 5 times, most recently from 9466108 to ee25ba1 Compare May 27, 2026 06:08
@jsun-splunk jsun-splunk force-pushed the jsun-runtime-libs branch 7 times, most recently from d7a0e51 to 497b12d Compare June 5, 2026 02:38
@jsun-splunk jsun-splunk changed the title Derive runtime search dirs from foreign cc deps feat(foreign-cc): derive runtime library search directories Jun 5, 2026
@jsun-splunk jsun-splunk force-pushed the jsun-runtime-libs branch 6 times, most recently from a1eda81 to 0284492 Compare June 11, 2026 10:48
@jsun-splunk jsun-splunk force-pushed the jsun-runtime-libs branch 4 times, most recently from 47d6468 to cb4638f Compare June 23, 2026 07:28
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.
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.

1 participant