Skip to content

Commit

Permalink
Add nix build
Browse files Browse the repository at this point in the history
Modifies the flake and Makefile to be proper, letting nix build work.
  • Loading branch information
BolunThompson committed Oct 2, 2024
1 parent 343720a commit 4d7055a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
17 changes: 12 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
33 changes: 20 additions & 13 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
'';
};
};
}
2 changes: 1 addition & 1 deletion kvm_sectorlisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

0 comments on commit 4d7055a

Please sign in to comment.