Skip to content

bazel: build xcb-util-cursor from source in qt-bazel#10412

Closed
oharboe wants to merge 1 commit into
The-OpenROAD-Project:masterfrom
oharboe:qt-bazel-xcb-cursor-from-source
Closed

bazel: build xcb-util-cursor from source in qt-bazel#10412
oharboe wants to merge 1 commit into
The-OpenROAD-Project:masterfrom
oharboe:qt-bazel-xcb-cursor-from-source

Conversation

@oharboe
Copy link
Copy Markdown
Collaborator

@oharboe oharboe commented May 13, 2026

Summary

Removes the host libxcb-cursor0 runtime dependency from
--//:platform=gui and :openroad-qt builds by patching
qt-bazel (via MODULE.bazel) to compile xcb-util-cursor 0.1.5
from source as a cc_library, replacing the upstream
cc_import(system_provided = True).

Why

On #8532, @gadfort reported:

./bazel-bin/openroad: error while loading shared libraries: libxcb-cursor.so.0: cannot open shared object file: No such file or directory — I needed to run sudo apt-get install libxcb-cursor0.

@maliberty then asked @QuantamHD "is it possible to avoid the
need for the user to install this package separately?"
— that
question never got answered and the PR has been stalled since.

This PR is the "yes" answer. After it lands, a user can build the
Qt-linked openroad on a clean machine without apt-installing
libxcb-cursor0 first. It is intentionally a standalone change so
it can be reviewed and merged independently of the GUI-by-default
flip (which will follow as a stacked PR).

How

The fix is ported verbatim from the public sibling repo
The-OpenROAD-Project/bazel-orfs,
where it has been in use for some time. Two pieces:

  • MODULE.bazel — extend the existing qt-bazel git_override
    with patch_cmds (downloads xcb-util-cursor-0.1.5.tar.xz
    from xorg.freedesktop.org with retry/--fail so transient
    network hiccups produce a clear error instead of a truncated
    tar) and patches.
  • bazel/qt-bazel-xcb-cursor-from-source.patch — new file,
    copied verbatim from bazel-orfs/patches/. Replaces qt-bazel's
    cc_import(name = "xcb_cursor_ifso", system_provided = True)
    with a cc_library(name = "xcb_cursor", ...) compiled from
    cursor.c / load_cursor.c / parse_cursor_file.c / shape_to_id.c, and rewires interface_libs/xcb:xcb to
    depend on it instead of the ifso.

Sits alongside the existing
bazel/boost_context_disable_parse_headers.patch for consistency.

Test plan

  • bazelisk build --//:platform=cli //:openroad still works
    (no behavior change for CLI users).
  • bazelisk build --//:platform=gui //:openroad and
    bazelisk build //:openroad-qt succeed on a host that does
    not have libxcb-cursor0 installed.
  • readelf -d bazel-bin/openroad | grep -i cursor returns
    nothing — libxcb-cursor.so.0 is no longer in DT_NEEDED.
  • macOS CI (which currently passes --//:platform=gui //:openroad) stays green.

Follow-up

A second PR will flip BUILD.bazel's string_flag(name = "platform", build_setting_default = "gui") to make the GUI
build the default — picking up where #8532 left off. That PR is
stacked on this one because the default flip is only safe once
the cursor dependency is bundled.

Copy link
Copy Markdown
Contributor

@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 modifies the qt-bazel dependency to build xcb-util-cursor from source, eliminating the requirement for a system-provided library. This is achieved by adding a git_override with patch_cmds to download the source and applying a patch to define the corresponding Bazel targets. Feedback was provided regarding the curl command in MODULE.bazel, specifically noting that the --retry-all-errors flag may cause compatibility issues on older systems and recommending the addition of a checksum verification step to ensure the integrity of the downloaded asset.

Comment thread MODULE.bazel Outdated
# feed a truncated/HTML response into tar (seen in CI as "xz:
# File format not recognized"). Stage to a file first for a
# clearer error if extraction fails.
"curl -sSfL --retry 5 --retry-all-errors --retry-delay 5 -o xcb-util-cursor-0.1.5.tar.xz https://xorg.freedesktop.org/archive/individual/lib/xcb-util-cursor-0.1.5.tar.xz && tar xJf xcb-util-cursor-0.1.5.tar.xz --strip-components=1 -C interface_libs/xcb xcb-util-cursor-0.1.5/cursor && rm xcb-util-cursor-0.1.5.tar.xz",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

security-high high

The curl command uses --retry-all-errors, which was introduced in version 7.71.0. This may cause build failures on older systems, such as Ubuntu 20.04 (which ships with curl 7.68.0).

Additionally, downloading external assets without verifying their integrity (e.g., via a SHA256 checksum) is a security risk and can lead to non-deterministic builds if the source is compromised or corrupted. Adding a checksum verification step ensures that the downloaded tarball is exactly what is expected.

Suggested change
"curl -sSfL --retry 5 --retry-all-errors --retry-delay 5 -o xcb-util-cursor-0.1.5.tar.xz https://xorg.freedesktop.org/archive/individual/lib/xcb-util-cursor-0.1.5.tar.xz && tar xJf xcb-util-cursor-0.1.5.tar.xz --strip-components=1 -C interface_libs/xcb xcb-util-cursor-0.1.5/cursor && rm xcb-util-cursor-0.1.5.tar.xz",
"curl -sSfL --retry 5 --retry-delay 5 -o xcb-util-cursor-0.1.5.tar.xz https://xorg.freedesktop.org/archive/individual/lib/xcb-util-cursor-0.1.5.tar.xz && echo '28a89960303756adcf596d9e47907f744e3d13d26a613334d9ee452273081e23 xcb-util-cursor-0.1.5.tar.xz' | shasum -a 256 -c && tar xJf xcb-util-cursor-0.1.5.tar.xz --strip-components=1 -C interface_libs/xcb xcb-util-cursor-0.1.5/cursor && rm xcb-util-cursor-0.1.5.tar.xz",

@github-actions
Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@QuantamHD
Copy link
Copy Markdown
Collaborator

Can you send this to the upstream repo instead of patching it. Also I think someone added xcb to bcr so maybe that would work

Repin qt-bazel at oharboe/qt_bazel_prebuilts#xcb-cursor-from-source
HEAD (878efffc), which builds xcb-util-cursor 0.1.5 from source as
a static cc_library instead of letting interface_libs/xcb dlopen
libxcb-cursor.so.0 from the host. That removes the apt-install
libxcb-cursor0 step gadfort hit on The-OpenROAD-Project#8532, unblocking the
GUI-by-default switch in the follow-up PR.

The upstream PR is The-OpenROAD-Project/qt_bazel_prebuilts#11;
once that merges, this commit will be repinned to the merged SHA
on the The-OpenROAD-Project remote and the oharboe fork URL will
be replaced.

Replaces the earlier downstream-patch approach (curl in
patch_cmds, no sha256 verification) with @QuantamHD's suggestion
of fixing it upstream.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
@oharboe oharboe force-pushed the qt-bazel-xcb-cursor-from-source branch from 5aa6e5e to 14f25c0 Compare May 13, 2026 06:12
@oharboe
Copy link
Copy Markdown
Collaborator Author

oharboe commented May 13, 2026

Good call, @QuantamHD — sent the fix upstream as The-OpenROAD-Project/qt_bazel_prebuilts#11. This PR is now just a git_override commit bump pointing at that branch (currently on my fork; will repin to the merged SHA in The-OpenROAD-Project remote once #11 lands).

For @gemini-code-assist's earlier sha256 / dependency-on-curl notes: the upstream PR uses an http_archive with use_repo_rule so the tarball is fetched + sha256-verified by Bazel itself — no curl in patch_cmds, and xcb-util-cursor isn't on BCR so a plain bazel_dep isn't an option.

For xcb on BCR — libxcb is there (qt-bazel already uses libxcb 1.17.0.bcr.2), but xcb-util-cursor is a separate library and isn't published, so we still need the http_archive.

Verified end-to-end locally with local_path_override against the qt-bazel branch:

  • bazelisk build --//:platform=gui //:openroad succeeds
  • readelf -d bazel-bin/openroad | grep -i cursor → empty
  • libxcb-cursor.so.0 no longer in DT_NEEDED

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Thank you for the update, @oharboe. This approach—submitting the fix upstream and using a temporary git_override—is the correct way to handle this dependency issue. Your explanation regarding the availability of xcb-util-cursor on the BCR versus libxcb is clear and justifies the use of http_archive in the patch. The verification steps you've performed, particularly confirming that libxcb-cursor.so.0 is no longer in DT_NEEDED, provide strong evidence that the issue is resolved. I look forward to seeing this repinned to the official upstream commit once it is merged.

@oharboe
Copy link
Copy Markdown
Collaborator Author

oharboe commented May 13, 2026

Can you send this to the upstream repo instead of patching it. Also I think someone added xcb to bcr so maybe that would work

The-OpenROAD-Project/qt_bazel_prebuilts#11

@oharboe
Copy link
Copy Markdown
Collaborator Author

oharboe commented May 13, 2026

once The-OpenROAD-Project/qt_bazel_prebuilts#11 is filed, bumping qt-bazel will fix this problem.

@oharboe oharboe closed this May 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants