5 source "$__RepoRootDir/eng/native/init-distro-rid.sh"
7 local passedRootfsDir=""
9 # Only pass ROOTFS_DIR if cross is specified.
10 if [[ "$__CrossBuild" == 1 ]]; then
11 passedRootfsDir="$ROOTFS_DIR"
14 initDistroRidGlobal "$__TargetOS" "$__BuildArch" "$__PortableBuild" "$passedRootfsDir"
17 isMSBuildOnNETCoreSupported()
19 __IsMSBuildOnNETCoreSupported="$__msbuildonunsupportedplatform"
21 if [[ "$__IsMSBuildOnNETCoreSupported" == 1 ]]; then
25 if [[ "$__SkipManaged" == 1 ]]; then
26 __IsMSBuildOnNETCoreSupported=0
30 if [[ ( "$__HostOS" == "Linux" ) && ( "$__HostArch" == "x64" || "$__HostArch" == "arm" || "$__HostArch" == "armel" || "$__HostArch" == "arm64" ) ]]; then
31 __IsMSBuildOnNETCoreSupported=1
32 elif [[ ( "$__HostOS" == "OSX" || "$__HostOS" == "FreeBSD" ) && "$__HostArch" == "x64" ]]; then
33 __IsMSBuildOnNETCoreSupported=1
39 echo Setting up directories for build
41 mkdir -p "$__RootBinDir"
43 mkdir -p "$__IntermediatesDir"
46 # Check the system to ensure the right prereqs are in place
49 echo "Checking prerequisites..."
51 # Check presence of CMake on the path
52 command -v cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
54 function version { echo "$@" | awk -F. '{ printf("%d%02d%02d\n", $1,$2,$3); }'; }
56 local cmake_version="$(cmake --version | awk '/^cmake version [0-9]+\.[0-9]+\.[0-9]+$/ {print $3}')"
58 if [[ "$(version "$cmake_version")" -lt "$(version 3.14.2)" ]]; then
59 echo "Please install CMake 3.14.2 or newer from http://www.cmake.org/download/ or https://apt.kitware.com and ensure it is on your path."; exit 1;
62 if [[ "$__UseNinja" == 1 ]]; then
63 command -v ninja 2>/dev/null || command -v ninja-build 2>/dev/null || { echo "Unable to locate ninja!"; exit 1; }
75 # All set to commence the build
76 echo "Commencing build of \"$message\" for $__TargetOS.$__BuildArch.$__BuildType in $intermediatesDir"
78 if [[ "$__UseNinja" == 1 ]]; then
80 buildTool="$(command -v ninja || command -v ninja-build)"
85 if [[ "$__SkipConfigure" == 0 ]]; then
86 # if msbuild is not supported, then set __SkipGenerateVersion to 1
87 if [[ "$__IsMSBuildOnNETCoreSupported" == 0 ]]; then __SkipGenerateVersion=1; fi
89 __versionSourceFile="$intermediatesDir/version.c"
91 if [[ ! -z "${__LogsDir}" ]]; then
92 __binlogArg="-bl:\"$__LogsDir/GenNativeVersion_$__TargetOS.$__BuildArch.$__BuildType.binlog\""
95 if [[ "$__SkipGenerateVersion" == 0 ]]; then
96 "$__RepoRootDir/eng/common/msbuild.sh" /clp:nosummary "$__ArcadeScriptArgs" "$__RepoRootDir"/eng/empty.csproj \
97 /p:NativeVersionFile="$__versionSourceFile" \
98 /t:GenerateNativeVersionFile /restore \
99 $__CommonMSBuildArgs $__binlogArg $__UnprocessedBuildArgs
101 if [[ "$exit_code" != 0 ]]; then
102 echo "${__ErrMsgPrefix}Failed to generate native version file."
106 # Generate the dummy version.c, but only if it didn't exist to make sure we don't trigger unnecessary rebuild
107 __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
108 if [[ -e "$__versionSourceFile" ]]; then
109 read existingVersionSourceLine < "$__versionSourceFile"
111 if [[ "$__versionSourceLine" != "$existingVersionSourceLine" ]]; then
112 echo "$__versionSourceLine" > "$__versionSourceFile"
116 if [[ "$__StaticAnalyzer" == 1 ]]; then
117 scan_build=scan-build
120 engNativeDir="$__RepoRootDir/eng/native"
121 __CMakeArgs="-DCLR_ENG_NATIVE_DIR=\"$engNativeDir\" $__CMakeArgs"
122 nextCommand="\"$engNativeDir/gen-buildsys.sh\" \"$cmakeDir\" \"$tryrunDir\" \"$intermediatesDir\" $platformArch $__Compiler \"$__CompilerMajorVersion\" \"$__CompilerMinorVersion\" $__BuildType \"$generator\" $scan_build $__CMakeArgs"
123 echo "Invoking $nextCommand"
127 if [[ "$exit_code" != 0 ]]; then
128 echo "${__ErrMsgPrefix}Failed to generate \"$message\" build project!"
133 # Check that the makefiles were created.
134 if [[ ! -f "$intermediatesDir/CMakeCache.txt" ]]; then
135 echo "${__ErrMsgPrefix}Unable to find generated build files for \"$message\" project!"
140 if [[ "$__ConfigureOnly" == 1 ]]; then
141 echo "Finish configuration & skipping \"$message\" build."
145 if [[ "$__StaticAnalyzer" == 1 ]]; then
146 pushd "$intermediatesDir"
148 buildTool="$SCAN_BUILD_COMMAND -o $__BinDir/scan-build-log $buildTool"
149 echo "Executing $buildTool install -j $__NumProc"
150 "$buildTool" install -j "$__NumProc"
155 if [[ "$build_arch" == "wasm" ]]; then
156 cmake_command="emcmake $cmake_command"
159 echo "Executing $cmake_command --build \"$intermediatesDir\" --target install -j $__NumProc"
160 $cmake_command --build "$intermediatesDir" --target install -j "$__NumProc"
164 if [[ "$exit_code" != 0 ]]; then
165 echo "${__ErrMsgPrefix}Failed to build \"$message\"."
172 echo "Usage: $0 <options>"
174 echo "Common Options:"
176 echo "BuildArch can be: -arm, -armel, -arm64, x64, x86, -wasm"
177 echo "BuildType can be: -debug, -checked, -release"
178 echo "-os: target OS (defaults to running OS)"
179 echo "-bindir: output directory (defaults to $__ProjectRoot/artifacts)"
180 echo "-ci: indicates if this is a CI build."
181 echo "-clang: optional argument to build using clang in PATH (default)."
182 echo "-clangx.y: optional argument to build using clang version x.y."
183 echo "-cmakeargs: user-settable additional arguments passed to CMake."
184 echo "-configureonly: do not perform any builds; just configure the build."
185 echo "-cross: optional argument to signify cross compilation,"
186 echo " will use ROOTFS_DIR environment variable if set."
187 echo "-gcc: optional argument to build using gcc in PATH."
188 echo "-gccx.y: optional argument to build using gcc version x.y."
189 echo "-msbuildonunsupportedplatform: build managed binaries even if distro is not officially supported."
190 echo "-ninja: target ninja instead of GNU make"
191 echo "-numproc: set the number of build processes."
192 echo "-portablebuild: pass -portablebuild=false to force a non-portable build."
193 echo "-skipconfigure: skip build configuration."
194 echo "-skipgenerateversion: disable version generation even if MSBuild is supported."
195 echo "-verbose: optional argument to enable verbose build output."
197 echo "Additional Options:"
199 for i in "${!usage_list[@]}"; do
200 echo "${usage_list[${i}]}"
206 source "$__RepoRootDir/eng/native/init-os-and-arch.sh"
214 __msbuildonunsupportedplatform=0
217 if [[ "$#" -le 0 ]]; then
221 lowerI="$(echo "$1" | awk '{print tolower($0)}')"
241 if [[ -n "$2" ]]; then
243 if [[ ! -d "$__RootBinDir" ]]; then
244 mkdir "$__RootBinDir"
246 __RootBinParent=$(dirname "$__RootBinDir")
247 __RootBinName="${__RootBinDir##*/}"
248 __RootBinDir="$(cd "$__RootBinParent" &>/dev/null && printf %s/%s "$PWD" "$__RootBinName")"
251 echo "ERROR: 'bindir' requires a non-empty option argument"
261 __ArcadeScriptArgs="--ci"
262 __ErrMsgPrefix="##vso[task.logissue type=error]"
267 # clangx.y or clang-x.y
268 version="$(echo "$lowerI" | tr -d '[:alpha:]-=')"
269 parts=(${version//./ })
270 __CompilerMajorVersion="${parts[0]}"
271 __CompilerMinorVersion="${parts[1]}"
272 if [[ -z "$__CompilerMinorVersion" && "$__CompilerMajorVersion" -le 6 ]]; then
273 __CompilerMinorVersion=0;
277 cmakeargs|-cmakeargs)
278 if [[ -n "$2" ]]; then
279 __CMakeArgs="$2 $__CMakeArgs"
282 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
287 configureonly|-configureonly)
304 version="$(echo "$lowerI" | tr -d '[:alpha:]-=')"
305 parts=(${version//./ })
306 __CompilerMajorVersion="${parts[0]}"
307 __CompilerMinorVersion="${parts[1]}"
310 msbuildonunsupportedplatform|-msbuildonunsupportedplatform)
311 __msbuildonunsupportedplatform=1
319 if [[ -n "$2" ]]; then
323 echo "ERROR: 'numproc' requires a non-empty option argument"
328 portablebuild=false|-portablebuild=false)
336 skipconfigure|-skipconfigure)
340 skipgenerateversion|-skipgenerateversion)
341 __SkipGenerateVersion=1
361 if [[ -n "$2" ]]; then
365 echo "ERROR: 'os' requires a non-empty option argument"
371 handle_arguments "$1" "$2"
372 if [[ "$__ShiftArgs" == 1 ]]; then
382 # Get the number of processors available to the scheduler
383 # Other techniques such as `nproc` only get the number of
384 # processors available to a single process.
386 if [[ "$platform" == "FreeBSD" ]]; then
387 __NumProc=$(sysctl hw.ncpu | awk '{ print $2+1 }')
388 elif [[ "$platform" == "NetBSD" || "$platform" == "SunOS" ]]; then
389 __NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
390 elif [[ "$platform" == "Darwin" ]]; then
391 __NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
393 __NumProc=$(nproc --all)
396 __CommonMSBuildArgs="/p:TargetArchitecture=$__BuildArch /p:Configuration=$__BuildType /p:TargetOS=$__TargetOS /nodeReuse:false $__OfficialBuildIdArg $__SignTypeArg $__SkipRestoreArg"
398 # Configure environment if we are doing a verbose build
399 if [[ "$__VerboseBuild" == 1 ]]; then
402 __CommonMSBuildArgs="$__CommonMSBuildArgs /v:detailed"
405 if [[ "$__PortableBuild" == 0 ]]; then
406 __CommonMSBuildArgs="$__CommonMSBuildArgs /p:PortableBuild=false"
409 # Configure environment if we are doing a cross compile.
410 if [[ "$__CrossBuild" == 1 ]]; then
413 if [[ ! -n "$ROOTFS_DIR" ]]; then
414 ROOTFS_DIR="$__RepoRootDir/.tools/rootfs/$__BuildArch"
419 # init the target distro name
422 # Init if MSBuild for .NET Core is supported for this platform
423 isMSBuildOnNETCoreSupported