# Build process

## Introduction

In this file, we will see how you can build and boot successfully into a VM containing a Vystem disk image or boot a Vystem instance on a real computer. It's recommanded to read the whole documentation for better understanding of why certains parts are necessary.

## Prerequisites

You should have cloned the full repository on your device. You can uses Vystem in two cases:
- in a VM
- on a real computer

In both cases, Vystem has been designed to be build and run from a standard Linux system. Any Linux distro should work. A WSL environnement can also work but, if you are testing in a VM, the VM might be very slow or unstable in the benchmark results, because of KVM unavailability. Make sure you have KVM enable and accessible before starting, or else remove the `-accel kvm` argument at the end of the `build.json` file.

Before starting, please make sure that you have the following binary reachable in your terminal path:
``` 
python3 python nasm g++ gcc iasl git make unzip  
```

You may also want `qemu-system-x86_64` if you are testing Vystem in a VM.

Finally, please make sure that you have an internet connexion if EDK II isn't yet setuped as well as root access/sudo permissions, as it is necessary for running `keygen`. Root permissions is only obtained as soon as it's needed.

## Build and run

Once you are ready, run the following command while being in the root folder:
``` bash
vybuild/build.sh
```

This script is designed to be used only from the root folder.

This will build the `vybuild` executable inside the `vybuild` folder. This part isn't multithreaded and can take up to a whole minute depending on your device.

Then, to start the build process, you can start VyBuild on the `build.json` file in the root folder like this:
``` bash
vybuild/vybuild build.json
```

This will compile, assemble and generate every asset together. This can take a while depending on your internet connexion, since EDK II is quite heavy and will be downloaded from it's source repository and locally compiled, with OVMF. For the moment, using packaged versions of EDK II and/or OVMF provided by packages managers isn't supported. 

The VM will automatically be launched with 4 gigabytes of RAM (you can obviously raise or lower that amount depending on your device), KVM enabled and serial port output redirected inside the terminal.

To generate the disk image without starting the VM, you can use the following command:
``` bash
vybuild/vybuild build.json img
```

Then, just flash the generated disk image on a USB disk and boot from it on real hardware.

**Warning:** depending the properties of the firmware and available video cards on the hardware used to test Vystem, the EFI GOP framebuffer might not survive after ExitBootServices.

## Troubleshooting

If anything goes wrong, VyBuild will stop and show you the error. Sometimes it's just a dependency that isn't reachable. Carefully analyse the error message and try to install the missing dependencies, also check that the required dependencies listed above are all installed.

If it's related to EDK II (which occur the majority of the time), it could be that a new update in EDK II has broken something. Don't hesitate to open an issue, and this should be fix fairly quickly.
