From 4d7055a2ddcefc426a817fadceadd1a5764a6926 Mon Sep 17 00:00:00 2001 From: Bolun Thompson Date: Tue, 1 Oct 2024 18:00:23 -0700 Subject: [PATCH] Add nix build Modifies the flake and Makefile to be proper, letting nix build work. --- Makefile | 17 ++++++++++++----- flake.nix | 33 ++++++++++++++++++++------------- kvm_sectorlisp.c | 2 +- readme.md | 11 +++++++++++ 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index cddde03..252ba88 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,22 @@ +# until gcc has "#embed" support CC=clang CFLAGS=-std=c23 -O3 -Wpedantic -Wall -Wextra -g .PHONY: all -all: kvm_sectorlisp sectorlisp/sectorlisp.bin +all: kvm_sectorlisp .PHONY: clean clean: - $(RM) kvm_sectorlisp sectorlisp/sectorlisp.bin + $(RM) kvm_sectorlisp sectorlisp.bin + $(MAKE) -C sectorlisp clean -sectorlisp/sectorlisp.bin: +kvm_sectorlisp: kvm_sectorlisp.c sectorlisp.bin + $(CC) kvm_sectorlisp.c -o kvm_sectorlisp $(CFLAGS) + +sectorlisp.bin: sectorlisp + ln -sf sectorlisp/sectorlisp.bin sectorlisp.bin + +.PHONY: sectorlisp +sectorlisp: $(MAKE) -C sectorlisp sectorlisp.bin -kvm_sectorlisp: kvm_sectorlisp.c - $(CC) kvm_sectorlisp.c -o kvm_sectorlisp $(CFLAGS) diff --git a/flake.nix b/flake.nix index 2993d00..cda5708 100644 --- a/flake.nix +++ b/flake.nix @@ -8,20 +8,27 @@ outputs = { self, nixpkgs }: let pkgs = nixpkgs.legacyPackages.x86_64-linux; + stdenv = pkgs.llvmPackages_19.stdenv; in { - devShells.x86_64-linux.default = pkgs.mkShell { - name = "KVM Sectorlisp Shell"; - nativeBuildInputs = with pkgs; with llvmPackages_19; [ - clang-tools - clang - ]; - packages = with pkgs; with llvmPackages_19; [ - gdb - binutils - blink - git - ]; - }; + devShells.x86_64-linux.default = pkgs.mkShell.override {inherit stdenv;} { + name = "KVM Sectorlisp Shell"; + packages = with pkgs; with llvmPackages_19; [ + gdb + blink + binutils + git + clang-tools + ]; + }; + defaultPackage.x86_64-linux = stdenv.mkDerivation { + name = "KVM Sectorlisp"; + version = "1.0.0"; + src = ./.; + installPhase = '' + mkdir -p $out/bin + mv kvm_sectorlisp $out/bin + ''; + }; }; } diff --git a/kvm_sectorlisp.c b/kvm_sectorlisp.c index 2f61329..4a38071 100644 --- a/kvm_sectorlisp.c +++ b/kvm_sectorlisp.c @@ -15,7 +15,7 @@ #define GET_IO_ADDR(kvm_run) (((uint8_t *)kvm_run) + kvm_run->io.data_offset) static const uint8_t SECTORLISP_BIN[] = { -#embed "sectorlisp/sectorlisp.bin" +#embed "sectorlisp.bin" }; // uncomfortable global vars diff --git a/readme.md b/readme.md index 580e67e..96ef075 100644 --- a/readme.md +++ b/readme.md @@ -9,3 +9,14 @@ Requirements: - To compile: clang 19+ (to support C23's `#embed` feature) Great thanks to the [LWN post on the KVM API](https://lwn.net/Articles/658511/) for acting as a guide. + +## Building +``` +git clone --recurse-submodules +make +``` +Clang 19 is the only dependency (for C23 support). + +### NixOS Notes + +To build for NixOS, run `nix build '.?submodules=1'`. See [discourse for why](https://discourse.nixos.org/t/get-nix-flake-to-include-git-submodule/30324/16).