Closed rdw-software closed 1 year ago
An alternative that avoids any hacks would be to ditch the concatenation in the macro and have it take the full function name, i.e.
- ret = uv_fs_##func(data->ctx->loop, req, __VA_ARGS__,
+ ret = func(data->ctx->loop, req, __VA_ARGS__,
and then at each FS_CALL
usage:
- FS_CALL(open, req, path, flags, mode);
+ FS_CALL(uv_fs_open, req, path, flags, mode);
func
is only used at that one spot in the FS_CALL
macro so there's no real benefit to having it only take the part after the uv_fs_
prefix.
When trying to build luv with gcc on MSYS2/MINGW64 (Windows), the
uv_fs_stat
anduv_fs_fstat
APIs aren't exported.This is likely due to some MINGW defines for
stat
andfstat
messing up theFS_CALL
(andFS_CALL_NORETURN
) macros insrc/fs.c
: Instead ofuv_fs_stat
the output becomesuv_fs__stat64
anduv_fs_fstat
becomesuv_fs__fstat64
.More context: https://github.com/msys2/MINGW-packages/issues/10591
Steps to reproduce:
pacman -S git make mingw-w64-x86_64-gcc ninja mingw-w64-x86_64-cmake --noconfirm
)git clone https://github.com/luvit/luv.git --recursive
cd luv
cmake -S . -B cmakebuild-msys2 -G Ninja -DBUILD_MODULE=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON
cmake --build cmakebuild-msys2 --clean-first
Expected result: All compilation steps succeed without issues
Actual result: The following warning appears:
Needless to say, the resulting library is broken (
undefined reference to `uv_fs__stat64'
error when trying to link with it).To confirm the problem is as I suspected, I applied a naive "hackfix" to
fs.c
.Insert before definitions of
luv_fs_stat
andluv_fs_fstat
:Then I reset the defines afterwards:
Not exactly a great solution, but it should illustrate the nature of the problem.
Happy to submit a PR if you can suggest a better approach - or maybe this is fine?