build.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash -eu
  2. # Build directory
  3. mkdir -p build
  4. cd build
  5. # Configure
  6. cmake .. \
  7. -G Ninja \
  8. -DCMAKE_C_COMPILER="${CC}" \
  9. -DCMAKE_CXX_COMPILER="${CXX}" \
  10. -DCMAKE_C_FLAGS="${CFLAGS}" \
  11. -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
  12. -DASSIMP_BUILD_ZLIB=ON \
  13. -DASSIMP_BUILD_TESTS=OFF \
  14. -DASSIMP_BUILD_ASSIMP_TOOLS=OFF \
  15. -DBUILD_SHARED_LIBS=OFF \
  16. -DASSIMP_BUILD_ALL_IMPORTERS_BY_DEFAULT=ON \
  17. -DASSIMP_BUILD_ALL_EXPORTERS_BY_DEFAULT=ON
  18. # Build the library
  19. ninja
  20. # Helper function to build fuzzers
  21. build_fuzzer() {
  22. local fuzzer_name=$1
  23. local source_file=$2
  24. echo "Building $fuzzer_name..."
  25. $CXX $CXXFLAGS -I../include -I../build/include -c "$source_file" -o "${fuzzer_name}.o"
  26. $CXX $CXXFLAGS $LIB_FUZZING_ENGINE "${fuzzer_name}.o" -o "$OUT/${fuzzer_name}" \
  27. ./lib/libassimp.a \
  28. ./contrib/zlib/libzlibstatic.a \
  29. -lpthread -ldl
  30. }
  31. # 1. Generic Fuzzer
  32. build_fuzzer "assimp_fuzzer" "../fuzz/assimp_fuzzer.cc"
  33. # Corpus for generic fuzzer (all models)
  34. (cd ../test/models && zip -q -r $OUT/assimp_fuzzer_seed_corpus.zip .)
  35. # Dictionary
  36. cp ../fuzz/assimp_fuzzer.dict $OUT/assimp_fuzzer.dict || true
  37. # 2. OBJ Fuzzer
  38. build_fuzzer "assimp_fuzzer_obj" "../fuzz/assimp_fuzzer_obj.cc"
  39. if [ -d "../test/models/OBJ" ]; then
  40. (cd ../test/models/OBJ && zip -q -r $OUT/assimp_fuzzer_obj_seed_corpus.zip .)
  41. fi
  42. cp ../fuzz/assimp_fuzzer.dict $OUT/assimp_fuzzer_obj.dict || true
  43. # 3. GLTF Fuzzer (text format only, glTF and glTF2 versions)
  44. build_fuzzer "assimp_fuzzer_gltf" "../fuzz/assimp_fuzzer_gltf.cc"
  45. mkdir -p gltf_corpus
  46. [ -d "../test/models/glTF" ] && cp -r ../test/models/glTF/* gltf_corpus/
  47. [ -d "../test/models/glTF2" ] && cp -r ../test/models/glTF2/* gltf_corpus/
  48. if [ -d "gltf_corpus" ] && [ "$(ls -A gltf_corpus)" ]; then
  49. (cd gltf_corpus && zip -q -r $OUT/assimp_fuzzer_gltf_seed_corpus.zip .)
  50. fi
  51. rm -rf gltf_corpus
  52. cp ../fuzz/assimp_fuzzer.dict $OUT/assimp_fuzzer_gltf.dict || true
  53. # 4. GLB Fuzzer (binary glTF format)
  54. build_fuzzer "assimp_fuzzer_glb" "../fuzz/assimp_fuzzer_glb.cc"
  55. mkdir -p glb_corpus
  56. # GLB files can be found in glTF and glTF2 directories
  57. [ -d "../test/models/glTF" ] && find ../test/models/glTF -name "*.glb" -exec cp {} glb_corpus/ \; 2>/dev/null || true
  58. [ -d "../test/models/glTF2" ] && find ../test/models/glTF2 -name "*.glb" -exec cp {} glb_corpus/ \; 2>/dev/null || true
  59. if [ -d "glb_corpus" ] && [ "$(ls -A glb_corpus)" ]; then
  60. (cd glb_corpus && zip -q -r $OUT/assimp_fuzzer_glb_seed_corpus.zip .)
  61. fi
  62. rm -rf glb_corpus
  63. cp ../fuzz/assimp_fuzzer.dict $OUT/assimp_fuzzer_glb.dict || true
  64. # 5. FBX Fuzzer
  65. build_fuzzer "assimp_fuzzer_fbx" "../fuzz/assimp_fuzzer_fbx.cc"
  66. if [ -d "../test/models/FBX" ]; then
  67. (cd ../test/models/FBX && zip -q -r $OUT/assimp_fuzzer_fbx_seed_corpus.zip .)
  68. fi
  69. cp ../fuzz/assimp_fuzzer.dict $OUT/assimp_fuzzer_fbx.dict || true
  70. # 6. Collada Fuzzer
  71. build_fuzzer "assimp_fuzzer_collada" "../fuzz/assimp_fuzzer_collada.cc"
  72. if [ -d "../test/models/Collada" ]; then
  73. (cd ../test/models/Collada && zip -q -r $OUT/assimp_fuzzer_collada_seed_corpus.zip .)
  74. fi
  75. cp ../fuzz/assimp_fuzzer.dict $OUT/assimp_fuzzer_collada.dict || true
  76. # 7. STL Fuzzer
  77. build_fuzzer "assimp_fuzzer_stl" "../fuzz/assimp_fuzzer_stl.cc"
  78. if [ -d "../test/models/STL" ]; then
  79. (cd ../test/models/STL && zip -q -r $OUT/assimp_fuzzer_stl_seed_corpus.zip .)
  80. fi
  81. cp ../fuzz/assimp_fuzzer.dict $OUT/assimp_fuzzer_stl.dict || true