-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·102 lines (80 loc) · 3.46 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
#!/usr/bin/env bash
#
# Shell script to build cargo-nextest tool on OpenBSD-stable
#
set -eu
# Rust profile for build
# PROFILE="debug"
PROFILE="release"
usage() {
echo "usage: build.sh NEXTEST_VERSION [WRKDIR]"
printf "\n - NEXTEST_VERSION\tversion of cargo-nextest to build\n"
printf " - WRKDIR\t\tdirectory to download sources and build tool "
echo "(default = /tmp/cargo-nextest-build-<NEXTEST_VERSION>)"
}
# Check args to get version
if [ $# -lt 1 ]; then
printf "ERROR: unable to get cargo-nextest version\n\n"
usage
exit 1
elif [ $# -gt 2 ]; then
usage
exit 1
fi
# cargo-nextest version
VERSION=$1
echo "[*] Build cargo-nextest version ${VERSION} on OpenBSD $(uname -r)"
rm -f /tmp/cargo-nextest-"${VERSION}".tar.gz
# Check version and download sources for cargo-nextest
STATUSCODE=$(curl -sL "https://github.com/nextest-rs/nextest/archive/refs/tags/cargo-nextest-${VERSION}.tar.gz" -O --output-dir /tmp --write-out "%{http_code}")
if test "$STATUSCODE" -eq 404; then
rm -f /tmp/cargo-nextest-"${VERSION}".tar.gz
echo "ERROR: non existent cargo-nextest version '${VERSION}'"
exit 1
fi
if test "$STATUSCODE" -gt 400; then
echo "ERROR: unable to download sources for cargo-nextest - HTTP Status-Code = ${STATUSCODE}"
exit 1
fi
# Set WRKDIR from args (optional)
WRKDIR=${2:-/tmp/cargo-nextest-build-"${VERSION}"}
echo "[*] WRKDIR=${WRKDIR}"
echo "[*] Download sources for cargo-nextest-build-${VERSION}"
# Prepare sources for cargo-nextest
tar xzf /tmp/cargo-nextest-"${VERSION}".tar.gz -C /tmp
cp -a /tmp/nextest-cargo-nextest-"${VERSION}"/. "${WRKDIR}"
rm -f /tmp/cargo-nextest-"${VERSION}".tar.gz
mkdir -p "${WRKDIR}"/crates
# Download crate openssl-sys
echo "[*] Download sources for openssl-sys-0.9.104 crate"
cd "${WRKDIR}"
curl -sL https://crates.io/api/v1/crates/openssl-sys/0.9.104/download|tar xzf - -C crates
# Patch crate openssl-sys
echo "[*] Patch sources for openssl-sys-0.9.104 crate"
cd "${WRKDIR}"/crates/openssl-sys-0.9.104
sed -i.orig -e "/ => ('.', '.'),/h" -e "/ => ('.', '.', '.'),/h" -e "/_ => version_error(),/{g; s/(.*) =>/_ =>/; }" build/main.rs
# Download crate zstd-sys-2.0.13+zstd.1.5.6
echo "[*] Download sources for zstd-sys-2.0.13+zstd.1.5.6 crate"
cd "${WRKDIR}"
curl -sL https://crates.io/api/v1/crates/zstd-sys/2.0.13+zstd.1.5.6/download|tar xzf - -C crates
# Patch crate zstd-sys-2.0.13+zstd.1.5.6
echo "[*] Patch sources for zstd-sys-2.0.13+zstd.1.5.6 crate"
cd "${WRKDIR}"/crates/zstd-sys-2.0.13+zstd.1.5.6
rm -rf zstd
sed -i.orig -e 's,^fn main() {,fn main() { println!("cargo:rustc-link-lib=zstd"); return;,' build.rs
sed -i '1s/^/#![allow(unreachable_code)]\'$'\n/' build.rs
# Patch cargo configuration for modified crates
echo "[*] Patch cargo configuration in .cargo/config.toml"
printf "\n[patch.crates-io]\n" > /tmp/cargo_config-patch.toml
printf "openssl-sys = { path = 'crates/openssl-sys-0.9.104'}\n" >> /tmp/cargo_config-patch.toml
printf "zstd-sys = { path = 'crates/zstd-sys-2.0.13+zstd.1.5.6' }\n" >> /tmp/cargo_config-patch.toml
cat /tmp/cargo_config-patch.toml >> "${WRKDIR}"/.cargo/config.toml
rm -f /tmp/cargo_config-patch.toml
cd "${WRKDIR}"
# Build cargo-nextest with cargo - self-update feature disabled
echo "[*] Build cargo-nextest with profile ${PROFILE}"
if [ "${PROFILE}" = "release" ]; then
OPENSSL_NO_VENDOR=1 RUSTFLAGS=-L/usr/local/lib cargo build --release --no-default-features --features default-no-update
else
OPENSSL_NO_VENDOR=1 RUSTFLAGS=-L/usr/local/lib cargo build --no-default-features --features default-no-update
fi