Skip to content

Commit 66ffae7

Browse files
committed
Fix missing declarations of "POSIX" read()/write() on Windows with Clang
When (cross?) compiling this crate to Windows (in a Rust project) using Clang 16 or newer, we're seeing these declaration errors: > cargo b --target x86_64-pc-windows-msvc warning: [email protected]: /usr/local/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/metis-sys-0.3.1/vendor/GKlib/io.c(63,18): error: call to undeclared function 'read'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] warning: [email protected]: 63 | if ((rsize = read(fd, buf, tsize)) == -1) warning: [email protected]: | ^ ... warning: [email protected]: /usr/local/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/metis-sys-0.3.1/vendor/GKlib/io.c(84,17): error: call to undeclared function 'write'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] warning: [email protected]: 84 | if ((size = write(fd, buf, tsize)) == -1) warning: [email protected]: | ^ (LIHPC-Computational-Geometry/metis-rs#43 (comment)) Now it's yet unknown (we haven't checked) if older Clang had these declarations in a header, or didn't treat this warning as error yet, but the functions are POSIX which Windows isn't required to implement. Fortunately they provide it but with a deprecation warning and a recommended replacement of `_read()` (and `_write()`), but for this `<io.h>` needs to be included: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/posix-read https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/read The same is true for `getpid()` that commit a8e7e25 ("port to vs2017") used to provide a `win32/adapt.c/h` workaround for, but this can instead be pulled from `<process.h>` (equally with a deprecation warning, but we should probably address these all in a consistent manner instead of defining a workaround). Let's take this as a starting point and go from there.
1 parent ea01742 commit 66ffae7

File tree

4 files changed

+4
-30
lines changed

4 files changed

+4
-30
lines changed

CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ target_sources(${PROJECT_NAME}
6060
include/gk_mkpqueue2.h include/gk_mkrandom.h include/gk_mksort.h
6161
include/gk_mkutils.h include/gk_proto.h include/gk_struct.h
6262
include/gk_types.h include/gkregex.h include/gk_ms_inttypes.h
63-
include/gk_ms_stat.h include/gk_ms_stdint.h
64-
# the following are shims for win32 systems
65-
$<$<PLATFORM_ID:Windows>:src/win32/adapt.c
66-
include/win32/adapt.h>)
63+
include/gk_ms_stat.h include/gk_ms_stdint.h)
6764

6865
target_compile_definitions(${PROJECT_NAME}
6966
PUBLIC $<$<PLATFORM_ID:Linux>:LINUX>)

include/gk_arch.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
#include "gk_ms_stdint.h"
3636
#include "gk_ms_inttypes.h"
3737
#include "gk_ms_stat.h"
38-
#include "win32/adapt.h"
38+
#include <io.h>
39+
#include <process.h>
40+
typedef int pid_t;
3941
#else
4042
#ifndef SUNOS
4143
#include <stdint.h>

include/win32/adapt.h

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/win32/adapt.c

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)