This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
build.sh
executable file
·740 lines (610 loc) · 26.8 KB
/
build.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
#!/usr/bin/env bash
# Work around Jenkins CI + msbuild problem: Jenkins sometimes creates very large environment
# variables, and msbuild can't handle environment blocks with such large variables. So clear
# out the variables that might be too large.
export ghprbCommentBody=
# resolve python-version to use
if [ "$PYTHON" == "" ] ; then
if ! PYTHON=$(command -v python3 || command -v python2 || command -v python || command -v py)
then
echo "Unable to locate build-dependency python!" 1>&2
exit 1
fi
fi
# validate python-dependency
# useful in case of explicitly set option.
if ! command -v $PYTHON > /dev/null
then
echo "Unable to locate build-dependency python ($PYTHON)!" 1>&2
exit 1
fi
export PYTHON
usage_list=("-crossgenonly: only run native image generation.")
usage_list+=("-disableoss: Disable Open Source Signing for System.Private.CoreLib.")
usage_list+=("-ibcinstrument: generate IBC-tuning-enabled native images when invoking crossgen.")
usage_list+=("-nopgooptimize: do not use profile guided optimizations.")
usage_list+=("-officialbuildid=^<ID^>: specify the official build ID to be used by this build.")
usage_list+=("-partialngen: build CoreLib as PartialNGen.")
usage_list+=("-pgoinstrument: generate instrumented code for profile guided optimization enabled binaries.")
usage_list+=("-skipcrossgen: skip native image generation.")
usage_list+=("-skipcrossarchnative: Disable Open Source Signing for System.Private.CoreLib.")
usage_list+=("-skipmanagedtools: generate instrumented code for profile guided optimization enabled binaries.")
usage_list+=("-skipmscorlib: generate IBC-tuning-enabled native images when invoking crossgen.")
usage_list+=("-skipnuget: do not use profile guided optimizations.")
usage_list+=("-skiprestore: specify the official build ID to be used by this build.")
usage_list+=("-skiprestoreoptdata: build CoreLib as PartialNGen.")
usage_list+=("-staticanalyzer: skip native image generation.")
usage_list+=("-stripSymbols: skip native image generation.")
setup_dirs()
{
echo Setting up directories for build
mkdir -p "$__RootBinDir"
mkdir -p "$__BinDir"
mkdir -p "$__LogsDir"
mkdir -p "$__MsbuildDebugLogsDir"
mkdir -p "$__IntermediatesDir"
if [ $__CrossBuild == 1 ]; then
mkdir -p "$__CrossComponentBinDir"
fi
}
# Check the system to ensure the right prereqs are in place
check_prereqs()
{
echo "Checking prerequisites..."
# Check presence of CMake on the path
hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
function version { echo "$@" | awk -F. '{ printf("%d%02d%02d\n", $1,$2,$3); }'; }
local cmake_version=$(cmake --version | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")
if [[ $(version $cmake_version) -lt $(version 3.14.0) ]]; then
echo "Please install CMake 3.14 or newer from http://www.cmake.org/download/ or https://apt.kitware.com and ensure it is on your path."; exit 1;
fi
# Minimum required version of clang is version 4.0 for arm/armel cross build
if [[ $__CrossBuild == 1 && $__GccBuild == 0 && ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") ]]; then
if ! [[ "$__ClangMajorVersion" -ge "4" ]]; then
echo "Please install clang4.0 or latest for arm/armel cross build"; exit 1;
fi
fi
# Check for clang
if [[ $__GccBuild == 0 ]]; then
__ClangCombinedDottedVersion=$__ClangMajorVersion;
if [[ "$__ClangMinorVersion" != "" ]]; then
__ClangCombinedDottedVersion=$__ClangCombinedDottedVersion.$__ClangMinorVersion
fi
hash clang-$__ClangCombinedDottedVersion 2>/dev/null || hash clang$__ClangMajorVersion$__ClangMinorVersion 2>/dev/null || hash clang 2>/dev/null || { echo >&2 "Please install clang-$__ClangMajorVersion.$__ClangMinorVersion before running this script"; exit 1; }
else
__GccCombinedDottedVersion=$__GccMajorVersion;
if [[ "$__GccMinorVersion" != "" ]]; then
__GccCombinedDottedVersion=$__GccCombinedDottedVersion.$__GccMinorVersion
fi
hash gcc-$__GccCombinedDottedVersion 2>/dev/null || hash gcc$__GccMajorVersion$__GccMinorVersion 2>/dev/null || hash gcc 2>/dev/null || { echo >&2 "Please install gcc-$__GccMajorVersion.$__GccMinorVersion before running this script"; exit 1; }
fi
}
restore_optdata()
{
local OptDataProjectFilePath="$__ProjectRoot/src/.nuget/optdata/optdata.csproj"
if [[ ( $__SkipRestoreOptData == 0 ) && ( $__isMSBuildOnNETCoreSupported == 1 ) ]]; then
echo "Restoring the OptimizationData package"
"$__RepoRootDir/eng/common/msbuild.sh" $__ArcadeScriptArgs \
$OptDataProjectFilePath /t:Restore /m \
$__CommonMSBuildArgs $__UnprocessedBuildArgs
local exit_code=$?
if [ $exit_code != 0 ]; then
echo "${__ErrMsgPrefix}Failed to restore the optimization data package."
exit $exit_code
fi
fi
if [ $__isMSBuildOnNETCoreSupported == 1 ]; then
# Parse the optdata package versions out of msbuild so that we can pass them on to CMake
local PgoDataPackagePathOutputFile="${__IntermediatesDir}/optdatapath.txt"
local IbcDataPackagePathOutputFile="${__IntermediatesDir}/ibcoptdatapath.txt"
# Writes into ${PgoDataPackagePathOutputFile}
"$__RepoRootDir/eng/common/msbuild.sh" $__ArcadeScriptArgs $OptDataProjectFilePath /t:DumpPgoDataPackagePath ${__CommonMSBuildArgs} /p:PgoDataPackagePathOutputFile=${PgoDataPackagePathOutputFile} 2>&1 > /dev/null
local exit_code=$?
if [ $exit_code != 0 ] || [ ! -f "${PgoDataPackagePathOutputFile}" ]; then
echo "${__ErrMsgPrefix}Failed to get PGO data package path."
exit $exit_code
fi
__PgoOptDataPath=$(<"${PgoDataPackagePathOutputFile}")
# Writes into ${IbcDataPackagePathOutputFile}
"$__RepoRootDir/eng/common/msbuild.sh" $__ArcadeScriptArgs $OptDataProjectFilePath /t:DumpIbcDataPackagePath ${__CommonMSBuildArgs} /p:IbcDataPackagePathOutputFile=${IbcDataPackagePathOutputFile} 2>&1 > /dev/null
local exit_code=$?
if [ $exit_code != 0 ] || [ ! -f "${IbcDataPackagePathOutputFile}" ]; then
echo "${__ErrMsgPrefix}Failed to get IBC data package path."
exit $exit_code
fi
__IbcOptDataPath=$(<"${IbcDataPackagePathOutputFile}")
fi
}
generate_event_logging_sources()
{
__OutputEventingDir=$1
__PythonWarningFlags="-Wall"
if [[ $__IgnoreWarnings == 0 ]]; then
__PythonWarningFlags="$__PythonWarningFlags -Werror"
fi
echo "Laying out dynamically generated EventSource classes"
$PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genRuntimeEventSources.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir"
}
generate_event_logging()
{
# Event Logging Infrastructure
if [[ $__SkipMSCorLib == 0 ]]; then
generate_event_logging_sources "$__ArtifactsIntermediatesDir/Eventing/$__BuildArch/$__BuildType"
fi
}
build_native()
{
skipCondition=$1
platformArch="$2"
intermediatesForBuild="$3"
extraCmakeArguments="$4"
message="$5"
if [ $skipCondition == 1 ]; then
echo "Skipping $message build."
return
fi
# All set to commence the build
echo "Commencing build of $message for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesForBuild"
generator=""
buildTool="make"
if [ $__UseNinja == 1 ]; then
generator="ninja"
if ! buildTool=$(command -v ninja || command -v ninja-build); then
echo "Unable to locate ninja!" 1>&2
exit 1
fi
fi
if [ $__SkipConfigure == 0 ]; then
# if msbuild is not supported, then set __SkipGenerateVersion to 1
if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
# Drop version.c file
__versionSourceFile="$intermediatesForBuild/version.c"
if [ $__SkipGenerateVersion == 0 ]; then
pwd
"$__RepoRootDir/eng/common/msbuild.sh" $__ArcadeScriptArgs $__RepoRootDir/eng/empty.csproj \
/p:NativeVersionFile=$__versionSourceFile \
/t:GenerateNativeVersionFile /restore \
$__CommonMSBuildArgs $__UnprocessedBuildArgs
local exit_code=$?
if [ $exit_code != 0 ]; then
echo "${__ErrMsgPrefix}Failed to generate native version file."
exit $exit_code
fi
else
# Generate the dummy version.c, but only if it didn't exist to make sure we don't trigger unnecessary rebuild
__versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
if [ -e $__versionSourceFile ]; then
read existingVersionSourceLine < $__versionSourceFile
fi
if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then
echo $__versionSourceLine > $__versionSourceFile
fi
fi
# Regenerate the CMake solution
scriptDir="$__ProjectRoot/src/pal/tools"
if [[ $__GccBuild == 0 ]]; then
echo "Invoking \"$scriptDir/find-clang.sh\" $__ClangMajorVersion \"$__ClangMinorVersion\""
source "$scriptDir/find-clang.sh" $__ClangMajorVersion "$__ClangMinorVersion"
if [[ $__StaticAnalyzer == 1 ]]; then
scan_build=scan-build
fi
else
echo "Invoking \"$scriptDir/find-gcc.sh\" \"$__GccMajorVersion\" \"$__GccMinorVersion\""
source "$scriptDir/find-gcc.sh" "$__GccMajorVersion" "$__GccMinorVersion"
fi
if [[ -n "$__CodeCoverage" ]]; then
extraCmakeArguments="$extraCmakeArguments -DCLR_CMAKE_ENABLE_CODE_COVERAGE=1"
fi
nextCommand="\"$scriptDir/gen-buildsys.sh\" \"$__ProjectRoot\" \"$intermediatesForBuild\" $platformArch $__BuildType $generator $scan_build $extraCmakeArguments $__cmakeargs"
echo "Invoking $nextCommand"
eval $nextCommand
if [ $? != 0 ]; then
echo "${__ErrMsgPrefix}Failed to generate $message build project!"
exit 1
fi
fi
if [ ! -f "$intermediatesForBuild/CMakeCache.txt" ]; then
echo "${__ErrMsgPrefix}Unable to find generated build files for $message project!"
exit 1
fi
# Build
if [ $__ConfigureOnly == 1 ]; then
echo "Finish configuration & skipping $message build."
return
fi
# Check that the makefiles were created.
if [ $__StaticAnalyzer == 1 ]; then
pushd "$intermediatesForBuild"
buildTool="$SCAN_BUILD_COMMAND $buildTool"
echo "Executing $buildTool install -j $__NumProc"
$buildTool install -j $__NumProc
popd
else
echo "Executing cmake --build \"$intermediatesForBuild\" --target install -j $__NumProc"
cmake --build "$intermediatesForBuild" --target install -j $__NumProc
fi
local exit_code=$?
if [ $exit_code != 0 ]; then
echo "${__ErrMsgPrefix}Failed to build $message."
exit $exit_code
fi
}
build_cross_architecture_components()
{
local intermediatesForBuild="$__IntermediatesDir/Host$__CrossArch/crossgen"
local crossArchBinDir="$__BinDir/$__CrossArch"
mkdir -p "$intermediatesForBuild"
mkdir -p "$crossArchBinDir"
generate_event_logging_sources "$intermediatesForBuild" "the crossarch build system"
__SkipCrossArchBuild=1
# check supported cross-architecture components host(__HostArch)/target(__BuildArch) pair
if [[ ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") && ("$__CrossArch" == "x86" || "$__CrossArch" == "x64") ]]; then
__SkipCrossArchBuild=0
elif [[ "$__BuildArch" == "arm64" && "$__CrossArch" == "x64" ]]; then
__SkipCrossArchBuild=0
else
# not supported
return
fi
export __CMakeBinDir="$crossArchBinDir"
export CROSSCOMPILE=0
__ExtraCmakeArgs="-DCLR_CMAKE_TARGET_ARCH=$__BuildArch -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument -DCLR_CMAKE_OPTDATA_PATH=$__PgoOptDataPath -DCLR_CMAKE_PGO_OPTIMIZE=$__PgoOptimize -DCLR_CROSS_COMPONENTS_BUILD=1"
build_native $__SkipCrossArchBuild "$__CrossArch" "$intermediatesForBuild" "$__ExtraCmakeArgs" "cross-architecture components"
export CROSSCOMPILE=1
}
build_CoreLib_ni()
{
local __CrossGenExec=$1
local __CoreLibILDir=$2
if [ $__PartialNgen == 1 ]; then
export COMPlus_PartialNGen=1
fi
if [ -e $__CrossGenCoreLibLog ]; then
rm $__CrossGenCoreLibLog
fi
echo "Generating native image of System.Private.CoreLib.dll for $__BuildOS.$__BuildArch.$__BuildType. Logging to \"$__CrossGenCoreLibLog\"."
echo "$__CrossGenExec /Platform_Assemblies_Paths $__CoreLibILDir $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__CoreLibILDir/System.Private.CoreLib.dll"
$__CrossGenExec /Platform_Assemblies_Paths $__CoreLibILDir $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__CoreLibILDir/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1
local exit_code=$?
if [ $exit_code != 0 ]; then
echo "${__ErrMsgPrefix}Failed to generate native image for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog"
exit $exit_code
fi
if [ "$__BuildOS" == "Linux" ]; then
echo "Generating symbol file for System.Private.CoreLib.dll"
echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll"
$__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1
local exit_code=$?
if [ $exit_code != 0 ]; then
echo "${__ErrMsgPrefix}Failed to generate symbol file for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog"
exit $exit_code
fi
fi
}
build_CoreLib()
{
if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
echo "System.Private.CoreLib.dll build unsupported."
return
fi
if [ $__SkipMSCorLib == 1 ]; then
echo "Skipping building System.Private.CoreLib."
return
fi
echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
# Invoke MSBuild
__ExtraBuildArgs=""
if [[ "$__IbcTuning" == "" ]]; then
__ExtraBuildArgs="$__ExtraBuildArgs /p:OptimizationDataDir=\"$__IbcOptDataPath/data\""
__ExtraBuildArgs="$__ExtraBuildArgs /p:EnableProfileGuidedOptimization=true"
fi
if [[ "$__BuildManagedTools" -eq "1" ]]; then
__ExtraBuildArgs="$__ExtraBuildArgs /p:BuildManagedTools=true"
fi
"$__RepoRootDir/eng/common/msbuild.sh" $__ArcadeScriptArgs \
$__ProjectDir/src/build.proj /t:Restore \
/p:PortableBuild=true /maxcpucount /p:IncludeRestoreOnlyProjects=true \
/flp:Verbosity=normal\;LogFile=$__LogsDir/System.Private.CoreLib_$__BuildOS__$__BuildArch__$__BuildType.log \
/p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir \
$__CommonMSBuildArgs $__ExtraBuildArgs $__UnprocessedBuildArgs
local exit_code=$?
if [ $exit_code != 0 ]; then
echo "${__ErrMsgPrefix}Failed to restore managed components."
exit $exit_code
fi
"$__RepoRootDir/eng/common/msbuild.sh" $__ArcadeScriptArgs \
$__ProjectDir/src/build.proj \
/p:PortableBuild=true /maxcpucount \
/flp:Verbosity=normal\;LogFile=$__LogsDir/System.Private.CoreLib_$__BuildOS__$__BuildArch__$__BuildType.log \
/p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir \
$__CommonMSBuildArgs $__ExtraBuildArgs $__UnprocessedBuildArgs
local exit_code=$?
if [ $exit_code != 0 ]; then
echo "${__ErrMsgPrefix}Failed to build managed components."
exit $exit_code
fi
if [[ "$__BuildManagedTools" -eq "1" ]]; then
echo "Publishing crossgen2 for $__DistroRid"
"$__ProjectRoot/dotnet.sh" publish --self-contained -r $__DistroRid -c $__BuildType -o "$__BinDir/crossgen2" "$__ProjectRoot/src/tools/crossgen2/crossgen2/crossgen2.csproj" /p:BuildArch=$__BuildArch
local exit_code=$?
if [ $exit_code != 0 ]; then
echo "${__ErrMsgPrefix}Failed to build crossgen2."
exit $exit_code
fi
if [ "$__HostOS" == "OSX" ]; then
cp "$__BinDir/libclrjit.dylib" "$__BinDir/crossgen2/libclrjitilc.dylib"
cp "$__BinDir/libjitinterface.dylib" "$__BinDir/crossgen2/libjitinterface.dylib"
else
cp "$__BinDir/libclrjit.so" "$__BinDir/crossgen2/libclrjitilc.so"
cp "$__BinDir/libjitinterface.so" "$__BinDir/crossgen2/libjitinterface.so"
fi
fi
local __CoreLibILDir=$__BinDir/IL
if [ $__SkipCrossgen == 1 ]; then
echo "Skipping generating native image"
if [ $__CrossBuild == 1 ]; then
# Crossgen not performed, so treat the IL version as the final version
cp $__CoreLibILDir/System.Private.CoreLib.dll $__BinDir/System.Private.CoreLib.dll
fi
return
fi
# The cross build generates a crossgen with the target architecture.
if [ $__CrossBuild == 0 ]; then
if [ $__SkipCoreCLR == 1 ]; then
return
fi
# The architecture of host pc must be same architecture with target.
if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
build_CoreLib_ni "$__BinDir/crossgen" $__CoreLibILDir
elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
build_CoreLib_ni "$__BinDir/crossgen" $__CoreLibILDir
elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
build_CoreLib_ni "$__BinDir/crossgen" $__CoreLibILDir
else
exit 1
fi
else
if [[ ( "$__CrossArch" == "x86" ) && ( "$__BuildArch" == "arm" ) ]]; then
build_CoreLib_ni "$__CrossComponentBinDir/crossgen" $__CoreLibILDir
elif [[ ( "$__CrossArch" == "x64" ) && ( "$__BuildArch" == "arm" ) ]]; then
build_CoreLib_ni "$__CrossComponentBinDir/crossgen" $__CoreLibILDir
elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "arm64" ) ]]; then
build_CoreLib_ni "$__CrossComponentBinDir/crossgen" $__CoreLibILDir
else
# Crossgen not performed, so treat the IL version as the final version
cp $__CoreLibILDir/System.Private.CoreLib.dll $__BinDir/System.Private.CoreLib.dll
fi
fi
}
generate_NugetPackages()
{
# We can only generate nuget package if we also support building mscorlib as part of this build.
if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
echo "Nuget package generation unsupported."
return
fi
# Since we can build mscorlib for this OS, did we build the native components as well?
if [[ $__SkipCoreCLR == 1 && $__CrossgenOnly == 0 ]]; then
echo "Unable to generate nuget packages since native components were not built."
return
fi
echo "Generating nuget packages for "$__BuildOS
echo "DistroRid is "$__DistroRid
echo "ROOTFS_DIR is "$ROOTFS_DIR
# Build the packages
# Package build uses the Arcade system and scripts, relying on it to restore required toolsets as part of build
$__RepoRootDir/eng/common/build.sh -r -b -projects $__SourceDir/.nuget/packages.builds \
-verbosity minimal -bl:$__LogsDir/Nuget_$__BuildOS__$__BuildArch__$__BuildType.binlog \
/p:PortableBuild=true \
/p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir /p:__DoCrossArchBuild=$__CrossBuild \
$__CommonMSBuildArgs $__UnprocessedBuildArgs
local exit_code=$?
if [ $exit_code != 0 ]; then
echo "${__ErrMsgPrefix}Failed to generate Nuget packages."
exit $exit_code
fi
}
handle_arguments() {
case $1 in
crossgenonly|-crossgenonly)
__SkipMSCorLib=1
__SkipCoreCLR=1
__CrossgenOnly=1
;;
disableoss|-disableoss)
__SignTypeArg="/p:SignType=real"
;;
ibcinstrument|-ibcinstrument)
__IbcTuning="/Tuning"
;;
ignorewarnings|-ignorewarnings)
__IgnoreWarnings=1
__cmakeargs="$__cmakeargs -DCLR_CMAKE_WARNINGS_ARE_ERRORS=OFF"
;;
nopgooptimize|-nopgooptimize)
__PgoOptimize=0
__SkipRestoreOptData=1
;;
officialbuildid=*|-officialbuildid=*)
__Id=$(echo "$1" | cut -d'=' -f 2)
__OfficialBuildIdArg="/p:OfficialBuildId=$__Id"
;;
partialngen|-partialngen)
__PartialNgen=1
;;
pgoinstrument|-pgoinstrument)
__PgoInstrument=1
;;
skipcoreclr|-skipcoreclr)
# Accept "skipcoreclr" for backwards-compatibility.
__SkipCoreCLR=1
;;
skipcrossarchnative|-skipcrossarchnative)
__SkipCrossArchNative=1
;;
skipcrossgen|-skipcrossgen)
__SkipCrossgen=1
;;
skipmanagedtools|-skipmanagedtools)
__BuildManagedTools=0
;;
skipmscorlib|-skipmscorlib)
__SkipMSCorLib=1
;;
skipnuget|-skipnuget|skipbuildpackages|-skipbuildpackages)
__SkipNuget=1
;;
skiprestore|-skiprestore)
__SkipRestoreArg="/p:RestoreDuringBuild=false"
;;
staticanalyzer|-staticanalyzer)
__StaticAnalyzer=1
;;
stripsymbols|-stripsymbols)
__cmakeargs="$__cmakeargs -DSTRIP_SYMBOLS=true"
;;
*)
__UnprocessedBuildArgs+=("$1")
;;
esac
}
echo "Commencing CoreCLR Repo build"
# Argument types supported by this script:
#
# Build architecture - valid values are: x64, ARM.
# Build Type - valid values are: Debug, Checked, Release
#
# Set the default arguments for build
# Obtain the location of the bash script to figure out where the root of the subrepo is.
__ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Some paths are relative to the main repo root
__RepoRootDir="${__ProjectRoot}/../.."
# BEGIN SECTION to remove after repo consolidation
if [ ! -f "${__RepoRootDir}/.dotnet-runtime-placeholder" ]; then
__RepoRootDir=${__ProjectRoot}
fi
# END SECTION to remove after repo consolidation
__BuildArch=
__BuildType=Debug
__CodeCoverage=
__IgnoreWarnings=0
# Set the various build properties here so that CMake and MSBuild can pick them up
__BuildManagedTools=1
__ClangMajorVersion=0
__ClangMinorVersion=0
__CommonMSBuildArgs=
__ConfigureOnly=0
__CrossBuild=0
__CrossgenOnly=0
__DistroRid=""
__GccBuild=0
__GccMajorVersion=0
__GccMinorVersion=0
__IbcOptDataPath=""
__IbcTuning=""
__MSBCleanBuildArgs=
__OfficialBuildIdArg=""
__PartialNgen=0
__PgoInstrument=0
__PgoOptDataPath=""
__PgoOptimize=1
__PortableBuild=1
__ProjectDir="$__ProjectRoot"
__RootBinDir="$__ProjectDir/bin"
__SignTypeArg=""
__SkipConfigure=0
__SkipCoreCLR=0
__SkipCrossArchNative=0
__SkipCrossgen=0
__SkipGenerateVersion=0
__SkipMSCorLib=0
__SkipManaged=0
__SkipNuget=0
__SkipRestore=""
__SkipRestoreArg="/p:RestoreDuringBuild=true"
__SkipRestoreOptData=0
__SourceDir="$__ProjectDir/src"
__StaticAnalyzer=0
__UnprocessedBuildArgs=
__UseNinja=0
__VerboseBuild=0
__ValidateCrossArg=1
__cmakeargs=""
__msbuildonunsupportedplatform=0
source "$__ProjectRoot"/_build-commons.sh
if [ "${__BuildArch}" != "${__HostArch}" ]; then
__CrossBuild=1
fi
# Set dependent variables
__LogsDir="$__RootBinDir/Logs"
__MsbuildDebugLogsDir="$__LogsDir/MsbuildDebugLogs"
# Set the remaining variables based upon the determined build configuration
__BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
__PackagesBinDir="$__BinDir/.nuget"
export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
export __ArtifactsIntermediatesDir="$__ProjectDir/artifacts/obj"
__isMSBuildOnNETCoreSupported=0
__CrossComponentBinDir="$__BinDir"
__CrossArch="$__HostArch"
if [ $__CrossBuild == 1 ]; then
__CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
fi
__CrossGenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$__BuildArch.$__BuildType.log"
# Configure environment if we are doing a cross compile.
if [ $__CrossBuild == 1 ]; then
export CROSSCOMPILE=1
if ! [[ -n "$ROOTFS_DIR" ]]; then
export ROOTFS_DIR="$__RepoRootDir/eng/common/cross/rootfs/$__BuildArch"
fi
fi
# init the target distro name
initTargetDistroRid
if [ $__PortableBuild == 0 ]; then
__CommonMSBuildArgs="$__CommonMSBuildArgs /p:PortableBuild=false"
fi
# Init if MSBuild for .NET Core is supported for this platform
isMSBuildOnNETCoreSupported
# CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
# This is needed by CLI to function.
if [ -z "$HOME" ]; then
if [ ! -d "$__ProjectDir/temp_home" ]; then
mkdir temp_home
fi
export HOME=$__ProjectDir/temp_home
echo "HOME not defined; setting it to $HOME"
fi
# Specify path to be set for CMAKE_INSTALL_PREFIX.
# This is where all built CoreClr libraries will copied to.
export __CMakeBinDir="$__BinDir"
# Make the directories necessary for build if they don't exist
setup_dirs
# Set up the directory for MSBuild debug logs.
export MSBUILDDEBUGPATH="${__MsbuildDebugLogsDir}"
# Check prereqs.
check_prereqs
# Restore the package containing profile counts for profile-guided optimizations
restore_optdata
# Generate event logging infrastructure sources
generate_event_logging
# Build the coreclr (native) components.
__ExtraCmakeArgs="-DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument -DCLR_CMAKE_OPTDATA_PATH=$__PgoOptDataPath -DCLR_CMAKE_PGO_OPTIMIZE=$__PgoOptimize"
build_native $__SkipCoreCLR "$__BuildArch" "$__IntermediatesDir" "$__ExtraCmakeArgs" "CoreCLR component"
# Build cross-architecture components
if [ $__SkipCrossArchNative != 1 ]; then
if [[ $__CrossBuild == 1 ]]; then
build_cross_architecture_components
fi
fi
# Build System.Private.CoreLib.
build_CoreLib
if [ $__CrossgenOnly == 1 ]; then
build_CoreLib_ni "$__BinDir/crossgen"
fi
# Generate nuget packages
if [ $__SkipNuget != 1 ]; then
generate_NugetPackages
fi
# Build complete
echo "Repo successfully built."
echo "Product binaries are available at $__BinDir"
exit 0