Skip to content

Commit

Permalink
feat(pkgs/dmd): Automate definition of package versions
Browse files Browse the repository at this point in the history
* Move hashes for each supported version to machine-generated JSON files
* Automatically generate derivations per each supported source and binary
  version
  • Loading branch information
PetarKirov committed Jan 25, 2024
1 parent fd26c1a commit 12a0ae6
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 75 deletions.
72 changes: 65 additions & 7 deletions pkgs/default.nix
Original file line number Diff line number Diff line change
@@ -1,27 +1,85 @@
{inputs, ...}: {
{
inputs,
lib,
...
}: let
inherit (builtins) attrNames listToAttrs map mapAttrs;
inherit (lib) nameValuePair pipe optionalAttrs;
in {
imports = [inputs.flake-parts.flakeModules.easyOverlay];

perSystem = {
self',
pkgs,
...
}: let
inherit (pkgs) callPackage lib darwin hostPlatform;
inherit (pkgs) callPackage hostPlatform;
darwinPkgs = {
inherit (darwin.apple_sdk.frameworks) Foundation;
inherit (pkgs.darwin.apple_sdk.frameworks) Foundation;
};

genPkgVersions = pkgName: let
mod = ./. + "/${pkgName}/version-catalog.nix";
inherit
(import mod)
supportedVersions
getSourceVersion
getBinaryVersion
;
getVersion = type:
if type == "source"
then getSourceVersion
else getBinaryVersion;
in {
flattened = type: let
nameSuffix =
if type == "binary"
then "-binary"
else "";
in
pipe (attrNames supportedVersions."${type}") [
(
map (
version:
nameValuePair
"${pkgName}${nameSuffix}-${version}"
(callPackage (getVersion type version) darwinPkgs)
)
)
listToAttrs
];

hierarchical = {
"${pkgName}" = pipe ["source" "binary"] [
(map (type:
nameValuePair type (
mapAttrs
(version: _: (callPackage (getVersion type version) darwinPkgs))
supportedVersions."${type}"
)))
listToAttrs
];
};
};
in {
overlayAttrs = self'.packages;
legacyPackages =
{}
// (genPkgVersions "dmd").hierarchical;
packages =
{
ldc-binary = callPackage ./ldc/bootstrap.nix {};
ldc = callPackage ./ldc {};

dub = callPackage ./dub {};
}
// lib.optionalAttrs hostPlatform.isx86 {
dmd-binary = callPackage ./dmd/bootstrap.nix {};
dmd = callPackage ./dmd darwinPkgs;
};
// optionalAttrs hostPlatform.isx86 (
{
dmd-bootstrap = self'.packages."dmd-binary-2.098.0";
dmd = self'.packages."dmd-2.100.2";
}
// (genPkgVersions "dmd").flattened "binary"
// (genPkgVersions "dmd").flattened "source"
);
};
}
7 changes: 0 additions & 7 deletions pkgs/dmd/2.098.nix

This file was deleted.

7 changes: 0 additions & 7 deletions pkgs/dmd/2.100.nix

This file was deleted.

6 changes: 0 additions & 6 deletions pkgs/dmd/2.102.nix

This file was deleted.

6 changes: 4 additions & 2 deletions pkgs/dmd/binary.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
version,
hashes,
}: {
lib,
stdenv,
fetchurl,
Expand All @@ -7,8 +10,7 @@
autoPatchelfHook,
fixDarwinDylibNames,
gccForLibs,
version,
hashes,
...
}: let
inherit (stdenv) hostPlatform;
OS =
Expand Down
3 changes: 1 addition & 2 deletions pkgs/dmd/bootstrap.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{callPackage}:
callPackage ./binary.nix {
import ./binary.nix {
version = "2.098.0";
hashes = {
# COMPILER=dmd VERSION=2.098.0 ./scripts/fetch-binary
Expand Down
94 changes: 51 additions & 43 deletions pkgs/dmd/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,20 @@
then "druntime"
else "dmd/druntime";

commonBuildFlags = [
"-fposix.mak"
"SHELL=${bash}/bin/bash"
"DMD=$(NIX_BUILD_TOP)/dmd/${buildPath}/dmd"
"CC=${if stdenv.isDarwin then stdenv.cc else gcc11}/bin/cc"
"HOST_DMD=${HOST_DMD}"
"PIC=1"
"BUILD=${buildMode}"
]
commonBuildFlags =
[
"-fposix.mak"
"SHELL=${bash}/bin/bash"
"DMD=$(NIX_BUILD_TOP)/dmd/${buildPath}/dmd"
"CC=${
if stdenv.isDarwin
then stdenv.cc
else gcc11
}/bin/cc"
"HOST_DMD=${HOST_DMD}"
"PIC=1"
"BUILD=${buildMode}"
]
# There is an "ifdef ENABLE_COVERAGE" rule in Phobos posix.max causing
# coverage to be enabled even if it's set to 0. For consistency we leave
# any false values unset.
Expand All @@ -107,37 +112,39 @@ in

enableParallelBuilding = true;

srcs = [
(fetchFromGitHub {
owner = "dlang";
repo = "dmd";
rev = "v${version}";
sha256 = dmdSha256;
name = "dmd";
})
(fetchFromGitHub {
owner = "dlang";
repo = "phobos";
rev = "v${version}";
sha256 = phobosSha256;
name = "phobos";
})
(fetchFromGitHub {
owner = "dlang";
repo = "tools";
rev = "v${version}";
sha256 = toolsSha256;
name = "tools";
})
] ++ lib.optionals druntimeRepo [
(fetchFromGitHub {
owner = "dlang";
repo = "druntime";
rev = "v${version}";
sha256 = druntimeSha256;
name = "druntime";
})
];
srcs =
[
(fetchFromGitHub {
owner = "dlang";
repo = "dmd";
rev = "v${version}";
sha256 = dmdSha256;
name = "dmd";
})
(fetchFromGitHub {
owner = "dlang";
repo = "phobos";
rev = "v${version}";
sha256 = phobosSha256;
name = "phobos";
})
(fetchFromGitHub {
owner = "dlang";
repo = "tools";
rev = "v${version}";
sha256 = toolsSha256;
name = "tools";
})
]
++ lib.optionals druntimeRepo [
(fetchFromGitHub {
owner = "dlang";
repo = "druntime";
rev = "v${version}";
sha256 = druntimeSha256;
name = "druntime";
})
];

sourceRoot = ".";

Expand Down Expand Up @@ -247,7 +254,8 @@ in
export MAKEFLAGS="-j$buildJobs"
make -C dmd $buildFlags
${lib.optionalString druntimeRepo
${
lib.optionalString druntimeRepo
"make -C druntime $buildFlags"
}
make -C phobos $buildFlags DFLAGS="${phobosDflags}"
Expand Down Expand Up @@ -282,8 +290,8 @@ in
make -C dmd test $checkFlags
${lib.optionalString druntimeRepo ''
NIX_ENFORCE_PURITY= \
make -C druntime unittest $checkFlags
NIX_ENFORCE_PURITY= \
make -C druntime unittest $checkFlags
''}
NIX_ENFORCE_PURITY= \
Expand Down
19 changes: 19 additions & 0 deletions pkgs/dmd/supported-source-versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"2.098.1": {
"dmd": "sha256-61hViU/IBUKHwXO+mt63lo3kBGL4Gtve83Uxi32gwnU=",
"druntime": "sha256-HN/bxmGJHqubiUESZ7Y/4gdUj8ja9WhyLq24IDdZoe0=",
"phobos": "sha256-GMa3k9QWfDiLSx0HH+n6eqgY6Pq0qkmXhbAslTsCH9A=",
"tools": "sha256-+pH7X9YRh0yG0iZoDkC6X50uscb4WKXmk2V+74cMSW8="
},
"2.100.2": {
"dmd": "sha256-o4+G3ARXIGObYHtHooYZKr+Al6kHpiwpMIog3i4BlDM=",
"druntime": "sha256-qXvY1ECN4mPwOGgOE1FWwvxoRvlSww3tGLWgBdhzAKo=",
"phobos": "sha256-kTHRaAKG7cAGb4IE/NGHWaZ8t7ZceKj03l6E8wLzJzs=",
"tools": "sha256-2yzdkarbsf0kOXzLaS6bvBFoiYbDulnEHTozmHX3Oc4="
},
"2.102.2": {
"dmd": "sha256-der9nb31hJ+K1aJZdzIgs8+eRgVVsH97QnYEnVbKUws=",
"phobos": "sha256-SracmUm2aY/LDCyDqYuVS39pCbwO8UCL3TSB0CVHpHE=",
"tools": "sha256-XM4gUxcarQCOBR8W/o0iWAI54PyLDkH6CsDce22Cnu4="
}
}
38 changes: 38 additions & 0 deletions pkgs/dmd/version-catalog.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
rec {
supportedVersions = {
source = builtins.fromJSON (
builtins.readFile ./supported-source-versions.json
);

binary = builtins.fromJSON (
builtins.readFile ./supported-binary-versions.json
);
};

getSourceVersion = version:
assert builtins.hasAttr version supportedVersions.source; let
componentHashes = supportedVersions.source."${version}";
in
import ./generic.nix ({
inherit version;
dmdSha256 = componentHashes.dmd;
phobosSha256 = componentHashes.phobos;
toolsSha256 = componentHashes.tools;
}
// (
if componentHashes ? "druntime"
then {
druntimeSha256 = componentHashes.druntime;
}
else {}
));

getBinaryVersion = version:
assert builtins.hasAttr version supportedVersions.binary; let
componentHashes = supportedVersions.binary."${version}";
in
import ./binary.nix {
inherit version;
hashes = componentHashes;
};
}
2 changes: 1 addition & 1 deletion pkgs/ldc/binary.nix
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ in
maintainers = with maintainers; [ThomasMader lionello];
# FIXME: change to the following after the CI verifies it:
# platforms = builtins.attrNames systemToArchivePlatform;
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
platforms = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
};
}

0 comments on commit 12a0ae6

Please sign in to comment.