2024-06-05 15:53:02 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
stdenv,
|
|
|
|
fetchFromSourcehut,
|
|
|
|
harec,
|
|
|
|
scdoc,
|
|
|
|
tzdata,
|
|
|
|
mailcap,
|
|
|
|
substituteAll,
|
|
|
|
callPackage,
|
|
|
|
enableCrossCompilation ? (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.is64bit),
|
|
|
|
pkgsCross,
|
|
|
|
x86_64PkgsCrossToolchain ? pkgsCross.gnu64,
|
|
|
|
aarch64PkgsCrossToolchain ? pkgsCross.aarch64-multiplatform,
|
|
|
|
riscv64PkgsCrossToolchain ? pkgsCross.riscv64,
|
2024-01-02 11:29:13 +00:00
|
|
|
}:
|
|
|
|
|
2024-02-07 01:22:34 +00:00
|
|
|
# There's no support for `aarch64` or `riscv64` for freebsd nor for openbsd on nix.
|
2024-01-25 14:12:00 +00:00
|
|
|
# See `lib.systems.doubles.aarch64` and `lib.systems.doubles.riscv64`.
|
2024-06-05 15:53:02 +00:00
|
|
|
assert
|
|
|
|
let
|
|
|
|
inherit (stdenv.hostPlatform) isLinux is64bit;
|
|
|
|
inherit (lib) intersectLists platforms concatStringsSep;
|
|
|
|
workingPlatforms = intersectLists platforms.linux (with platforms; x86_64 ++ aarch64 ++ riscv64);
|
|
|
|
in
|
|
|
|
(enableCrossCompilation -> !(isLinux && is64bit))
|
2024-01-25 14:12:00 +00:00
|
|
|
-> builtins.throw ''
|
2024-06-05 15:53:02 +00:00
|
|
|
The cross-compilation toolchains may only be enabled on the following platforms:
|
|
|
|
${concatStringsSep "\n" workingPlatforms}
|
|
|
|
'';
|
2024-01-25 14:12:00 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
let
|
2024-06-20 14:57:18 +00:00
|
|
|
inherit (harec) qbe;
|
2024-06-05 15:53:02 +00:00
|
|
|
buildArch = stdenv.buildPlatform.uname.processor;
|
2024-01-02 11:29:13 +00:00
|
|
|
arch = stdenv.hostPlatform.uname.processor;
|
2024-01-25 14:12:00 +00:00
|
|
|
platform = lib.toLower stdenv.hostPlatform.uname.system;
|
2024-06-05 15:53:02 +00:00
|
|
|
qbePlatform =
|
|
|
|
{
|
|
|
|
x86_64 = "amd64_sysv";
|
|
|
|
aarch64 = "arm64";
|
|
|
|
riscv64 = "rv64";
|
|
|
|
}
|
|
|
|
.${arch};
|
2024-01-25 14:12:00 +00:00
|
|
|
embeddedOnBinaryTools =
|
|
|
|
let
|
2024-06-05 15:53:02 +00:00
|
|
|
genPaths =
|
|
|
|
toolchain:
|
2024-01-25 14:12:00 +00:00
|
|
|
let
|
2024-06-05 15:53:02 +00:00
|
|
|
inherit (toolchain.stdenv.cc) targetPrefix;
|
|
|
|
inherit (toolchain.stdenv.targetPlatform.uname) processor;
|
2024-01-25 14:12:00 +00:00
|
|
|
in
|
|
|
|
{
|
2024-06-05 15:53:02 +00:00
|
|
|
"${processor}" = {
|
|
|
|
"ld" = lib.getExe' toolchain.buildPackages.binutils "${targetPrefix}ld";
|
|
|
|
"as" = lib.getExe' toolchain.buildPackages.binutils "${targetPrefix}as";
|
|
|
|
"cc" = lib.getExe' toolchain.stdenv.cc "${targetPrefix}cc";
|
|
|
|
};
|
2024-01-25 14:12:00 +00:00
|
|
|
};
|
|
|
|
in
|
2024-06-05 15:53:02 +00:00
|
|
|
builtins.foldl' (acc: elem: acc // (genPaths elem)) { } [
|
|
|
|
x86_64PkgsCrossToolchain
|
|
|
|
aarch64PkgsCrossToolchain
|
|
|
|
riscv64PkgsCrossToolchain
|
|
|
|
];
|
|
|
|
crossCompMakeFlags = builtins.filter (x: !(lib.hasPrefix (lib.toUpper buildArch) x)) [
|
|
|
|
"RISCV64_AS=${embeddedOnBinaryTools.riscv64.as}"
|
|
|
|
"RISCV64_CC=${embeddedOnBinaryTools.riscv64.cc}"
|
|
|
|
"RISCV64_LD=${embeddedOnBinaryTools.riscv64.ld}"
|
|
|
|
"AARCH64_AS=${embeddedOnBinaryTools.aarch64.as}"
|
|
|
|
"AARCH64_CC=${embeddedOnBinaryTools.aarch64.cc}"
|
|
|
|
"AARCH64_LD=${embeddedOnBinaryTools.aarch64.ld}"
|
|
|
|
"X86_64_AS=${embeddedOnBinaryTools.x86_64.as}"
|
|
|
|
"X86_64_CC=${embeddedOnBinaryTools.x86_64.cc}"
|
|
|
|
"X86_64_LD=${embeddedOnBinaryTools.x86_64.ld}"
|
|
|
|
];
|
2024-01-02 11:29:13 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation (finalAttrs: {
|
|
|
|
pname = "hare";
|
2024-07-27 06:49:29 +00:00
|
|
|
version = "0.24.2";
|
2024-01-02 11:29:13 +00:00
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
outputs = [
|
|
|
|
"out"
|
|
|
|
"man"
|
|
|
|
];
|
2024-01-02 11:29:13 +00:00
|
|
|
|
|
|
|
src = fetchFromSourcehut {
|
|
|
|
owner = "~sircmpwn";
|
|
|
|
repo = "hare";
|
2024-02-29 20:09:43 +00:00
|
|
|
rev = finalAttrs.version;
|
2024-07-27 06:49:29 +00:00
|
|
|
hash = "sha256-61lckI0F+Ez5LR/8g6ftS0W7Q/+EU/1flTDFleBg6pc=";
|
2024-01-02 11:29:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
patches = [
|
|
|
|
# Replace FHS paths with nix store
|
|
|
|
(substituteAll {
|
|
|
|
src = ./001-tzdata.patch;
|
|
|
|
inherit tzdata;
|
|
|
|
})
|
2024-04-21 15:54:59 +00:00
|
|
|
# Don't build haredoc since it uses the build `hare` bin, which breaks
|
|
|
|
# cross-compilation.
|
|
|
|
./002-dont-build-haredoc.patch
|
2024-06-05 15:53:02 +00:00
|
|
|
# Hardcode harec and qbe.
|
|
|
|
(substituteAll {
|
|
|
|
src = ./003-hardcode-qbe-and-harec.patch;
|
2024-07-27 06:49:29 +00:00
|
|
|
harec_bin = lib.getExe harec;
|
|
|
|
qbe_bin = lib.getExe qbe;
|
2024-06-05 15:53:02 +00:00
|
|
|
})
|
|
|
|
# Use mailcap `/etc/mime.types` for Hare's mime module
|
|
|
|
(substituteAll {
|
2024-07-27 06:49:29 +00:00
|
|
|
src = ./004-use-mailcap-for-mimetypes.patch;
|
2024-06-05 15:53:02 +00:00
|
|
|
inherit mailcap;
|
|
|
|
})
|
2024-01-02 11:29:13 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
harec
|
|
|
|
qbe
|
|
|
|
scdoc
|
|
|
|
];
|
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
harec
|
|
|
|
qbe
|
|
|
|
];
|
|
|
|
|
|
|
|
makeFlags = [
|
|
|
|
"HARECACHE=.harecache"
|
|
|
|
"PREFIX=${builtins.placeholder "out"}"
|
|
|
|
"ARCH=${arch}"
|
2024-02-29 20:09:43 +00:00
|
|
|
"VERSION=${finalAttrs.version}-nixpkgs"
|
2024-04-21 15:54:59 +00:00
|
|
|
"QBEFLAGS=-t${qbePlatform}"
|
|
|
|
"AS=${stdenv.cc.targetPrefix}as"
|
|
|
|
"LD=${stdenv.cc.targetPrefix}ld"
|
2024-06-05 15:53:02 +00:00
|
|
|
"${lib.toUpper buildArch}_AS=${embeddedOnBinaryTools.${buildArch}.as}"
|
|
|
|
"${lib.toUpper buildArch}_CC=${embeddedOnBinaryTools.${buildArch}.cc}"
|
|
|
|
"${lib.toUpper buildArch}_LD=${embeddedOnBinaryTools.${buildArch}.ld}"
|
2024-01-25 14:12:00 +00:00
|
|
|
# Strip the variable of an empty $(SRCDIR)/hare/third-party, since nix does
|
|
|
|
# not follow the FHS.
|
|
|
|
"HAREPATH=$(SRCDIR)/hare/stdlib"
|
2024-06-05 15:53:02 +00:00
|
|
|
] ++ lib.optionals enableCrossCompilation crossCompMakeFlags;
|
2024-01-02 11:29:13 +00:00
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
|
|
|
# Append the distribution name to the version
|
|
|
|
env.LOCALVER = "nixpkgs";
|
|
|
|
|
|
|
|
strictDeps = true;
|
|
|
|
|
|
|
|
doCheck = true;
|
|
|
|
|
2024-02-07 01:22:34 +00:00
|
|
|
postConfigure = ''
|
|
|
|
ln -s configs/${platform}.mk config.mk
|
2024-01-02 11:29:13 +00:00
|
|
|
'';
|
|
|
|
|
2024-01-25 14:12:00 +00:00
|
|
|
passthru = {
|
2024-06-05 15:53:02 +00:00
|
|
|
tests =
|
|
|
|
lib.optionalAttrs enableCrossCompilation {
|
|
|
|
crossCompilation = callPackage ./cross-compilation-tests.nix { hare = finalAttrs.finalPackage; };
|
|
|
|
}
|
|
|
|
// lib.optionalAttrs (stdenv.buildPlatform.canExecute stdenv.hostPlatform) {
|
|
|
|
mimeModule = callPackage ./mime-module-test.nix { hare = finalAttrs.finalPackage; };
|
2024-07-31 10:19:44 +00:00
|
|
|
}
|
|
|
|
//
|
|
|
|
lib.optionalAttrs (enableCrossCompilation && stdenv.buildPlatform.canExecute stdenv.hostPlatform)
|
|
|
|
{
|
|
|
|
crossCompilation = callPackage ./cross-compilation-tests.nix { hare = finalAttrs.finalPackage; };
|
|
|
|
};
|
2024-06-20 14:57:18 +00:00
|
|
|
# To be propagated by `hareHook`.
|
|
|
|
inherit harec qbe;
|
2024-01-25 14:12:00 +00:00
|
|
|
};
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
meta = {
|
|
|
|
homepage = "https://harelang.org/";
|
|
|
|
description = "Systems programming language designed to be simple, stable, and robust";
|
|
|
|
license = lib.licenses.gpl3Only;
|
|
|
|
maintainers = with lib.maintainers; [ onemoresuza ];
|
|
|
|
mainProgram = "hare";
|
|
|
|
inherit (harec.meta) platforms badPlatforms;
|
|
|
|
};
|
|
|
|
})
|