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

[iOS] Configure script does not support miphonesimulator-version-min or other possibilities #6838

Closed
manuyavuz-pointr opened this issue Apr 2, 2021 · 7 comments
Labels

Comments

@manuyavuz-pointr
Copy link

I did this

CFLAGS='-Os -arch x86_64 -miphonesimulator-version-min=10.0 -isysroot /Applications/Xcode-11.3.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk'
./configure --host=x86_64-apple-darwin --with-darwinssl --enable-static --disable-shared --enable-threaded-resolver --disable-verbose --enable-ipv6

I get the following result:

Click to see `./configure` output

``` ./configure --prefix=/Users/pointr/manuyavuz/core-bootstrap/core-dependencies/build/curl/iossimulator/x86_64 --host=x86_64-apple-darwin --with-darwinssl --enable-static --disable-shared --enable-threaded-resolver --disable-verbose --enable-ipv6 checking whether to enable maintainer-specific portions of Makefiles... no checking whether make supports nested variables... yes checking whether to enable debug build options... no checking whether to enable compiler optimizer... (assumed) yes checking whether to enable strict compiler warnings... no checking whether to enable compiler warnings as errors... no checking whether to enable curl debug memory tracking... no checking whether to enable hiding of library internal symbols... yes checking whether to enable c-ares for DNS lookups... no checking whether to disable dependency on -lrt... (assumed no) checking for path separator... : checking for sed... /usr/bin/sed checking for grep... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking for x86_64-apple-darwin-ar... no checking for ar... /usr/bin/ar checking for a BSD-compatible install... /usr/bin/install -c checking for x86_64-apple-darwin-gcc... no checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... yes checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking whether gcc understands -c and -o together... yes checking how to run the C preprocessor... gcc -E checking for a sed that does not truncate output... (cached) /usr/bin/sed checking whether to build with code coverage support... no checking whether build environment is sane... yes checking for x86_64-apple-darwin-strip... no checking for strip... strip configure: WARNING: using cross tools not prefixed with host triplet checking for a thread-safe mkdir -p... ./install-sh -c -d checking for gawk... no checking for mawk... no checking for nawk... no checking for awk... awk checking whether make sets $(MAKE)... yes checking whether make supports the include directive... yes (GNU style) checking dependency style of gcc... gcc3 checking curl version... 7.60.0-DEV checking build system type... x86_64-apple-darwin19.6.0 checking host system type... x86_64-apple-darwin checking for grep that handles long lines and -e... (cached) /usr/bin/grep checking for egrep... /usr/bin/grep -E checking if OS is AIX (to define _ALL_SOURCE)... no checking if _THREAD_SAFE is already defined... no checking if _THREAD_SAFE is actually needed... no checking if _THREAD_SAFE is onwards defined... no checking if _REENTRANT is already defined... no checking if _REENTRANT is actually needed... no checking if _REENTRANT is onwards defined... no checking for special C compiler options needed for large files... no checking for _FILE_OFFSET_BITS value needed for large files... no checking how to print strings... printf checking for a sed that does not truncate output... (cached) /usr/bin/sed checking for fgrep... /usr/bin/grep -F checking for ld used by gcc... /Applications/Xcode-11.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld checking if the linker (/Applications/Xcode-11.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) is GNU ld... no checking for BSD- or MS-compatible name lister (nm)... no checking for x86_64-apple-darwin-dumpbin... no checking for x86_64-apple-darwin-link... no checking for dumpbin... no checking for link... link -dump checking the name lister (nm) interface... BSD nm checking whether ln -s works... yes checking the maximum length of command line arguments... 196608 checking how to convert x86_64-apple-darwin19.6.0 file names to x86_64-apple-darwin format... func_convert_file_noop checking how to convert x86_64-apple-darwin19.6.0 file names to toolchain format... func_convert_file_noop checking for /Applications/Xcode-11.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld option to reload object files... -r checking for x86_64-apple-darwin-objdump... no checking for objdump... objdump checking how to recognize dependent libraries... pass_all checking for x86_64-apple-darwin-dlltool... no checking for dlltool... no checking how to associate runtime and link libraries... printf %s\n checking for x86_64-apple-darwin-ar... /usr/bin/ar checking for archiver @file support... no checking for x86_64-apple-darwin-strip... strip checking for x86_64-apple-darwin-ranlib... no checking for ranlib... ranlib checking command to parse nm output from gcc object... ok checking for sysroot... no checking for a working dd... /bin/dd checking how to truncate binary pipes... /bin/dd bs=4096 count=1 checking for x86_64-apple-darwin-mt... no checking for mt... no checking if : is a manifest tool... no checking for x86_64-apple-darwin-dsymutil... no checking for dsymutil... dsymutil checking for x86_64-apple-darwin-nmedit... no checking for nmedit... nmedit checking for x86_64-apple-darwin-lipo... no checking for lipo... lipo checking for x86_64-apple-darwin-otool... no checking for otool... otool checking for x86_64-apple-darwin-otool64... no checking for otool64... no checking for -single_module linker flag... yes checking for -exported_symbols_list linker flag... yes checking for -force_load linker flag... yes checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for dlfcn.h... yes checking for objdir... .libs checking if gcc supports -fno-rtti -fno-exceptions... yes checking for gcc option to produce PIC... -fno-common -DPIC checking if gcc PIC flag -fno-common -DPIC works... yes checking if gcc static flag -static works... no checking if gcc supports -c -o file.o... yes checking if gcc supports -c -o file.o... (cached) yes checking whether the gcc linker (/Applications/Xcode-11.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes checking dynamic linker characteristics... darwin dyld checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... no checking whether to build static libraries... yes checking whether to build shared libraries with -version-info... yes checking whether to build shared libraries with -no-undefined... no checking whether to build shared libraries with -mimpure-text... no checking whether to build shared libraries with PIC... yes checking whether to build static libraries with PIC... no checking whether to build shared libraries only... no checking whether to build static libraries only... yes checking for inline... inline checking if cpp -P is needed... no checking if compiler is DEC/Compaq/HP C... no checking if compiler is HP-UX C... no checking if compiler is IBM C... no checking if compiler is Intel C... no checking if compiler is clang... yes checking if compiler is GNU C... no checking if compiler is LCC... no checking if compiler is SGI MIPSpro C... no checking if compiler is SGI MIPS C... no checking if compiler is SunPro C... no checking if compiler is Tiny C... no checking if compiler is Watcom C... no checking if compiler accepts some basic options... yes configure: compiler options added: -Qunused-arguments checking if compiler accepts debug disabling options... yes configure: compiler options added: checking if compiler optimizer assumed setting might be used... no checking if compiler halts on compilation errors... yes checking if compiler halts on negative sized arrays... yes checking if compiler halts on function prototype mismatch... yes checking if compiler supports hiding library internal symbols... yes checking for windows.h... no checking whether build target is a native Windows one... no checking whether build target supports WIN32 file API... no checking for good-to-use Mac CFLAGS... yes checking for *version-min in CFLAGS... -mmacosx-version-min=10.8 set checking whether gcc accepts -Werror=partial-availability... no checking to see if the compiler supports __builtin_available()... no checking whether to support http... yes checking whether to support ftp... yes checking whether to support file... yes checking whether to support ldap... yes checking whether to support ldaps... yes checking whether to support rtsp... yes checking whether to support proxies... yes checking whether to support dict... yes checking whether to support telnet... yes checking whether to support tftp... yes checking whether to support pop3... yes checking whether to support imap... yes checking whether to support smb... yes checking whether to support smtp... yes checking whether to support gopher... yes checking whether to provide built-in manual... yes checking whether to enable generation of C code... yes checking whether to use libgcc... no checking if X/Open network library is required... no checking for gethostbyname... no checking for gethostbyname in -lnsl... no checking for gethostbyname in -lsocket... no checking for gethostbyname in -lwatt... no checking for gethostbyname with both nsl and socket libs... no checking for gethostbyname for Minix 3... no checking for gethostbyname for eCos... no checking for gethostbyname in -lnetwork... no checking for gethostbyname in -lnet... no configure: error: couldn't find libraries for gethostbyname() ```

Important part is this:

checking for *version-min in CFLAGS... -mmacosx-version-min=10.8 set

Apparently, the regex used to check version-min looks for os in the string, which is not always the case:

curl/acinclude.m4

Line 2609 in 3085ccf

elif test -z "$(echo $CFLAGS $CC | grep m.*os.*-version-min)"; then

I think this check should be updated to provide correct flags.

Here are the all possible values:
https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mios-simulator-version-min
https://bcain-llvm.readthedocs.io/projects/clang/en/latest/ClangCommandLineReference/#cmdoption-clang-mtvos-simulator-version-min
https://bcain-llvm.readthedocs.io/projects/clang/en/latest/ClangCommandLineReference/#cmdoption-clang-mwatchos-simulator-version-min
https://bcain-llvm.readthedocs.io/projects/clang/en/latest/ClangCommandLineReference/#cmdoption-clang-miphoneos-version-min
https://bcain-llvm.readthedocs.io/projects/clang/en/latest/ClangCommandLineReference/#cmdoption-clang-mmacosx-version-min

Therefore, correct regex should be m.*-version-min imo.

I expected the following

Build successfully.

curl/libcurl version

Building from tagcurl-7_76_0

operating system

% uname -a
Darwin pointrs-Mac-7.local 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64
@bagder bagder added the build label Apr 2, 2021
bagder added a commit that referenced this issue Apr 2, 2021
To make it work with -miphonesimulator-version-min and others.

Reported-by: manuyavuz-pointr on github
Fixes #6838
@manuyavuz
Copy link
Contributor

Hi @bagder,

I think this solution won't be generic enough. Currently, curl's configure script does a very strict assumption about the host and sets -macosx-version-min=10.8 if it does not see a *-version-min flag or a *-DEPLOYMENT_TARGET flag.

However, clang itself could infer deployment target from various sources as can be seen in the function here:

https://github.com/llvm/llvm-project/blob/66af90b46e1fe395806474dde2d49b8dc78bae1a/clang/lib/Driver/ToolChains/Darwin.cpp#L1803

The ordering of sources is here:

https://github.com/llvm/llvm-project/blob/66af90b46e1fe395806474dde2d49b8dc78bae1a/clang/lib/Driver/ToolChains/Darwin.cpp#L1377-L1388

Basically, clang infers deployment target with the following order:

  1. -target flag
  2. -m*-version-min flags
  3. -*_DEPLOYMENT_TARGET envs
  4. -isysroot flag
  5. SDKROOT env
  6. If none of the above is provided, it infers deployment version from host machine.

Due to current behavior, it's not possible to build for ios/tvos/watchos or their simulator variants unless you provide -version-min or -DEPLOYMENT_TARGET, which is not something actually necessary to provide.

Therefore, I think this default -mmacosx-version-min=10.8 should either be removed, or applied only when we are sure that the build is for macos, which can be inferred by looking into provided -isysroot or SDKROOT values.

Once these are fixed, compiling for ios or similar platforms will be very simple as follows:

xcrun -sdk $SDK_NAME ./configure --host $ARCH-apple-darwin
xcrun -sdk $SDK_NAME make

And if someone needs a custom minimum deployment target, the change is as follows:

xcrun -sdk $SDK_NAME ./configure --host $ARCH-apple-darwin
# either this
$($PLATFORM)-DEPLOYMENT_TARGET=$MIN_VERSION xcrun -sdk $SDK_NAME make
# or this
CFLAGS='-m${PLATFORM}-version-min=$MIN_VERSION' xcrun -sdk $SDK_NAME make

If proposed solution is good for you, I can open a PR with the changes, along with updated documentation for building for ios/tvos/watchos platforms.

@bagder
Copy link
Member

bagder commented Apr 5, 2021

I really don't know this stuff. It sounds fine and reasonable to me but I don't know details or specifics to tell if there are any flaws in this approach. Go ahead!

@manuyavuz
Copy link
Contributor

Hey, I can definitely help, but we need to decide what policy will be used for Darwin platforms.

  1. Do not add anything by default, and expect the developer to add whatever min version they would need.
  2. Cover the last n major versions, and add that as default. (deployment target iOS 11.0 for sdk target iOS 14.4 for example)
  3. Add hardcoded small enough versions for all SDKs (macosx, iphoneos, iphoneossimulator, tvos, tvsimulator, watchos, watchsimulator).

I suggest the option 1. Others would require having a check if min version has been added by user manually, and adding it if it's not. And still, it would break developer's expectation if developer just wants to build with the compiler default min version behavior. Also, they would require maintenance operations in future (new possible sdk platforms, breaking deployment version changes in new releases etc.).

I have checked the original issue causing this default min version addition:
https://curl.se/mail/lib-2016-09/0055.html

The problem there was that the developer was supposed to add a deployment target that he wants to support. In Xcode for example, if you don't do anything, it gives you the highest possible deployment target (14.4 if your SDK version is 14.4), and you are supposed to change it if needed. So it should not be a problem.

If wanted, configure script can warn user if they did not set any deployment target, but that should be all I think.

Btw, -werror=partial-availability will still exist, as it would guarantee compilation to fail if there is an API curl uses that is not supported in provided deployment target version.

@bagder if you are ok with this, I will do required changes.

@bagder
Copy link
Member

bagder commented Apr 7, 2021

/cc @mstorsjo any feedback? I believe you were involved when this logic was added back in 2016.

@mstorsjo
Copy link
Contributor

mstorsjo commented Apr 7, 2021

I think it should be fairly safe to remove this bit indeed.

We're pretty far past that particular transition, so making default builds rely on things from 10.12 (from 2016) if they don't explicitly set the deployment target probably is uncontroversial at this point. Anybody wanting to target an older version needs to make sure to set the minimum deployment version explicitly, which isn't unresonable at this point.

@manuyavuz
Copy link
Contributor

Ok then, I will be keeping -werror=partial-availability, removing other checks and default setting, and add documentation for cross compilation for ios and similar platforms.

@bagder
Copy link
Member

bagder commented Apr 7, 2021

sounds excellent!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 participants