build.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash -eu
  2. # ClusterFuzzLite build script (T4-3): compile every cargo-fuzz target and
  3. # stage the binaries plus any checked-in seed corpus into $OUT.
  4. #
  5. # Hermetic by construction: every target exercises only pure parsers (no
  6. # network, Postgres, or Redis), so the OSS-Fuzz sandbox needs no services.
  7. cd "$SRC/d-oauth-server/fuzz"
  8. # The OSS-Fuzz base image exports CXX=clang++ with a CXXFLAGS that selects
  9. # libc++ (-stdlib=libc++). libfuzzer-sys's build script compiles libFuzzer's
  10. # C++ runtime with those flags, but rustc/cc links the C++ stdlib as libstdc++
  11. # (-lstdc++), so the runtime's libc++ (std::__1::) symbols end up undefined at
  12. # link time. clang++ defaults to libstdc++ when the flag is absent, so drop it
  13. # to make the compiled runtime and the link line agree.
  14. CXXFLAGS="${CXXFLAGS:-}"
  15. export CXXFLAGS="${CXXFLAGS//-stdlib=libc++/}"
  16. # ClusterFuzzLite exports sanitizer RUSTFLAGS globally (-Cpasses=sancov-module,
  17. # -Zsanitizer=address, ...). Cargo applies RUSTFLAGS to every unit including
  18. # host proc-macro dylibs; an instrumented proc-macro (e.g. sqlx-macros) then
  19. # fails at dlopen with `undefined symbol: __sancov_lowest_stack`, because the
  20. # sancov runtime links only into the final fuzz executable. Host and target
  21. # share the same triple here, so per-target rustflags would match proc-macros
  22. # too. Drop the inherited flags and let `cargo fuzz` re-apply its own scoped
  23. # sanitizer/coverage flags (the same mechanism `ci.yml fuzz-build` relies on,
  24. # which runs with no sanitizer env).
  25. unset RUSTFLAGS
  26. cargo fuzz build -O --debug-assertions
  27. for target_path in fuzz_targets/*.rs; do
  28. target="$(basename "$target_path" .rs)"
  29. cp "build/x86_64-unknown-linux-gnu/release/$target" "$OUT/" 2>/dev/null \
  30. || cp "target/x86_64-unknown-linux-gnu/release/$target" "$OUT/"
  31. if [ -d "corpus/$target" ]; then
  32. zip -j "$OUT/${target}_seed_corpus.zip" "corpus/$target/"* 2>/dev/null || true
  33. fi
  34. done