Upgrade to Swift 4.1 (Xcode 9.3)

This commit is contained in:
Andrew Bettison 2018-05-01 18:20:03 +09:30
parent f91033820b
commit e6e1a4b0a2
5 changed files with 160 additions and 62 deletions

View File

@ -1,6 +1,6 @@
Serval DNA Build and Test
=========================
[Serval Project][], December 2017
[Serval Project][], May 2018
Supported Architectures
-----------------------
@ -22,8 +22,8 @@ are separate build instructions:
Linux kernels 2.6.x and 3.x, Arm architecture, using [gcc 4.4][] supplied as
part of [Android NDK][] Revision 7b
* [Serval DNA on iOS][iOS] gives instructions for [Apple iOS][] using
[Xcode][] versions 8, supplemented by [homebrew][]
* [Serval DNA on iOS][iOS] gives instructions for [Apple iOS][] using [Xcode
version 9.3][Xcode 9], supplemented by [homebrew][]
* [Serval DNA on OpenWRT][OpenWRT] gives instructions for the embedded router
Linux distribution, as used by the [Serval Mesh Extender][], the [Mesh
@ -62,7 +62,7 @@ Mandatory dependencies:
Optional:
* [Java][] compiler and SDK 1.6.0 or later
* [Swift][] 3 or 4 compiler
* [Swift][] 4.1 compiler
* ALSA sound library and headers (present on Linux, not on Android)
Test dependencies:
@ -75,10 +75,10 @@ Test dependencies:
Apple Mac OS
------------
On Apple Mac OS, the following dependencies are provided by the [Xcode][]
package:
On Apple Mac OS, the following dependencies are provided by the [Xcode version
9.3][Xcode 9] package:
* all libraries and headers listed above
* **Swift** 3 or 4
* **Swift** 4.1
* **Bash** 3.2.48
* **curl** 7.45
@ -276,8 +276,8 @@ The [native build](#native-build) process produces the following artifacts:
* **tfw_createfile** is an executable utility needed by test scripts for
creating large data files with unique, non-repeating content.
In addition, the following artifacts are produced [if a Swift compiler is
present][Swift development]:
In addition, the following artifacts are produced [if a suitable Swift compiler
is present][Swift development]:
* **servaldswift** is a statically linked Serval DNA executable identical to
*servald*, but its *main* entry point is compiled from a [Swift][] program to
@ -344,7 +344,7 @@ and may need to be changed for your particular circumstances.
-----
**Copyright 2013-2015 Serval Project Inc.**
**Copyright 2016-2017 Flinders University**
**Copyright 2016-2018 Flinders University**
![CC-BY-4.0](./cc-by-4.0.png)
This document is available under the [Creative Commons Attribution 4.0 International licence][CC BY 4.0].
@ -357,6 +357,7 @@ This document is available under the [Creative Commons Attribution 4.0 Internati
[Android 2.2 “Froyo”]: http://developer.android.com/about/versions/android-2.2-highlights.html
[Android NDK]: http://developer.android.com/tools/sdk/ndk/index.html
[Xcode]: https://developer.apple.com/xcode/
[Xcode 9]: https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html
[gcc 4.4]: http://gcc.gnu.org/gcc-4.4/
[gcc 5]: http://gcc.gnu.org/gcc-5/
[gcc 6]: http://gcc.gnu.org/gcc-6/
@ -386,6 +387,5 @@ This document is available under the [Creative Commons Attribution 4.0 Internati
[Git]: http://git-scm.com/
[Subversion]: http://subversion.apache.org/
[Bourne shell]: http://en.wikipedia.org/wiki/Bourne_shell
[Xcode]: https://developer.apple.com/xcode/
[homebrew]: http://brew.sh/
[CC BY 4.0]: ./LICENSE-DOCUMENTATION.md

View File

@ -154,7 +154,7 @@ AS_IF([test "x$enable_xcode_sdk" != x], [ dnl
dnl Check for C assembler.
AM_PROG_AS
dnl Check for a Swift 3 or 4 compiler; set SWIFTC if found.
dnl Check for a Swift 4.1 compiler; set SWIFTC if found.
AC_PROG_SWIFTC
AS_IF([test "x$SWIFTC" != x], [ dnl
@ -188,16 +188,13 @@ AS_IF([test "x$SWIFTC" != x], [ dnl
)
AC_MSG_RESULT([$swiftc_target])
dnl Check whether the Swift compiler will compile a simple Swift 4 program with the supplied flags.
dnl If not, report failure but keep going.
AC_PROG_SWIFTC_IS_SWIFT4
AS_IF([test "x$ac_cv_prog_swiftc_is_swift4" = xyes], [SWIFT_VERSION=4], [ dnl
AC_PROG_SWIFTC_IS_SWIFT3
AS_IF([test "x$ac_cv_prog_swiftc_is_swift3" = xyes], [SWIFT_VERSION=3], [ dnl
AC_MSG_WARN([$SWIFTC version is too old; omitting Swift API])
SWIFT_VERSION=
SWIFTC=
])
dnl Check whether the Swift compiler will compile a simple Swift 4.1
dnl program with the supplied flags. If not, report failure and carry on
dnl without support for Swift.
AC_PROG_SWIFTC_IS_SWIFT4_1
AS_IF([test "x$ac_cv_prog_swiftc_is_swift4_1" = xyes], [], [ dnl
AC_MSG_WARN([$SWIFTC version is too old; omitting Swift API])
SWIFTC=
])
dnl Set up the Swift compiler for cross compilation; invoke it using the Xcode xcrun wrapper
@ -215,7 +212,6 @@ AS_IF([test "x$SWIFTC" != x && test "x$SWIFT_BUILD" = x], [
dnl Swift definitions that get expanded in Makefiles.
AC_SUBST([SWIFTC])
AC_SUBST([SWIFTCFLAGS])
AC_SUBST([SWIFT_VERSION])
AC_SUBST([SWIFT_BUILD])
dnl The C compilation and linking flags used in all Makefiles and all the following

View File

@ -1,6 +1,6 @@
Serval DNA on iOS
=================
[Serval Project][], November 2017
[Serval Project][], May 2018
These instructions describe how to embed [Serval DNA][] into an [Apple iOS][]
app.
@ -10,28 +10,41 @@ This work was funded by a grant from the [NLnet Foundation][].
Introduction
------------
Please see the [build instructions][build] and [Notes for Developers][develop]
for an introduction to the [Serval DNA][] native build and development
environment. (To summarise: the [Serval DNA][] build and development toolchain
is completely oriented around the [Bash shell][] command-line on [Unix][]
platforms such as [GNU][]/[Linux][] and [Darwin][], and uses [GNU autoconf][]
achieve portability between different platforms.)
The [build instructions][build] and [Notes for Developers][develop] introduce
[Serval DNA][]'s build and development environment. To summarise:
The only platform available for developing iOS apps is the [Xcode][] integrated
development environment from Apple. Xcode is only available on Mac OS-X, so
[Serval DNA][]'s iOS development toolchain is based entirely on the
[Darwin][]/[Xcode][] environment and is not complicated by portability issues.
Xcode builds iOS apps by [cross compiling][] to the selected target.
* the build toolchain is completely oriented around the [Bash shell][]
command-line on [Unix][] platforms such as [GNU][]/[Linux][] and [Darwin][]
The [ios](../ios) subdirectory contains scripts for building Serval DNA into a
multi-target [Framework Bundle][] that can be imported into any Xcode project.
The framework provides access to all public C functions in the Serval DNA
source code, and to all entry points of the Serval DNA Swift API.
* [GNU autoconf][] is used to achieve portability between different platforms
Serval DNA does not support building by [IDE][]s, however the only platform
available for developing iOS apps is the [Xcode][] IDE from Apple. Xcode is
only available for Mac OS-X, and it builds iOS apps by [cross compiling][] to
the selected target.
Overview
--------
To use Serval DNA in an iOS app, a developer must use the Mac OSX command line
to configure and build Serval DNA into a multi-target [Framework Bundle][] for
iOS. This framework allows an app to call all entry points of the Serval DNA
Swift API, and also to call any public C function in the Serval DNA source
code.
Once the Serval DNA framework bundle is built, the developer may then import it
into any Xcode project.
The scripts for building the Serval DNA framework bundle are in the
[ios](../ios/) sub-directory. [Serval DNA][]'s iOS support is based on recent
versions of the [Darwin][]/[Xcode][] environment, so these scripts are not
complicated by the kinds of portability issues that plague other environments,
like GNU/Linux and POSIX.
Supported targets
-----------------
The supported operating systems are:
The supported target operating systems are:
* [iOS 10][] or later (iPhoneOS and iPhoneSimulator)
@ -61,16 +74,18 @@ the above list, the supported targets are:
Dependencies
------------
Building [Serval DNA][] for iOS requires [Xcode version 8][Xcode 8] or later,
because the [Swift 3][] programming language was first introduced in [Xcode
version 8][Xcode 8], and Serval DNA exposes its API in iOS using Swift 3.
[Serval DNA][] exposes its API using the [Swift 4.1][] programming language, so
building it for iOS requires:
[Xcode 8][] provides the following command-line utilities:
* [Xcode version 9.3][Xcode 9] or later (which introduced Swift 4.1), which in turn requires
* [Mac OS 10.13 “High Sierra”][] or later.
[Xcode 9][] provides the following command-line utilities:
* [Bash shell][] version 3.2
* [GNU make][] version 3.81
* [Clang][] compiler for [C11][] based on LLVM version 8
* [Swift 3][] compiler based on LLVM version 8
* [Swift 4.1][] compiler based on LLVM version 8
* standard BSD utilities such as [sed][], [tr][], and [mkdir][]
These are adequate for cross-compiling for iOS as described below, but may not
@ -276,11 +291,13 @@ This document is available under the [Creative Commons Attribution 4.0 Internati
[Clang]: https://en.wikipedia.org/wiki/Clang
[build]: ../INSTALL.md
[develop]: ./Development.md
[IDE]: https://en.wikipedia.org/wiki/Integrated_development_environment
[Xcode]: https://en.wikipedia.org/wiki/Xcode
[Xcode 8]: https://developer.apple.com/swift/blog/?id=36
[Xcode 9]: https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html
[C11]: https://en.wikipedia.org/wiki/C11_(C_standard_revision)
[Swift 3]: https://swift.org/blog/swift-3-0-released/
[Swift 4.1]: https://swift.org/blog/swift-4-1-released/
[cross compiling]: https://en.wikipedia.org/wiki/Cross_compiler
[Mac OS 10.13 “High Sierra”]: https://en.wikipedia.org/wiki/MacOS_High_Sierra
[iOS 10]: https://en.wikipedia.org/wiki/IOS_10
[iPhone 5]: https://en.wikipedia.org/wiki/IPhone_5
[iPhone 5C]: https://en.wikipedia.org/wiki/IPhone_5C
@ -297,3 +314,4 @@ This document is available under the [Creative Commons Attribution 4.0 Internati
[Framework Bundle]: https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPFrameworks/Frameworks.html
[Clang module]: https://clang.llvm.org/docs/Modules.html
[lipo(1)]: http://www.manpages.info/macosx/lipo.1.html
[CC BY 4.0]: ../LICENSE-DOCUMENTATION.md

View File

@ -1,6 +1,6 @@
Notes for Serval DNA Developers
===============================
[Serval Project][], December 2017
[Serval Project][], May 2018
This document is intended for all developers of [Serval DNA][], and also for
non-developers who are experiencing errors in the [build][] process.
@ -14,12 +14,11 @@ around the [Bash shell][] command-line on [Unix][] platforms such as
between different platforms.
To date, the [Serval Project][] has not dedicated effort to integrating with
GUI development environments such as [Android Studio][] or supporting non-Unix
platforms such as [Microsoft Windows][], because the ongoing effort of
maintaining compatibility with so many platforms would detract from the
development of core features. Anybody is welcome to contribute support for
more platforms, but at this stage, the Serval Project cannot commit to
maintaining any contributed integrations.
[IDE][]s such as [Android Studio][] or supporting non-Unix platforms such as
[Microsoft Windows][], because the ongoing effort of maintaining compatibility
with so many platforms would detract from the development of core features.
Anybody is welcome to contribute support for more platforms, but at this stage,
the Serval Project cannot commit to maintaining any contributed integrations.
Autotools
---------
@ -253,11 +252,10 @@ Swift
Serval DNA supports [Swift][], the language that Apple recommend for developing
iOS apps for their mobile devices such as phones and tablets. The
`./configure` script [generated from configure.ac](#autotools) detects whether
a [Swift 4][] compiler is present, or failing that, a [Swift 3][] compiler, and
if so, then produces a Makefile that will compile [servaldswift.swift][] into
the *servaldswift* executable, to prove that the Swift [module
map](../module.modulemap) allows Swift source code to invoke internal Serval
DNA functions.
a [Swift 4.1][] compiler is present, and if so, then produces a Makefile that
will compile [servaldswift.swift][] into the *servaldswift* executable, to
prove that the Swift [module map](../module.modulemap) allows Swift source code
to invoke internal Serval DNA functions.
The `./configure` script can be passed the following variables, either as
environment variables or using the `VARNAME=value` syntax on its command line:
@ -344,7 +342,7 @@ and may need to be changed for your particular circumstances.
-----
**Copyright 2015 Serval Project Inc.**
**Copyright 2016-2017 Flinders University**
**Copyright 2016-2018 Flinders University**
![CC-BY-4.0](./cc-by-4.0.png)
Available under the [Creative Commons Attribution 4.0 International licence][CC BY 4.0].
@ -393,8 +391,10 @@ Available under the [Creative Commons Attribution 4.0 International licence][CC
[JNI]: http://en.wikipedia.org/wiki/Java_Native_Interface
[Swift]: https://en.wikipedia.org/wiki/Swift_(programming_language)
[Swift module]: https://swift.org/package-manager/#modules
[Swift 3]: https://swift.org/blog/swift-3-0-released/
[Swift 4]: https://swift.org/blog/swift-4-0-released/
[Swift 4.1]: https://swift.org/blog/swift-4-1-released/
[URLSession]: https://developer.apple.com/documentation/foundation/urlsession
[gold]: https://en.wikipedia.org/wiki/Gold_(linker)
[IDE]: https://en.wikipedia.org/wiki/Integrated_development_environment
[Android Studio]: https://en.wikipedia.org/wiki/Android_Studio
[Microsoft Windows]: https://en.wikipedia.org/wiki/Microsoft_Windows
[Bourne shell]: http://en.wikipedia.org/wiki/Bourne_shell

View File

@ -0,0 +1,84 @@
# Serval Project Swift language support
#
# SYNOPSIS
#
# AX_PROG_SWIFTC_IS_SWIFT4_1
#
# DESCRIPTION
#
# AX_PROG_SWIFTC_IS_SWIFT4_1 tests whether the Swift compiler in the SWIFTC
# variable (eg, as detected by the AX_PROG_SWIFTC macro) can compile a Swift
# 4.1 program to a working native executable, with the given SWIFTCFLAGS
# compiler options.
#
# LICENSE
#
# Copyright (C) 2017-2018 Flinders University
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
# scripts that are the output of Autoconf when processing the Macro. You
# need not follow the terms of the GNU General Public License when using
# or distributing such scripts, even though portions of the text of the
# Macro appear in them. The GNU General Public License (GPL) does govern
# all other use of the material that constitutes the Autoconf Macro.
#
# This special exception to the GPL applies to versions of the Autoconf
# Macro released by the Autoconf Archive. When you make and distribute a
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.
AU_ALIAS([AC_PROG_SWIFTC_IS_SWIFT4_1], [AX_PROG_SWIFTC_IS_SWIFT4_1])
AC_DEFUN([AX_PROG_SWIFTC_IS_SWIFT4_1],[
AC_REQUIRE([AX_TMPDIR_SWIFT])
AC_CACHE_CHECK([if $SWIFTC supports Swift 4.1], ac_cv_prog_swiftc_is_swift4_1, [
[
cat <<EOF > "$ax_tmpdir_swift/Test.swift"
/* canImport() was introduced in Swift 4.1 */
#if canImport(os)
import os
#endif
/* Substring was introduced in Swift 4 */
let a = "test"
let b : Substring = a[a.startIndex ... a.index(a.startIndex, offsetBy: 2)]
precondition(b == "tes")
/* Swift 2 uses Process.arguments, so this only compiles in Swift 3 and later */
print(CommandLine.arguments)
EOF
]
if AC_TRY_COMMAND($SWIFTC $SWIFTCFLAGS -emit-executable -o "$ax_tmpdir_swift/Test" "$ax_tmpdir_swift/Test.swift") >/dev/null 2>&1; then
if AC_TRY_COMMAND("$ax_tmpdir_swift/Test" one two three) > "$ax_tmpdir_swift/Test.out" 2>&1; then
ac_swift_test_out=`cat "$ax_tmpdir_swift/Test.out"`
if test "x$ac_swift_test_out" = ['x["'"$ax_tmpdir_swift"'/Test", "one", "two", "three"]']; then
ac_cv_prog_swiftc_is_swift4_1=yes
else
echo "incorrect output was: $ac_swift_test_out" >&AS_MESSAGE_LOG_FD
ac_cv_prog_swiftc_is_swift4_1=no
fi
else
echo "failed "$ax_tmpdir_swift/Test" execution produced output:" >&AS_MESSAGE_LOG_FD
cat "$ax_tmpdir_swift/Test.out" >&AS_MESSAGE_LOG_FD
ac_cv_prog_swiftc_is_swift4_1=no
fi
else
echo "compilation failed for:" >&AS_MESSAGE_LOG_FD
cat "$ax_tmpdir_swift/Test.swift" >&AS_MESSAGE_LOG_FD
ac_cv_prog_swiftc_is_swift4_1=no
fi
rm -f Test.swift Test Test.out
])
AC_PROVIDE([$0])dnl
])