|
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# Run pointwise metrics on lighttpd_rust_amalgamated. |
| 5 | + |
| 6 | +if [[ $# -ne 1 ]]; then |
| 7 | + echo "Usage: $0 <path/to/lighttpd_rust_amalgamated/>" |
| 8 | + exit 1 |
| 9 | +fi |
| 10 | + |
| 11 | +SCRIPT_DIR="$(dirname "$0")" |
| 12 | + |
| 13 | +# Get the path to lighttpd_rust_amalgamated |
| 14 | +MODULE_DIR="$1" |
| 15 | +shift 1 |
| 16 | + |
| 17 | +# Find the sysroot directory of rustc |
| 18 | +SYSROOT="$(rustc --print sysroot)" |
| 19 | + |
| 20 | +# Find the necessary rlibs |
| 21 | +extern() { |
| 22 | + local name=$1 |
| 23 | + local rlib=$(find "$MODULE_DIR/target/debug/deps" -name "lib${name}*.rlib" -print -quit) |
| 24 | + echo >&2 "found rlib for $name: $rlib" |
| 25 | + echo --extern $name=$rlib |
| 26 | +} |
| 27 | + |
| 28 | +now=$(date +%Y%m%d-%H%M%S) |
| 29 | + |
| 30 | + |
| 31 | +# Set $rustc_flags and run the analysis as appropriate for the target project. |
| 32 | +# $rustc_flags is also used below for `pointwise_try_build.sh`. |
| 33 | +project="$(basename "$MODULE_DIR")" |
| 34 | +case "$project" in |
| 35 | + lighttpd_*) |
| 36 | + rustc_flags=( |
| 37 | + --edition 2021 |
| 38 | + --crate-type rlib |
| 39 | + #--sysroot "$SYSROOT" |
| 40 | + -L "dependency=$MODULE_DIR/target/debug/deps" |
| 41 | + $(extern c2rust_bitfields) |
| 42 | + $(extern libc) |
| 43 | + -A warnings |
| 44 | + ) |
| 45 | + |
| 46 | + C2RUST_ANALYZE_NO_CARGO=1 \ |
| 47 | + C2RUST_ANALYZE_REWRITE_MODE=pointwise \ |
| 48 | + C2RUST_ANALYZE_USE_MANUAL_SHIMS=1 \ |
| 49 | + cargo run --bin c2rust-analyze --release -- "$MODULE_DIR/src/main.rs" \ |
| 50 | + --crate-name "$(basename "$MODULE_DIR")" \ |
| 51 | + "${rustc_flags[@]}" \ |
| 52 | + |& tee pointwise-lighttpd-analyze-$now.log \ |
| 53 | + || true |
| 54 | + |
| 55 | + ;; |
| 56 | + |
| 57 | + cfs_*) |
| 58 | + : cargo run --bin c2rust-analyze --release -- \ |
| 59 | + --rewrite-mode pointwise --use-manual-shims -- \ |
| 60 | + build --manifest-path "$MODULE_DIR/Cargo.toml" \ |
| 61 | + |& tee pointwise-cfs-analyze-$now.log \ |
| 62 | + || true |
| 63 | + |
| 64 | + rustc_flags=( |
| 65 | + --edition 2021 |
| 66 | + --crate-type rlib |
| 67 | + #--sysroot "$SYSROOT" |
| 68 | + -L "dependency=$MODULE_DIR/target/debug/deps" |
| 69 | + $(extern c2rust_bitfields) |
| 70 | + $(extern f128) |
| 71 | + $(extern libc) |
| 72 | + $(extern memoffset) |
| 73 | + -A warnings |
| 74 | + ) |
| 75 | + |
| 76 | + ;; |
| 77 | + |
| 78 | + *) |
| 79 | + echo "unsupported project $project" 1>&2 |
| 80 | + exit 1 |
| 81 | +esac |
| 82 | + |
| 83 | + |
| 84 | +# Try to compile each function separately. |
| 85 | + |
| 86 | +pointwise_log_file=pointwise-lighttpd-pointwise-$now.log |
| 87 | +for f in "$MODULE_DIR"/src/main.*.rs; do |
| 88 | + "$SCRIPT_DIR/pointwise_try_build.sh" "$f" pointwise "${rustc_flags[@]}" || true |
| 89 | +done |& tee "$pointwise_log_file" |
| 90 | + |
| 91 | +unmodified_log_file=pointwise-lighttpd-unmodified-$now.log |
| 92 | +for f in "$MODULE_DIR"/src/main.*.rs; do |
| 93 | + "$SCRIPT_DIR/pointwise_try_build.sh" "$f" unmodified "${rustc_flags[@]}" || true |
| 94 | +done |& tee "$unmodified_log_file" |
| 95 | + |
| 96 | +echo |
| 97 | +echo |
| 98 | + |
| 99 | +python3 "$SCRIPT_DIR/pointwise_metrics.py" "$pointwise_log_file" "$unmodified_log_file" |
0 commit comments