Skip to content

Commit c5b81d1

Browse files
WIP: trying to get libc++ to build
also, I had libc++abi built, but upon wiping my build artifacts and rerunning fresh, that doesn't build anymore...
1 parent e253969 commit c5b81d1

3 files changed

Lines changed: 65 additions & 13 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# third party sources
2+
13
linux/
24
llvm-project/
35
musl/
46

7+
# build outputs
58
sysroot/
6-
kernel-headers/

bootstrap.sh

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1415
function 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

1826
function 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
8898
function 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=

kernel.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ function get_or_fetch_linux_kernel () {
2222
}
2323

2424
function build_kernel_headers () {
25-
if [[ -d kernel-headers ]]; then
26-
return
27-
fi
25+
SYSROOT=$(readlink -f sysroot)
2826

2927
pushd linux
30-
make LLVM=1 INSTALL_HDR_PATH=../kernel-headers mrproper headers_install -j$(nproc)
28+
make LLVM=1 INSTALL_HDR_PATH=$SYSROOT/usr/local mrproper headers_install -j$(nproc)
3129
popd
3230
}
3331

0 commit comments

Comments
 (0)