Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

rust: enable build on LLVM-only systems #304

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion extra/rust/build
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,33 @@ jemalloc = false
debug-assertions = false
codegen-tests = false
codegen-units-std = 1
EOF

case $("$CC" -print-file-name=libunwind.so) in */*)
cat >> config.toml <<EOF
llvm-libunwind = "system"
EOF
esac

cat >> config.toml <<EOF
[target.x86_64-unknown-linux-musl]
llvm-config = "/usr/bin/llvm-config"
crt-static = false
EOF

# Since libgcc_s.so is needed for Rust's own bootstrap binary, and
# it's dynamically linked, we'll have to add two files, libgcc_s.so.1
# for the symlink, and libgcc_s.so so the linker points to libunwind.
case $("$CC" -print-file-name=libunwind.so) in */*)
mkdir -p libgcc
ln -sf /usr/lib/libunwind.so.1 libgcc/libgcc_s.so.1
cat > libgcc/libgcc_s.so <<EOF
INPUT(-lunwind)
EOF
export LD_LIBRARY_PATH="$PWD/libgcc:$LD_LIBRARY_PATH"
export LIBRARY_PATH="$PWD/libgcc:$LIBRARY_PATH"
esac

Comment on lines +76 to +88
Copy link
Member

Choose a reason for hiding this comment

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

Is upstream doing anything about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not that I know of. But I think they should've statically compiled the bootstrap binary instead of making it dynamically linked. Also, it's ugly so I understand if this ended up not being merged.

Copy link

Choose a reason for hiding this comment

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

They can't statically compile it because proc_macro doesn't support static linking or at least that's what the upstream rust people said when I bought up the idea. I can say that libunwind.so is mostly ABI compatible on x86_64 systems, on aarch64 and others the rust binary requires symbols such as __clear_cache which are provided by compiler-rt. I solved this with the below command:

clang -shared -o build/libgcc_s.so.1 \
-Wl,--allow-multiple-definition -Wl,--whole-archive \
$(clang -print-libgcc-file-name) -lunwind

Copy link
Contributor Author

@konimex konimex Aug 4, 2021

Choose a reason for hiding this comment

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

I'll try this later on my build file. Thanks!

python3 ./x.py build -j "$(nproc)"
python3 ./x.py install

Expand All @@ -73,4 +94,3 @@ rm -rf \
"$1/usr/share/doc" \
"$1/usr/share/zsh" \
"$1/usr/lib/rustlib/uninstall.sh"