From 6f909b610ddbda3a3c1d9a03e7ec6dd6dcd957a0 Mon Sep 17 00:00:00 2001 From: Kenichi KATO Date: Wed, 9 Oct 2024 01:02:26 +0900 Subject: [PATCH] Add option to install source code. --- README.md | 6 ++++++ bin/install | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/README.md b/README.md index 6eb36aa..90b0ab7 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,12 @@ RUST_WITHOUT=rust-docs,rust-other-component asdf install rust 1.51.0 export RUST_WITHOUT=rust-docs ``` +Also, the Standalone installers do not install source code, which may cause problems in some development environments. If you need the source code, please use the environment variable `RUST_SOURCE` to perform an additional installation. + +```sh +RUST_SOURCE=1 asdf install rust 1.51.0 +``` + ## License Licensed under the diff --git a/bin/install b/bin/install index 185e322..cecb1ac 100755 --- a/bin/install +++ b/bin/install @@ -45,9 +45,11 @@ install_rust() { esac local download_url="https://static.rust-lang.org/dist/rust-${version}-${architecture}-${platform}.tar.gz" + local download_src_url="https://static.rust-lang.org/dist/rustc-${version}-src.tar.xz" local tmp_download_dir tmp_download_dir=$(mktemp -d -t rust_tmp_XXXXXX) local source_path="${tmp_download_dir}/rust.tar.gz" + local source_src_path="${tmp_download_dir}/rust-src.tar.gz" local distination_path="${tmp_download_dir}/dist" ( @@ -60,6 +62,17 @@ install_rust() { cd "$distination_path" ./install.sh "$configure_options" || fail "Could not install" + if [ "${RUST_SOURCE}" ]; then + echo "RUST_SOURCE is set, download and install source code..." + echo "∗ Downloading Source Code..." + curl --silent --location --create-dirs --output "$source_src_path" "$download_src_url" || fail "Could not download rust source code $version" + + echo "∗ Installing Source Code..." + local rustlib_src_path="$install_path/lib/rustlib/src/rust" + mkdir -p "$rustlib_src_path" + tar zxf "$source_src_path" -C "$rustlib_src_path" --strip-components=1 || fail "Could not uncompress source code" + fi + rm -rf "$tmp_download_dir" echo "The installation was successful!"