Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3934543

Browse files
committed
Improve our heuristic for selecting PG_SYSROOT on macOS.
In cases where Xcode is newer than the underlying macOS version,asking xcodebuild for the SDK path will produce a pointer to theSDK shipped with Xcode, which may end up building code that doesnot work on the underlying macOS version. It appears that insuch cases, xcodebuild's answer also fails to match the defaultbehavior of Apple's compiler: assuming one has installed Xcode's"command line tools", there will be an SDK for the OS's own versionin /Library/Developer/CommandLineTools, and the compiler willdefault to using that. This is all pretty poorly documented,but experimentation suggests that "xcrun --show-sdk-path" givesthe sysroot path that the compiler is actually using, at leastin some cases. Hence, try that first, but revert to xcodebuildif xcrun fails (in very old Xcode, it is missing or lacks the--show-sdk-path switch).Also, "xcrun --show-sdk-path" may give a path that is valid but lacksany OS version identifier. We don't really want that, since mostof the motivation for wiring -isysroot into the build flags at allis to ensure that all parts of a PG installation are built againstthe same SDK, even when considering extensions built later and/or ona different machine. Insist on finding "N.N" in the directory namebefore accepting the result. (Adding "--sdk macosx" to the xcruncall seems to produce the same answer as xcodebuild, but usuallymore quickly because it's cached, so we also try that as a fallback.)The core reason why we don't want to use Xcode's default SDK in caseslike this is that Apple's technology for introducing new syscallsdoes not play nice with Autoconf: for example, configure will thinkthat preadv/pwritev exist when using a Big Sur SDK, even when buildingon an older macOS version where they don't exist. It'd be nice tohave a better solution to that problem, but this patch doesn't attemptto fix that.Per report from Sergey Shinderuk. Back-patch to all supported versions.Discussion:https://postgr.es/m/ed3b8e5d-0da8-6ebd-fd1c-e0ac80a4b204@postgrespro.ru
1 parent2d19f13 commit3934543

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

‎src/template/darwin

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,27 @@
33
# Note: Darwin is the original code name for macOS, also known as OS X.
44
# We still use "darwin" as the port name, partly because config.guess does.
55

6-
# Select where system include files should be sought.
6+
# Select where system include files should be sought, if user didn't say.
77
if test x"$PG_SYSROOT" = x"" ; then
8-
PG_SYSROOT=`xcodebuild -version -sdk macosx Path 2>/dev/null`
8+
# This is far more complicated than it ought to be. We first ask
9+
# "xcrun --show-sdk-path", which seems to match the default -isysroot
10+
# setting of Apple's compilers. However, that may produce no result or
11+
# a result that is not version-specific (i.e., just ".../SDKs/MacOSX.sdk").
12+
# Using a version-specific sysroot seems desirable, so if there are not
13+
# digits in the directory name, try "xcrun --sdk macosx --show-sdk-path";
14+
# and if that still doesn't work, fall back to asking xcodebuild,
15+
# which is often a good deal slower.
16+
PG_SYSROOT=`xcrun --show-sdk-path 2>/dev/null`
17+
if expr x"$PG_SYSROOT" : '.*[0-9]\.[0-9][^/]*$' >/dev/null ; then : okay
18+
else
19+
PG_SYSROOT=`xcrun --sdk macosx --show-sdk-path 2>/dev/null`
20+
if expr x"$PG_SYSROOT" : '.*[0-9]\.[0-9][^/]*$' >/dev/null ; then : okay
21+
else
22+
PG_SYSROOT=`xcodebuild -version -sdk macosx Path 2>/dev/null`
23+
fi
24+
fi
925
fi
10-
#Old xcodebuild versions may produce garbage, so validate the result.
26+
#Validate the result: if it doesn't point at a directory, ignore it.
1127
if test x"$PG_SYSROOT" != x"" ; then
1228
if test -d "$PG_SYSROOT" ; then
1329
CPPFLAGS="-isysroot $PG_SYSROOT $CPPFLAGS"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp