Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8.11.0 - macOS getpass_r error building CMake #15557

Closed
danoli3 opened this issue Nov 12, 2024 · 5 comments
Closed

8.11.0 - macOS getpass_r error building CMake #15557

danoli3 opened this issue Nov 12, 2024 · 5 comments
Labels
appleOS specific to an Apple operating system cmake

Comments

@danoli3
Copy link

danoli3 commented Nov 12, 2024

I did this

Error on getpass

error: call to undeclared function 'getpass_r'; ISO C99 and later do not support implicit function declarations

/Users/runner/work/apothecary/apothecary/apothecary/build/curl/src/tool_paramhlp.c:569:5: error: call to undeclared function 'getpass_r'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    getpass_r(prompt, passwd, sizeof(passwd));
    ^
/Users/runner/work/apothecary/apothecary/apothecary/build/curl/src/tool_paramhlp.c:569:5: note: did you mean 'getpass'?
/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/unistd.h:559:7: note: 'getpass' declared here
char    *getpass(const char *) __POSIX_C_DEPRECATED(199506L);
         ^
1 error generated.
make[2]: *** [src/CMakeFiles/curl.dir/tool_paramhlp.c.o] Error 1
make[1]: *** [src/CMakeFiles/curl.dir/all] Error 2
make: *** [all] Error 2
curl/src/tool_paramhlp.c:569:5

Building with CMake

 echo "building curl $TYPE | $PLATFORM"
        echo "--------------------"
        mkdir -p "build_${TYPE}_${PLATFORM}"
        cd "build_${TYPE}_${PLATFORM}"
        rm -f CMakeCache.txt *.a *.o *.lib
        cmake  .. \
            -DCMAKE_C_STANDARD=${C_STANDARD} \
            -DCMAKE_CXX_STANDARD=${CPP_STANDARD} \
            -DCMAKE_CXX_STANDARD_REQUIRED=ON \
            -DCMAKE_CXX_FLAGS="-DUSE_PTHREADS=1 ${FLAG_RELEASE} " \
            -DCMAKE_C_FLAGS="-DUSE_PTHREADS=1 ${FLAG_RELEASE} " \
            -DCMAKE_CXX_EXTENSIONS=OFF \
            -DBUILD_SHARED_LIBS=OFF \
            -DCURL_STATICLIB=ON \
            -DBUILD_STATIC_LIBS=ON \
            -DENABLE_UNICODE=ON \
            -DCMAKE_BUILD_TYPE=Release \
            -DCMAKE_INSTALL_PREFIX=Release \
            -DDEPLOYMENT_TARGET=${MIN_SDK_VER} \
            -DCMAKE_INCLUDE_OUTPUT_DIRECTORY=include \
            -DHAVE__FSEEKI64=OFF \
            -DCMAKE_INSTALL_INCLUDEDIR=include \
            -DCMAKE_TOOLCHAIN_FILE=$APOTHECARY_DIR/toolchains/ios.toolchain.cmake \
            -DPLATFORM=$PLATFORM \
            -DENABLE_BITCODE=OFF \
            -DCMAKE_USE_SYSTEM_CURL=OFF \
            -DENABLE_ARC=ON \
            -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \
            -DCURL_DISABLE_LDAP=ON \
            -DENABLE_VISIBILITY=OFF \
            ${SSL_DEFS} \
            -DCMAKE_PREFIX_PATH="${LIBS_ROOT}" \
            -DZLIB_ROOT=${ZLIB_ROOT} \
            -DZLIB_INCLUDE_DIR=${ZLIB_INCLUDE_DIR} \
            -DZLIB_INCLUDE_DIRS=${ZLIB_INCLUDE_DIR} \
            -DZLIB_LIBRARY=${ZLIB_LIBRARY} \
            -DZLIB_LIBRARIES=${ZLIB_LIBRARY} \
            -DENABLE_ARES=OFF \
            -DCMAKE_VERBOSE_MAKEFILE=${VERBOSE_MAKEFILE} \
            -DENABLE_UNIX_SOCKETS=OFF \
            -DHAVE_LIBSOCKET=OFF \
            -DCURL_ENABLE_SSL=${CURL_ENABLE_SSL} \
            -DCMAKE_MACOSX_BUNDLE=OFF \
            -DUSE_SECURE_TRANSPORT=${USE_SECURE_TRANSPORT} \
            -DCURL_USE_SECTRANSP=${USE_SECURE_TRANSPORT} \
            -DUSE_NGHTTP2=OFF \
            -DCURL_DISABLE_POP3=ON \
            -DCURL_CA_FALLBACK=ON \
            -DCURL_DISABLE_IMAP=ON \
            -DENABLE_WEBSOCKETS=ON \
            -DENABLE_UNIX_SOCKETS=ON \
            -DCURL_BROTLI=ON \
            -DBROTLI_INCLUDE_DIRS=${LIBBROTLI_INCLUDE_DIR} \
            -DBROTLIDEC_LIBRARY=${LIBBROTLI_DEC_LIB} \
            -DBROTLICOMMON_LIBRARY=${LIBBROTLI_LIBRARY} \
            -DBROTLI_INCLUDE_DIR=${LIBBROTLI_INCLUDE_DIR} \
            -DBROTLI_LIBRARIES="${LIBBROTLI_LIBRARY} ;${LIBBROTLI_DEC_LIB};${LIBBROTLI_ENC_LIB}" \
            -DUSE_LIBIDN2=OFF \
            -DENABLE_VERBOSE=ON \
            -DENABLE_THREADED_RESOLVER=ON \
            -DENABLE_IPV6=ON
        cmake --build . --config Release --target install
        cd ..

fulllog.log

I expected the following

Build success

curl/libcurl version

curl 8.11.0

operating system

buildinfo.configure.generator: Unix Makefiles
buildinfo.configure.make: /usr/bin/make
buildinfo.host.cpu: arm64
buildinfo.host.os: Darwin
buildinfo.target.cpu: x86_64
buildinfo.target.os: Darwin
buildinfo.target.flags: APPLE UNIX CROSS
buildinfo.compiler: AppleClang
buildinfo.compiler.version: 15.0.0.15000309
buildinfo.sysroot: /Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk

on macOS latest runner GitHub Actions https://github.com/actions/runner-images/blob/main/images/macos/macos-14-Readme.md

@danoli3
Copy link
Author

danoli3 commented Nov 12, 2024

#ifdef __APPLE__
    strncpy(passwd, getpass(prompt), sizeof(passwd) - 1);
    passwd[sizeof(passwd) - 1] = '\0';
#else
    getpass_r(prompt, passwd, sizeof(passwd));
#endif
```

@vszakats

This comment was marked as resolved.

@vszakats
Copy link
Member

This look to be the culprit:

-- Looking for getpass_r - found

Could be a sibling to issue #15525.

One common pattern is the use of ios.toolchain.cmake.

Where to find this file?

vszakats added a commit to vszakats/curl that referenced this issue Nov 12, 2024
It's not offered by Apple operating system, but in some cases it may get
mis-detected when using `check_function_exists()`, then making the build
fail later.

A better fix would be to figure out why are these mis-detections. One
common pattern seen is this option, but it may or not be the cause:
```
-DCMAKE_TOOLCHAIN_FILE=[...]/toolchains/ios.toolchain.cmake
```
Ref: curl#15525

Regression from 8e34505 curl#15164

Reported-by: Dan Rosser
Fixes curl#15557
Closes curl#15558
vszakats added a commit to vszakats/curl that referenced this issue Nov 12, 2024
It's not offered by Apple operating system, but in some cases it may get
mis-detected when using `check_function_exists()`, then making the build
fail later.

A better fix would be to figure out why are these mis-detections. One
common pattern seen is this option, but it may or not be the cause:
```
-DCMAKE_TOOLCHAIN_FILE=[...]/toolchains/ios.toolchain.cmake
```
Ref: curl#15525

Regression from 8e34505 curl#15164

Reported-by: Dan Rosser
Fixes curl#15557
Closes curl#15558
vszakats added a commit to vszakats/curl that referenced this issue Nov 12, 2024
It's not offered by Apple operating system, but in some cases it may get
mis-detected when using `check_function_exists()`, then making the build
fail later.

A better fix would be to figure out why are these mis-detections. One
common pattern seen is this option, but it may or not be the cause:
```
-DCMAKE_TOOLCHAIN_FILE=[...]/toolchains/ios.toolchain.cmake
```
Ref: curl#15525

Regression from 8e34505 curl#15164

Reported-by: Dan Rosser
Fixes curl#15557
Closes curl#15558
vszakats added a commit to vszakats/curl that referenced this issue Nov 12, 2024
It's not offered by Apple operating systems, but in some cases it gets
mis-detected when using `check_function_exists()`. Then making the build
fail later.

A better fix would be to figure out why are these mis-detections. One
common pattern seen is this option, but it may or not be the cause:
```
-DCMAKE_TOOLCHAIN_FILE=[...]/toolchains/ios.toolchain.cmake
```
Ref: curl#15525

Regression from 8e34505 curl#15164

Reported-by: Dan Rosser
Fixes curl#15557
Closes curl#15558
@danoli3
Copy link
Author

danoli3 commented Nov 12, 2024

This look to be the culprit:

-- Looking for getpass_r - found

Could be a sibling to issue #15525.

One common pattern is the use of ios.toolchain.cmake.

Where to find this file?

https://github.com/leetal/ios-cmake
https://github.com/leetal/ios-cmake/blob/master/ios.toolchain.cmake

@vszakats vszakats added cmake appleOS specific to an Apple operating system labels Nov 12, 2024
@vszakats
Copy link
Member

vszakats commented Nov 12, 2024

I could trace this back to an issue in ios.toolchain.cmake.
Details and possible upstream workaround:
#15559 (comment)

The same issue is causing this pre-existing workaround in OP:
-DHAVE_LIBSOCKET=OFF.

vszakats added a commit to vszakats/curl that referenced this issue Nov 12, 2024
It's not offered by Apple operating systems, but in some cases it gets
mis-detected when using `check_function_exists()`. Then making the build
fail later.

A better fix would be to figure out why are these mis-detections. One
common pattern seen is this option, but it may or not be the cause:
```
-DCMAKE_TOOLCHAIN_FILE=[...]/toolchains/ios.toolchain.cmake
```
Ref: curl#15525

Regression from 8e34505 curl#15164

Reported-by: Dan Rosser
Fixes curl#15557
Closes curl#15558
@danoli3 danoli3 closed this as completed Nov 13, 2024
vszakats added a commit that referenced this issue Nov 13, 2024
Fix builds with CMake configured to falsely return successful detection
when using `check_function_exists()` (and `check_library_exists()`, and
anything based on `try_compile()` that's relying on the linker). After
such mis-detection the build fails when trying to use the feature that
doesn't in fact exist.

The mis-detection is caused by this CMake setting:
```
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
```
It is set by default (or on conditions) when using 3rd-party toolchain:
https://github.com/leetal/ios-cmake/blob/master/ios.toolchain.cmake

After this patch the curl build overrides this setting for the duration
of feature tests, and logs a message about it.

Also preset and skip feature tests for known mis-detections:
- `connect()` in `libsocket`
- `getpass_r()`
- `eventfd()` (did not cause an issue due to a separate bug)
- `sendmmsg()` (did not cause an issue because it's Linux-only)

If mis-detections are still seen, the workaround is to force-set the
specific feature by passing `-DHAVE_*=OFF` to cmake.
Also consider passing `-DENABLE_STRICT_TRY_COMPILE=ON` for
`ios.toolchain.cmake` to fix the root cause.

Interestingly curl itself uses this setting to speed up compile-only
detections: be17f29 #3744

Also:
- OtherTests.cmake: restore original value of
  `CMAKE_TRY_COMPILE_TARGET_TYPE`. Before this patch it reset it
  to empty.
- OtherTests.cmake: unset a local variable after use, quote a string.

Follow-up to 8e34505 #15164
Follow-up to 8b76a8a #15525
Ref: leetal/ios-cmake#47
Ref: https://gitlab.kitware.com/cmake/cmake/-/issues/18121
Ref: https://cmake.org/cmake/help/latest/variable/CMAKE_TRY_COMPILE_TARGET_TYPE.html
Reported-by: Dan Rosser
Fixes #15557
Closes #15559
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
appleOS specific to an Apple operating system cmake
2 participants