-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
build-native.sh
executable file
·177 lines (158 loc) · 6.75 KB
/
build-native.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
#!/usr/bin/env bash
usage_list=("-outconfig: Configuration, typically a quadruplet such as 'net8.0-linux-Release-x64', used to name output directory.")
usage_list+=("-staticLibLink: Optional argument to statically link any native library.")
__scriptpath="$(cd "$(dirname "$0")"; pwd -P)"
__nativeroot="$__scriptpath"
__RepoRootDir="$(cd "$__scriptpath"/../../..; pwd -P)"
__artifactsDir="$__RepoRootDir/artifacts"
handle_arguments() {
case "$1" in
outconfig|-outconfig)
__outConfig="$2"
__ShiftArgs=1
;;
icudir|-icudir)
__icuDir="$2"
__ShiftArgs=1
;;
usepthreads|-usepthreads)
__usePThreads=1
;;
staticliblink|-staticliblink)
__StaticLibLink=1
;;
*)
__UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
esac
}
# Set the various build properties here so that CMake and MSBuild can pick them up
__TargetArch=x64
__TargetOS=linux
__BuildType=Debug
__CMakeArgs=""
__Compiler=clang
__CrossBuild=0
__PortableBuild=1
__RootBinDir="$__RepoRootDir/artifacts"
__SkipConfigure=0
__StaticLibLink=0
__UnprocessedBuildArgs=
__VerboseBuild=false
__icuDir=""
__usePThreads=0
source "$__RepoRootDir"/eng/native/build-commons.sh
# Set cross build
if [[ "$__TargetOS" == browser ]]; then
if [[ -z "$EMSDK_PATH" ]]; then
if [[ -d "$__RepoRootDir"/src/mono/browser/emsdk/ ]]; then
export EMSDK_PATH="$__RepoRootDir"/src/mono/browser/emsdk/
else
echo "Error: You need to set the EMSDK_PATH environment variable pointing to the emscripten SDK root."
exit 1
fi
fi
source "$EMSDK_PATH"/emsdk_env.sh
export CLR_CC=$(which emcc)
elif [[ "$__TargetOS" == wasi ]]; then
if [[ -z "$WASI_SDK_PATH" ]]; then
if [[ -d "$__RepoRootDir"/src/mono/wasi/wasi-sdk ]]; then
export WASI_SDK_PATH="$__RepoRootDir"/src/mono/wasi/wasi-sdk
else
echo "Error: You need to set the WASI_SDK_PATH environment variable pointing to the WASI SDK root."
exit 1
fi
fi
export WASI_SDK_PATH="${WASI_SDK_PATH%/}/"
export CLR_CC="$WASI_SDK_PATH"bin/clang
export TARGET_BUILD_ARCH=wasm
__CMakeArgs="-DCLR_CMAKE_TARGET_OS=wasi -DCLR_CMAKE_TARGET_ARCH=wasm -DWASI_SDK_PREFIX=$WASI_SDK_PATH -DCMAKE_TOOLCHAIN_FILE=${__RepoRootDir}/src/native/external/wasi-sdk-p2.cmake $__CMakeArgs"
elif [[ "$__TargetOS" == ios || "$__TargetOS" == iossimulator ]]; then
# nothing to do here
true
elif [[ "$__TargetOS" == tvos || "$__TargetOS" == tvossimulator ]]; then
# nothing to do here
true
elif [[ "$__TargetOS" == android && -z "$ROOTFS_DIR" ]]; then
# nothing to do here
true
else
__CMakeArgs="-DFEATURE_DISTRO_AGNOSTIC_SSL=$__PortableBuild $__CMakeArgs"
__CMakeArgs="-DCMAKE_STATIC_LIB_LINK=$__StaticLibLink $__CMakeArgs"
if [[ "$__TargetOS" != linux-bionic && "$__TargetArch" != x86 && "$__TargetArch" != x64 && "$__TargetArch" != "$__HostArch" ]]; then
__CrossBuild=1
echo "Set CrossBuild for $__TargetArch build"
fi
fi
if [[ "$__TargetOS" == android && -z "$ROOTFS_DIR" ]]; then
# Android SDK defaults to c++_static; we only need C support
__CMakeArgs="-DANDROID_STL=none $__CMakeArgs"
elif [[ "$__TargetOS" == linux-bionic && -z "$ROOTFS_DIR" ]]; then
# Android SDK defaults to c++_static; we only need C support
__CMakeArgs="-DFORCE_ANDROID_OPENSSL=1 -DANDROID_STL=none -DANDROID_FORCE_ICU_DATA_DIR=1 $__CMakeArgs"
elif [[ "$__TargetOS" == iossimulator ]]; then
# set default iOS simulator deployment target
# keep in sync with SetOSTargetMinVersions in the root Directory.Build.props
__CMakeArgs="-DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_DEPLOYMENT_TARGET=12.2 $__CMakeArgs"
if [[ "$__TargetArch" == x64 ]]; then
__CMakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"x86_64\" $__CMakeArgs"
elif [[ "$__TargetArch" == x86 ]]; then
__CMakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"i386\" $__CMakeArgs"
elif [[ "$__TargetArch" == arm64 ]]; then
__CMakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"arm64\" $__CMakeArgs"
else
echo "Error: Unknown iOS Simulator architecture $__TargetArch."
exit 1
fi
elif [[ "$__TargetOS" == ios ]]; then
# set default iOS device deployment target
# keep in sync with SetOSTargetMinVersions in the root Directory.Build.props
__CMakeArgs="-DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_DEPLOYMENT_TARGET=12.2 $__CMakeArgs"
if [[ "$__TargetArch" == arm64 ]]; then
__CMakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"arm64\" $__CMakeArgs"
elif [[ "$__TargetArch" == arm ]]; then
__CMakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"armv7;armv7s\" $__CMakeArgs"
else
echo "Error: Unknown iOS architecture $__TargetArch."
exit 1
fi
elif [[ "$__TargetOS" == tvossimulator ]]; then
# set default tvOS simulator deployment target
# keep in sync with SetOSTargetMinVersions in the root Directory.Build.props
__CMakeArgs="-DCMAKE_SYSTEM_NAME=tvOS -DCMAKE_OSX_SYSROOT=appletvsimulator -DCMAKE_OSX_DEPLOYMENT_TARGET=12.2 $__CMakeArgs"
if [[ "$__TargetArch" == x64 ]]; then
__CMakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"x86_64\" $__CMakeArgs"
elif [[ "$__TargetArch" == arm64 ]]; then
__CMakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"arm64\" $__CMakeArgs"
else
echo "Error: Unknown tvOS Simulator architecture $__TargetArch."
exit 1
fi
elif [[ "$__TargetOS" == tvos ]]; then
# set default tvOS device deployment target
# keep in sync with the root Directory.Build.props
__CMakeArgs="-DCMAKE_SYSTEM_NAME=tvOS -DCMAKE_OSX_SYSROOT=appletvos -DCMAKE_OSX_DEPLOYMENT_TARGET=12.2 $__CMakeArgs"
if [[ "$__TargetArch" == arm64 ]]; then
__CMakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"arm64\" $__CMakeArgs"
else
echo "Error: Unknown tvOS architecture $__TargetArch."
exit 1
fi
fi
if [[ -n "$__icuDir" ]]; then
__CMakeArgs="-DCMAKE_ICU_DIR=\"$__icuDir\" $__CMakeArgs"
fi
__CMakeArgs="-DCMAKE_USE_PTHREADS=$__usePThreads $__CMakeArgs"
# Set the remaining variables based upon the determined build configuration
__outConfig="${__outConfig:-"$__TargetOS-$__TargetArch-$__BuildType"}"
__IntermediatesDir="$__RootBinDir/obj/native/$__outConfig"
__BinDir="$__RootBinDir/bin/native/$__outConfig"
# Specify path to be set for CMAKE_INSTALL_PREFIX.
# This is where all built CoreClr libraries will copied to.
__CMakeBinDir="$__BinDir"
export __CMakeBinDir
# Make the directories necessary for build if they don't exist
setup_dirs
# Check prereqs.
check_prereqs
# Build the corefx native components.
build_native "$__TargetOS" "$__TargetArch" "$__nativeroot" "$__IntermediatesDir" "install" "$__CMakeArgs" "native libraries component"