Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial Nix flake #233

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Source: http://sel4.systems

Files:
tool/microkit/Cargo.lock
flake.lock
CHANGES.md
VERSION
Copyright: 2024, UNSW
Expand Down
40 changes: 29 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ To build the documentation you also need
* texlive-fonts-extra
* texlive-latex-extra

### Linux (with apt)

On a Debian-like system you can do:

$ curl https://sh.rustup.rs -sSf | sh
Expand All @@ -68,6 +70,9 @@ On a Debian-like system you can do:
python3.9 python3.9-venv \
qemu-system-arm qemu-system-misc \
gcc-riscv64-unknown-elf
$ python3.9 -m venv pyenv
$ ./pyenv/bin/pip install --upgrade pip setuptools wheel
$ ./pyenv/bin/pip install -r requirements.txt

If you do not have Python 3.9 available, you can get it via the
*deadsnakes* PPA: https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa
Expand All @@ -77,39 +82,52 @@ To use this:
$ sudo apt update
$ sudo apt install python3.9 python3.9-venv

The ARM toolchain is available from:

https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads.

Development is done with the aarch64-none-elf- toolchain.

On Linux x86-64 the following version is used:
https://developer.arm.com/-/media/Files/downloads/gnu/12.2.rel1/binrel/arm-gnu-toolchain-12.2.rel1-x86_64-aarch64-none-elf.tar.xz?rev=28d5199f6db34e5980aae1062e5a6703&hash=F6F5604BC1A2BBAAEAC4F6E98D8DC35B

### macOS

On macOS, with the [Homebrew](https://brew.sh) package manager you can do:

$ curl https://sh.rustup.rs -sSf | sh
$ brew tap riscv-software-src/riscv
$ brew install riscv-tools
$ brew install pandoc cmake dtc ninja libxml2 [email protected] coreutils texlive qemu

Additonally, a number of Python libraries are needed.
These should be installed using `pip`.

$ python3.9 -m venv pyenv
$ ./pyenv/bin/pip install --upgrade pip setuptools wheel
$ ./pyenv/bin/pip install -r requirements.txt

Note: It is a high priority of the authors to ensure builds are self-contained and repeatable.
A high value is placed on using specifically versioned tools.
At this point in time this is not fully realised, however it is a high priority to enable this in the near future.

The ARM toolchain is available from:

https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads.

Development is done with the aarch64-none-elf- toolchain.

On Linux x86-64 the following version is used:
https://developer.arm.com/-/media/Files/downloads/gnu/12.2.rel1/binrel/arm-gnu-toolchain-12.2.rel1-x86_64-aarch64-none-elf.tar.xz?rev=28d5199f6db34e5980aae1062e5a6703&hash=F6F5604BC1A2BBAAEAC4F6E98D8DC35B

On macOS Apple Silicon/AArch64 the following version is used:
https://developer.arm.com/-/media/Files/downloads/gnu/12.2.rel1/binrel/arm-gnu-toolchain-12.2.rel1-darwin-arm64-aarch64-none-elf.tar.xz?rev=c5523a33dc7e49278f2a943a6a9822c4&hash=6DC6989BB1E6A9C7F8CBFEAA84842FA1

On macOS Intel/x86-64 the following version is used:
https://developer.arm.com/-/media/Files/downloads/gnu/12.2.rel1/binrel/arm-gnu-toolchain-12.2.rel1-darwin-x86_64-aarch64-none-elf.tar.xz?rev=09b11f159fc24fdda01e05bb32695dd5&hash=6AAF4239F28AE17389AB3E611DFFE0A6

### Nix

Running:

$ nix develop

Will give a shell with all the required dependencies to build the SDK.

An important note is that Nix's RISC-V cross-compiler will have a different
prefix to the default one the SDK build script expects.

When you build the SDK, provide an extra argument `--toolchain-prefix-riscv64 riscv64-none-elf`.

## seL4 Version

The SDK includes a binary of the seL4 kernel.
Expand Down
7 changes: 7 additions & 0 deletions build_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,13 @@ def main() -> None:

args = parser.parse_args()

global TOOLCHAIN_AARCH64
global TOOLCHAIN_RISCV
TOOLCHAIN_AARCH64 = args.toolchain_prefix_aarch64
TOOLCHAIN_RISCV = args.toolchain_prefix_riscv64

print(TOOLCHAIN_RISCV)

version = args.version

if args.boards is not None:
Expand Down
117 changes: 117 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

117 changes: 117 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#
# Copyright 2024, UNSW
# SPDX-License-Identifier: BSD-2-Clause
#
{
description = "A flake for building microkit";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/24.05";
utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, rust-overlay, treefmt-nix, ... }@inputs: inputs.utils.lib.eachSystem [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
]
(system:
let
pkgs = import nixpkgs {
inherit system;

overlays = [ (import rust-overlay) ];
};

treefmtEval = treefmt-nix.lib.evalModule pkgs (
{ ... }:
{
projectRootFile = "flake.nix";
programs.nixpkgs-fmt.enable = true;
}
);

aarch64-toolchain = import nixpkgs {
localSystem = "${system}";
crossSystem = {
config = "aarch64-none-elf";
};
};

# pyfdt is not officially supported in Nix so we compile it ourselves
pyfdt = with pkgs.python311Packages;
buildPythonPackage rec {
pname = "pyfdt";
version = "0.3";
src = pkgs.fetchFromGitHub {
owner = "superna9999";
repo = pname;
rev = "${pname}-${version}";
hash = "sha256-lt/Mcw3j1aTBVOVhDBSYtriDyzeJHcSli69EXLfsgDM=";
};

meta = with lib; {
description = "Python Flattened Device Tree Library";
homepage = "https://github.com/superna9999/pyfdt";
license = with licenses; [ asl20 ];
maintainers = with maintainers; [ wucke13 ];
};
};

pythonTool = pkgs.python311.withPackages (ps: [
ps.mypy
ps.black
ps.flake8
ps.ply
ps.jinja2
ps.pyaml
ps.lxml
pyfdt
ps.setuptools
]);

microkiToolToml = nixpkgs.lib.trivial.importTOML ./tool/microkit/Cargo.toml;
microkitToolVersion = microkiToolToml.package.rust-version;

rustTool = pkgs.rust-bin.stable.${microkitToolVersion}.default.override {
targets = [ pkgs.pkgsStatic.hostPlatform.rust.rustcTarget ];
};

in
{
# for `nix fmt`
formatter = treefmtEval.config.build.wrapper;
# for `nix flake check`
checks.formatting = treefmtEval.config.build.check self;

devShells.default = pkgs.mkShell rec {
name = "microkit-shell";

nativeBuildInputs = with pkgs; [
pkgsCross.aarch64-embedded.stdenv.cc.bintools
pkgsCross.aarch64-embedded.stdenv.cc.cc
pkgsCross.riscv64-embedded.stdenv.cc.bintools
pkgsCross.riscv64-embedded.stdenv.cc.cc
gnumake
dtc
expect
pythonTool
git
rustTool
pandoc
(texlive.combine {
inherit (texlive) scheme-medium titlesec enumitem sfmath roboto fontaxes isodate substr tcolorbox environ pdfcol;
})
cmake
ninja
libxml2
];
};
});
}
Loading