unikraft / kraftkit

Build and use highly customized and ultra-lightweight unikernel VMs.
https://unikraft.org/docs/cli
BSD 3-Clause "New" or "Revised" License
245 stars 64 forks source link

Configurable toolchain #673

Open nderjung opened 1 year ago

nderjung commented 1 year ago

Overview

Unikraft is a highly modular library operating system designed for the cloud. It's high degree of modularization allows for extreme customization and specialization. As such, its tooling should not interfere with the user's desire to support such customization. Towards increasing the unikernel's developer's ability to customize the build whilst simultaneously systemitizing the process of retrieving, organizing and generally facilitating the build of a unikernel based on Unikraft and its many components, the supported tooling, kraft, should allow for the injection of the user's environment and or additional toolchain requirements.

Feature request summary

This project is designed to better facilitate the dynamic injection of user provided variables into Unikraft's build system through the addition of a dynamically configured toolchain towards greater customization of the unikernel build through the use of its command-line companion client tool, kraft. This manifests itself as an injection into KraftKit's core configuration system and must propagate across the codebase appropriately.

Distinct results of this addition would enable, but are not limited to: alternating the GNU Compiler Collection (GCC) version, providing alternative compile-time flags, and more.

This project tracks the addition of a map to the internal configuration system entitled toolchain which sets the values of programs that are ultimately passed to Unikraft's build system.

The addition is first made as an entry to the KraftKit config structure in

  type KraftKit struct {
    [...]
+   Toolchain map[string]string `yaml:"toolchain" long:"toolchain" usage:"Set specific global programs in Unikraft's build system"
    [...]
  }

These values need to be passed any make invocations as in-line variables via the option make.WithVar in relevant parts of KraftKit's commands that interact with the build, namely in cmd/kraft/build/build.go since it is in these files that access to the map is possible via config.G[config.KraftKit](ctx).Toolchain.

Additionally, the specific entry for CC should be added as default during the installation process, i.e. the user should be asked whether they want to change the default value for CC which should be set to gcc.

A sample change to the user's configuration could look something like:

toolchain:
  CC: /path/to/alternative/gcc
  UK_CFLAGS: -fdiagnostics-color=always

The same top-level toolchain should also be added as a directive/element into the Kraftfile, with the ability to specify it per-target.

Such configuration changes, when applied to KraftKit's configuration system, would allow for the dynamic injection of toolchain arguments via command-line flags, e.g. during the the construction of a unikernel binary image:

kraft --toolchain.UK_CFLAGS="-fdiagnostics-color=always" build

Additional context

Such a configuration system will enable KraftKit users to pass in additional flags to Unikraft's build system following the merge of https://github.com/unikraft/unikraft/pull/957

### Steps
- [x] Test building an application via `make`
- [x] Try passing different toolchain options to the `make` command
- [ ] Try to hardcode-inject a toolchain option within the kraftkit `make` package. See if it works as expected, or needs redesigning
- [ ] Introduce the Toolchain global config variable as hinted above
- [ ] Introduce the toolchain kraftfile element (see https://github.com/unikraft/kraftkit/pull/1463 https://github.com/unikraft/kraftkit/pull/1286 for suggestions how to do things)
- [ ] Introduce cli options/commands to set/list toolchain variables
craciunoiuc commented 6 months ago

@UjjwalMahar this is an overview of the GSoC project that you are going to work on.

I'll assign this to myself cause for some reason I can't assign you.