consistent license, various updates
[buildscripts] / rust
1 #!/bin/bash
2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
7 # its license to GPL.
8
9 # Copyright 2024 Ian Kelling
10
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
14
15 # http://www.apache.org/licenses/LICENSE-2.0
16
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
22
23
24 source /a/bin/bash-bear-trap/bash-bear
25 source /a/bin/distro-functions/src/package-manager-abstractions
26
27 PATH="$PATH:$HOME/.cargo/bin"
28 hash -r
29
30 # todo: this should happen in some kind of sandbox or vm
31
32 # install rust.
33 if type -t rustc &>/dev/null; then
34 rustup update
35 else
36
37 # added stable due to this error
38 # Mar 11 00:13:15 info: no updatable toolchains installed
39 # Mar 11 00:13:15 info: checking for self-update
40 # Mar 11 00:13:15 info: cleaning up downloads & tmp directories
41 # Mar 11 00:13:15 error: rustup could not choose a version of cargo to run, because one wasn't specified explicitly, and no default is configured.
42 # Mar 11 00:13:15 help: run 'rustup default stable' to download the latest stable release of Rust and set it as your default toolchain.
43 # Mar 11 00:13:15 /a/bin/buildscripts/rust:31: `cargo install-update -a' returned 1
44
45 curl https://sh.rustup.rs -sSf | bash -s -- --default-toolchain stable -y
46 fi
47
48 if ! which rg &>/dev/null; then
49 cargo install ripgrep
50 fi
51
52 if ! type -t cargo-install-update &>/dev/null; then
53 # due to
54 # error: failed to run custom build command for `openssl-sys v0.9.53`
55 pi libssl-dev pkg-config
56 cargo install cargo-update
57 fi
58
59 cargo install-update -a
60
61 # https://github.com/rust-lang/cargo/issues/3289
62 # 149 mb on fresh install as of 07-2023
63 if du -s -t 500M ~/.cargo/registry | grep . &>/dev/null; then
64 rm -rf ~/.cargo/registry
65 fi