You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
2.0 KiB
52 lines
2.0 KiB
#!/bin/bash -eu
|
|
# Copyright 2020 Google Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
#
|
|
# This is a wrapper around calling cargo
|
|
# This just expands RUSTFLAGS in case of a coverage build
|
|
# We need this until https://github.com/rust-lang/cargo/issues/5450 is merged
|
|
# because cargo uses relative paths for the current crate
|
|
# and absolute paths for its dependencies
|
|
#
|
|
################################################################################
|
|
|
|
if [ "$SANITIZER" = "coverage" ] && [ $1 = "build" ]
|
|
then
|
|
crate_src_abspath=`cargo metadata --no-deps --format-version 1 | jq -r '.workspace_root'`
|
|
export RUSTFLAGS="$RUSTFLAGS --remap-path-prefix src=$crate_src_abspath/src"
|
|
fi
|
|
|
|
if [ "$SANITIZER" = "coverage" ] && [ $1 = "fuzz" ]
|
|
then
|
|
# hack to turn cargo fuzz build into cargo build so as to get coverage
|
|
# cargo fuzz adds "--target" "x86_64-unknown-linux-gnu"
|
|
(
|
|
# go into fuzz directory if not already the case
|
|
cd fuzz || true
|
|
fuzz_src_abspath=`pwd`
|
|
export RUSTFLAGS="$RUSTFLAGS --remap-path-prefix fuzz_targets=$fuzz_src_abspath/fuzz_targets"
|
|
# we do not want to trigger debug assertions and stops
|
|
export RUSTFLAGS="$RUSTFLAGS -C debug-assertions=no"
|
|
# do not optimize with --release, leading to Malformed instrumentation profile data
|
|
cargo build --bins
|
|
# copies the build output in the expected target directory
|
|
cd `cargo metadata --format-version 1 --no-deps | jq -r '.target_directory'`
|
|
mkdir -p x86_64-unknown-linux-gnu/release
|
|
cp -r debug/* x86_64-unknown-linux-gnu/release/
|
|
)
|
|
exit 0
|
|
fi
|
|
|
|
/rust/bin/cargo "$@"
|