aboutsummaryrefslogtreecommitdiffhomepage
path: root/projects/libjxl/build.sh
blob: 091c55a6c55cf68d7a227b82f43b96d9630f5a08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash -eu
# Copyright 2021 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################

build_args=(
  -G Ninja
  -DBUILD_TESTING=OFF
  -DJPEGXL_ENABLE_BENCHMARK=OFF
  -DJPEGXL_ENABLE_DEVTOOLS=ON
  -DJPEGXL_ENABLE_EXAMPLES=OFF
  -DJPEGXL_ENABLE_FUZZERS=ON
  -DJPEGXL_ENABLE_MANPAGES=OFF
  -DJPEGXL_ENABLE_SJPEG=OFF
  -DJPEGXL_ENABLE_VIEWERS=OFF
  -DCMAKE_BUILD_TYPE=Release
)

# Build and generate a fuzzer corpus in release mode without instrumentation.
# This is done in a subshell since we change the environment.
(
  unset CFLAGS
  unset CXXFLAGS
  export AFL_NOOPT=1

  mkdir -p ${WORK}/libjxl-corpus
  cd ${WORK}/libjxl-corpus
  cmake "${build_args[@]}" "${SRC}/libjxl"
  ninja clean
  ninja fuzzer_corpus

  # Generate a fuzzer corpus.
  mkdir -p djxl_fuzzer_corpus
  tools/fuzzer_corpus -q -r djxl_fuzzer_corpus
  zip -q -j "${OUT}/djxl_fuzzer_seed_corpus.zip" djxl_fuzzer_corpus/*
)

# Build the fuzzers in release mode but force the inclusion of JXL_DASSERT()
# checks.
export CXXFLAGS="${CXXFLAGS} -DJXL_IS_DEBUG_BUILD=1"

mkdir -p ${WORK}/libjxl-fuzzer
cd ${WORK}/libjxl-fuzzer
cmake \
  "${build_args[@]}" \
  -DJPEGXL_FUZZER_LINK_FLAGS="${LIB_FUZZING_ENGINE}" \
  "${SRC}/libjxl"

fuzzers=(
  color_encoding_fuzzer
  djxl_fuzzer
  fields_fuzzer
  icc_codec_fuzzer
  rans_fuzzer
)

ninja clean
ninja "${fuzzers[@]}"
for fuzzer in "${fuzzers[@]}"; do
  cp tools/${fuzzer} "${OUT}/"
done