Skip to content

Commit

Permalink
Update building instructions
Browse files Browse the repository at this point in the history
Update x86_64 building instructions

Signed-off-by: Peter Shkenev <[email protected]>
  • Loading branch information
petershh authored Sep 10, 2023
1 parent 797f1b4 commit e1ae5b0
Showing 1 changed file with 43 additions and 19 deletions.
62 changes: 43 additions & 19 deletions doc/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,61 @@ This guide documents the Onyx build process. For example usage of this building

Note that steps 0, 1 and 2 can be skipped if you have already done them before.

## Step 0: Set up the build environment
## Step 0: Get required packages

First, you'll need to download the [minimal sysroot](https://storage.googleapis.com/onyx-stuffs/minimal-sysroot.tar.zst).
You need the following packages and programs: mtools, xorriso, ninja, gn, grub-mkrescue.
Also you need development files for MPC, MPFR and GMP and texinfo package if you are going to build gcc
and cmake if you are going to build LLVM.

## Step 1: Fetch submodules

Either use `--recursive` flag while cloning the Onyx repository, or issue these commands in repository:

```
git submodule init
git submodule update --recursive
```

## Step 2: Get minimal sysroot (skip if using prebuilt toolchain)

First, you'll need to download the minimal sysroot available in project's github actions artifacts.
This allows you to have the toolchain build against a sane libc.
Be sure to export `SYSROOT=$PWD/sysroot` and `ONYX_ARCH=x86_64` (right now, only x86_64 is supported).

## Step 1: Get the toolchains
If you are going to build **gcc**, uncompress sysroot for your arch into the project root.

If you so desire, you can find prebuilts for Linux and macOS in the project's github action artifacts,
under `build-toolchain-${os}` or `build-toolchain-llvm-${os}`. Note that macOS LLVM builds are broken.
If you are going to build **LLVM**, you will need sysroots for all supported architectures,
namely x86_64, riscv64 and arm64. Uncompress these sysroots to `sysroots/$arch` directory in
the project root. Additionally, make sysroots/i386 a symlink to x86_64 (`ln -s x86_64 sysroots/i386`
in the project root).

You can find two scripts, `build_gcc.sh` and `build_llvm.sh`, under `toolchains/scripts`. These build a
GCC and LLVM toolchain for Onyx, respectively. Use these and install the toolchains to a known location.
Note: $GCC_TOOLCHAIN/bin needs to be on the system's $PATH. LLVM has no such requirement.
## Step 3: Prepare build environment

1. `export ONYX_ARCH=x86_64`
2. Install appropriate kernel config under `kernel/kernel.config`. There are pre-existing examples in
`kernel/configs`, these are fine choices.

## Step 4: Build or obtain the toolchains

### Obtaining prebuilt toolchains

These are available for Linux and macOS in the project's github action artifacts,
under `build-toolchain-${os}` or `build-toolchain-llvm-${os}`. Note that macOS LLVM builds are broken.

## Step 2: Set up the kernel config
### Building toolchains

The kernel build requires a valid `kernel.config` under kernel/. You can look at pre-existing examples
(.example and .minimal) and lay the kernel out yourself; kernel.config.example is a fine choice.
`toolchains/scripts/build_toolchain.sh` will do it for you. You need to choose staging and target
directory toolchain. Target toolchain directory further will be referred as `$TOOLCHAIN_TARGET_DIR`.

After this point, it's required that SYSROOT, ONYX_ARCH are set and that, if using LLVM, CLANG_PATH points to the
installation path of the LLVM toolchain.
### Adding toolchain paths to environment

## Step 3: Set up the build
If using **gcc**: add `$TOOLCHAIN_TARGET_DIR/bin` to `$PATH`.

This step only needs to be done once. Run `./scripts/setup_build.sh`.
If using **LLVM**: `export CLANG_PATH=$TOOLCHAIN_TARGET_DIR`.

## Step 4: Build
## Step 5: Build

Do `make -j <nproc> iso` where nproc is the number of threads you want the build to use.
First, run `scripts/setup_build.sh`

`RUN_CLANG_TIDY=0` might be a useful flag to pass, as it stops the kernel build from running clang-tidy on files.
Then do `make -j <nproc> liveiso` where nproc is the number of threads you want the build to use.

If everything went well, you will have a Onyx.iso under the base directory!

0 comments on commit e1ae5b0

Please sign in to comment.