diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 5b225b89a3..f745c75385 100755 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -49,3 +49,6 @@ RUN chmod -R a+rw $CARGO_HOME \ # Switch back to dialog for any ad-hoc use of apt-get ENV DEBIAN_FRONTEND=dialog + +# Required if we want to use `lld` as the default linker for RuSTy +RUN ln -sf /usr/bin/ld.lld-$LLVM_VER /usr/bin/ld.lld \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7579a409ae..1e1572cef6 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,8 @@ *.bc *.a *.elf + +# Introduced with issue #679: +# We're assuming config.toml to be a local config file for now. +# This entry has to be removed if a global config file is needed in the near future. +.cargo/config.toml \ No newline at end of file diff --git a/book/src/build_and_install.md b/book/src/build_and_install.md index f8c3aa6809..6108e70284 100644 --- a/book/src/build_and_install.md +++ b/book/src/build_and_install.md @@ -38,5 +38,9 @@ cargo build --release You can find the binary at `./target/release/rustyc`. +## Improving Compile Times +By default Rust uses the GNU Linker on Linux which compared to [lld](https://lld.llvm.org/) is slower by a margin of [~2x - 4x](https://llvm.org/devmtg/2016-10/slides/Ueyama-lld.pdf). To improve compile times we can therefore use `lld`. To do so you will need to run the `rusty/scripts/lld.sh` script inside the `rusty` root folder, i.e. by executing `./scripts/lld.sh`. **Note** that the script was only tested on Ubuntu based distributions thus far. + + ## Installing _TODO_ diff --git a/scripts/lld.sh b/scripts/lld.sh new file mode 100755 index 0000000000..05719bfc03 --- /dev/null +++ b/scripts/lld.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env sh + +LD_LLD_WITH_VERSION=$(command -v ld.lld-$1) +LD_LLD_WITHOUT_VERSION=$(command -v ld.lld) + +if [ -z $1 ]; then + echo "No version specified!" + echo "Usage: $0 " + echo "Example: $0 13" + exit 1 +fi + +# Check if the specified `lld` version is present on the system +if [ -z $LD_LLD_WITH_VERSION ]; then + echo "Could not find ld.lld-$1, make sure lld is installed" + exit 1 +fi + +# Check if `ld.lld` is present on the system +if [ -z $LD_LLD_WITHOUT_VERSION ]; then + # Not present, create a symlink into ~/.local/bin + mkdir -p $HOME/.local/bin + ln -svf $LD_LLD_WITH_VERSION $HOME/.local/bin/ld.lld + + # Append new $PATH to `.bashrc` + echo 'export PATH=$HOME/.local/bin:$PATH' >> $HOME/.bashrc + echo 'A new $PATH entry has been added to your .bashrc' + echo 'For changes to take effect close and reopen your current shell.' + +else + # Present, do nothing because we don't want to modifiy system-wide configurations + echo "Note: Using already present $LD_LLD_WITHOUT_VERSION binary" +fi + +# Create `config.toml` to make `lld` the default linker for RuSTy +mkdir -p .cargo +echo -n '[build] +rustflags = ["-C", "link-arg=-fuse-ld=lld"]' > .cargo/config.toml + +# Makes sure new builds with lld succeed +cargo clean \ No newline at end of file