xmake require --export 无法导出完整的库文件
Xmake 版本
3.0.1
操作系统版本和架构
Fedora Linux 42, Linux 6.16.12-200.fc42.x86_64
描述问题
直接使用 xmake i 命令无法同步打包三方库中的 动态库
尝试使用 xmake require --export <libname> 命令导出时仅导出被导出库的依赖库,但是没有导出库本身。
> xmake require --export --packagedir=./install librdkafka
exporting ninja-1.12.1 [host, from:cmake]
-> ./install/n/ninja/latest/725e51fe81b74141ade9efbd3ccaf900
exporting cmake-3.31.6 [host, from:librdkafka,libcurl]
-> ./install/c/cmake/latest/725e51fe81b74141ade9efbd3ccaf900
exporting libcurl-8.14.1 [toolchains:"LLVM-21", from:librdkafka]
-> ./install/l/libcurl/8.14.1/5c480ea6262e44b8bd99d359d3bb6013
exporting openssl3-3.6.0 [toolchains:"LLVM-21", from:librdkafka, license:Apache-2.0]
-> ./install/o/openssl3/3.6.0/bc7463caf64941abb5cbf63f82bc5a83
> tree install -L 2
install
├── c
│ └── cmake
├── l
│ └── libcurl
├── n
│ └── ninja
└── o
└── openssl3
9 directories, 0 files
这里看到动态库编译的 librdkafka 没有被导出, 但是 静态库 编译的依赖 openssl 和 libcurl 的目录被创建了。
期待的结果
- 工程内部脚本域
on_install(function (target))中,如果通过 target 对象获取到自身 deps() 的 package 的 安装路径? 以允许我通过os.cp()在安装时复制动态库。 - 亦或者,是我使用
xmake require --export存在问题?
工程配置
工程本体(部分)
add_requires("librdkafka", {
system = false,
configs = {
shared = true,
ssl = true -- 连接本地包中的 openssl3
},
debug = false
})
target("capture", function()
add_packages(
"boost",
"librdkafka", -- 其他库不列出
{ public = true }
)
end)
### 附加信息和错误日志
一次xmake f 生成了两个 rdkafka 路径,但是工程内部仅仅 `add_deps` 和 `add_requires` 了一次 librdkafka。
```console
ll /home/nmpassthf/.xmake/packages/l/librdkafka/2.12.1/5212c166342b43488a191aba8349bfd6/lib
total 13M
drwxr-xr-x 1 nmpassthf nmpassthf 14 Nov 5 15:03 cmake/
lrwxrwxrwx 1 nmpassthf nmpassthf 17 Nov 5 15:03 librdkafka++.so -> librdkafka++.so.1*
lrwxrwxrwx 1 nmpassthf nmpassthf 15 Nov 5 15:03 librdkafka.so -> librdkafka.so.1*
-rwxr-xr-x 1 nmpassthf nmpassthf 204K Nov 5 15:03 librdkafka++.so.1*
-rwxr-xr-x 1 nmpassthf nmpassthf 12M Nov 5 15:03 librdkafka.so.1*
drwxr-xr-x 1 nmpassthf nmpassthf 44 Nov 5 15:03 pkgconfig/
ll /home/nmpassthf/.xmake/packages/l/librdkafka/2.12.1/5212c166342b43488a191aba8349bfd6/
total 8.0K
drwxr-xr-x 1 nmpassthf nmpassthf 20 Nov 5 15:03 include/
drwxr-xr-x 1 nmpassthf nmpassthf 148 Nov 5 15:03 lib/
-rw-r--r-- 1 nmpassthf nmpassthf 1.3K Nov 5 15:03 manifest.txt
-rw-r--r-- 1 nmpassthf nmpassthf 56 Nov 5 15:03 references.txt
drwxr-xr-x 1 nmpassthf nmpassthf 16 Nov 5 15:03 share/
ll /home/nmpassthf/.xmake/packages/l/librdkafka/2.12.1/81642a055b4540d1823df1dec27d8a08/
total 0
背景信息
工程内部使用 离线的 xmake (xmake g --network=private),使用 package() 功能描述并安装三方库,package 包的 lua 部分主要参考了 xrepo, 但是包的源码使用 file:// 协议从本地拉取。
其中,cmake 等系统工具使用如下描述:
package("cmake")
set_kind("binary")
add_extsources("dnf::cmake")
其余普通 package 与 xrepo 中区别不大。
最小可复现工程
初始化: xmake create test_kafka
工程 xmake.lua :
add_rules("mode.debug", "mode.release")
add_requires("librdkafka", {
system = false,
configs = {
shared = true,
ssl = true
},
debug = false
})
target("test_kafka")
set_kind("binary")
add_files("src/*.cpp")
add_packages("librdkafka")
配置: xmake f -m debug -c
输出日志:
xmake f -m debug -c
checking for platform ... linux
checking for architecture ... x86_64
updating repositories .. ok
note: install or modify (m) these packages (pass -y to skip confirm)?
in xmake-repo:
-> lz4 v1.10.0 [from:librdkafka, license:BSD-2-Clause]
-> libcurl 8.11.0 [from:librdkafka, license:MIT]
-> librdkafka v2.12.1 [shared:y, ssl:y, license:BSD-2-Clause]
please input: y (y/n/m)
y
=> download https://github.com/lz4/lz4/archive/refs/tags/v1.10.0.tar.gz .. ok
=> download https://github.com/curl/curl/releases/download/curl-8_11_0/curl-8.11.0.tar.bz2 .. ok
=> install lz4 v1.10.0 .. ok
=> install libcurl 8.11.0 .. ok
=> download https://github.com/confluentinc/librdkafka/archive/refs/tags/v2.12.1.tar.gz .. ok
=> install librdkafka v2.12.1 .. ok
warning: {buildir = } has been deprecated, please use {builddir = } in cmake.install
xmake require --fetch -vD "librdkafka"
/usr/bin/git rev-parse HEAD
finding librdkafka from xmake ..
checking for xmake::librdkafka ... no
finding librdkafka from brew ..
finding librdkafka from vcpkg ..
finding librdkafka from conan ..
finding librdkafka from pkgconfig ..
finding librdkafka from system ..
> /usr/bin/gcc -c -m64 -o /tmp/.xmake1003/251105/_D41AC234F6514320803A0C89077C2450.o /tmp/.xmake1003/251105/_775FB00633BC4F66BF87D39CCDE5CF30.c
> /usr/bin/g++ -o /tmp/.xmake1003/251105/_D41AC234F6514320803A0C89077C2450.b /tmp/.xmake1003/251105/_D41AC234F6514320803A0C89077C2450.o -m64 -llibrdkafka
/usr/bin/ld: cannot find -llibrdkafka: No such file or directory
collect2: error: ld returned 1 exit status
> checking for c links(librdkafka)
> checking for c snippet(find_package/librdkafka)
checkinfo: ...gramdir/core/sandbox/modules/import/core/tool/linker.lua:75: @programdir/core/sandbox/modules/os.lua:378: execv(/usr/bin/g++ -o /tmp/.xmake1003/251105/_D41AC234F6514320803A0C89077C2450.b /tmp/.xmake1003/251105/_D41AC234F6514320803A0C89077C2450.o -m64 -llibrdkafka) failed(1)
stack traceback:
[C]: in function 'error'
[@programdir/core/base/os.lua:1075]:
[@programdir/core/sandbox/modules/os.lua:378]: in function 'execv'
[@programdir/modules/core/tools/gcc.lua:948]:
[C]: in function 'xpcall'
[@programdir/core/base/utils.lua:246]:
[@programdir/core/tool/linker.lua:233]: in function 'link'
[...gramdir/core/sandbox/modules/import/core/tool/linker.lua:73]: in function 'link'
[@programdir/modules/lib/detect/check_cxsnippets.lua:249]:
[C]: in function 'xpcall'
[@programdir/core/base/utils.lua:246]: in function 'trycall'
[@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
[@programdir/modules/lib/detect/check_cxsnippets.lua:237]:
[@programdir/modules/package/manager/system/find_package.lua:73]:
[@programdir/modules/package/manager/find_package.lua:86]: in function '_find_package_with_builtin_rule'
[@programdir/modules/package/manager/find_package.lua:132]: in function '_find_package'
[@programdir/modules/package/manager/find_package.lua:196]:
[@programdir/modules/lib/detect/find_package.lua:86]:
[@programdir/core/package/package.lua:1950]: in function '_fetch_library'
[@programdir/core/package/package.lua:2123]: in function 'fetch'
[@programdir/modules/private/action/require/fetch.lua:53]:
[@programdir/actions/require/main.lua:117]:
[C]: in function 'xpcall'
[@programdir/core/base/utils.lua:246]:
[@programdir/core/base/task.lua:504]: in function 'run'
[@programdir/core/main.lua:327]: in function 'cotask'
[@programdir/core/base/scheduler.lua:406]:
checking for librdkafka ... no
此时使用 xmake require --export --packagedir=./install -vD "librdkafka" 尝试导出 kafka 库文件,
finding librdkafka from xmake ..
checking for xmake::librdkafka ... no
失败,最终没有导出库文件。只导出了前置依赖库 libcurl 和 lz4。
附加信息
注意到 xmake require --info 显示的 librdkafka 的 installdir 在 81642a055b4540d1823df1dec27d8a08, 但是工程内实际搜索和link的目录都是用的 5212c166342b43488a191aba8349bfd6 下的完整库。 这个问题应该是由于 xmake require --export 导致的,重新编译库之后直接查看 info 时只有一个库
发现xmake 查找 xmake::librdkafka 失败了
xmake require --export --packagedir=./install -vD --extra="{debug=false}" "librdkafka"
checking for ninja ... no
checking for ninja ... no
checking for ninja ... /usr/bin/ninja
exporting ninja-1.12.1 [host, from:cmake]
-> ./install/n/ninja/latest/725e51fe81b74141ade9efbd3ccaf900
checking for cmake ... no
checking for cmake ... no
checking for cmake ... /usr/bin/cmake
exporting cmake-3.31.6 [host, from:librdkafka,libcurl]
-> ./install/c/cmake/latest/725e51fe81b74141ade9efbd3ccaf900
finding libcurl from xmake ..
checking for xmake::libcurl ... libcurl 8.14.1
exporting libcurl-8.14.1 [toolchains:"LLVM-21", from:librdkafka]
-> ./install/l/libcurl/8.14.1/5c480ea6262e44b8bd99d359d3bb6013
finding librdkafka from xmake ..
checking for xmake::librdkafka ... no
finding librdkafka from brew ..
finding librdkafka from vcpkg ..
finding librdkafka from conan ..
finding librdkafka from pkgconfig ..
finding librdkafka from system ..
checking for the c compiler (cc) ... clang
> /opt/LLVM-21.1.3-Linux-X64/bin/clang -c -Qunused-arguments -o /tmp/.xmake1003/251105/_8881F8853D1E4200870A6E3794674040.o /tmp/.xmake1003/251105/_775FB00633BC4F66BF87D39CCDE5CF30.c
checking for the linker (ld) ... clang++
> /opt/LLVM-21.1.3-Linux-X64/bin/clang++ -o /tmp/.xmake1003/251105/_8881F8853D1E4200870A6E3794674040.b /tmp/.xmake1003/251105/_8881F8853D1E4200870A6E3794674040.o -llibrdkafka
/usr/bin/ld: cannot find -llibrdkafka: No such file or directory
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
> checking for c links(librdkafka)
> checking for c snippet(find_package/librdkafka)
checkinfo: ...gramdir/core/sandbox/modules/import/core/tool/linker.lua:75: @programdir/core/sandbox/modules/os.lua:378: execv(/opt/LLVM-21.1.3-Linux-X64/bin/clang++ -o /tmp/.xmake1003/251105/_8881F8853D1E4200870A6E3794674040.b /tmp/.xmake1003/251105/_8881F8853D1E4200870A6E3794674040.o -llibrdkafka) failed(1)
stack traceback:
[C]: in function 'error'
[@programdir/core/base/os.lua:1075]:
[@programdir/core/sandbox/modules/os.lua:378]: in function 'execv'
[@programdir/modules/core/tools/gcc.lua:948]:
[C]: in function 'xpcall'
[@programdir/core/base/utils.lua:246]:
[@programdir/core/tool/linker.lua:233]: in function 'link'
[...gramdir/core/sandbox/modules/import/core/tool/linker.lua:73]: in function 'link'
[@programdir/modules/lib/detect/check_cxsnippets.lua:249]:
[C]: in function 'xpcall'
[@programdir/core/base/utils.lua:246]: in function 'trycall'
[@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
[@programdir/modules/lib/detect/check_cxsnippets.lua:237]:
[@programdir/modules/package/manager/system/find_package.lua:73]:
[@programdir/modules/package/manager/find_package.lua:86]: in function '_find_package_with_builtin_rule'
[@programdir/modules/package/manager/find_package.lua:132]: in function '_find_package'
[@programdir/modules/package/manager/find_package.lua:196]:
[@programdir/modules/lib/detect/find_package.lua:86]:
[@programdir/core/package/package.lua:1950]: in function '_fetch_library'
[@programdir/core/package/package.lua:2123]: in function 'fetch'
[.../modules/private/action/require/impl/export_packages.lua:48]:
[@programdir/modules/private/action/require/export.lua:50]:
[@programdir/actions/require/main.lua:102]:
[C]: in function 'xpcall'
[@programdir/core/base/utils.lua:246]:
[@programdir/core/base/task.lua:504]: in function 'run'
[@programdir/core/main.lua:327]: in function 'cotask'
[@programdir/core/base/scheduler.lua:406]:
checking for librdkafka ... no
xmake require --info librdkafka
xmake require --info librdkafka
The package info of project:
require(ninja):
-> version: latest
-> cachedir: /home/nmpassthf/.xmake/cache/packages/2511/n/ninja/latest
-> installdir: /home/nmpassthf/.xmake/packages/n/ninja/latest/725e51fe81b74141ade9efbd3ccaf900
-> searchdirs:
-> searchnames:
-> fetchinfo: latest, system
-> program: /usr/bin/ninja
-> version: 1.12.1
-> name: ninja
-> platforms: all
-> requires:
-> plat: linux
-> arch: x86_64
-> configs:
-> pic: true
-> debug: false
-> shared: false
-> configs:
-> configs (builtin):
-> debug: Enable debug symbols. (default: false)
-> shared: Build shared library. (default: false)
-> pic: Enable the position independent code. (default: true)
-> lto: Enable the link-time build optimization. (type: boolean)
-> asan: Enable the address sanitizer. (type: boolean)
-> runtimes: Set the compiler runtimes.
-> values: {"MT","MTd","MD","MDd","c++_static","c++_shared","stdc++_static","stdc++_shared"}
-> vs_runtime: Set vs compiler runtime.
-> values: {"MT","MTd","MD","MDd"}
-> toolchains: Set package toolchains only for cross-compilation.
-> cflags: Set the C compiler flags.
-> cxflags: Set the C/C++ compiler flags.
-> cxxflags: Set the C++ compiler flags.
-> asflags: Set the assembler flags.
-> ldflags: Set the binary linker flags.
-> shflags: Set the shared library linker flags.
require(cmake):
-> description: A cross-platform family of tool designed to build, test and package software
-> version: latest
-> deps:
-> ninja
-> cachedir: /home/nmpassthf/.xmake/cache/packages/2511/c/cmake/latest
-> installdir: /home/nmpassthf/.xmake/packages/c/cmake/latest/725e51fe81b74141ade9efbd3ccaf900
-> searchdirs:
-> searchnames:
-> fetchinfo: latest, system
-> program: /usr/bin/cmake
-> version: 3.31.6
-> name: cmake
-> platforms: all
-> requires:
-> plat: linux
-> arch: x86_64
-> configs:
-> pic: true
-> debug: false
-> shared: false
-> configs:
-> configs (builtin):
-> debug: Enable debug symbols. (default: false)
-> shared: Build shared library. (default: false)
-> pic: Enable the position independent code. (default: true)
-> lto: Enable the link-time build optimization. (type: boolean)
-> asan: Enable the address sanitizer. (type: boolean)
-> runtimes: Set the compiler runtimes.
-> values: {"MT","MTd","MD","MDd","c++_static","c++_shared","stdc++_static","stdc++_shared"}
-> vs_runtime: Set vs compiler runtime.
-> values: {"MT","MTd","MD","MDd"}
-> toolchains: Set package toolchains only for cross-compilation.
-> cflags: Set the C compiler flags.
-> cxflags: Set the C/C++ compiler flags.
-> cxxflags: Set the C++ compiler flags.
-> asflags: Set the assembler flags.
-> ldflags: Set the binary linker flags.
-> shflags: Set the shared library linker flags.
require(libcurl):
-> version: 8.14.1
-> urls:
-> file://home/nmpassthf/ndlp/monitor-scan/3rdparty/repositories/curl-8.14.1.tar.xz
-> f4619a1e2474c4bbfedc88a7c2191209c8334b48fa1f4e53fd584cc12e9120dd
-> deps:
-> ninja
-> cmake
-> cachedir: /home/nmpassthf/.xmake/cache/packages/2511/l/libcurl/8.14.1
-> installdir: /home/nmpassthf/.xmake/packages/l/libcurl/8.14.1/5c480ea6262e44b8bd99d359d3bb6013
-> searchdirs:
-> searchnames:
-> curl-8.14.1.tar.xz
-> libcurl-8.14.1.tar.xz
-> fetchinfo: 8.14.1
-> sysincludedirs: /home/nmpassthf/.xmake/packages/l/libcurl/8.14.1/5c480ea6262e44b8bd99d359d3bb6013/include
-> libfiles: /home/nmpassthf/.xmake/packages/l/libcurl/8.14.1/5c480ea6262e44b8bd99d359d3bb6013/lib/libcurl.a
-> links: curl
-> static: true
-> linkdirs: /home/nmpassthf/.xmake/packages/l/libcurl/8.14.1/5c480ea6262e44b8bd99d359d3bb6013/lib
-> version: 8.14.1
-> platforms: all
-> requires:
-> plat: linux
-> arch: x86_64
-> configs:
-> pic: true
-> toolchains: LLVM-21
-> debug: false
-> shared: false
-> configs:
-> configs (builtin):
-> debug: Enable debug symbols. (default: false)
-> shared: Build shared library. (default: false)
-> pic: Enable the position independent code. (default: true)
-> lto: Enable the link-time build optimization. (type: boolean)
-> asan: Enable the address sanitizer. (type: boolean)
-> runtimes: Set the compiler runtimes.
-> values: {"MT","MTd","MD","MDd","c++_static","c++_shared","stdc++_static","stdc++_shared"}
-> vs_runtime: Set vs compiler runtime.
-> values: {"MT","MTd","MD","MDd"}
-> toolchains: Set package toolchains only for cross-compilation.
-> cflags: Set the C compiler flags.
-> cxflags: Set the C/C++ compiler flags.
-> cxxflags: Set the C++ compiler flags.
-> asflags: Set the assembler flags.
-> ldflags: Set the binary linker flags.
-> shflags: Set the shared library linker flags.
-> references:
-> 251105: /home/nmpassthf/ndlp/monitor-scan
require(openssl3):
-> description: A robust, commercial-grade, and full-featured toolkit for TLS and SSL.
-> version: 3.6.0
-> license: Apache-2.0
-> urls:
-> file://home/nmpassthf/ndlp/monitor-scan/3rdparty/repositories/openssl-3.6.0.tar.gz
-> b6a5f44b7eb69e3fa35dbf15524405b44837a481d43d81daddde3ff21fcbb8e9
-> cachedir: /home/nmpassthf/.xmake/cache/packages/2511/o/openssl3/3.6.0
-> installdir: /home/nmpassthf/.xmake/packages/o/openssl3/3.6.0/bc7463caf64941abb5cbf63f82bc5a83
-> searchdirs:
-> searchnames:
-> openssl-3.6.0.tar.gz
-> openssl3-3.6.0.tar.gz
-> fetchinfo: 3.6.0
-> syslinks: pthread dl
-> sysincludedirs: /home/nmpassthf/.xmake/packages/o/openssl3/3.6.0/bc7463caf64941abb5cbf63f82bc5a83/include
-> links: ssl crypto
-> linkdirs: /home/nmpassthf/.xmake/packages/o/openssl3/3.6.0/bc7463caf64941abb5cbf63f82bc5a83/lib64
-> version: 3.6.0
-> static: true
-> license: Apache-2.0
-> libfiles: /home/nmpassthf/.xmake/packages/o/openssl3/3.6.0/bc7463caf64941abb5cbf63f82bc5a83/lib64/libssl.a /home/nmpassthf/.xmake/packages/o/openssl3/3.6.0/bc7463caf64941abb5cbf63f82bc5a83/lib64/libcrypto.a
-> platforms: linux, msys, android, bsd, macosx, mingw, windows, wasm, iphoneos, cross
-> requires:
-> plat: linux
-> arch: x86_64
-> configs:
-> toolchains: LLVM-21
-> debug: false
-> md2: false
-> pic: true
-> shared: false
-> configs:
-> md2: Enable MD2 on OpenSSl3 or not (default: false)
-> configs (builtin):
-> debug: Enable debug symbols. (default: false)
-> shared: Build shared library. (default: false)
-> pic: Enable the position independent code. (default: true)
-> lto: Enable the link-time build optimization. (type: boolean)
-> asan: Enable the address sanitizer. (type: boolean)
-> runtimes: Set the compiler runtimes.
-> values: {"MT","MTd","MD","MDd","c++_static","c++_shared","stdc++_static","stdc++_shared"}
-> vs_runtime: Set vs compiler runtime.
-> values: {"MT","MTd","MD","MDd"}
-> toolchains: Set package toolchains only for cross-compilation.
-> cflags: Set the C compiler flags.
-> cxflags: Set the C/C++ compiler flags.
-> cxxflags: Set the C++ compiler flags.
-> asflags: Set the assembler flags.
-> ldflags: Set the binary linker flags.
-> shflags: Set the shared library linker flags.
-> references:
-> 251105: /home/nmpassthf/ndlp/monitor-scan
require(librdkafka):
-> description: The Apache Kafka C/C++ library
-> version: 2.12.1
-> urls:
-> file://home/nmpassthf/ndlp/monitor-scan/3rdparty/repositories/librdkafka-v2.12.1.tar.gz
-> ec103fa05cb0f251e375f6ea0b6112cfc9d0acd977dc5b69fdc54242ba38a16f
-> deps:
-> ninja
-> cmake
-> libcurl
-> openssl3
-> cachedir: /home/nmpassthf/.xmake/cache/packages/2511/l/librdkafka/2.12.1
-> installdir: /home/nmpassthf/.xmake/packages/l/librdkafka/2.12.1/81642a055b4540d1823df1dec27d8a08
-> searchdirs:
-> searchnames:
-> librdkafka-v2.12.1.tar.gz
-> librdkafka-2.12.1.tar.gz
-> fetchinfo: 2.12.1, remote(in unknown)
-> platforms: all
-> requires:
-> plat: linux
-> arch: x86_64
-> configs:
-> zlib: false
-> ssl: true
-> pic: true
-> lz4_ext: false
-> zstd: false
-> sasl: false
-> toolchains: LLVM-21
-> debug: false
-> shared: false
-> configs:
-> zlib: Enable zlib support. (default: false)
-> lz4_ext: Enable lz4_ext support. (default: false)
-> zstd: Enable zstd support. (default: false)
-> sasl: Enable sasl support. (default: false)
-> ssl: Enable ssl support. (default: true)
-> configs (builtin):
-> debug: Enable debug symbols. (default: false)
-> shared: Build shared library. (default: false)
-> pic: Enable the position independent code. (default: true)
-> lto: Enable the link-time build optimization. (type: boolean)
-> asan: Enable the address sanitizer. (type: boolean)
-> runtimes: Set the compiler runtimes.
-> values: {"MT","MTd","MD","MDd","c++_static","c++_shared","stdc++_static","stdc++_shared"}
-> vs_runtime: Set vs compiler runtime.
-> values: {"MT","MTd","MD","MDd"}
-> toolchains: Set package toolchains only for cross-compilation.
-> cflags: Set the C compiler flags.
-> cxflags: Set the C/C++ compiler flags.
-> cxxflags: Set the C++ compiler flags.
-> asflags: Set the assembler flags.
-> ldflags: Set the binary linker flags.
-> shflags: Set the shared library linker flags.
xmake scan:
xmake require --scan librdkafka
scanning packages ..
librdkafka-2.12.1:
-> 5212c166342b43488a191aba8349bfd6: linux, x86_64
-> {debug=false,lz4_ext=false,pic=true,sasl=false,shared=true,ssl=true,toolchains="LLVM-21",zlib=false,zstd=false}
-> 81642a055b4540d1823df1dec27d8a08: , , empty
librdkafka 包的定义:
package("librdkafka")
set_homepage("https://github.com/edenhill/librdkafka")
set_description("The Apache Kafka C/C++ library")
on_source(function (package)
import("xmake_scripts.3rdparty_package", { rootdir = os.projectdir() })
(package, "librdkafka-v2.12.1.tar.gz", "2.12.1", "ec103fa05cb0f251e375f6ea0b6112cfc9d0acd977dc5b69fdc54242ba38a16f")
end)
if is_plat("windows", "mingw") then
-- Do not build static library for window.
add_configs("shared", {description = "Build shared library.", default = true, type = "boolean", readonly = true})
add_configs("vs_runtime", {description = "Set vs compiler runtime.", default = "MD", readonly = true})
end
-- lz4_ext means using external lz4 library instead of librdkafka's bundled one.
-- When lz4_ext is disabled, we still need to link with external lz4 library.
local config_default = {lz4_ext = false, sasl = false, ssl = true, zlib = false, zstd = false}
local configdeps = {lz4_ext = "lz4", sasl = "cyrus-sasl", ssl = "openssl3", zlib = "zlib", zstd = "zstd"}
for config, dep in pairs(configdeps) do
add_configs(config, {description = "Enable " .. config .. " support.", default = config_default[config] or false, type = "boolean"})
end
add_deps("cmake", "libcurl")
add_links("rdkafka++", "rdkafka")
-- These syslinks come from PKG_CONFIG_LIBS_PRIVATE in librdkafka/src/CMakeLists.txt
if is_plat("linux") or is_plat("bsd") then
add_syslinks("pthread", "dl")
elseif is_plat("mingw", "windows") then
add_syslinks("ws2_32", "secur32", "crypt32")
end
on_load(function (package)
for name, dep in pairs(configdeps) do
if package:config(name) then
package:add("deps", dep)
end
end
end)
on_install(function (package)
local configs = {
"-DRDKAFKA_BUILD_EXAMPLES=OFF",
"-DRDKAFKA_BUILD_TESTS=OFF",
"-DWITH_BUNDLED_SSL=OFF",
}
table.insert(configs, "-DWITH_SSL=" .. (package:config("ssl") and "ON" or "OFF"))
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
table.insert(configs, "-DRDKAFKA_BUILD_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
for config, dep in pairs(configdeps) do
table.insert(configs, "-DWITH_" .. config:upper() .. "=" .. (package:config(config) and "ON" or "OFF"))
end
import("package.tools.cmake").install(package, configs)
end)
3rdparty_package.lua:
function main(package, source_tarname, version, sha)
package:add("urls", "file:/" .. path.join(os.projectdir(), "3rdparty", "repositories", source_tarname))
package:add("versions", version, sha)
end
Bot detected the issue body's language is not English, translate it automatically.
Title: xmake require --export cannot export the complete library file
Xmake version
3.0.1
Operating system version and architecture
Fedora Linux 42, Linux 6.16.12-200.fc42.x86_64
Describe the problem
Directly using the xmake i command cannot synchronously package the dynamic library in the third-party library
When trying to export using the xmake require --export <libname> command, only the dependent libraries of the exported library will be exported, but the library itself will not be exported.
> xmake require --export --packagedir=./install librdkafka
exporting ninja-1.12.1 [host, from:cmake]
-> ./install/n/ninja/latest/725e51fe81b74141ade9efbd3ccaf900
exporting cmake-3.31.6 [host, from:librdkafka,libcurl]
-> ./install/c/cmake/latest/725e51fe81b74141ade9efbd3ccaf900
exporting libcurl-8.14.1 [toolchains:"LLVM-21", from:librdkafka]
-> ./install/l/libcurl/8.14.1/5c480ea6262e44b8bd99d359d3bb6013
exporting openssl3-3.6.0 [toolchains:"LLVM-21", from:librdkafka, license:Apache-2.0]
-> ./install/o/openssl3/3.6.0/bc7463caf64941abb5cbf63f82bc5a83
> tree install -L 2
install
├── c
│ └── cmake
├── l
│ └── libcurl
├── n
│ └── ninja
└──o
└── openssl3
9 directories, 0 files
Here we see that the librdkafka compiled by the dynamic library is not exported, but the directories dependent on openssl and libcurl compiled by the `static library' are created.
Expected results
- In the project internal script domain
on_install(function (target)), if the installation path of the package of its own deps() is obtained through the target object? to allow me to copy the dynamic library on install viaos.cp(). - Or is there a problem with my use of
xmake require --export?
Project configuration
Engineering ontology (part)
add_requires("librdkafka", {
system = false,
configs = {
shared = true,
ssl = true -- connect to openssl3 in local package
},
debug=false
})
target("capture", function()
add_packages(
"boost",
"librdkafka", -- other libraries are not listed
{ public = true }
)
end)
### Additional information and error logs
One xmake f generated two rdkafka paths, but `add_deps` and `add_requires` were used for librdkafka only once inside the project.
```console
ll /home/nmpassthf/.xmake/packages/l/librdkafka/2.12.1/5212c166342b43488a191aba8349bfd6/lib
total 13M
drwxr-xr-x 1 nmpassthf nmpassthf 14 Nov 5 15:03 cmake/
lrwxrwxrwx 1 nmpassthf nmpassthf 17 Nov 5 15:03 librdkafka++.so -> librdkafka++.so.1*
lrwxrwxrwx 1 nmpassthf nmpassthf 15 Nov 5 15:03 librdkafka.so -> librdkafka.so.1*
-rwxr-xr-x 1 nmpassthf nmpassthf 204K Nov 5 15:03 librdkafka++.so.1*
-rwxr-xr-x 1 nmpassthf nmpassthf 12M Nov 5 15:03 librdkafka.so.1*
drwxr-xr-x 1 nmpassthf nmpassthf 44 Nov 5 15:03 pkgconfig/
ll /home/nmpassthf/.xmake/packages/l/librdkafka/2.12.1/5212c166342b43488a191aba8349bfd6/
total 8.0K
drwxr-xr-x 1 nmpassthf nmpassthf 20 Nov 5 15:03 include/
drwxr-xr-x 1 nmpassthf nmpassthf 148 Nov 5 15:03 lib/
-rw-r--r-- 1 nmpassthf nmpassthf 1.3K Nov 5 15:03 manifest.txt
-rw-r--r-- 1 nmpassthf nmpassthf 56 Nov 5 15:03 references.txt
drwxr-xr-x 1 nmpassthf nmpassthf 16 Nov 5 15:03 share/
ll /home/nmpassthf/.xmake/packages/l/librdkafka/2.12.1/81642a055b4540d1823df1dec27d8a08/
total 0
Background information
The project uses offline xmake (xmake g --network=private) internally, and uses the package() function to describe and install third-party libraries. The lua part of the package package mainly refers to xrepo, but the source code of the package is pulled from the local using the file:// protocol.
Among them, the use of system tools such as cmake is described as follows:
package("cmake")
set_kind("binary")
add_extsources("dnf::cmake")
The rest of the normal package is not much different from that in xrepo.
走 xmake-repo 仓库,没法复现
note: install or modify (m) these packages (pass -y to skip confirm)?
in xmake-repo:
-> lz4 v1.10.0 [from:librdkafka, license:BSD-2-Clause]
-> librdkafka v2.11.1 [shared:y, ssl:y, license:BSD-2-Clause]
please input: y (y/n/m)
=> download https://github.com/lz4/lz4/archive/refs/tags/v1.10.0.tar.gz .. ok
=> install lz4 v1.10.0 .. ok
=> download https://github.com/confluentinc/librdkafka/archive/refs/tags/v2.11.1.tar.gz .. ok
=> install librdkafka v2.11.1 .. ok
ruki:test3 ruki$ xmake require --export --packagedir=./install librdkafka
exporting ninja-1.11.1 [host, from:cmake, license:Apache-2.0]
-> ./install/n/ninja/v1.13.1/4b5fb445e9104f33bade9151c48b7c60
exporting cmake-3.25.3 [host, from:libcurl,librdkafka,lz4]
-> ./install/c/cmake/4.0.3/d80ce2465e4b493d9b67bdeeb800a282
exporting libcurl-7.54.0 [from:librdkafka, license:MIT]
-> ./install/l/libcurl/8.11.0/dd993c1b67a64d7dbaacf30f9c515ab6
exporting lz4-v1.10.0 [from:librdkafka, license:BSD-2-Clause]
-> ./install/l/lz4/v1.10.0/0693c66179c8474c988fcb8b649527c1
exporting librdkafka-2.6.0 [license:BSD-2-Clause]
-> ./install/l/librdkafka/v2.11.1/00296dabbd6f41a48e7e7f928bab3e99
走 xmake-repo 仓库,没法复现
note: install or modify (m) these packages (pass -y to skip confirm)? in xmake-repo: -> lz4 v1.10.0 [from:librdkafka, license:BSD-2-Clause] -> librdkafka v2.11.1 [shared:y, ssl:y, license:BSD-2-Clause] please input: y (y/n/m)
=> download https://github.com/lz4/lz4/archive/refs/tags/v1.10.0.tar.gz .. ok => install lz4 v1.10.0 .. ok
=> download https://github.com/confluentinc/librdkafka/archive/refs/tags/v2.11.1.tar.gz .. ok => install librdkafka v2.11.1 .. ok
ruki:test3 ruki$ xmake require --export --packagedir=./install librdkafka exporting ninja-1.11.1 [host, from:cmake, license:Apache-2.0] -> ./install/n/ninja/v1.13.1/4b5fb445e9104f33bade9151c48b7c60 exporting cmake-3.25.3 [host, from:libcurl,librdkafka,lz4] -> ./install/c/cmake/4.0.3/d80ce2465e4b493d9b67bdeeb800a282 exporting libcurl-7.54.0 [from:librdkafka, license:MIT] -> ./install/l/libcurl/8.11.0/dd993c1b67a64d7dbaacf30f9c515ab6 exporting lz4-v1.10.0 [from:librdkafka, license:BSD-2-Clause] -> ./install/l/lz4/v1.10.0/0693c66179c8474c988fcb8b649527c1 exporting librdkafka-2.6.0 [license:BSD-2-Clause] -> ./install/l/librdkafka/v2.11.1/00296dabbd6f41a48e7e7f928bab3e99
为什么这些文件夹下面都是空的