Skip to content

fix(build): make cmake --install produce a usable SDK - #40

Merged
Antruly merged 3 commits into
masterfrom
fix/install-complete
Oct 20, 2026
Merged

Antruly merged 3 commits into
masterfrom
fix/install-complete

Conversation

@Antruly

@Antruly Antruly commented Oct 19, 2026

Copy link
Copy Markdown
Owner

问题

tests/tools/package_release.py 手工组装的 release zip 可以使用,但从源码 cmake --install --prefix X 出来的前缀不行:

  • Linux:libuvcpp.so 的 DT_NEEDED 里有 libllhttp.so.9.2,前缀里没有;ldd 显示 not found;
  • Windows MinGW:libuvcpp.dll 的导入表依赖 libllhttp.dll,前缀 bin/ 里没有,程序以 0xC0000135(STATUS_DLL_NOT_FOUND)静默退出;
  • 安装后的共享库没有 RPATH,即使把依赖手工拷到同一个 lib/ 也找不到;
  • 用 FetchContent 编 libuv 时,头装在 include/libuv/,但公开头写的是 #include <uv.h>,导出的 CMake target 没有把这个目录传给消费者。

修改

  • 安装 FetchContent 依赖里所有 SHARED_LIBRARY target(llhttp、zlib、libuv);install(TARGETS ...) 会一并生成 SONAME 符号链接。
  • 给 uvcpp / uvcpp_s 设置 INSTALL_RPATH:Linux $ORIGIN,macOS @loader_path。
  • 只在自己编译 libuv 时把 include/libuv 写进 INTERFACE_INCLUDE_DIRECTORIES;系统 libuv 不安装这个目录,无条件写会让 find_package 在 generate 阶段报 “includes non-existent path”。
  • 同一配置下在 uvcpp.pc 的 Cflags 里补 -I${includedir}/libuv。

验证(Linux x64)

$ cmake --install build --prefix /tmp/uvcpp-install-pr
$ ls /tmp/uvcpp-install-pr/lib
libllhttp.so  libllhttp.so.9.2  libllhttp.so.9.2.0  libuvcpp.so  cmake  pkgconfig

$ readelf -d /tmp/uvcpp-install-pr/lib/libuvcpp.so | grep RUNPATH
Library runpath: [$ORIGIN]

$ ldd /tmp/uvcpp-install-pr/lib/libuvcpp.so | grep llhttp
libllhttp.so.9.2 => /tmp/uvcpp-install-pr/lib/libllhttp.so.9.2

消费者:

find_package(uvcpp CONFIG REQUIRED)
target_link_libraries(consumer PRIVATE uvcpp::uvcpp)

配置、编译、运行通过:

uv=1.48.0 web=1
libuvcpp.so => /tmp/uvcpp-install-pr/lib/libuvcpp.so
libllhttp.so.9.2 => /tmp/uvcpp-install-pr/lib/libllhttp.so.9.2

建议

增加一个 CI 冒烟格:安装到临时前缀,配置并运行一个只包含 <uvcpp.h>、<net/uvcpp_tcp_client.h> 的消费者。这样 install 规则和 package_release.py 两条路径不会再次漂移。

兼容性

  • 不改变公开 API 和链接接口。
  • Windows 的 DLL 安装路径需要在 MinGW CI 上确认;Linux x64 已完整验证。

Antruly added a commit that referenced this pull request Oct 19, 2026
- `CMakeLists.txt` 在 install 段前插入 61 行、pkg-config 段前再插入 6 行,
  被引区间整体 +61/+67;`uvcpp_http_client.cpp` 的助手与新读循环让它后段
  +8/+20/+91/+148;`uvcpp_http_client.h` 的两处参数说明 +2。
  按 check_doc_lines.py --update 的 [移] 报告逐条改文档正文后刷新锁。
- `doc/web-http-guide.md`「三个容易写错的地方」第三节/第四节原本描述的是
  修复前的行为(timeout 仅 Windows、失败交默认 200 OK),改写为现在的语义
  (两个平台都设、每次 I/O 超时、失败返回 NONE 与负错误码)。
- 同页两处裸/歧义引用人工定到正确目标:`set_keep_alive` 声明改指
  `uvcpp_http_client.h:242`;`doc/http2-status.md` 的 `set_http2_enabled`
  声明改指 `.h:307`;`RELEASE.md` 的 `CMakeLists.txt:3099-3518` 随插入
  改为 `3099-3579`。
Three gaps made an installed prefix unusable even though a release zip built
by package_release.py worked:

* shared FetchContent dependencies (llhttp) were not installed, so the
  installed libuvcpp.so had a DT_NEEDED entry nothing in the prefix satisfied
  (STATUS_DLL_NOT_FOUND on Windows);
* installed shared libraries had no RPATH, so even a copied dependency in the
  same lib/ directory was not found;
* consumers of a libuv-from-source build had no include path for <uv.h>.

Install shared dependency targets, set INSTALL_RPATH to $ORIGIN/@loader_path,
and expose include/libuv only when that directory is actually installed. Add
the matching -I flag to uvcpp.pc for that configuration.
CMakeLists.txt 增加了 install 规则段,CMake 变量引用与内部
target 名移位,同步更新所有文档、脚本、workflow 中的行号引用。
@Antruly
Antruly force-pushed the fix/install-complete branch from 0e57c31 to 1ca6f65 Compare October 20, 2026 02:57
The callback posts the semaphore before the library runs finish_one(), so the
main thread can wake while in_flight is still 1. This shows up reliably on
Windows MSVC. Poll (bounded to 5s) until the counter reaches 0.
@Antruly
Antruly merged commit 9b338b4 into master Oct 20, 2026
55 of 56 checks passed
@Antruly
Antruly deleted the fix/install-complete branch October 20, 2026 08:04
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