@@ -6,13 +6,21 @@ function update_llvm () {
66 pushd llvm-project
77 # hack for https://reviews.llvm.org/D97572.
88 git fetch --depth 1 origin 3a6365a439ede4b7c65076bb42b1b7dbf72216b5
9+ # git checkout FETCH_HEAD
910 # git fetch --depth 1
1011 git reset --hard FETCH_HEAD
1112 popd
1213}
1314
1415function fetch_llvm () {
15- git clone --depth=1 $LLVM_URL --branch main --single-branch
16+ # git clone --depth=1 $LLVM_URL --branch main --single-branch
17+ mkdir llvm-project
18+ pushd llvm-project
19+ git init
20+ git remote add origin $LLVM_URL
21+ git fetch --depth 1 origin 3a6365a439ede4b7c65076bb42b1b7dbf72216b5
22+ git checkout FETCH_HEAD
23+ popd
1624}
1725
1826function get_or_fetch_llvm () {
@@ -85,6 +93,8 @@ function build_libunwind () {
8593 popd
8694}
8795
96+ # Saleem: c++abi is the libc equivalent for c++: it is the language runtime;
97+ # libc++ is the C++ standard library
8898function build_libcxxabi () {
8999 SYSROOT=$( readlink -f sysroot/)
90100 RESOURCE=$( readlink -f sysroot/usr/local)
@@ -102,7 +112,7 @@ function build_libcxxabi () {
102112 fi
103113 popd
104114
105- rm -rf llvm-project/libcxxabi/build #
115+ # rm -rf llvm-project/libcxxabi/build #
106116 mkdir -p llvm-project/libcxxabi/build
107117 pushd llvm-project/libcxxabi/build
108118 # TODO: link with lld
@@ -134,9 +144,51 @@ function build_libcxxabi () {
134144 popd
135145}
136146
137- # get_or_fetch_llvm
138- # bootstrap_compiler_rt
139- # ./kernel.sh
140- # ./musl.sh
141- # build_libunwind
142- build_libcxxabi
147+ function build_libcxx () {
148+ CC=$( which clang)
149+ CXX=$( which clang++)
150+ SYSROOT=$( readlink -f sysroot/)
151+ RESOURCE=$( readlink -f sysroot/usr/local)
152+
153+ # rm -rf llvm-project/libcxx/build #
154+ mkdir -p llvm-project/libcxx/build
155+ pushd llvm-project/libcxx/build
156+
157+ # TODO: link with lld
158+ cmake \
159+ -D CMAKE_BUILD_TYPE=Release \
160+ -D CMAKE_CXX_COMPILER=$CXX \
161+ -D CMAKE_CXX_COMPILER_TARGET=x86_64-unknown-linux-musl \
162+ -D CMAKE_CXX_COMPILER_WORKS=YES \
163+ -D CMAKE_C_COMPILER=$CC \
164+ -D CMAKE_C_COMPILER_TARGET=x86_64-unknown-linux-musl \
165+ -D LIBCXX_ENABLE_STATIC=NO \
166+ -D LIBCXX_CXX_ABI=libcxxabi \
167+ -D LIBCXX_TARGET_TRIPLE=x86_64-unknown-linux-musl \
168+ -D LIBCXX_SYSROOT=$SYSROOT /usr/local \
169+ -D LIBCXX_HAS_MUSL_LIBC=YES \
170+ -D LIBCXX_USE_COMPILER_RT=YES \
171+ --debug-trycompile \
172+ -D CMAKE_EXE_LINKER_FLAGS=" -rtlib=compiler-rt -resource-dir=$RESOURCE --sysroot=$RESOURCE " \
173+ -G Ninja \
174+ -S ..
175+ # -D CMAKE_C_COMPILER_WORKS=YES \
176+ # -D LIBCXX_LINK_FLAGS="-stdlib=libc++" \
177+ # -D LIBCXX_LINK_FLAGS="-nodefaultlibs -lc -rtlib=compiler-rt" \
178+ ninja libc++.so
179+
180+
181+ popd
182+ }
183+
184+ get_or_fetch_llvm
185+ bootstrap_compiler_rt
186+ ./kernel.sh
187+ ./musl.sh
188+ build_libunwind
189+ # build_libcxxabi
190+ # TODO: this doesn't work yet
191+ # build_libcxx
192+
193+ # Fangrui says try:
194+ # -DLLVM_HOST_TRIPLE=
0 commit comments