blob: c11aec5c72596b3e0908fe690a8b9f2b65400a7f [file] [log] [blame]
#!/bin/bash
# Copyright 2018 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#### CATEGORY=Source tree
### updates rustc_library and rustc_binary third_party dependencies
## usage: fx update-rustc-third-party
## Updates third_party/rust_crates based on the contents of
## third_party/rust_crates/Cargo.toml
##
## After updating third_party/rust_crates, the pinned revision of
## third_party/rust_crates will need to be updated in garnet/manifest/third_party.
## See https://fuchsia.dev/fuchsia-src/development/languages/rust/third_party.md
## for more details.
set -e
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/../lib/vars.sh || exit $?
fx-config-read
case "$(uname -s)" in
Linux*) ;;
Darwin*)
if ! [[ -x "$(command -v brew)" ]]; then
fx-error "'brew' binary not found"
fx-error "A homebrew <https://brew.sh> installation of opensslis required in order to update"
fx-error "Rust third party crates on the Mac."
exit 1
fi
declare -x LDFLAGS="-L$(brew --prefix)/opt/openssl/lib"
declare -x CPPFLAGS="-I$(brew --prefix)/opt/openssl/include";;
*) fx-error "unrecognized OS"; exit 1;;
esac
declare -x PATH=$PREBUILT_CMAKE_DIR/cmake/bin:$PATH
export RUSTC=$PREBUILT_RUST_DIR/bin/rustc
export CARGO=$PREBUILT_RUST_DIR/bin/cargo
GNAW_TARGET="host-tools/gnaw"
GNAW_BIN="${FUCHSIA_BUILD_DIR}/${GNAW_TARGET}"
if [[ "$1" == "--no-build" ]]; then
if [ ! -f "$GNAW_BIN" ]; then
fx-error "--no-build was specified, but $GNAW_BIN does not exist."
fx-error "Rerun without --no-build to build cargo-gnaw."
exit 1
fi
else
fx-command-run build ${GNAW_TARGET} || ( \
fx-error "Failed to build cargo-gnaw."; \
fx-error "This can happen after cargo-gnaw exits early."; \
fx-error "To retry an old build of cargo-gnaw, specify --no-build."; \
exit 1
)
fi
(cd $FUCHSIA_DIR; $PREBUILT_RUST_DIR/bin/cargo vendor \
--manifest-path $FUCHSIA_DIR/third_party/rust_crates/Cargo.toml \
$FUCHSIA_DIR/third_party/rust_crates/vendor \
-q)
(cd $FUCHSIA_DIR; $GNAW_BIN \
--manifest-path $FUCHSIA_DIR/third_party/rust_crates/Cargo.toml \
--project-root $FUCHSIA_DIR \
--cargo $CARGO \
-o $FUCHSIA_DIR/third_party/rust_crates/BUILD.gn \
--gn-bin $PREBUILT_GN \
--skip-root)
$FUCHSIA_DIR/scripts/rust/check_rust_licenses.py \
--directory $FUCHSIA_DIR/third_party/rust_crates/vendor