1#!/bin/bash -eu
2# Copyright 2019 Google Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16################################################################################
17
18PROJECT=osquery
19
20# Move the project content into the current overlay.
21# CMake builtin 'rename' will attempt a hardlink.
22( cd / &&\
23  mv "${SRC}/${PROJECT}" "${SRC}/${PROJECT}-dev" &&\
24  mv "${SRC}/${PROJECT}-dev" "${SRC}/${PROJECT}" )
25
26pushd "${SRC}/${PROJECT}"
27
28mkdir build && pushd build
29
30cmake \
31  -DOSQUERY_VERSION:string=0.0.0-fuzz \
32  -DOSQUERY_ENABLE_ADDRESS_SANITIZER:BOOL=ON \
33  -DOSQUERY_BUILD_FUZZERS:BOOL=ON \
34  -DOSQUERY_IGNORE_CMAKE_MAX_VERSION_CHECK:BOOL=ON \
35  -DOSQUERY_BUILD_AWS:BOOL=OFF \
36  ..
37
38cmake \
39  "-DCMAKE_EXE_LINKER_FLAGS=${LIB_FUZZING_ENGINE} -Wl,-rpath,'\$ORIGIN/lib'" \
40  ..
41
42# Build harnesses
43cmake --build . -j$(nproc) --target osqueryfuzz-config
44cmake --build . -j$(nproc) --target osqueryfuzz-sqlquery
45
46# Cleanup
47find . -type f -name '*.o' -delete
48rm -rf "${SRC}/${PROJECT}/libraries/cmake/source/libudev/src/test"
49rm -rf libs/src/patched-source/libudev/src/test
50
51# Move libunwind to output path
52mkdir -p "${OUT}/lib"
53cp /usr/lib/x86_64-linux-gnu/libunwind.so.8 "${OUT}/lib"
54
55# Move harnesses to output path
56cp osquery/main/harnesses/osqueryfuzz-config "${OUT}/osqueryfuzz-config"
57cp osquery/main/harnesses/osqueryfuzz-sqlquery "${OUT}/osqueryfuzz-sqlquery"
58
59# Build supporting files
60popd
61tools/harnesses/osqueryfuzz_config_corpus.sh "${OUT}/osqueryfuzz-config_seed_corpus.zip"
62tools/harnesses/osqueryfuzz_config_dict.sh "${OUT}/osqueryfuzz-config.dict"
63tools/harnesses/osqueryfuzz_sqlquery_corpus.sh "${OUT}/osqueryfuzz-sqlquery_seed_corpus.zip"
64cp tools/harnesses/osqueryfuzz_sqlquery.dict "${OUT}/osqueryfuzz-sqlquery.dict"
65