forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-archive.sh
executable file
·140 lines (115 loc) · 3.61 KB
/
build-archive.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env bash
# build.sh
#
# SUMMARY
#
# Used to build a tar.gz archive for the specified $TARGET
#
# ENV VARS
#
# $FEATURES - a list of Vector features to include when building, defaults to all
# $NATIVE_BUILD - whether to pass the --target flag when building via cargo
# $RUST_LTO - possible values are "lto", "lto=thin", ""
# $STRIP - whether or not to strip the binary
# $TARGET - a target triple. ex: x86_64-apple-darwin
# $ARCHIVE_TYPE - archive type, either "tar.gz" or "zip"
NATIVE_BUILD=${NATIVE_BUILD:-}
RUST_LTO=${RUST_LTO:-}
STRIP=${STRIP:-}
FEATURES=${FEATURES:-}
ARCHIVE_TYPE=${ARCHIVE_TYPE:-tar.gz}
if [ -z "$FEATURES" ]; then
FEATURES="default"
fi
CHANNEL="$(scripts/util/release-channel.sh)"
if [ "$CHANNEL" == "nightly" ]; then
FEATURES="$FEATURES nightly"
fi
set -eu
echo "Building Vector archive"
echo "Target: $TARGET"
echo "Native build: $NATIVE_BUILD"
echo "Features: $FEATURES"
# Setup directories
artifacts_dir="target/artifacts"
if [ -z "$NATIVE_BUILD" ]; then
target_dir="target/$TARGET"
else
target_dir="target"
fi
archive_dir_name="vector-$TARGET"
archive_dir="$target_dir/$archive_dir_name"
# Build
build_flags="--release"
if [ -z "$NATIVE_BUILD" ]; then
build_flags="$build_flags --target $TARGET"
fi
on_exit=""
# Currently the only way to set Rust codegen LTO type (-C lto, as opposed to
# -C compiler-plugin-lto) at build time for a crate with library dependencies
# is to patch Cargo.toml before the build. See
# https://github.com/rust-lang/cargo/issues/4349 and
# https://bugzilla.mozilla.org/show_bug.cgi?id=1386371#c2.
if [ -n "$RUST_LTO" ]; then
on_exit="mv Cargo.toml.orig Cargo.toml; $on_exit"
trap "$on_exit" EXIT
cp Cargo.toml Cargo.toml.orig
case "$RUST_LTO" in
lto) lto_value="true";;
lto=thin) lto_value="\"thin\"";;
esac
printf "[profile.release]\nlto = $lto_value" >> Cargo.toml
fi
if [ "$FEATURES" != "default" ]; then
cargo build $build_flags --no-default-features --features "$FEATURES"
else
cargo build $build_flags
fi
# Strip the output binary
if [ "$STRIP" != "false" ]; then
strip $target_dir/release/vector
fi
# Build the archive directory
rm -rf $archive_dir
mkdir -p $archive_dir
# Copy root level files
if [[ $TARGET == *windows* ]]; then
suffix=".txt"
else
suffix=""
fi
cp -av README.md $archive_dir/README.md$suffix
# Create the license file for binary distributions (LICENSE + NOTICE)
cat LICENSE NOTICE > $archive_dir/LICENSE$suffix
# Copy the vector binary to /bin
mkdir -p $archive_dir/bin
cp -av $target_dir/release/vector $archive_dir/bin
# Copy the entire config dir to /config
cp -rv config $archive_dir/config
# Remove templates sources
rm $archive_dir/config/*.erb
if [[ $TARGET == *linux* ]]; then
# Copy /etc useful files
mkdir -p $archive_dir/etc/systemd
cp -av distribution/systemd/vector.service $archive_dir/etc/systemd
mkdir -p $archive_dir/etc/init.d
cp -av distribution/init.d/vector $archive_dir/etc/init.d
fi
# Build the release archive
_old_dir=$(pwd)
cd $target_dir
if [ "$ARCHIVE_TYPE" == "tar.gz" ]; then
tar cvf - ./$archive_dir_name | gzip -9 > vector-$TARGET.$ARCHIVE_TYPE
elif [ "$ARCHIVE_TYPE" == "zip" ] && [[ $TARGET == *windows* ]]; then
powershell '$progressPreference = "silentlyContinue"; Compress-Archive -DestinationPath vector-'$TARGET'.'$ARCHIVE_TYPE' -Path "./'$archive_dir_name'/*"'
else
echo "Unsupported combination of ARCHIVE_TYPE and TARGET"
exit 1
fi
cd $_old_dir
# Move to the artifacts dir
mkdir -p $artifacts_dir
mv -v $target_dir/vector-$TARGET.$ARCHIVE_TYPE $artifacts_dir
echo "Moved $target_dir/vector-$TARGET.$ARCHIVE_TYPE to $artifacts_dir"
# Cleanup
rm -rf $archive_dir