Skip to content

Commit 470f342

Browse files
committed
8296904: Improve handling of macos xcode toolchain
Reviewed-by: erikj, ihse
1 parent b4bd287 commit 470f342

File tree

3 files changed

+80
-54
lines changed

3 files changed

+80
-54
lines changed

doc/building.html

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -495,26 +495,26 @@ <h2 id="native-compiler-toolchain-requirements">Native Compiler
495495
<table>
496496
<thead>
497497
<tr class="header">
498-
<th style="text-align: left;">Operating system</th>
499-
<th style="text-align: left;">Supported toolchain</th>
498+
<th>Operating system</th>
499+
<th>Supported toolchain</th>
500500
</tr>
501501
</thead>
502502
<tbody>
503503
<tr class="odd">
504-
<td style="text-align: left;">Linux</td>
505-
<td style="text-align: left;">gcc, clang</td>
504+
<td>Linux</td>
505+
<td>gcc, clang</td>
506506
</tr>
507507
<tr class="even">
508-
<td style="text-align: left;">macOS</td>
509-
<td style="text-align: left;">Apple Xcode (using clang)</td>
508+
<td>macOS</td>
509+
<td>Apple Xcode (using clang)</td>
510510
</tr>
511511
<tr class="odd">
512-
<td style="text-align: left;">AIX</td>
513-
<td style="text-align: left;">IBM XL C/C++</td>
512+
<td>AIX</td>
513+
<td>IBM XL C/C++</td>
514514
</tr>
515515
<tr class="even">
516-
<td style="text-align: left;">Windows</td>
517-
<td style="text-align: left;">Microsoft Visual Studio</td>
516+
<td>Windows</td>
517+
<td>Microsoft Visual Studio</td>
518518
</tr>
519519
</tbody>
520520
</table>
@@ -527,23 +527,22 @@ <h2 id="native-compiler-toolchain-requirements">Native Compiler
527527
<table>
528528
<thead>
529529
<tr class="header">
530-
<th style="text-align: left;">Operating system</th>
531-
<th style="text-align: left;">Toolchain version</th>
530+
<th>Operating system</th>
531+
<th>Toolchain version</th>
532532
</tr>
533533
</thead>
534534
<tbody>
535535
<tr class="odd">
536-
<td style="text-align: left;">Linux</td>
537-
<td style="text-align: left;">gcc 11.2.0</td>
536+
<td>Linux</td>
537+
<td>gcc 11.2.0</td>
538538
</tr>
539539
<tr class="even">
540-
<td style="text-align: left;">macOS</td>
541-
<td style="text-align: left;">Apple Xcode 10.1 (using clang 10.0.0)</td>
540+
<td>macOS</td>
541+
<td>Apple Xcode 10.1 (using clang 10.0.0)</td>
542542
</tr>
543543
<tr class="odd">
544-
<td style="text-align: left;">Windows</td>
545-
<td style="text-align: left;">Microsoft Visual Studio 2022 update
546-
17.1.0</td>
544+
<td>Windows</td>
545+
<td>Microsoft Visual Studio 2022 update 17.1.0</td>
547546
</tr>
548547
</tbody>
549548
</table>
@@ -565,19 +564,25 @@ <h3 id="clang">clang</h3>
565564
<code>--with-toolchain-type=clang</code>.</p>
566565
<h3 id="apple-xcode">Apple Xcode</h3>
567566
<p>The oldest supported version of Xcode is 8.</p>
568-
<p>You will need the Xcode command lines developers tools to be able to
569-
build the JDK. (Actually, <em>only</em> the command lines tools are
567+
<p>You will need the Xcode command line developer tools to be able to
568+
build the JDK. (Actually, <em>only</em> the command line tools are
570569
needed, not the IDE.) The simplest way to install these is to run:</p>
571570
<pre><code>xcode-select --install</code></pre>
572-
<p>It is advisable to keep an older version of Xcode for building the
573-
JDK when updating Xcode. This <a
574-
href="http://iosdevelopertips.com/xcode/install-multiple-versions-of-xcode.html">blog
575-
page</a> has good suggestions on managing multiple Xcode versions. To
576-
use a specific version of Xcode, use <code>xcode-select -s</code> before
577-
running <code>configure</code>, or use
578-
<code>--with-toolchain-path</code> to point to the version of Xcode to
579-
use, e.g.
580-
<code>configure --with-toolchain-path=/Applications/Xcode8.app/Contents/Developer/usr/bin</code></p>
571+
<p>When updating Xcode, it is advisable to keep an older version for
572+
building the JDK. To use a specific version of Xcode you have multiple
573+
options:</p>
574+
<ul>
575+
<li>Use <code>xcode-select -s</code> before running
576+
<code>configure</code>, e.g.
577+
<code>xcode-select -s /Applications/Xcode13.1.app</code>. The drawback
578+
is that the setting is system wide and you may have to revert it after
579+
an OpenJDK build.</li>
580+
<li>Use configure option <code>--with-xcode-path</code>, e.g.
581+
<code>configure --with-xcode-path=/Applications/Xcode13.1.app</code>
582+
This allows using a specific Xcode version for an OpenJDK build,
583+
independently of the active Xcode version by
584+
<code>xcode-select</code>.</li>
585+
</ul>
581586
<p>If you have recently (inadvertently) updated your OS and/or Xcode
582587
version, and the JDK can no longer be built, please see the section on
583588
<a href="#problems-with-the-build-environment">Problems with the Build

doc/building.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,12 @@ ongoing efforts to loosen this strict coupling between compiler and operating
316316
system (see [JDK-8288293](https://bugs.openjdk.org/browse/JDK-8288293)) but it
317317
will likely be a very long time before this goal can be realized.
318318

319-
Operating system Supported toolchain
320-
------------------ -------------------------
321-
Linux gcc, clang
322-
macOS Apple Xcode (using clang)
323-
AIX IBM XL C/C++
324-
Windows Microsoft Visual Studio
319+
| Operating system | Supported toolchain |
320+
| ------------------ | ------------------------- |
321+
| Linux | gcc, clang |
322+
| macOS | Apple Xcode (using clang) |
323+
| AIX | IBM XL C/C++ |
324+
| Windows | Microsoft Visual Studio |
325325

326326
Please see the individual sections on the toolchains for version
327327
recommendations. As a reference, these versions of the toolchains are used, at
@@ -330,11 +330,11 @@ possible to compile the JDK with both older and newer versions, but the closer
330330
you stay to this list, the more likely you are to compile successfully without
331331
issues.
332332

333-
Operating system Toolchain version
334-
------------------ -------------------------------------------------------
335-
Linux gcc 11.2.0
336-
macOS Apple Xcode 10.1 (using clang 10.0.0)
337-
Windows Microsoft Visual Studio 2022 update 17.1.0
333+
| Operating system | Toolchain version |
334+
| ------------------ | ------------------------------------------ |
335+
| Linux | gcc 11.2.0 |
336+
| macOS | Apple Xcode 10.1 (using clang 10.0.0) |
337+
| Windows | Microsoft Visual Studio 2022 update 17.1.0 |
338338

339339
All compilers are expected to be able to compile to the C99 language standard,
340340
as some C99 features are used in the source code. Microsoft Visual Studio
@@ -362,20 +362,20 @@ To use clang instead of gcc on Linux, use `--with-toolchain-type=clang`.
362362

363363
The oldest supported version of Xcode is 8.
364364

365-
You will need the Xcode command lines developers tools to be able to build
366-
the JDK. (Actually, *only* the command lines tools are needed, not the IDE.)
365+
You will need the Xcode command line developer tools to be able to build
366+
the JDK. (Actually, *only* the command line tools are needed, not the IDE.)
367367
The simplest way to install these is to run:
368368
```
369369
xcode-select --install
370370
```
371371

372-
It is advisable to keep an older version of Xcode for building the JDK when
373-
updating Xcode. This [blog page](
374-
http://iosdevelopertips.com/xcode/install-multiple-versions-of-xcode.html) has
375-
good suggestions on managing multiple Xcode versions. To use a specific version
376-
of Xcode, use `xcode-select -s` before running `configure`, or use
377-
`--with-toolchain-path` to point to the version of Xcode to use, e.g.
378-
`configure --with-toolchain-path=/Applications/Xcode8.app/Contents/Developer/usr/bin`
372+
When updating Xcode, it is advisable to keep an older version for building the JDK.
373+
To use a specific version of Xcode you have multiple options:
374+
375+
* Use `xcode-select -s` before running `configure`, e.g. `xcode-select -s /Applications/Xcode13.1.app`. The drawback is that the setting
376+
is system wide and you may have to revert it after an OpenJDK build.
377+
* Use configure option `--with-xcode-path`, e.g. `configure --with-xcode-path=/Applications/Xcode13.1.app`
378+
This allows using a specific Xcode version for an OpenJDK build, independently of the active Xcode version by `xcode-select`.
379379

380380
If you have recently (inadvertently) updated your OS and/or Xcode version, and
381381
the JDK can no longer be built, please see the section on [Problems with the

make/autoconf/basic.m4

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ AC_DEFUN([BASIC_SETUP_XCODE_SYSROOT],
144144
if test $? -ne 0; then
145145
AC_MSG_ERROR([The xcodebuild tool in the devkit reports an error: $XCODEBUILD_OUTPUT])
146146
fi
147+
elif test "x$TOOLCHAIN_PATH" != x; then
148+
UTIL_LOOKUP_PROGS(XCODEBUILD, xcodebuild, $TOOLCHAIN_PATH)
149+
if test "x$XCODEBUILD" != x; then
150+
XCODEBUILD_OUTPUT=`"$XCODEBUILD" -version 2>&1`
151+
if test $? -ne 0; then
152+
AC_MSG_WARN([Ignoring the located xcodebuild tool $XCODEBUILD due to an error: $XCODEBUILD_OUTPUT])
153+
XCODEBUILD=
154+
fi
155+
fi
147156
else
148157
UTIL_LOOKUP_PROGS(XCODEBUILD, xcodebuild)
149158
if test "x$XCODEBUILD" != x; then
@@ -293,6 +302,22 @@ AC_DEFUN_ONCE([BASIC_SETUP_DEVKIT],
293302
[UTIL_PREPEND_TO_PATH([TOOLCHAIN_PATH],$with_toolchain_path)]
294303
)
295304
305+
AC_ARG_WITH([xcode-path], [AS_HELP_STRING([--with-xcode-path],
306+
[set up toolchain on Mac OS using a path to an Xcode installation])])
307+
308+
if test "x$with_xcode_path" != x; then
309+
if test "x$OPENJDK_BUILD_OS" = "xmacosx"; then
310+
UTIL_PREPEND_TO_PATH([TOOLCHAIN_PATH],
311+
$with_xcode_path/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:$with_xcode_path/Contents/Developer/usr/bin)
312+
else
313+
AC_MSG_WARN([Option --with-xcode-path is only valid on Mac OS, ignoring.])
314+
fi
315+
fi
316+
317+
AC_MSG_CHECKING([for toolchain path])
318+
AC_MSG_RESULT([$TOOLCHAIN_PATH])
319+
AC_SUBST(TOOLCHAIN_PATH)
320+
296321
AC_ARG_WITH([extra-path], [AS_HELP_STRING([--with-extra-path],
297322
[prepend these directories to the default path])],
298323
[UTIL_PREPEND_TO_PATH([EXTRA_PATH],$with_extra_path)]
@@ -311,10 +336,6 @@ AC_DEFUN_ONCE([BASIC_SETUP_DEVKIT],
311336
AC_MSG_RESULT([$SYSROOT])
312337
AC_SUBST(SYSROOT)
313338
314-
AC_MSG_CHECKING([for toolchain path])
315-
AC_MSG_RESULT([$TOOLCHAIN_PATH])
316-
AC_SUBST(TOOLCHAIN_PATH)
317-
318339
AC_MSG_CHECKING([for extra path])
319340
AC_MSG_RESULT([$EXTRA_PATH])
320341
])

0 commit comments

Comments
 (0)