1
1
#! /bin/bash
2
2
3
+ # Find all the directories we might need (based on
4
+ # heroku-buildpack-nodejs code).
5
+ BUILD_DIR=${1:- }
6
+ CACHE_DIR=${2:- }
7
+ ENV_DIR=${3:- }
8
+ BP_DIR=$( cd $( dirname ${0:- } ) ; cd ..; pwd)
9
+
3
10
# Set defaults for our configuration variables. Stable Rust is sufficiently
4
11
# stable at this point that I think we can just default it.
5
12
VERSION=stable
6
13
7
14
# Load our configuration variables, if any were specified.
8
- if [ -f " $1 /RustConfig" ]; then
9
- . " $1 /RustConfig"
15
+ if [ -f " $BUILD_DIR /RustConfig" ]; then
16
+ . " $BUILD_DIR /RustConfig"
10
17
fi
11
18
12
19
# Standard paranoia.
20
27
21
28
# Notify users running old, unstable versions of Rust about how to deploy
22
29
# successfully.
23
- if [ ! -z ${CARGO_URL+x} ] || [ ! -f " $1 /Cargo.toml" ]; then
30
+ if [ ! -z ${CARGO_URL+x} ] || [ ! -f " $BUILD_DIR /Cargo.toml" ]; then
24
31
>&2 cat << EOF
25
32
To deploy a modern Rust app, make sure you have a Cargo.toml file, and that
26
33
you do not define CARGO_URL or CARGO_VERSION in RustConfig. If you're
42
49
exit 1
43
50
fi
44
51
45
- # Switch to our cache directory.
46
- mkdir -p " $2 "
47
- cd " $2 "
48
-
49
- # Rustup wants to create `~/.multirust` and fill it with toolchains. If we
50
- # set $HOME to our cache directory, it will do the right thing.
51
- export HOME=" ` pwd` "
52
+ # Record our Rust build environment configuration in an export file, in
53
+ # case another buildpack needs it to build Ruby gems that use Rust or
54
+ # something like that.
55
+ cat << EOF > $BP_DIR /export
56
+ # Our rustup installation.
57
+ export RUSTUP_HOME="$CACHE_DIR /multirust"
52
58
53
- # This is where we will cache our downloaded compilers, as well as git
54
- # repositories downloaded by Cargo. We implicitly trust Rustup and Cargo
59
+ # Our cargo installation. We implicitly trust Rustup and Cargo
55
60
# to do the right thing when new versions are released.
56
- export CARGO_HOME=" ` pwd` /cargo"
61
+ export CARGO_HOME="$CACHE_DIR /cargo"
62
+
63
+ # Include binaries installed by cargo and rustup in our path.
64
+ PATH="\$ CARGO_HOME/bin:\$ PATH"
65
+ EOF
66
+
67
+ # Read our build environment back in and evaluate it so that we can use it.
68
+ . $BP_DIR /export
69
+
70
+ # Switch to our cache directory.
71
+ mkdir -p " $CACHE_DIR "
72
+ cd " $CACHE_DIR "
57
73
58
- # Make sure we have the correct Rust binaries and set up PATH. We don't
59
- # skip this step even if $RUST_HOME exists, because rustup may want to
60
- # update our channel.
61
- PATH=" $CARGO_HOME /bin:$PATH "
74
+ # Make sure we have an appropriate Rust toolchain installed.
62
75
if [ -d " $CARGO_HOME " ]; then
63
76
echo " -----> Checking for new releases of Rust $VERSION channel"
64
77
# It's possible that $VERSION has changed, or the `stable` channel has updated.
81
94
# This is where we will cache our Rust output. Note the suggestions at
82
95
# https://github.com/alexcrichton/cargo/commit/014765f788ca1c2476936835ca32cc2746f99b42
83
96
# which describe how this needs to be named.
84
- export CARGO_TARGET_DIR=" $2 /target"
97
+ export CARGO_TARGET_DIR=" $CACHE_DIR /target"
85
98
86
99
# Build our project (into CARGO_TARGET_DIR so we have caching) and copy it
87
100
# back to the source tree. In theory, we could probably just copy the
@@ -92,7 +105,7 @@ export CARGO_TARGET_DIR="$2/target"
92
105
# export RUST_LOG="cargo::sources::git=debug"
93
106
# To debug compiler and linking issues, add `--verbose`.
94
107
echo " -----> Building application using Cargo"
95
- cd " $1 "
108
+ cd " $BUILD_DIR "
96
109
rm -rf target/
97
110
cargo build --release
98
111
cp -a " $CARGO_TARGET_DIR " target
0 commit comments