# AFL++ Rust overlay generated by scripts/build_afl_rust.py
FROM rust@sha256:f2c004e3d2d8b547e8cf7ffbc29205385f4e71d23e53e4e383065db5e9f822cd AS build
RUN apt-get update -qq && apt-get install -y --no-install-recommends clang llvm-dev g++ make python3 \
    && rm -rf /var/lib/apt/lists/*
RUN cargo install cargo-afl --version 0.18.2 --locked
WORKDIR /work
COPY fuzzing/afl-native/yaml/rust/granit_parser/Cargo.toml fuzzing/afl-native/yaml/rust/granit_parser/Cargo.lock /work/
COPY projects/yaml/rust/granit_parser/src /work/src
COPY fuzzing/afl-native/yaml/rust/granit_parser/afl_fuzzer.rs /work/src/bin/afl_fuzzer.rs
COPY fuzzing/afl-native/yaml/rust/granit_parser/rustc-scope.sh fuzzing/afl-native/yaml/rust/granit_parser/sancov_scope.py /work/
RUN cargo fetch --locked --target aarch64-unknown-linux-gnu
RUN cargo afl config --build --force \
    && AFL_SCOPE_CRATES='granit_parser parsarium_yaml_granit_parser_events' RUSTC_WRAPPER=/work/rustc-scope.sh cargo afl build --locked --target aarch64-unknown-linux-gnu --release --bin afl_fuzzer \
    && cp target/aarch64-unknown-linux-gnu/release/afl_fuzzer /work/afl_fuzzer \
    && python3 /work/sancov_scope.py 'granit_parser parsarium_yaml_granit_parser_events' target/aarch64-unknown-linux-gnu/release/deps /work/afl_fuzzer > /work/sancov-scope.json
FROM ubuntu@sha256:065aa8626841f16057b78b027b464cd59c4fac36c204c72dcbf48d66f5fa8a96
RUN apt-get update -qq && apt-get install -y --no-install-recommends afl++=4.33c-1.1ubuntu1 libstdc++6 \
    && rm -rf /var/lib/apt/lists/*
COPY --from=build /work/afl_fuzzer /work/afl_fuzzer
COPY --from=build /work/sancov-scope.json /work/sancov-scope.log /work/
ENTRYPOINT ["/work/afl_fuzzer"]
