forked from softprops/lambda-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·61 lines (57 loc) · 1.72 KB
/
build.sh
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
#!/bin/bash
# build and pack a rust lambda library
# https://aws.amazon.com/blogs/opensource/rust-runtime-for-aws-lambda/
set -eo pipefail
mkdir -p target/lambda
export PROFILE=${PROFILE:-release}
# cargo uses different names for target
# of its build profiles
if [[ "${PROFILE}" == "release" ]]; then
TARGET_PROFILE="${PROFILE}"
else
TARGET_PROFILE="debug"
fi
export CARGO_TARGET_DIR=$PWD/target/lambda
(
if [[ $# -gt 0 ]]; then
yum install -y "$@"
fi
# source cargo
. $HOME/.cargo/env
# cargo only supports --release flag for release
# profiles. dev is implicit
if [ "${PROFILE}" == "release" ]; then
cargo build ${CARGO_FLAGS:-} --${PROFILE}
else
cargo build ${CARGO_FLAGS:-}
fi
) 1>&2
function package() {
file="$1"
if [[ "${PROFILE}" == "release" ]]; then
objcopy --only-keep-debug "$file" "$file.debug"
objcopy --strip-debug --strip-unneeded "$file"
objcopy --add-gnu-debuglink="$file.debug" "$file"
fi
rm "$file.zip" > 2&>/dev/null || true
# note: would use printf "@ $(basename $file)\n@=bootstrap" | zipnote -w "$file.zip"
# if not for https://bugs.launchpad.net/ubuntu/+source/zip/+bug/519611
if [ "$file" != ./bootstrap ] && [ "$file" != bootstrap ]; then
mv "${file}" bootstrap
mv "${file}.debug" bootstrap.debug > 2&>/dev/null || true
fi
zip "$file.zip" bootstrap
rm bootstrap
}
cd "${CARGO_TARGET_DIR}/${TARGET_PROFILE}"
(
. $HOME/.cargo/env
if [ -z "$BIN" ]; then
IFS=$'\n'
for executable in $(cargo read-manifest | jq -r '.targets[] | select(.kind[] | contains("bin")) | .name'); do
package "$executable"
done
else
package "$BIN"
fi
) 1>&2