2024-01-02 11:29:13 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, fetchFromSourcehut
|
|
|
|
, binutils-unwrapped
|
|
|
|
, harec
|
|
|
|
, makeWrapper
|
|
|
|
, qbe
|
2024-02-29 20:09:43 +00:00
|
|
|
, gitUpdater
|
2024-01-02 11:29:13 +00:00
|
|
|
, scdoc
|
|
|
|
, tzdata
|
|
|
|
, substituteAll
|
2024-01-25 14:12:00 +00:00
|
|
|
, 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`.
|
|
|
|
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))
|
|
|
|
-> builtins.throw ''
|
|
|
|
The cross-compilation toolchains may only be enabled on the following platforms:
|
|
|
|
${concatStringsSep "\n" workingPlatforms}
|
|
|
|
'';
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
let
|
|
|
|
arch = stdenv.hostPlatform.uname.processor;
|
2024-01-25 14:12:00 +00:00
|
|
|
platform = lib.toLower stdenv.hostPlatform.uname.system;
|
|
|
|
embeddedOnBinaryTools =
|
|
|
|
let
|
|
|
|
genToolsFromToolchain = toolchain:
|
|
|
|
let
|
|
|
|
crossTargetPrefix = toolchain.stdenv.cc.targetPrefix;
|
|
|
|
toolchainArch = toolchain.stdenv.hostPlatform.uname.processor;
|
|
|
|
absOrRelPath = toolDrv: toolBasename:
|
|
|
|
if arch == toolchainArch then toolBasename
|
|
|
|
else lib.getExe' toolDrv "${crossTargetPrefix}${toolBasename}";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
"ld" = absOrRelPath toolchain.buildPackages.binutils "ld";
|
|
|
|
"as" = absOrRelPath toolchain.buildPackages.binutils "as";
|
|
|
|
"cc" = absOrRelPath toolchain.stdenv.cc "cc";
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
x86_64 = genToolsFromToolchain x86_64PkgsCrossToolchain;
|
|
|
|
aarch64 = genToolsFromToolchain aarch64PkgsCrossToolchain;
|
|
|
|
riscv64 = genToolsFromToolchain riscv64PkgsCrossToolchain;
|
|
|
|
};
|
2024-01-02 11:29:13 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation (finalAttrs: {
|
|
|
|
pname = "hare";
|
2024-02-29 20:09:43 +00:00
|
|
|
version = "0.24.0";
|
2024-01-02 11:29:13 +00:00
|
|
|
|
|
|
|
outputs = [ "out" "man" ];
|
|
|
|
|
|
|
|
src = fetchFromSourcehut {
|
|
|
|
owner = "~sircmpwn";
|
|
|
|
repo = "hare";
|
2024-02-29 20:09:43 +00:00
|
|
|
rev = finalAttrs.version;
|
|
|
|
hash = "sha256-3T+BdNj+Th8QXrcsPMWlN9GBfuMF1ulneWHpDEtyBU8=";
|
2024-01-02 11:29:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
patches = [
|
|
|
|
# Replace FHS paths with nix store
|
|
|
|
(substituteAll {
|
|
|
|
src = ./001-tzdata.patch;
|
|
|
|
inherit tzdata;
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
harec
|
|
|
|
makeWrapper
|
|
|
|
qbe
|
|
|
|
scdoc
|
|
|
|
];
|
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
binutils-unwrapped
|
|
|
|
harec
|
|
|
|
qbe
|
|
|
|
tzdata
|
|
|
|
];
|
|
|
|
|
|
|
|
makeFlags = [
|
|
|
|
"HARECACHE=.harecache"
|
|
|
|
"PREFIX=${builtins.placeholder "out"}"
|
|
|
|
"ARCH=${arch}"
|
2024-02-29 20:09:43 +00:00
|
|
|
"VERSION=${finalAttrs.version}-nixpkgs"
|
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"
|
|
|
|
] ++ lib.optionals enableCrossCompilation [
|
|
|
|
"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
|
|
|
];
|
|
|
|
|
|
|
|
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
|
|
|
'';
|
|
|
|
|
|
|
|
postFixup = ''
|
|
|
|
wrapProgram $out/bin/hare \
|
|
|
|
--prefix PATH : ${lib.makeBinPath [binutils-unwrapped harec qbe]}
|
|
|
|
'';
|
|
|
|
|
|
|
|
setupHook = ./setup-hook.sh;
|
|
|
|
|
2024-01-25 14:12:00 +00:00
|
|
|
passthru = {
|
2024-02-29 20:09:43 +00:00
|
|
|
updateScript = gitUpdater { };
|
2024-01-25 14:12:00 +00:00
|
|
|
tests = lib.optionalAttrs enableCrossCompilation {
|
|
|
|
crossCompilation = callPackage ./cross-compilation-tests.nix {
|
|
|
|
hare = finalAttrs.finalPackage;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
})
|