/
cargo.sh
executable file
·40 lines (30 loc) · 1.3 KB
/
cargo.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
#!/usr/bin/env bash
set -e
REPO_ROOT=$(cd $(dirname "${BASH_SOURCE[0]}") && cd ../../.. && pwd -P)
# Exports:
# + CARGO_HOME: The CARGO_HOME of the Pants-controlled rust toolchain.
# Exposes:
# + ensure_native_build_prerequisites: Bootstraps a Pants-controlled rust toolchain and associated
# extras.
source "${REPO_ROOT}/build-support/bin/native/bootstrap_rust.sh"
ensure_native_build_prerequisites >&2
download_binary="${REPO_ROOT}/build-support/bin/download_binary.sh"
# The following is needed by grpcio-sys and we have no better way to hook its build.rs than this;
# ie: wrapping cargo.
cmakeroot="$("${download_binary}" "binaries.pantsbuild.org" "cmake" "3.9.5" "cmake.tar.gz")"
goroot="$("${download_binary}" "binaries.pantsbuild.org" "go" "1.7.3" "go.tar.gz")/go"
# Code generation in the bazel_protos crate needs to be able to find protoc on the PATH.
protoc="$("${download_binary}" "binaries.pantsbuild.org" "protobuf" "3.4.1" "protoc")"
export GOROOT="${goroot}"
export PATH="${cmakeroot}/bin:${goroot}/bin:${CARGO_HOME}/bin:$(dirname "${protoc}"):${PATH}"
cargo_bin="${CARGO_HOME}/bin/cargo"
if [[ -n "${CARGO_WRAPPER_DEBUG}" ]]; then
cat << DEBUG >&2
>>> Executing ${cargo_bin} $@
>>> In ENV:
>>> GOROOT=${GOROOT}
>>> PATH=${PATH}
>>>
DEBUG
fi
exec "${cargo_bin}" "$@"