-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
147 lines (134 loc) · 4.35 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
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
141
142
143
144
145
146
147
#!/bin/bash
############################
# libnss_shim build script #
############################
# Notes:
# - This script is intended to be run in a temporary container environment
# - Read the libnss_shim docs and the script itself before running it
# - Pay careful attention to the available options
########
# Exit immediately on error
set -e
# Set defaults
build_libnss_shim=true
install_cargo_deps=true
install_rust=true
package_deb=true
package_rpm=true
version_number=0.0.0
# Override default options based on launch arguments
# Idea from https://www.drupal.org/node/244924#script-based-on-guidelines-given-above
while [ $# -gt 0 ]; do
case "$1" in
--build_libnss_shim=* )
build_libnss_shim="${1#*=}"
;;
--install_cargo_deps=* )
install_cargo_deps="${1#*=}"
;;
--install_rust=* )
install_rust="${1#*=}"
;;
--package_deb=* )
package_deb="${1#*=}"
;;
--package_rpm=* )
package_rpm="${1#*=}"
;;
--version_number=* )
version_number="${1#*=}"
;;
* )
printf "BUILD ERROR: unknown argument %s\n" ${!$1}
exit 1
esac
shift
done
# Determine platform and warn if it is unsupported
echo "BUILD: Detecting architecture..."
architecture=$(uname -m)
case $architecture in
x86_64 | amd64 )
architecture="amd64"
;;
arm | arm64 | aarch64 )
architecture="aarch64"
;;
* )
echo "BUILD WARNING: Unexpected architecture ${architecture}"
esac
echo "BUILD ${architecture}: Architecture detected"
echo "================"
# Prep
if [[ $version_number != "0.0.0" ]]
then
echo "BUILD ${architecture}: Setting version in Cargo.toml..."
sed -i "/^version /s/=.*$/= \"${version_number}\"/" Cargo.toml
echo "BUILD ${architecture}: Version set to ${version_number}"
echo "================"
fi
if $install_rust
then
echo "BUILD ${architecture}: Installing Rust..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
. "$HOME/.cargo/env"
echo "================"
fi
if $install_cargo_deps
then
echo "BUILD ${architecture}: Installing cargo dependencies..."
# Do not upgrade cargo-deb beyond version 2.2.0 until ready as 2.4.0 has major changes
# https://github.com/kornelski/cargo-deb/blob/main/CHANGELOG.md#240
cargo install --version 2.2.0 cargo-deb
# Do not upgrade cargo-generate-rpm beyond version 0.14.0 until ready to drop CentOS 7
# https://github.com/cat-in-136/cargo-generate-rpm/releases/tag/v0.15.0
cargo install --version 0.14.0 cargo-generate-rpm
echo "================"
fi
# Build
if $build_libnss_shim
then
echo "BUILD ${architecture}: Building for release..."
cargo build --release --verbose
echo "BUILD ${architecture}: Built for release"
ls -lah target/release
echo "================"
fi
# Packaging
if $package_deb
then
echo "BUILD ${architecture}: Packaging deb..."
cargo deb --verbose --no-build
echo "BUILD ${architecture}: Packaged deb"
ls -lah target/debian
echo "================"
fi
if $package_rpm
then
echo "BUILD ${architecture}: Packaging RPM..."
cargo generate-rpm --payload-compress none
echo "BUILD ${architecture}: Packaged RPM"
ls -lah target/generate-rpm
echo "================"
fi
# TODO: enable local cross-build to arm64 with docker-in-docker using `cross`
#env CROSS_CONTAINER_IN_CONTAINER=true cross build --release --target aarch64-unknown-linux-gnu
#echo "BUILD ARM64: Cross-building for release (arm64/aarch64)"
#cargo install --version 0.2.5 cross
#env CROSS_CONTAINER_IN_CONTAINER=true cross build --release --target aarch64-unknown-linux-gnu
#echo "BUILD ARM64: built for release (arm64/aarch64)"
#ls -lah target/aarch64-unknown-linux-gnu/release
#
#echo "BUILD ARM64: Packaging deb (arm64/aarch64)"
#cargo deb --target=aarch64-unknown-linux-gnu --no-build --verbose
#echo "BUILD ARM64: deb packaged (arm64/aarch64)"
#ls -lah target/aarch64-unknown-linux-gnu/debian
#
#echo "BUILD ARM64: Packaging RPM (arm64/aarch64)"
## FIXME: use script when possible for --auto-req
## See https://github.com/cat-in-136/cargo-generate-rpm/issues/107
## --auto-req "cross/find-requires.sh"
#cargo generate-rpm --payload-compress none --target aarch64-unknown-linux-gnu --auto-req disabled
#echo "BUILD ARM64: RPM packaged (arm64/aarch64)"
#ls -lah target/aarch64-unknown-linux-gnu/generate-rpm
echo "BUILD ${architecture}: Complete"