Skip to content

Commit d39af6f

Browse files
authored
Merge pull request #17 from bandi13/IDE-XCODE
Add in XCode support
2 parents 4c74197 + 7f39fb0 commit d39af6f

11 files changed

Lines changed: 404 additions & 10 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
# Installed dependencies
5656
/openssl*
5757
/wolfssl*
58+
/artifacts
5859

5960
IDE/Android/android-ndk-r26b/
6061
IDE/Android/openssl-source/

IDE/XCODE/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This example will create the artifacts necessary for building applications using XCODE. It consists of 3 parts:
2+
- Building OpenSSL (build-openssl-framework.sh)
3+
- Building WolfSSL (build-wolfssl-framework.sh)
4+
- Building WolfProvider (build-wolfprovider-framework.sh)
5+
6+
Using the `build-all.sh` script it will invoke all the required steps with the necessary dependencies. Once the artifacts are created in each of the respective source directories the `run_openssl.sh` script can be used to run a few simple tests of libwolfprov with the specific version of OpenSSL. Most of the examples use `libwolfprov.so/dll/dylib` so we do a simple trick to create a symbolic link that has the proper filename.

IDE/XCODE/build-all.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
set -e # Fail on any error
4+
5+
XCODE_SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
6+
WOLFPROV_DIR=${XCODE_SCRIPTS_DIR}/../..
7+
SCRIPT_DIR=${WOLFPROV_DIR}/scripts
8+
OUTDIR=${WOLFPROV_DIR}/artifacts
9+
LOG_FILE=${OUTDIR}/wolfProvider.log
10+
11+
source ${SCRIPT_DIR}/utils-openssl.sh
12+
source ${SCRIPT_DIR}/utils-wolfssl.sh
13+
14+
mkdir -p ${OUTDIR}
15+
16+
clone_openssl
17+
cd ${WOLFPROV_DIR}/openssl-source && ${XCODE_SCRIPTS_DIR}/build-openssl-framework.sh
18+
19+
clone_wolfssl
20+
cd ${WOLFPROV_DIR}/wolfssl-source && ${XCODE_SCRIPTS_DIR}/build-wolfssl-framework.sh -c "--enable-opensslcoexist --enable-cmac --enable-keygen --enable-sha --enable-aesctr --enable-aesccm --enable-x963kdf --enable-compkey --enable-certgen --enable-aeskeywrap --enable-enckeys --enable-base16 --enable-aesgcm-stream --enable-pwdbased" -p "-I${OPENSSL_SOURCE_DIR} -DHAVE_AES_ECB -DWOLFSSL_AES_DIRECT -DWC_RSA_NO_PADDING -DWOLFSSL_PUBLIC_MP -DECC_MIN_KEY_SZ=192 -DHAVE_PUBLIC_FFDHE -DHAVE_FFDHE_6144 -DHAVE_FFDHE_8192 -DFP_MAX_BITS=16384 -DWOLFSSL_DH_EXTRA -DWOLFSSL_PSS_LONG_SALT -DWOLFSSL_PSS_SALT_LEN_DISCOVER"
21+
22+
cd ${WOLFPROV_DIR} && ${XCODE_SCRIPTS_DIR}/build-wolfprovider-framework.sh
23+
24+
clang ${WOLFPROV_DIR}/examples/openssl_example.c -I ${WOLFPROV_DIR}/openssl-source/artifacts/xcframework/libopenssl.xcframework/macos-arm64_x86_64/Headers -L ${WOLFPROV_DIR}/openssl-source/artifacts/xcframework/libopenssl.xcframework/macos-arm64_x86_64/ -lcrypto -o ${WOLFPROV_DIR}/artifacts/openssl_example
25+
26+
echo "Script ran for $SECONDS seconds"
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/bin/bash
2+
3+
# build-openssl-framework.sh
4+
#
5+
# Copyright (C) 2006-2023 wolfSSL Inc.
6+
#
7+
# This file is part of wolfSSL.
8+
#
9+
# wolfSSL is free software; you can redistribute it and/or modify
10+
# it under the terms of the GNU General Public License as published by
11+
# the Free Software Foundation; either version 2 of the License, or
12+
# (at your option) any later version.
13+
#
14+
# wolfSSL is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# along with this program; if not, write to the Free Software
21+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
22+
23+
set -euo pipefail
24+
25+
WOLFSSL_DIR=$(pwd)
26+
OUTDIR=$(pwd)/artifacts
27+
LIPODIR=${OUTDIR}/lib
28+
SDK_OUTPUT_DIR=${OUTDIR}/xcframework
29+
30+
CFLAGS_COMMON=""
31+
# Base configure flags
32+
CONF_OPTS=""
33+
34+
helpFunction()
35+
{
36+
echo ""
37+
echo "Usage: $0 [-c <config flags>]"
38+
echo -e "\t-c Extra flags to be passed to ./configure"
39+
exit 1 # Exit script after printing help
40+
}
41+
42+
# Parse command line arguments
43+
while getopts ":c:" opt; do
44+
case $opt in
45+
c)
46+
CONF_OPTS+=" $OPTARG"
47+
;;
48+
\?)
49+
echo "Invalid option: -$OPTARG" >&2; helpFunction
50+
;;
51+
esac
52+
done
53+
54+
mkdir -p $LIPODIR
55+
mkdir -p $SDK_OUTPUT_DIR
56+
57+
build() { # <ARCH=arm64|x86_64> <TYPE=iphonesimulator|iphoneos|macosx|watchos|watchsimulator|appletvos|appletvsimulator>
58+
set -x
59+
pushd .
60+
61+
ARCH=$1
62+
HOST="${ARCH}-apple-darwin"
63+
TYPE=$2
64+
SDK_ROOT=$(xcrun --sdk ${TYPE} --show-sdk-path)
65+
TARGET="darwin64-${ARCH}-cc"
66+
67+
mkdir -p ${OUTDIR}/${TYPE}-${ARCH} && cd ${OUTDIR}/${TYPE}-${ARCH}
68+
69+
CC="clang" CXX="clang" CFLAGS="${CFLAGS_COMMON} -Os -arch ${ARCH} -isysroot ${SDK_ROOT}" LDFLAGS="-arch ${ARCH} -isysroot ${SDK_ROOT}" ${WOLFSSL_DIR}/Configure no-asm ${TARGET} --prefix=${OUTDIR}/openssl-install-${TYPE}-${ARCH} ${CONF_OPTS}
70+
make -j
71+
make install
72+
73+
popd
74+
set +x
75+
}
76+
77+
XCFRAMEWORKS=
78+
for type in iphonesimulator macosx ; do
79+
build arm64 ${type}
80+
build x86_64 ${type}
81+
82+
# Create universal binaries from architecture-specific static libraries
83+
lipo \
84+
"$OUTDIR/openssl-install-${type}-x86_64/lib/libssl.a" \
85+
"$OUTDIR/openssl-install-${type}-arm64/lib/libssl.a" \
86+
-create -output $LIPODIR/libopenssl-${type}.a
87+
88+
echo "Checking libraries"
89+
xcrun -sdk ${type} lipo -info $LIPODIR/libopenssl-${type}.a
90+
XCFRAMEWORKS+=" -library ${LIPODIR}/libopenssl-${type}.a -headers ${OUTDIR}/openssl-install-${type}-arm64/include"
91+
done
92+
93+
for type in iphoneos ; do
94+
build arm64 ${type}
95+
96+
# Create universal binaries from architecture-specific static libraries
97+
lipo \
98+
"$OUTDIR/openssl-install-${type}-arm64/lib/libssl.a" \
99+
-create -output $LIPODIR/libopenssl-${type}.a
100+
101+
echo "Checking libraries"
102+
xcrun -sdk ${type} lipo -info $LIPODIR/libopenssl-${type}.a
103+
XCFRAMEWORKS+=" -library ${LIPODIR}/libopenssl-${type}.a -headers ${OUTDIR}/openssl-install-${type}-arm64/include"
104+
done
105+
106+
############################################################################################################################################
107+
# ********** BUILD FRAMEWORK
108+
############################################################################################################################################
109+
110+
xcodebuild -create-xcframework ${XCFRAMEWORKS} -output ${SDK_OUTPUT_DIR}/libopenssl.xcframework
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/bash
2+
3+
# build-wolfprov-framework.sh
4+
#
5+
# Copyright (C) 2006-2023 wolfSSL Inc.
6+
#
7+
# This file is part of wolfSSL.
8+
#
9+
# wolfSSL is free software; you can redistribute it and/or modify
10+
# it under the terms of the GNU General Public License as published by
11+
# the Free Software Foundation; either version 2 of the License, or
12+
# (at your option) any later version.
13+
#
14+
# wolfSSL is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# along with this program; if not, write to the Free Software
21+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
22+
23+
set -euo pipefail
24+
25+
WOLFPROV_DIR=$(pwd)
26+
OUTDIR=$(pwd)/artifacts
27+
LIPODIR=${OUTDIR}/lib
28+
SDK_OUTPUT_DIR=${OUTDIR}/xcframework
29+
30+
CFLAGS_COMMON=""
31+
# Base configure flags
32+
CONF_OPTS=""
33+
34+
helpFunction()
35+
{
36+
echo ""
37+
echo "Usage: $0 [-c <config flags>]"
38+
echo -e "\t-c Extra flags to be passed to ./configure"
39+
exit 1 # Exit script after printing help
40+
}
41+
42+
# Parse command line arguments
43+
while getopts ":c:" opt; do
44+
case $opt in
45+
c)
46+
CONF_OPTS+=" $OPTARG"
47+
;;
48+
\?)
49+
echo "Invalid option: -$OPTARG" >&2; helpFunction
50+
;;
51+
esac
52+
done
53+
54+
mkdir -p $LIPODIR
55+
mkdir -p $SDK_OUTPUT_DIR
56+
cd $WOLFPROV_DIR && ./autogen.sh
57+
58+
build() { # <ARCH=arm64|x86_64> <TYPE=iphonesimulator|iphoneos|macosx|watchos|watchsimulator|appletvos|appletvsimulator>
59+
set -x
60+
pushd .
61+
cd $WOLFPROV_DIR
62+
63+
ARCH=$1
64+
HOST="${ARCH}-apple-darwin"
65+
TYPE=$2
66+
SDK_ROOT=$(xcrun --sdk ${TYPE} --show-sdk-path)
67+
68+
./configure -prefix=${OUTDIR}/wolfprov-${TYPE}-${ARCH} ${CONF_OPTS} --host=${HOST} \
69+
--with-openssl=${WOLFPROV_DIR}/openssl-source/artifacts/openssl-install-${TYPE}-${ARCH} \
70+
--with-wolfssl=${WOLFPROV_DIR}/wolfssl-source/artifacts/wolfssl-install-${TYPE}-${ARCH} \
71+
CFLAGS="${CFLAGS_COMMON} -arch ${ARCH} -isysroot ${SDK_ROOT}" \
72+
LDFLAGS="-framework CoreFoundation -framework Security"
73+
make -j
74+
make install
75+
76+
popd
77+
set +x
78+
}
79+
80+
XCFRAMEWORKS=
81+
for type in iphonesimulator macosx ; do
82+
build arm64 ${type}
83+
build x86_64 ${type}
84+
85+
# Create universal binaries from architecture-specific static libraries
86+
lipo \
87+
"$OUTDIR/wolfprov-${type}-x86_64/lib/libwolfprov.dylib" \
88+
"$OUTDIR/wolfprov-${type}-arm64/lib/libwolfprov.dylib" \
89+
-create -output $LIPODIR/libwolfprov-${type}.dylib
90+
91+
echo "Checking libraries"
92+
xcrun -sdk ${type} lipo -info $LIPODIR/libwolfprov-${type}.dylib
93+
XCFRAMEWORKS+=" -library ${LIPODIR}/libwolfprov-${type}.dylib"
94+
done
95+
96+
for type in iphoneos ; do
97+
build arm64 ${type}
98+
99+
# Create universal binaries from architecture-specific static libraries
100+
lipo \
101+
"$OUTDIR/wolfprov-${type}-arm64/lib/libwolfprov.dylib" \
102+
-create -output $LIPODIR/libwolfprov-${type}.dylib
103+
104+
echo "Checking libraries"
105+
xcrun -sdk ${type} lipo -info $LIPODIR/libwolfprov-${type}.dylib
106+
XCFRAMEWORKS+=" -library ${LIPODIR}/libwolfprov-${type}.dylib"
107+
done
108+
109+
############################################################################################################################################
110+
# ********** BUILD FRAMEWORK
111+
############################################################################################################################################
112+
113+
xcodebuild -create-xcframework ${XCFRAMEWORKS} -headers ${WOLFPROV_DIR}/include -output ${SDK_OUTPUT_DIR}/libwolfprov.xcframework
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/bin/bash
2+
3+
# build-wolfssl-framework.sh
4+
#
5+
# Copyright (C) 2006-2023 wolfSSL Inc.
6+
#
7+
# This file is part of wolfSSL.
8+
#
9+
# wolfSSL is free software; you can redistribute it and/or modify
10+
# it under the terms of the GNU General Public License as published by
11+
# the Free Software Foundation; either version 2 of the License, or
12+
# (at your option) any later version.
13+
#
14+
# wolfSSL is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# along with this program; if not, write to the Free Software
21+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
22+
23+
set -euo pipefail
24+
25+
WOLFSSL_DIR=$(pwd)
26+
OUTDIR=$(pwd)/artifacts
27+
LIPODIR=${OUTDIR}/lib
28+
SDK_OUTPUT_DIR=${OUTDIR}/xcframework
29+
30+
CFLAGS_COMMON=""
31+
CPPFLAGS_COMMON=""
32+
# Base configure flags
33+
CONF_OPTS="--disable-shared --enable-static"
34+
35+
helpFunction()
36+
{
37+
echo ""
38+
echo "Usage: $0 [-c <config flags>]"
39+
echo -e "\t-c Extra flags to be passed to ./configure"
40+
exit 1 # Exit script after printing help
41+
}
42+
43+
# Parse command line arguments
44+
while getopts ":c:p:" opt; do
45+
case $opt in
46+
c)
47+
CONF_OPTS+=" $OPTARG"
48+
;;
49+
p)
50+
CPPFLAGS_COMMON+=" $OPTARG"
51+
;;
52+
\?)
53+
echo "Invalid option: -$OPTARG" >&2; helpFunction
54+
;;
55+
esac
56+
done
57+
58+
mkdir -p $LIPODIR
59+
mkdir -p $SDK_OUTPUT_DIR
60+
cd $WOLFSSL_DIR && ./autogen.sh
61+
62+
build() { # <ARCH=arm64|x86_64> <TYPE=iphonesimulator|iphoneos|macosx|watchos|watchsimulator|appletvos|appletvsimulator>
63+
set -x
64+
pushd .
65+
cd $WOLFSSL_DIR
66+
67+
ARCH=$1
68+
HOST="${ARCH}-apple-darwin"
69+
TYPE=$2
70+
SDK_ROOT=$(xcrun --sdk ${TYPE} --show-sdk-path)
71+
72+
./configure -prefix=${OUTDIR}/wolfssl-install-${TYPE}-${ARCH} ${CONF_OPTS} --host=${HOST} \
73+
CFLAGS="${CFLAGS_COMMON} -arch ${ARCH} -isysroot ${SDK_ROOT}" CPPFLAGS="${CPPFLAGS_COMMON}"
74+
make
75+
make install
76+
77+
popd
78+
set +x
79+
}
80+
81+
XCFRAMEWORKS=
82+
for type in iphonesimulator macosx ; do
83+
build arm64 ${type}
84+
build x86_64 ${type}
85+
86+
# Create universal binaries from architecture-specific static libraries
87+
lipo \
88+
"$OUTDIR/wolfssl-install-${type}-x86_64/lib/libwolfssl.a" \
89+
"$OUTDIR/wolfssl-install-${type}-arm64/lib/libwolfssl.a" \
90+
-create -output $LIPODIR/libwolfssl-${type}.a
91+
92+
echo "Checking libraries"
93+
xcrun -sdk ${type} lipo -info $LIPODIR/libwolfssl-${type}.a
94+
XCFRAMEWORKS+=" -library ${LIPODIR}/libwolfssl-${type}.a -headers ${OUTDIR}/wolfssl-install-${type}-arm64/include"
95+
done
96+
97+
for type in iphoneos ; do
98+
build arm64 ${type}
99+
100+
# Create universal binaries from architecture-specific static libraries
101+
lipo \
102+
"$OUTDIR/wolfssl-install-${type}-arm64/lib/libwolfssl.a" \
103+
-create -output $LIPODIR/libwolfssl-${type}.a
104+
105+
echo "Checking libraries"
106+
xcrun -sdk ${type} lipo -info $LIPODIR/libwolfssl-${type}.a
107+
XCFRAMEWORKS+=" -library ${LIPODIR}/libwolfssl-${type}.a -headers ${OUTDIR}/wolfssl-install-${type}-arm64/include"
108+
done
109+
110+
############################################################################################################################################
111+
# ********** BUILD FRAMEWORK
112+
############################################################################################################################################
113+
114+
xcodebuild -create-xcframework ${XCFRAMEWORKS} -output ${SDK_OUTPUT_DIR}/libwolfssl.xcframework

0 commit comments

Comments
 (0)