bazel: installer for ubuntu26#10778
Conversation
Signed-off-by: Peter Gadfort <gadfort@zeroasic.com>
There was a problem hiding this comment.
Code Review
This pull request updates etc/DependencyInstaller.sh to support Ubuntu 26.04+ by installing libxml2-dev instead of libxml2 and creating a compatibility symlink libxml2.so.2 for the prebuilt LLVM toolchain. Feedback was provided regarding the use of a pipeline (ls | grep | head) which can cause the script to crash under set -eo pipefail if no matching files are found; a pure Bash loop with globbing was suggested as a safer and more robust alternative.
| local libxml2_so | ||
| libxml2_so=$(ls "${libdir}"/libxml2.so.* 2>/dev/null \ | ||
| | grep -v 'libxml2.so.2$' | head -n1) |
There was a problem hiding this comment.
Since set -euo pipefail is active at the top of the script, any command in a pipeline that exits with a non-zero status will cause the entire pipeline to fail, which in turn triggers set -e and terminates the script immediately.
If ls "${libdir}"/libxml2.so.* does not match any files (for example, if libxml2 is not installed, is in a different directory, or if the directory doesn't exist), ls will exit with a non-zero status. This will cause the pipeline to fail and the script to crash.
Using a pure Bash loop with globbing avoids spawning external processes (ls, grep, head), is completely safe under set -eo pipefail, and is more efficient. Additionally, when searching for libraries in a shared prefix on Linux, we should account for multiarch layouts by including globs for architecture-specific subdirectories (e.g., "${libdir}"/*/libxml2.so.*).
| local libxml2_so | |
| libxml2_so=$(ls "${libdir}"/libxml2.so.* 2>/dev/null \ | |
| | grep -v 'libxml2.so.2$' | head -n1) | |
| local libxml2_so="" | |
| local f | |
| for f in "${libdir}"/libxml2.so.* "${libdir}"/*/libxml2.so.*; do | |
| if [[ -e "${f}" && "${f}" != *"/libxml2.so.2" ]]; then | |
| libxml2_so="${f}" | |
| break | |
| fi | |
| done |
References
- When cleaning up or searching for libraries in a shared prefix on Linux, account for multiarch layouts by including globs for architecture-specific subdirectories (e.g., "lib/*/").
|
@maliberty if we merged the stubbing out of libxml then we could forget all about this and ditch the kludge on next llvm. uodate |
|
@hzeller I think the libxml stubbing hack would have been preferable. Add hack and delete it on next llvm upgrade and forget all about it, more hermetic too. |
|
@oharboe unfortunately it seems the llvm is built assuming a particular name for the library and the linker fails without this hack on ubuntu26 (it's fine elsewhere). If they fix it upstream that would be great too. |
|
It is fixed in LLVM main, it just missed the llvm release we are using in bazel by a hair. |
|
@oharboe ahh, thats good, in that case this only needs to live for a while (hopefully) until it's available |
|
@oharboe that PR is closed, not sure it's worth debugging further on my end, others are much better suited to find the upstream fix. |
I can re-open it if there's interest. It is what we're running with on Ubuntu 26.04 and it also fixes hermeticy issues with OpenROAD and bazel-orfs. Works great! |
|
If there is a later release we can use to bypass all this that would be great too. |
Yes: first thing to do is to try to upgrade LLVM bazel uses, if that doesn't work, then either apply the hack or we can suffer the pain meanwhile in various other ways... |
|
supposedly: bazel-contrib/toolchains_llvm#657 so maybe 1.7 or 1.8 |
Waiting worked! https://registry.bazel.build/modules/toolchains_llvm/1.8.0 is out |
|
Just to be clear: I'm enormously appreciative that @maliberty takes the time to push back on simply accepting cruft patches that supposedly clean themselves up with future upgrades and create pressure to update bazel bcr and fix things upstream. It greatly simplifies my life and reduces the over time constant size pile of patches that I have to maintain. Matt is providing the "community gradient" towards whittling down patches over time... |
|
@oharboe unfortunately 1.8.0 with 21.1.8 still needs this hack to function. @maliberty until the upstream is fixed, this atleast allows ubuntu26 machines to be able to compile openroad on bazel. |
|
Or apply the libmxl hack I made: removes system dependency. |

Summary
Update dep installer for ubuntu26.
Type of Change
Impact
Ensures the bazel build completes on a ubunu26 system
Verification
./etc/Build.sh).Related Issues
#10761