• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2020 Google Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16# This is a wrapper around calling cargo
17# This just expands RUSTFLAGS in case of a coverage build
18# We need this until https://github.com/rust-lang/cargo/issues/5450 is merged
19# because cargo uses relative paths for the current crate
20# and absolute paths for its dependencies
21#
22################################################################################
23
24if [ "$SANITIZER" = "coverage" ] && [ $1 = "build" ]
25then
26    crate_src_abspath=`cargo metadata --no-deps --format-version 1 | jq -r '.workspace_root'`
27    export RUSTFLAGS="$RUSTFLAGS --remap-path-prefix src=$crate_src_abspath/src"
28fi
29
30if [ "$SANITIZER" = "coverage" ] && [ $1 = "fuzz" ]
31then
32    # hack to turn cargo fuzz build into cargo build so as to get coverage
33    # cargo fuzz adds "--target" "x86_64-unknown-linux-gnu"
34    (
35    # go into fuzz directory if not already the case
36    cd fuzz || true
37    fuzz_src_abspath=`pwd`
38    export RUSTFLAGS="$RUSTFLAGS --remap-path-prefix fuzz_targets=$fuzz_src_abspath/fuzz_targets"
39    # we do not want to trigger debug assertions and stops
40    export RUSTFLAGS="$RUSTFLAGS -C debug-assertions=no"
41    # do not optimize with --release, leading to Malformed instrumentation profile data
42    cargo build --bins
43    # copies the build output in the expected target directory
44    cd `cargo metadata --format-version 1 --no-deps | jq -r '.target_directory'`
45    mkdir -p x86_64-unknown-linux-gnu/release
46    cp -r debug/* x86_64-unknown-linux-gnu/release/
47    )
48    exit 0
49fi
50
51/rust/bin/cargo "$@"
52