@@ -404,13 +404,75 @@ function install_rustup {
404404 rustup show
405405}
406406
407- function install_cargo_binstall {
408- curl -L --proto ' =https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
409- cargo binstall -V
410- }
411-
412407function install_sccache {
413- cargo binstall -y --disable-strategies compile sccache
408+ local version=" $1 "
409+
410+ echo " ==> installing sccache..."
411+ if sccache --version & > /dev/null; then
412+ echo " sccache is already installed"
413+ return
414+ fi
415+
416+ if [[ -z " $version " ]]; then
417+ echo " Missing sccache version"
418+ return 1
419+ fi
420+
421+ local os
422+ os=" $( uname -s) "
423+ if [[ " $os " == " Darwin" ]]; then
424+ brew install sccache
425+ sccache --version
426+ return
427+ fi
428+
429+ if [[ " $os " != " Linux" ]]; then
430+ echo " Unsupported operating system for sccache: $( uname -s) "
431+ return 1
432+ fi
433+
434+ local arch triple asset url tmpdir extract_dir cargo_bin
435+ case " $( uname -m) " in
436+ x86_64 | amd64)
437+ triple=" x86_64-unknown-linux-musl"
438+ ;;
439+ aarch64 | arm64)
440+ triple=" aarch64-unknown-linux-musl"
441+ ;;
442+ * )
443+ echo " Unsupported architecture for sccache: $( uname -m) "
444+ return 1
445+ ;;
446+ esac
447+
448+ asset=" sccache-${version} -${triple} .tar.gz"
449+ url=" https://github.com/mozilla/sccache/releases/download/${version} /${asset} "
450+ tmpdir=$( mktemp -d)
451+ if ! curl -fsSL " $url " -o " ${tmpdir} /${asset} " ; then
452+ rm -rf " $tmpdir "
453+ echo " Failed to download sccache from ${url} "
454+ return 1
455+ fi
456+
457+ if ! tar -xzf " ${tmpdir} /${asset} " -C " $tmpdir " ; then
458+ rm -rf " $tmpdir "
459+ echo " Failed to extract sccache archive"
460+ return 1
461+ fi
462+
463+ CARGO_HOME=" ${CARGO_HOME:- ${HOME} / .cargo} "
464+ cargo_bin=" ${CARGO_HOME} /bin"
465+ mkdir -p " $cargo_bin "
466+ extract_dir=" ${tmpdir} /sccache-${version} -${triple} "
467+ if [[ ! -f " ${extract_dir} /sccache" ]]; then
468+ rm -rf " $tmpdir "
469+ echo " sccache binary not found in archive"
470+ return 1
471+ fi
472+
473+ install -m 755 " ${extract_dir} /sccache" " ${cargo_bin} /sccache"
474+ rm -rf " $tmpdir "
475+
414476 sccache --version
415477}
416478
@@ -497,6 +559,155 @@ function install_taplo_cli {
497559 " ${taplo_bin} /taplo" --version
498560}
499561
562+ function install_cargo_machete {
563+ local version=" $1 "
564+
565+ echo " ==> installing cargo-machete..."
566+ if cargo machete --version & > /dev/null; then
567+ echo " cargo-machete is already installed"
568+ return
569+ fi
570+ if [[ -z " $version " ]]; then
571+ echo " Missing cargo-machete version"
572+ return 1
573+ fi
574+
575+ local os arch triple asset url tmpdir extract_dir cargo_bin
576+ os=" $( uname -s) "
577+ case " $os " in
578+ Darwin | Linux) ;;
579+ * )
580+ echo " Unsupported operating system for cargo-machete: $( uname -s) "
581+ return 1
582+ ;;
583+ esac
584+
585+ case " $( uname -m) " in
586+ x86_64 | amd64)
587+ arch=" x86_64"
588+ ;;
589+ aarch64 | arm64)
590+ arch=" aarch64"
591+ ;;
592+ * )
593+ echo " Unsupported architecture for cargo-machete: $( uname -m) "
594+ return 1
595+ ;;
596+ esac
597+
598+ if [[ " $os " == " Darwin" ]]; then
599+ triple=" ${arch} -apple-darwin"
600+ else
601+ if [[ " $arch " == " x86_64" ]]; then
602+ triple=" ${arch} -unknown-linux-musl"
603+ else
604+ triple=" ${arch} -unknown-linux-gnu"
605+ fi
606+ fi
607+
608+ asset=" cargo-machete-${version} -${triple} .tar.gz"
609+ url=" https://github.com/bnjbvr/cargo-machete/releases/download/${version} /${asset} "
610+ tmpdir=$( mktemp -d)
611+ if ! curl -fsSL " $url " -o " ${tmpdir} /${asset} " ; then
612+ rm -rf " $tmpdir "
613+ echo " Failed to download cargo-machete from ${url} "
614+ return 1
615+ fi
616+
617+ if ! tar -xzf " ${tmpdir} /${asset} " -C " $tmpdir " ; then
618+ rm -rf " $tmpdir "
619+ echo " Failed to extract cargo-machete archive"
620+ return 1
621+ fi
622+
623+ CARGO_HOME=" ${CARGO_HOME:- ${HOME} / .cargo} "
624+ cargo_bin=" ${CARGO_HOME} /bin"
625+ mkdir -p " $cargo_bin "
626+ extract_dir=" ${tmpdir} /cargo-machete-${version} -${triple} "
627+ if [[ ! -f " ${extract_dir} /cargo-machete" ]]; then
628+ rm -rf " $tmpdir "
629+ echo " cargo-machete binary not found in archive"
630+ return 1
631+ fi
632+
633+ install -m 755 " ${extract_dir} /cargo-machete" " ${cargo_bin} /cargo-machete"
634+ rm -rf " $tmpdir "
635+ cargo machete --version
636+ }
637+ function install_cargo_audit {
638+ local version=" $1 "
639+
640+ echo " ==> installing cargo-audit..."
641+ if cargo audit --version & > /dev/null; then
642+ echo " cargo-audit is already installed"
643+ return
644+ fi
645+
646+ local os
647+ os=" $( uname -s) "
648+ if [[ " $os " == " Darwin" ]]; then
649+ brew install cargo-audit
650+ cargo audit --version
651+ return
652+ fi
653+
654+ if [[ " $os " != " Linux" ]]; then
655+ echo " Unsupported operating system for cargo-audit: $( uname -s) "
656+ return 1
657+ fi
658+
659+ if [[ -z " $version " ]]; then
660+ echo " Missing cargo-audit version"
661+ return 1
662+ fi
663+
664+ local arch triple asset url tmpdir extract_dir cargo_bin
665+ case " $( uname -m) " in
666+ x86_64 | amd64)
667+ triple=" x86_64-unknown-linux-musl"
668+ ;;
669+ aarch64 | arm64)
670+ triple=" aarch64-unknown-linux-gnu"
671+ ;;
672+ * )
673+ echo " Unsupported architecture for cargo-audit: $( uname -m) "
674+ return 1
675+ ;;
676+ esac
677+
678+ local tag
679+ tag=" cargo-audit%2F${version} "
680+ asset=" cargo-audit-${triple} -${version} .tgz"
681+ url=" https://github.com/rustsec/rustsec/releases/download/${tag} /${asset} "
682+ tmpdir=$( mktemp -d)
683+ if ! curl -fsSL " $url " -o " ${tmpdir} /${asset} " ; then
684+ rm -rf " $tmpdir "
685+ echo " Failed to download cargo-audit from ${url} "
686+ return 1
687+ fi
688+
689+ if ! tar -xzf " ${tmpdir} /${asset} " -C " $tmpdir " ; then
690+ rm -rf " $tmpdir "
691+ echo " Failed to extract cargo-audit archive"
692+ return 1
693+ fi
694+
695+ CARGO_HOME=" ${CARGO_HOME:- ${HOME} / .cargo} "
696+ cargo_bin=" ${CARGO_HOME} /bin"
697+ mkdir -p " $cargo_bin "
698+ extract_dir=" ${tmpdir} /cargo-audit-${triple} -${version} "
699+ if [[ ! -f " ${extract_dir} /cargo-audit" ]]; then
700+ rm -rf " $tmpdir "
701+ echo " cargo-audit binary not found in archive"
702+ return 1
703+ fi
704+
705+ install -m 755 " ${extract_dir} /cargo-audit" " ${cargo_bin} /cargo-audit"
706+ rm -rf " $tmpdir "
707+
708+ cargo audit --version
709+ }
710+
500711function install_typos_cli {
501712 echo " ==> installing typos CLI..."
502713 if typos --version & > /dev/null; then
@@ -710,7 +921,6 @@ if [ ! -f rust-toolchain.toml ]; then
710921 exit 1
711922fi
712923RUST_TOOLCHAIN=" $( awk -F' [ ="]+' ' $1 == "channel" { print $2 }' rust-toolchain.toml) "
713- MUSL_TARGET=" $( uname -m) -unknown-linux-musl"
714924
715925PACKAGE_MANAGER=
716926if [[ " $( uname) " == " Linux" ]]; then
@@ -788,32 +998,19 @@ if [[ "$INSTALL_BUILD_TOOLS" == "true" ]]; then
788998 # Any call to cargo will make rustup install the correct toolchain
789999 cargo version
7901000
791- install_cargo_binstall
792-
793- install_sccache
1001+ install_sccache " v0.12.0"
7941002 install_cargo_nextest
7951003fi
7961004
7971005if [[ " $INSTALL_CHECK_TOOLS " == " true" ]]; then
798- if [[ " $( uname) " == " Linux" ]]; then
799- # install musl target to avoid downloading the tools with incompatible GLIBC
800- export CARGO_BUILD_TARGET=" ${MUSL_TARGET} "
801- fi
802- if [[ -f scripts/setup/rust-tools.txt ]]; then
803- while read -r tool; do
804- cargo binstall -y --disable-strategies compile " $tool "
805- done < scripts/setup/rust-tools.txt
806- fi
807- if [[ " $( uname) " == " Linux" ]]; then
808- unset CARGO_BUILD_TARGET
809- fi
810-
8111006 if [[ " $PACKAGE_MANAGER " == " apk" ]]; then
8121007 # needed by lcov
8131008 echo http://nl.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories
8141009 fi
8151010 install_pkg lcov " $PACKAGE_MANAGER "
8161011
1012+ install_cargo_audit " v0.22.0"
1013+ install_cargo_machete " v0.9.1"
8171014 install_taplo_cli
8181015 install_typos_cli
8191016fi
0 commit comments