Don't count an empty start path as a directory in relativize() (#4503)
`_path_parts("")` returns `[""]`, because `"".split("/")` is `[""]`. So
`relativize(path, "")` counts the empty start as one directory and
returns `../path` instead of `path`.
`_compute_rpaths` passes the dirname of the output's `short_path` as the
start. For a shared library in the root package that dirname is `""`, so
the runfiles RPATH it computes points one level above the runfiles tree,
and the binary can't find its `_solib_*` libraries through it.
This drops empty components along with `.` and adds unit tests for
`relativize()`. Without the fix the new test fails with `Expected
"_solib_k8", but got "../_solib_k8"`.
An end-to-end reproduction is in [this
comment](https://github.com/bazelbuild/rules_rust/pull/4503#issuecomment-7324953997):
a root-package binary that links a shared library built in another
configuration fails to load it when run from its runfiles tree with
symlinks resolved.
This repository provides rules for building Rust projects with Bazel.
The fastest way to try this in an empty project is to click the green “Use this template” button on https://github.com/bazel-starters/rust.
General discussions and announcements take place in the GitHub Discussions, but there are additional places where community members gather to discuss rules_rust.
Please refer to the full documentation.