-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild
More file actions
executable file
·69 lines (59 loc) · 2.11 KB
/
Copy pathbuild
File metadata and controls
executable file
·69 lines (59 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
set -eo pipefail
echo "---> Rust Buildpack"
# 1. GET ARGS
layers_dir=$1
plan_path=$3
# 2. DOWNLOAD Rust
rust_layer_dir="${layers_dir}/rust"
mkdir -p "${rust_layer_dir}"
export RUSTUP_HOME="${rust_layer_dir}/multirust"
# Our cargo installation. We implicitly trust Rustup and Cargo
# to do the right thing when new versions are released.
export CARGO_HOME="${rust_layer_dir}"
# Default build flags to pass to `cargo build`.
RUST_CARGO_BUILD_FLAGS="--release"
# determine rust version provided during detection
rust_version=$(< "${plan_path}" yj -t | jq -r '.entries[] | select(.name == "rust") | .version')
remote_rust_version="not found"
if [[ -f "${rust_layer_dir}.toml" ]]; then
remote_rust_version=$(< "${rust_layer_dir}.toml" yj -t | jq -r .metadata 2>/dev/null || echo 'not found')
fi
if [[ "${rust_version}" == "${remote_rust_version}" ]] ; then
echo "---> Reusing rustup, checking for new releases of Rust $rust_version channel"
"${rust_layer_dir}"/bin/rustup self update
"${rust_layer_dir}"/bin/rustup update "$rust_version"
"${rust_layer_dir}"/bin/rustup default "$rust_version"
else
# Standard paranoia.
set -eu
echo "---> Downloading rustup"
curl https://sh.rustup.rs -sSf > rustup.sh
chmod u+x rustup.sh
echo "---> Using rustup to install Rust channel ${rust_version}"
./rustup.sh -y --default-toolchain "${rust_version}"
rm rustup.sh
mv "${CARGO_HOME}/env" "${CARGO_HOME}/bin"
if [ ! -x "${CARGO_HOME}/bin/rustc" ]; then
echo "failed: Cannot find Rust binaries at ${rust_layer_dir}"
exit 1
fi
cat > "${rust_layer_dir}.toml" <<EOL
cache = true
build = true
launch = true
metadata = "${rust_version}"
EOL
fi
# 3. MAKE RUST AVAILABLE TO THIS SCRIPT
export PATH="${CARGO_HOME}/bin:${PATH}"
export CARGO_TARGET_DIR="${CARGO_HOME}/target"
echo "-----> Building application using Cargo"
if [ -s .cargo/config ]; then
cp -f .cargo/config "${CARGO_HOME}/config"
fi
rm -rf target/
cargo build $RUST_CARGO_BUILD_FLAGS
mkdir -p target/release
find "$CARGO_TARGET_DIR/release" -maxdepth 1 -type f -executable -exec cp -a -t target/release {} \;
generate-launch.sh "${layers_dir}"