-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild
More file actions
executable file
·68 lines (56 loc) · 1.5 KB
/
build
File metadata and controls
executable file
·68 lines (56 loc) · 1.5 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
#!/usr/bin/env bash
set -eo pipefail
echo "---> Rust Buildpack"
# 1. GET ARGS
layers_dir=$1
plan_path=$3
# shellcheck source=/dev/null
. generate-project.sh "${layers_dir}"
# 2. Install build deps
# shellcheck source=/dev/null
. generate-layers.sh "${layers_dir}"
generate_deps_layer build-deps
generate_deps_layer run-deps
# 3. install rust
generate_stack_layer rust "${plan_path}" false
# shellcheck source=/dev/null
. init-stack
echo "-----> Building application using Cargo"
if [ -s .cargo/config ]; then
cp -f .cargo/config /opt/drycc/rust/config
fi
# cargo layer
cargo_layer_dir="${layers_dir}/cargo"
mkdir -p "${cargo_layer_dir}"
echo "---> Generating cargo layers"
cat >"${cargo_layer_dir}.toml" <<EOL
[types]
cache = true
build = true
launch = false
EOL
# target layer
target_layer_dir="${layers_dir}"/target
mkdir -p "${target_layer_dir}"/{profile.d,release}
echo "---> Building target with cargo"
cp -rf "$(pwd)" /tmp/source \
&& cd /tmp/source \
&& export CARGO_HOME="${cargo_layer_dir}" \
&& export CARGO_TARGET_DIR=/tmp/source/target \
&& cargo build --release \
&& find "${CARGO_TARGET_DIR}"/release -maxdepth 1 -type f -executable -exec cp -a -t "${target_layer_dir}"/release {} \; \
&& cd -
cat >"${target_layer_dir}.toml" <<EOL
[types]
cache = false
build = true
launch = true
EOL
cat >"${target_layer_dir}/profile.d/copy_target.sh" <<EOL
# only execute at runtime
if [ -z "\$INIT_STACK" ]; then
rm -rf $(pwd)/target
cp -rf ${target_layer_dir} $(pwd)
fi
EOL
generate-launch.sh "${layers_dir}"