# A virtual machine to run https://github.com/google/oss-fuzz
Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/xenial64"

  config.vm.synced_folder "E:\\Git\\Arduino\\libraries\\ArduinoJson", "/host/ArduinoJson"
  config.vm.synced_folder "E:\\Git\\oss-fuzz", "/host/oss-fuzz"

  config.vm.network "forwarded_port", guest: 8001, host: 8001

  config.vm.provision "shell", privileged: false, inline: <<-SHELL
    set -x

    sudo apt-get update
    sudo apt-get install -y make git docker.io zip
    sudo groupadd docker
    sudo usermod -aG docker $USER

    git clone https://github.com/google/fuzzer-test-suite.git FTS
    ./FTS/tutorial/install-deps.sh  # Get deps
    ./FTS/tutorial/install-clang.sh # Get fresh clang binaries
    # Get libFuzzer sources and build it
    svn co http://llvm.org/svn/llvm-project/llvm/trunk/lib/Fuzzer
    Fuzzer/build.sh
    sudo mv libFuzzer.a /usr/local/lib/

    echo "export PROJECT_NAME='arduinojson'" >> $HOME/.profile
    echo "export CC='clang'" >> $HOME/.profile
    echo "export CXX='clang++'" >> $HOME/.profile
    echo "export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/" >> $HOME/.profile

    echo "Run /host/ArduinoJson/fuzzing/fuzz.sh" | sudo tee /etc/motd
  SHELL
end
