-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-cmd.sh
190 lines (157 loc) · 7.04 KB
/
build-cmd.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env bash
# turn on verbose debugging output for parabuild logs.
exec 4>&1; export BASH_XTRACEFD=4; set -x
# make errors fatal
set -e
# complain about undefined vars
set -u
if [ -z "$AUTOBUILD" ] ; then
exit 1
fi
if [ "$OSTYPE" = "cygwin" ] ; then
autobuild="$(cygpath -u $AUTOBUILD)"
else
autobuild="$AUTOBUILD"
fi
top="$(dirname "$0")"
STAGING_DIR="$(pwd)"
# load autbuild provided shell functions and variables
source_environment_tempfile="$STAGING_DIR/source_environment.sh"
"$autobuild" source_environment > "$source_environment_tempfile"
. "$source_environment_tempfile"
DISCORD_SOURCE_DIR=discord_game_sdk
DISCORD_VERSION="3.2.1"
echo "${DISCORD_VERSION}" > "${STAGING_DIR}/VERSION.txt"
# Create staging dirs
mkdir -p "$STAGING_DIR/include/discord"
mkdir -p "$STAGING_DIR/lib/debug"
mkdir -p "$STAGING_DIR/lib/release"
pushd "$top/$DISCORD_SOURCE_DIR/cpp"
case "$AUTOBUILD_PLATFORM" in
windows*)
load_vsvars
mkdir -p "build_release"
pushd "build_release"
# Invoke cmake and use as official build
cmake -G "$AUTOBUILD_WIN_CMAKE_GEN" -A "$AUTOBUILD_WIN_VSPLATFORM" .. \
-DCMAKE_INSTALL_PREFIX="$(cygpath -m $STAGING_DIR)/release"
cmake --build . --config Release --clean-first
cmake --install . --config Release
# conditionally run unit tests
if [ "${DISABLE_UNIT_TESTS:-0}" = "0" ]; then
ctest -C Release
fi
cp -a Release/*.lib $STAGING_DIR/lib/release/
popd
# copy libs
cp -a ../lib/x86_64/*.lib $STAGING_DIR/lib/release/
cp -a ../lib/x86_64/*.dll $STAGING_DIR/lib/release/
# copy headers
cp -a *.h $STAGING_DIR/include/discord/
;;
darwin*)
# Setup build flags
C_OPTS_X86="-arch x86_64 $LL_BUILD_RELEASE_CFLAGS"
C_OPTS_ARM64="-arch arm64 $LL_BUILD_RELEASE_CFLAGS"
CXX_OPTS_X86="-arch x86_64 $LL_BUILD_RELEASE_CXXFLAGS"
CXX_OPTS_ARM64="-arch arm64 $LL_BUILD_RELEASE_CXXFLAGS"
LINK_OPTS_X86="-arch x86_64 $LL_BUILD_RELEASE_LINKER"
LINK_OPTS_ARM64="-arch arm64 $LL_BUILD_RELEASE_LINKER"
# deploy target
export MACOSX_DEPLOYMENT_TARGET=${LL_BUILD_DARWIN_BASE_DEPLOY_TARGET}
mkdir -p "build_release_x86"
pushd "build_release_x86"
CFLAGS="$C_OPTS_X86" \
CXXFLAGS="$CXX_OPTS_X86" \
LDFLAGS="$LINK_OPTS_X86" \
cmake .. -G Ninja \
-DCMAKE_BUILD_TYPE="Release" \
-DCMAKE_C_FLAGS="$C_OPTS_X86" \
-DCMAKE_CXX_FLAGS="$CXX_OPTS_X86" \
-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64 \
-DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET} \
-DCMAKE_MACOSX_RPATH=YES \
-DCMAKE_INSTALL_PREFIX="$STAGING_DIR/release_x86"
cmake --build . --config Release
popd
mkdir -p "build_release_arm64"
pushd "build_release_arm64"
CFLAGS="$C_OPTS_ARM64" \
CXXFLAGS="$CXX_OPTS_ARM64" \
LDFLAGS="$LINK_OPTS_ARM64" \
cmake .. -G Ninja \
-DCMAKE_BUILD_TYPE="Release" \
-DCMAKE_C_FLAGS="$C_OPTS_ARM64" \
-DCMAKE_CXX_FLAGS="$CXX_OPTS_ARM64" \
-DCMAKE_OSX_ARCHITECTURES:STRING=arm64 \
-DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET} \
-DCMAKE_MACOSX_RPATH=YES \
-DCMAKE_INSTALL_PREFIX="$STAGING_DIR/release_arm64"
cmake --build . --config Release
popd
# create fat libraries
lipo -create build_release_x86/libdiscordgamesdk.a build_release_arm64/libdiscordgamesdk.a -output ${STAGING_DIR}/lib/release/libdiscordgamesdk.a
cp -a ../lib/x86_64/*.dylib $STAGING_DIR/lib/release/
pushd $STAGING_DIR/lib/release/
install_name_tool -id "@rpath/discord_game_sdk.dylib" "discord_game_sdk.dylib"
popd
if [ -n "${AUTOBUILD_KEYCHAIN_PATH:=""}" -a -n "${AUTOBUILD_KEYCHAIN_ID:=""}" ]; then
for dylib in $STAGING_DIR/lib/*/discord_game_sdk*.dylib;
do
if [ -f "$dylib" ]; then
codesign --keychain "$AUTOBUILD_KEYCHAIN_PATH" --sign "$AUTOBUILD_KEYCHAIN_ID" --force --timestamp "$dylib"
fi
done
else
echo "Code signing not configured; skipping codesign."
fi
# copy headers
cp -a *.h $STAGING_DIR/include/discord/
;;
linux*)
# Linux build environment at Linden comes pre-polluted with stuff that can
# seriously damage 3rd-party builds. Environmental garbage you can expect
# includes:
#
# DISTCC_POTENTIAL_HOSTS arch root CXXFLAGS
# DISTCC_LOCATION top branch CC
# DISTCC_HOSTS build_name suffix CXX
# LSDISTCC_ARGS repo prefix CFLAGS
# cxx_version AUTOBUILD SIGN CPPFLAGS
#
# So, clear out bits that shouldn't affect our configure-directed build
# but which do nonetheless.
#
unset DISTCC_HOSTS CFLAGS CPPFLAGS CXXFLAGS
# Default target per --address-size
opts_c="${TARGET_OPTS:--m$AUTOBUILD_ADDRSIZE $LL_BUILD_RELEASE_CFLAGS}"
opts_cxx="${TARGET_OPTS:--m$AUTOBUILD_ADDRSIZE $LL_BUILD_RELEASE_CXXFLAGS}"
# Handle any deliberate platform targeting
if [ -z "${TARGET_CPPFLAGS:-}" ]; then
# Remove sysroot contamination from build environment
unset CPPFLAGS
else
# Incorporate special pre-processing flags
export CPPFLAGS="$TARGET_CPPFLAGS"
fi
mkdir -p "build_release"
pushd "build_release"
CFLAGS="$opts_c" \
cmake .. -GNinja -DBUILD_SHARED_LIBS:BOOL=OFF \
-DCMAKE_BUILD_TYPE="Release" \
-DCMAKE_CXX_STANDARD="17" \
-DCMAKE_C_FLAGS="$opts_c" \
-DCMAKE_CXX_FLAGS="$opts_cxx" \
-DCMAKE_INSTALL_PREFIX="$STAGING_DIR/release"
cmake --build . --config Release
cp -a libdiscordgamesdk.a $STAGING_DIR/lib/release/
popd
# copy libs
cp -a ../lib/x86_64/discord_game_sdk.so $STAGING_DIR/lib/release/libdiscord_game_sdk.so
# copy headers
cp -a *.h $STAGING_DIR/include/discord/
;;
esac
mkdir -p "$STAGING_DIR/LICENSES"
touch "$STAGING_DIR/LICENSES/discord-gamesdk.txt"
popd