Skip to content

WASI build is broken on certain environments #110749

Closed
@FFY00

Description

@FFY00

Bug report

Bug description:

Building CPython main for WASI in quay.io/tiran/cpythonbuild:emsdk3 results in:

../../Parser/tokenizer/file_tokenizer.c:156:9: error: implicit declaration of function 'lseek' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        lseek(fd, (off_t)(pos > 0 ? pos - 1 : pos), SEEK_SET) == (off_t)-1) {
        ^
../../Parser/tokenizer/file_tokenizer.c:156:9: note: did you mean 'fseek'?
/opt/wasi-sdk/bin/../share/wasi-sysroot/include/stdio.h:95:5: note: 'fseek' declared here
int fseek(FILE *, long, int);
    ^
../../Parser/tokenizer/file_tokenizer.c:395:12: error: implicit declaration of function 'read' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    return read(b.fd, (void *)buf, size);
           ^
../../Parser/tokenizer/file_tokenizer.c:395:12: note: did you mean 'fread'?
/opt/wasi-sdk/bin/../share/wasi-sysroot/include/stdio.h:102:8: note: 'fread' declared here
size_t fread(void *__restrict, size_t, size_t, FILE *__restrict);
       ^
2 errors generated.

This seems to be due to GH-110684, which moved the unistd.h import to the top during the refactoring. The import is now happening before pyconfig.h is included, so HAVE_UNISTD_H may be undefined.

Old code:

#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "tokenizer.h" // struct tok_state
#include "errcode.h" // E_OK
#ifdef HAVE_UNISTD_H
# include <unistd.h> // read()
#endif

New code:

#ifdef HAVE_UNISTD_H
# include <unistd.h> // read()
#endif
#include "Python.h"
#include "pycore_call.h"
#include "pycore_import.h"
#include "pycore_fileutils.h"
#include "errcode.h"

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-wasibuildThe build process and cross-buildtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions