-
-
Save japaric/a643e1ac134a335a554ab40079e5dddb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -ex | |
main() { | |
rustup default stable | |
rustup component add rust-src | |
rm -rf hello | |
cargo new --bin hello | |
cd hello | |
build_libprofiler | |
RUSTFLAGS="-C passes=insert-gcov-profiling" cargo rustc -- \ | |
-C link-arg=-lprofiler \ | |
-C link-arg=-L$(pwd) | |
target/debug/hello | |
# OUTPUT main.gcda main.gcno | |
ls *.gc* | |
} | |
build_libprofiler() { | |
local sources=( | |
GCDAProfiling.c | |
InstrProfiling.c | |
InstrProfilingBuffer.c | |
InstrProfilingFile.c | |
InstrProfilingMerge.c | |
InstrProfilingMergeFile.c | |
InstrProfilingPlatformLinux.c | |
InstrProfilingRuntime.cc | |
InstrProfilingUtil.c | |
InstrProfilingValue.c | |
InstrProfilingWriter.c | |
) | |
local src_dir=$(rustc --print sysroot)/lib/rustlib/src/rust/src/compiler-rt/lib/profile | |
local td=$(mktemp -d) | |
for source in ${sources[@]}; do | |
gcc \ | |
-fPIC \ | |
-DVISIBILITY_HIDDEN \ | |
-c \ | |
-ffreestanding \ | |
-fno-builtin \ | |
-fomit-frame-pointer \ | |
-fvisibility=hidden \ | |
$src_dir/$source \ | |
-o $td/${source%.*}.o | |
done | |
local objs=( ${sources[@]/%.*/.o} ) | |
ar crus libprofiler.a ${objs[@]/#/$td/} | |
rm -rf $td | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment