about summary refs log tree commit diff
path: root/pkgs/development/compilers
diff options
context:
space:
mode:
authorAndersonTorres <torres.anderson.85@protonmail.com>2022-04-27 22:30:59 -0300
committerAndersonTorres <torres.anderson.85@protonmail.com>2022-05-03 08:23:32 -0300
commitb597b5c3fc97ea661692eb5ddfb7387af16fc7a4 (patch)
tree209b59c17f96a74e44d20908d95a9f2dd71d25ed /pkgs/development/compilers
parent9ded9f11002882d46c7be47527278ae01039c134 (diff)
hare: init at 0.pre+date=2022-04-27
Diffstat (limited to 'pkgs/development/compilers')
-rw-r--r--pkgs/development/compilers/hare/config-template.mk27
-rw-r--r--pkgs/development/compilers/hare/hare.nix91
2 files changed, 118 insertions, 0 deletions
diff --git a/pkgs/development/compilers/hare/config-template.mk b/pkgs/development/compilers/hare/config-template.mk
new file mode 100644
index 0000000000000..1d0783b118d3c
--- /dev/null
+++ b/pkgs/development/compilers/hare/config-template.mk
@@ -0,0 +1,27 @@
+## Template to generate config.mk via substitute-all
+
+# set PREFIX externally
+BINDIR = $(PREFIX)/bin
+MANDIR = $(PREFIX)/share/man
+SRCDIR = $(PREFIX)/src
+STDLIB = $(SRCDIR)/hare/stdlib
+
+HAREPATH = $(SRCDIR)/hare/stdlib:$(SRCDIR)/hare/third-party
+
+## Build configuration
+
+# Platform to build for
+PLATFORM = @platform@
+ARCH = @arch@
+
+# External tools and flags
+HAREC = harec
+HAREFLAGS = @hareflags@
+QBE = qbe
+AS = as
+LD = ld
+AR = ar
+SCDOC = scdoc
+
+# Where to store build artifacts
+# set HARECACHE externally
diff --git a/pkgs/development/compilers/hare/hare.nix b/pkgs/development/compilers/hare/hare.nix
new file mode 100644
index 0000000000000..4effebf0f84a3
--- /dev/null
+++ b/pkgs/development/compilers/hare/hare.nix
@@ -0,0 +1,91 @@
+{ lib
+, stdenv
+, fetchFromSourcehut
+, binutils-unwrapped
+, harec
+, makeWrapper
+, qbe
+, scdoc
+, substituteAll
+}:
+
+stdenv.mkDerivation rec {
+  pname = "hare";
+  version = "0.pre+date=2022-04-27";
+
+  src = fetchFromSourcehut {
+    name = pname + "-src";
+    owner = "~sircmpwn";
+    repo = pname;
+    rev = "1bfb2e6dee850c675a8831b41420800d3c62c2a0";
+    hash = "sha256-1b7U5u3PM3jmnH/OnY9O++GTPyVOdFkJ0fwJBoDZgSU=";
+  };
+
+  nativeBuildInputs = [
+    binutils-unwrapped
+    harec
+    makeWrapper
+    qbe
+    scdoc
+  ];
+
+  buildInputs = [
+    binutils-unwrapped
+    harec
+    qbe
+  ];
+
+  strictDeps = true;
+
+  configurePhase =
+    let
+      # https://harelang.org/platforms/
+      arch =
+        if stdenv.isx86_64 then "x86_64"
+        else if stdenv.isAarch64 then "aarch64"
+        else if stdenv.isRiscV64 then "riscv64"
+        else "unsupported";
+      platform =
+        if stdenv.isLinux then "linux"
+        else if stdenv.isFreeBSD then "freebsd"
+        else "unsupported";
+      hareflags = "";
+      config-file = substituteAll {
+        src = ./config-template.mk;
+        inherit arch platform hareflags;
+      };
+    in
+      ''
+        runHook preConfigure
+
+        export HARECACHE="$NIX_BUILD_TOP/.harecache"
+        cat ${config-file} > config.mk
+
+        runHook postConfigure
+      '';
+
+  makeFlags = [
+    "PREFIX=${placeholder "out"}"
+  ];
+
+  postInstall =
+    let
+      binPath = lib.makeBinPath [
+        binutils-unwrapped
+        harec
+        qbe
+      ];
+    in
+      ''
+        wrapProgram $out/bin/hare --prefix PATH : ${binPath}
+      '';
+
+  meta = with lib; {
+    homepage = "http://harelang.org/";
+    description =
+      "A systems programming language designed to be simple, stable, and robust";
+    license = licenses.gpl3Only;
+    maintainers = with maintainers; [ AndersonTorres ];
+    inherit (harec.meta) platforms badPlatforms;
+  };
+}