Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial pr #1

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
51 changes: 3 additions & 48 deletions bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
set -eu

LLVM_URL=https://github.com/llvm/llvm-project.git
MUSL_URL=git://git.musl-libc.org/musl

function update_llvm () {
pushd llvm-project
Expand All @@ -23,7 +22,7 @@ function get_or_fetch_llvm () {
}

function bootstrap_compiler_rt () {
rm -rf sysroot
#rm -rf sysroot
mkdir -p sysroot
SYSROOT=$(readlink -f sysroot)
CC=$(which clang)
Expand Down Expand Up @@ -57,51 +56,7 @@ function bootstrap_compiler_rt () {
popd
}

function update_musl () {
pushd musl
git fetch --depth 1
git reset --hard origin/master
popd
}

function fetch_musl () {
git clone --depth=1 $MUSL_URL --branch master --single-branch
}

function get_or_fetch_musl () {
if [[ -d musl ]]; then
update_musl
else
fetch_musl
fi;
}

function build_musl () {
BUILTINS=$(readlink -f sysroot/usr/local/lib/linux/libclang_rt.builtins-x86_64.a)
CC=$(which clang)
SYSROOT=$(readlink -f sysroot)
rm -rf musl/build
mkdir -p musl/build
pushd musl/build
LIBCC=$BUILTINS CC=$CC ../configure \
--prefix=/usr/local/ \
--host=x86_64-unknown-linux-musl \
--syslibdir=/usr/local/lib \
--disable-static

make -j$(nproc) AR=llvm-ar RANLIB=llvm-ranlib
make DESTDIR=$SYSROOT install-libs install-headers -j$(nproc)

# TODO: hack
pushd $SYSROOT/usr/local/lib
ln -sf libc.so ld-musl-x86_64.so.1
popd
popd
./test_lib.sh
}

#get_or_fetch_llvm
get_or_fetch_llvm
bootstrap_compiler_rt
./kernel.sh
#get_or_fetch_musl
build_musl
./musl.sh
56 changes: 56 additions & 0 deletions musl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
set -eu

MUSL_URL=git://git.musl-libc.org/musl

function update_musl () {
pushd musl
git fetch --depth 1
git reset --hard origin/master
popd
}

function fetch_musl () {
git clone --depth=1 $MUSL_URL --branch master --single-branch
}

function get_or_fetch_musl () {
if [[ -d musl ]]; then
update_musl
else
fetch_musl
fi;
}

function build_musl () {
# TODO: something better than this...like if we updated musl.
if [[ -d sysroot/usr/local/include ]]; then
if [[ -n "$(find sysroot/usr/local/include -type f | wc -l)" ]]; then
return
fi;
fi;

BUILTINS=$(readlink -f sysroot/usr/local/lib/linux/libclang_rt.builtins-x86_64.a)
CC=$(which clang)
SYSROOT=$(readlink -f sysroot)
rm -rf musl/build
mkdir -p musl/build
pushd musl/build
LIBCC=$BUILTINS CC=$CC ../configure \
--prefix=/usr/local/ \
--host=x86_64-unknown-linux-musl \
--syslibdir=/usr/local/lib \
--disable-static

make -j$(nproc) AR=llvm-ar RANLIB=llvm-ranlib
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
make -j$(nproc) AR=llvm-ar RANLIB=llvm-ranlib
make -j$(nproc) AR=${AR:-ar} RANLIB=${RANLIB:-ranlib}

The user can specify AR=llvm-ar RANLIB=llvm-ranlib to select it.

make DESTDIR=$SYSROOT install-libs install-headers -j$(nproc)

# TODO: hack
pushd $SYSROOT/usr/local/lib
ln -sf libc.so ld-musl-x86_64.so.1
popd
popd
./test_lib.sh
}

get_or_fetch_musl
build_musl