-
Notifications
You must be signed in to change notification settings - Fork 4
/
run
executable file
·99 lines (86 loc) · 2.64 KB
/
run
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
#!/usr/bin/env bash
set -e
sysroot="$(rustc --print sysroot)"
postgres_targets=("x86_64-postgres-linux-gnu" "aarch64-postgres-linux-gnu")
# Experimental support for apple targets. Note that cross-compiling to one
# target from the other is generally supported without extra work.
if [ "Darwin" = "$(uname -s)" ]; then
echo "warning: macOS support is still experimental" >&2
postgres_targets=("x86_64-apple-darwin-postgres" "aarch64-apple-darwin-postgres")
fi
if [ -n "${STD_TARGETS}" ]; then
# Split on spaces or commas
IFS=', ' read -r -a postgres_targets <<< "${STD_TARGETS}"
fi
# If you have `cargo zigbuild` installed and want to attempt using it for cross
# compiling postgrestd (It seems to be able to go from macOS to linux pretty
# well, and probably between linuxes without further config, but other things
# are untested).
CARGO_CMD="build"
if [ "${CROSS_WITH_CARGO_ZIGBUILD}" = "1" ]; then
echo "warning: 'cargo zigbuild' support is still experimental" >&2
CARGO_CMD="zigbuild"
fi
main() {
case "$1" in
build)
setup_dir
run_build
;;
install)
setup_dir
run_build
remove_rlibs
copy_rlibs
;;
clean)
cargo clean
remove_rlibs
;;
help)
print_help
;;
*)
print_help
exit 1
;;
esac
}
print_help() {
echo "Usage: $0 help | build | clean | install"
}
setup_dir() {
for target in "${postgres_targets[@]}"; do
mkdir -p "${sysroot}"/lib/rustlib/"${target}"/lib
cp -f -v ./"${target}.json" "${sysroot}"/lib/rustlib/"${target}"/target.json
done
}
copy_json() {
for target in "${postgres_targets[@]}"; do
cp -f -v ./"${target}.json" "${sysroot}"/lib/rustlib/"${target}"/target.json
done
}
remove_rlibs() {
for target in "${postgres_targets[@]}"; do
rm -f -v "${sysroot}"/lib/rustlib/"${target}"/lib/*.rlib
done
}
copy_rlibs() {
for target in "${postgres_targets[@]}"; do
cp -f -v target/"${target}"/release/deps/*.rlib "${sysroot}/lib/rustlib/${target}/lib"
done
}
run_build() {
for target in "${postgres_targets[@]}"; do
RUSTC_BOOTSTRAP=1 \
RUSTFLAGS="-Cforce-unwind-tables=yes -Cembed-bitcode=yes -Aunused-unsafe -Aunused-imports" \
__CARGO_DEFAULT_LIB_METADATA="postgrestd" \
cargo "${CARGO_CMD}" \
--target "${target}" \
-Zbinary-dep-depinfo \
--release \
--features "compiler-builtins-mem" \
--manifest-path "library/sysroot/Cargo.toml"
done
}
main "$@"