Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 1f42d12

Browse files
dotnet-botnguerrera
authored andcommitted
Copy build scripts from dotnet/coreclr
1 parent 6804045 commit 1f42d12

File tree

2 files changed

+343
-0
lines changed

2 files changed

+343
-0
lines changed

src/Native/build.sh

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
#!/usr/bin/env bash
2+
3+
usage()
4+
{
5+
echo "Usage: $0 [BuildArch] [BuildType] [clean] [verbose] [clangx.y]"
6+
echo "BuildArch can be: x64"
7+
echo "BuildType can be: Debug, Release"
8+
echo "clean - optional argument to force a clean build."
9+
echo "verbose - optional argument to enable verbose build output."
10+
echo "clangx.y - optional argument to build using clang version x.y."
11+
12+
exit 1
13+
}
14+
15+
setup_dirs()
16+
{
17+
echo Setting up directories for build
18+
19+
mkdir -p "$__RootBinDir"
20+
mkdir -p "$__BinDir"
21+
mkdir -p "$__LogsDir"
22+
mkdir -p "$__IntermediatesDir"
23+
}
24+
25+
# Performs "clean build" type actions (deleting and remaking directories)
26+
27+
clean()
28+
{
29+
echo Cleaning previous output for the selected configuration
30+
rm -rf "$__BinDir"
31+
rm -rf "$__IntermediatesDir"
32+
33+
rm -rf "$__TestWorkingDir"
34+
rm -rf "$__TestIntermediatesDir"
35+
36+
rm -rf "$__LogsDir/*_$__BuildOS__$__BuildArch__$__BuildType.*"
37+
}
38+
39+
# Check the system to ensure the right pre-reqs are in place
40+
41+
check_prereqs()
42+
{
43+
echo "Checking pre-requisites..."
44+
45+
# Check presence of CMake on the path
46+
hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
47+
48+
# Check for clang
49+
hash clang-$__ClangMajorVersion.$__ClangMinorVersion 2>/dev/null || hash clang$__ClangMajorVersion$__ClangMinorVersion 2>/dev/null || hash clang 2>/dev/null || { echo >&2 "Please install clang before running this script"; exit 1; }
50+
51+
}
52+
53+
build_coreclr()
54+
{
55+
# All set to commence the build
56+
57+
echo "Commencing build of native components for $__BuildOS.$__BuildArch.$__BuildType"
58+
cd "$__IntermediatesDir"
59+
60+
# Regenerate the CMake solution
61+
echo "Invoking cmake with arguments: \"$__ProjectRoot\" $__CMakeArgs"
62+
"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion $__ClangMinorVersion $__CMakeArgs
63+
64+
# Check that the makefiles were created.
65+
66+
if [ ! -f "$__IntermediatesDir/Makefile" ]; then
67+
echo "Failed to generate native component build project!"
68+
exit 1
69+
fi
70+
71+
# Get the number of processors available to the scheduler
72+
# Other techniques such as `nproc` only get the number of
73+
# processors available to a single process.
74+
if [ `uname` = "FreeBSD" ]; then
75+
NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
76+
else
77+
NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
78+
fi
79+
80+
# Build CoreCLR
81+
82+
echo "Executing make install -j $NumProc $__UnprocessedBuildArgs"
83+
84+
make install -j $NumProc $__UnprocessedBuildArgs
85+
if [ $? != 0 ]; then
86+
echo "Failed to build coreclr components."
87+
exit 1
88+
fi
89+
}
90+
91+
echo "Commencing CoreCLR Repo build"
92+
93+
# Argument types supported by this script:
94+
#
95+
# Build architecture - valid value is: x64.
96+
# Build Type - valid values are: Debug, Release
97+
#
98+
# Set the default arguments for build
99+
100+
# Obtain the location of the bash script to figure out whether the root of the repo is.
101+
__ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
102+
__BuildArch=x64
103+
# Use uname to determine what the OS is.
104+
OSName=$(uname -s)
105+
case $OSName in
106+
Linux)
107+
__BuildOS=Linux
108+
;;
109+
110+
Darwin)
111+
__BuildOS=OSX
112+
;;
113+
114+
FreeBSD)
115+
__BuildOS=FreeBSD
116+
;;
117+
118+
OpenBSD)
119+
__BuildOS=OpenBSD
120+
;;
121+
122+
NetBSD)
123+
__BuildOS=NetBSD
124+
;;
125+
126+
*)
127+
echo "Unsupported OS $OSName detected, configuring as if for Linux"
128+
__BuildOS=Linux
129+
;;
130+
esac
131+
__MSBuildBuildArch=x64
132+
__BuildType=Debug
133+
__CMakeArgs=DEBUG
134+
135+
# Set the various build properties here so that CMake and MSBuild can pick them up
136+
__ProjectDir="$__ProjectRoot"
137+
__SourceDir="$__ProjectDir/src"
138+
__PackagesDir="$__ProjectDir/packages"
139+
__RootBinDir="$__ProjectDir/bin"
140+
__LogsDir="$__RootBinDir/Logs"
141+
__UnprocessedBuildArgs=
142+
__MSBCleanBuildArgs=
143+
__CleanBuild=false
144+
__VerboseBuild=false
145+
__ClangMajorVersion=3
146+
__ClangMinorVersion=5
147+
148+
for i in "$@"
149+
do
150+
lowerI="$(echo $i | awk '{print tolower($0)}')"
151+
case $lowerI in
152+
-?|-h|--help)
153+
usage
154+
exit 1
155+
;;
156+
x64)
157+
__BuildArch=x64
158+
__MSBuildBuildArch=x64
159+
;;
160+
debug)
161+
__BuildType=Debug
162+
;;
163+
release)
164+
__BuildType=Release
165+
__CMakeArgs=RELEASE
166+
;;
167+
clean)
168+
__CleanBuild=1
169+
;;
170+
verbose)
171+
__VerboseBuild=1
172+
;;
173+
clang3.5)
174+
__ClangMajorVersion=3
175+
__ClangMinorVersion=5
176+
;;
177+
clang3.6)
178+
__ClangMajorVersion=3
179+
__ClangMinorVersion=6
180+
;;
181+
clang3.7)
182+
__ClangMajorVersion=3
183+
__ClangMinorVersion=7
184+
;;
185+
*)
186+
__UnprocessedBuildArgs="$__UnprocessedBuildArgs $i"
187+
esac
188+
done
189+
190+
# Set the remaining variables based upon the determined build configuration
191+
__BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
192+
__PackagesBinDir="$__BinDir/.nuget"
193+
__ToolsDir="$__RootBinDir/tools"
194+
__TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
195+
__IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
196+
__TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
197+
198+
# Specify path to be set for CMAKE_INSTALL_PREFIX.
199+
# This is where all built CoreClr libraries will copied to.
200+
export __CMakeBinDir="$__BinDir"
201+
202+
# Configure environment if we are doing a clean build.
203+
if [ $__CleanBuild == 1 ]; then
204+
clean
205+
fi
206+
207+
# Configure environment if we are doing a verbose build
208+
if [ $__VerboseBuild == 1 ]; then
209+
export VERBOSE=1
210+
fi
211+
212+
# Make the directories necessary for build if they don't exist
213+
214+
setup_dirs
215+
216+
# Check prereqs.
217+
218+
check_prereqs
219+
220+
# Build the coreclr (native) components.
221+
222+
build_coreclr
223+
224+
# Build complete
225+
226+
echo "Repo successfully built."
227+
echo "Product binaries are available at $__BinDir"
228+
exit 0

src/Native/gen-buildsys-clang.sh

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/usr/bin/env bash
2+
#
3+
# This file invokes cmake and generates the build system for gcc.
4+
#
5+
6+
if [ $# -lt 3 -o $# -gt 4 ]
7+
then
8+
echo "Usage..."
9+
echo "gen-buildsys-clang.sh <path to top level CMakeLists.txt> <ClangMajorVersion> <ClangMinorVersion> [build flavor]"
10+
echo "Specify the path to the top level CMake file - <ProjectK>/src/NDP"
11+
echo "Specify the clang version to use, split into major and minor version"
12+
echo "Optionally specify the build configuration (flavor.) Defaults to DEBUG."
13+
exit 1
14+
fi
15+
16+
# Set up the environment to be used for building with clang.
17+
if which "clang-$2.$3" > /dev/null 2>&1
18+
then
19+
export CC="$(which clang-$2.$3)"
20+
export CXX="$(which clang++-$2.$3)"
21+
elif which "clang$2$3" > /dev/null 2>&1
22+
then
23+
export CC="$(which clang$2$3)"
24+
export CXX="$(which clang++$2$3)"
25+
elif which clang > /dev/null 2>&1
26+
then
27+
export CC="$(which clang)"
28+
export CXX="$(which clang++)"
29+
else
30+
echo "Unable to find Clang Compiler"
31+
exit 1
32+
fi
33+
34+
# Possible build types are DEBUG, RELEASE, RELWITHDEBINFO, MINSIZEREL.
35+
# Default to DEBUG
36+
if [ -z "$4" ]
37+
then
38+
echo "Defaulting to DEBUG build."
39+
buildtype="DEBUG"
40+
else
41+
buildtype="$4"
42+
fi
43+
44+
OS=`uname`
45+
46+
# Locate llvm
47+
# This can be a little complicated, because the common use-case of Ubuntu with
48+
# llvm-3.5 installed uses a rather unusual llvm installation with the version
49+
# number postfixed (i.e. llvm-ar-3.5), so we check for that first.
50+
# On FreeBSD the version number is appended without point and dash (i.e.
51+
# llvm-ar35).
52+
# Additionally, OSX doesn't use the llvm- prefix.
53+
if [ $OS = "Linux" -o $OS = "FreeBSD" -o $OS = "OpenBSD" -o $OS = "NetBSD" ]; then
54+
llvm_prefix="llvm-"
55+
elif [ $OS = "Darwin" ]; then
56+
llvm_prefix=""
57+
else
58+
echo "Unable to determine build platform"
59+
exit 1
60+
fi
61+
62+
desired_llvm_major_version=$2
63+
desired_llvm_minor_version=$3
64+
if [ $OS = "FreeBSD" ]; then
65+
desired_llvm_version="$desired_llvm_major_version$desired_llvm_minor_version"
66+
elif [ $OS = "OpenBSD" ]; then
67+
desired_llvm_version=""
68+
elif [ $OS = "NetBSD" ]; then
69+
desired_llvm_version=""
70+
else
71+
desired_llvm_version="-$desired_llvm_major_version.$desired_llvm_minor_version"
72+
fi
73+
locate_llvm_exec() {
74+
if which "$llvm_prefix$1$desired_llvm_version" > /dev/null 2>&1
75+
then
76+
echo "$(which $llvm_prefix$1$desired_llvm_version)"
77+
elif which "$llvm_prefix$1" > /dev/null 2>&1
78+
then
79+
echo "$(which $llvm_prefix$1)"
80+
else
81+
exit 1
82+
fi
83+
}
84+
85+
llvm_ar="$(locate_llvm_exec ar)"
86+
[[ $? -eq 0 ]] || { echo "Unable to locate llvm-ar"; exit 1; }
87+
llvm_link="$(locate_llvm_exec link)"
88+
[[ $? -eq 0 ]] || { echo "Unable to locate llvm-link"; exit 1; }
89+
llvm_nm="$(locate_llvm_exec nm)"
90+
[[ $? -eq 0 ]] || { echo "Unable to locate llvm-nm"; exit 1; }
91+
llvm_ranlib="$(locate_llvm_exec ranlib)"
92+
[[ $? -eq 0 ]] || { echo "Unable to locate llvm-ranlib"; exit 1; }
93+
if [ $OS = "Linux" -o $OS = "FreeBSD" -o $OS = "OpenBSD" -o $OS = "NetBSD" ]; then
94+
llvm_objdump="$(locate_llvm_exec objdump)"
95+
[[ $? -eq 0 ]] || { echo "Unable to locate llvm-objdump"; exit 1; }
96+
fi
97+
98+
cmake_extra_defines=
99+
if [[ -n "$LLDB_LIB_DIR" ]]; then
100+
cmake_extra_defines="$cmake_extra_defines -DWITH_LLDB_LIBS=$LLDB_LIB_DIR"
101+
fi
102+
if [[ -n "$LLDB_INCLUDE_DIR" ]]; then
103+
cmake_extra_defines="$cmake_extra_defines -DWITH_LLDB_INCLUDES=$LLDB_INCLUDE_DIR"
104+
fi
105+
106+
cmake \
107+
"-DCMAKE_USER_MAKE_RULES_OVERRIDE=$1/src/pal/tools/clang-compiler-override.txt" \
108+
"-DCMAKE_AR=$llvm_ar" \
109+
"-DCMAKE_LINKER=$llvm_link" \
110+
"-DCMAKE_NM=$llvm_nm" \
111+
"-DCMAKE_OBJDUMP=$llvm_objdump" \
112+
"-DCMAKE_RANLIB=$llvm_ranlib" \
113+
"-DCMAKE_BUILD_TYPE=$buildtype" \
114+
$cmake_extra_defines \
115+
"$1"

0 commit comments

Comments
 (0)