Skip to content

Commit

Permalink
added "-c" command line option to allow passing extra configure flags…
Browse files Browse the repository at this point in the history
…, removed curl and harden default options, updated documentation
  • Loading branch information
bigbrett committed Jul 17, 2023
1 parent d1db78a commit 425cd2c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 10 deletions.
11 changes: 11 additions & 0 deletions IDE/apple-universal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ This example consists of a build script and an Xcode example project. The build
## The build script
`build-wolfssl-framework.sh` compiles wolfSSL as static library for all modern Apple platforms and simulators. This includes MacOS (`arm64`,`x86_64`), iPhone (`arm64`), iPhoneSimulator (`arm64`,`x86_64`), appleTV (`arm64`), appleTVSimulator (`arm64`,`x86_64`), appleWatch (`arm64`), and appleWatchSimulator (`arm64`,`x86_64`). The script compiles wolfSSL for each platform, creates universal binaries for platforms that support multiple architectures (macOS and simulators) using [lipo](https://developer.apple.com/documentation/apple-silicon/building-a-universal-macos-binary), then combines all the static libraries together into an `xcframework` that can be imported into Xcode. It is meant to be used as an example rather than a build tool, and chooses simplicity and readability over flexibility (no command line options). For an explanation of how the script cross compiles wolfSSL, see the [Technical Details](technical-details) section.

To use the build script, you can run it without arguments to build a default configuration, or you can use the `-c` option to pass in a quoted string containing any additional flags to `configure` that you need. Note that `--enable-static --disable-shared` is always passed to `configure` by default. Consider the following usage example, with descriptions in the comments:

```
# default configuration
./build-wolfssl-framework.sh
# hardened configuration with curl support and FIPS-ready crypto
./build-wolfssl-framework.sh -c "--enable-harden --enable-curl --enable-fips=ready"
```

## Example project
`wolfssl-multiplatform` is an xcode project containing a simple swiftUI "hello world" app that has been modified to run the wolfCrypt tests and establish a TLS connection to `www.wolfssl.com` on startup. It also provides an example for basic Swift/C interoperability using a "bridging header". When the app launches, the swiftUI initialization handler calls a C test driver function, which is responsible for running the wolfSSL examples. An overview of the additional files is as follows:

Expand Down
58 changes: 48 additions & 10 deletions IDE/apple-universal/build-wolfssl-framework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,42 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA


set -euxo pipefail
set -euo pipefail

WOLFSSL_DIR=$(pwd)/../../
OUTDIR=$(pwd)/artifacts
LIPODIR=${OUTDIR}/lib
SDK_OUTPUT_DIR=${OUTDIR}/xcframework


ENABLE_FIPS="no"
CFLAGS_COMMON=""
CONF_OPTS_COMMON="--disable-shared --enable-static --enable-curl --enable-harden --enable-fips=${ENABLE_FIPS}"
# Optional configure flags passed in by user through -c argument
CONF_OPTS_EXTRA=""
# Base configure flags
CONF_OPTS_COMMON="--disable-shared --enable-static"

helpFunction()
{
echo ""
echo "Usage: $0 [-c <config flags>]"
echo -e "\t-c Extra flags to be passed to ./configure"
exit 1 # Exit script after printing help
}

# Parse command line arguments
while getopts ":c:" opt; do
case $opt in
c)
CONF_OPTS_EXTRA="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2; helpFunction
;;
esac
done

# Amalgamate extra CLI options with base options
CONF_OPTS="${CONF_OPTS_COMMON} ${CONF_OPTS_EXTRA}"

rm -rf $OUTDIR
mkdir -p $LIPODIR
Expand All @@ -41,121 +65,135 @@ mkdir -p $SDK_OUTPUT_DIR

buildIOSSim()
{
set -x
pushd .
cd $WOLFSSL_DIR

ARCH=$1
HOST="${ARCH}-apple-darwin"
SDK_ROOT=$(xcrun --sdk iphonesimulator --show-sdk-path)

./configure -prefix=${OUTDIR}/wolfssl-ios-simulator-${ARCH} ${CONF_OPTS_COMMON} --host=${HOST} \
./configure -prefix=${OUTDIR}/wolfssl-ios-simulator-${ARCH} ${CONF_OPTS} --host=${HOST} \
CFLAGS="${CFLAGS_COMMON} -arch ${ARCH} -isysroot ${SDK_ROOT}"
make -j
make install

popd
set +x
}

buildIOS()
{
set -x
pushd .
cd $WOLFSSL_DIR

ARCH=$1
HOST="${ARCH}-apple-darwin"
SDK_ROOT=$(xcrun --sdk iphoneos --show-sdk-path)

./configure -prefix=${OUTDIR}/wolfssl-ios-${ARCH} ${CONF_OPTS_COMMON} --host=${HOST} \
./configure -prefix=${OUTDIR}/wolfssl-ios-${ARCH} ${CONF_OPTS} --host=${HOST} \
CFLAGS="${CFLAGS_COMMON} -arch ${ARCH} -isysroot ${SDK_ROOT}"
make -j
make install

popd
set +x
}

buildMacOS()
{
set -x
pushd .
cd $WOLFSSL_DIR

ARCH=$1
HOST="${ARCH}-apple-darwin"
SDK_ROOT=$(xcrun --sdk macosx --show-sdk-path)

./configure -prefix=${OUTDIR}/wolfssl-macos-${ARCH} ${CONF_OPTS_COMMON} --host=${HOST} \
./configure -prefix=${OUTDIR}/wolfssl-macos-${ARCH} ${CONF_OPTS} --host=${HOST} \
CFLAGS="${CFLAGS_COMMON} -arch ${ARCH} -isysroot ${SDK_ROOT}"
make -j
make install

popd
set +x
}

buildWatchOS()
{
set -x
pushd .
cd $WOLFSSL_DIR

ARCH=$1
HOST="${ARCH}-apple-darwin"
SDK_ROOT=$(xcrun --sdk watchos --show-sdk-path)

./configure -prefix=${OUTDIR}/wolfssl-watchos-${ARCH} ${CONF_OPTS_COMMON} --host=${HOST} \
./configure -prefix=${OUTDIR}/wolfssl-watchos-${ARCH} ${CONF_OPTS} --host=${HOST} \
CFLAGS="${CFLAGS_COMMON} -arch ${ARCH} -isysroot ${SDK_ROOT}"
make -j
make install

popd
set +x
}

buildWatchOSSim()
{
set -x
pushd .
cd $WOLFSSL_DIR

ARCH=$1
HOST="${ARCH}-apple-darwin"
SDK_ROOT=$(xcrun --sdk watchsimulator --show-sdk-path)

./configure -prefix=${OUTDIR}/wolfssl-watchos-simulator-${ARCH} ${CONF_OPTS_COMMON} --host=${HOST} \
./configure -prefix=${OUTDIR}/wolfssl-watchos-simulator-${ARCH} ${CONF_OPTS} --host=${HOST} \
CFLAGS="${CFLAGS_COMMON} -arch ${ARCH} -isysroot ${SDK_ROOT}"
make -j
make install

popd
set +x
}

buildTVOS()
{
set -x
pushd .
cd $WOLFSSL_DIR

ARCH=arm64
HOST="${ARCH}-apple-darwin"
SDK_ROOT=$(xcrun --sdk appletvos --show-sdk-path)

./configure -prefix=${OUTDIR}/wolfssl-tvos-${ARCH} ${CONF_OPTS_COMMON} --host=${HOST} \
./configure -prefix=${OUTDIR}/wolfssl-tvos-${ARCH} ${CONF_OPTS} --host=${HOST} \
CFLAGS="${CFLAGS_COMMON} -arch ${ARCH} -isysroot ${SDK_ROOT}"
make -j
make install

popd
set +x
}

buildTVOSSim()
{
set -x
pushd .
cd $WOLFSSL_DIR

ARCH=$1
HOST="${ARCH}-apple-darwin"
SDK_ROOT=$(xcrun --sdk appletvsimulator --show-sdk-path)

./configure -prefix=${OUTDIR}/wolfssl-tvos-simulator-${ARCH} ${CONF_OPTS_COMMON} --host=${HOST} \
./configure -prefix=${OUTDIR}/wolfssl-tvos-simulator-${ARCH} ${CONF_OPTS} --host=${HOST} \
CFLAGS="${CFLAGS_COMMON} -arch ${ARCH} -isysroot ${SDK_ROOT}"
make -j
make install

popd
set +x
}

buildCatalyst()
Expand Down

0 comments on commit 425cd2c

Please sign in to comment.