Skip to content

Commit

Permalink
feat(pkgs/dmd): Made LDC the default bootstrap compiler.
Browse files Browse the repository at this point in the history
  • Loading branch information
dukc committed Mar 6, 2024
1 parent 8be4108 commit c83ca1b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
18 changes: 11 additions & 7 deletions pkgs/dmd/bootstrap.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import ./binary.nix {
version = "2.098.0";
import ../ldc/binary.nix {
version = "1.25.0";
hashes = {
# COMPILER=dmd VERSION=2.098.0 ./scripts/fetch-binary
"linux" = "sha256-EQTl5Z/UeCi3mNd6cr5Ue/CGu6HTdKGFXGtYFMTbAUU=";
"osx" = "sha256-d4Cq1EKdSZpkfn6Qdwb3dWVr539EJci0rqt5gCTH80I=";
"freebsd-64" = "sha256-c7ODMpI/kGdl3R4a7/gSTDzTcD3hbHtl4teHJvT0IGk=";
"windows" = "sha256-Yhw3hkkVdvHTayxdk/XNKZwrV8cDMfz63rgBqark+gU=";
"android-aarch64" = "sha256-kTlEPW3cLTze80bIxZ2LOvghcGeCiZkLj4aZYt6ozkc=";
"android-armv7a" = "sha256-4jN03bFJ+aNHRBkZUOcBik54WybchdBENcQi41sdheg=";
"freebsd-x86_64" = "sha256-s7EcW1CfjMY92yA3TsojvD+r08o4qmL/sBj6QWkZeoo=";
"linux-aarch64" = "sha256-UDZ43x4flSo+SfsPeE8juZO2Wtk2ZzwySk0ADHnvJBI=";
"linux-x86_64" = "sha256-sfg47RdlsIpryc3iZvE17OtLweh3Zw6DeuNJYgpuH+o=";
"osx-arm64" = "sha256-O/x0vy0wwQFaDc4uWSeMhx+chJKqbQb6e5QNYf+7DCw=";
"osx-x86_64" = "sha256-6iKnbS+oalLKmyS8qYD/wS21b7+O+VgsWG2iT4PrWPU=";
"windows-x64" = "sha256-Yc9vg6Uuw7Sn8Z+CfoCsgM8KqxvezS26h1NROsHWfd0=";
"windows-x86" = "sha256-iR28Yh+nQbCZvq8Lrey7ryvUq4ajsS27nXMsienFPcY=";
};
}
49 changes: 37 additions & 12 deletions pkgs/dmd/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,30 @@
installShellFiles,
git,
unzip,
HOST_DMD ? "${callPackage ./bootstrap.nix {}}/bin/dmd",
buildCompiler ? callPackage ./bootstrap.nix {},
}: let
inherit (import ../../lib/build-status.nix {inherit lib;}) getBuildStatus;
inherit (import ../../lib/version-utils.nix {inherit lib;}) versionBetween;

# results in "dmd" or "ldc", maybe "gdc" in the future.
buildCompilerAPI = builtins.substring 0 3 buildCompiler.name;

# todo: replace buildCompilerPath with `getDmdWrapper buildCompiler` once
# pull request 53 is merged
in with (if buildCompilerAPI == "dmd" then {
buildCompilerPath = buildCompiler + /bin/dmd;
buildFrontendVersion = buildCompiler.version;
}
else if buildCompilerAPI == "ldc" then {
buildCompilerPath = buildCompiler + /bin/ldmd2;

# Close enough! This gives the correct minor version number for all versions
# from 2.070 to 2.107 (the newest as of writing)
buildFrontendVersion = "2."
+ toString (builtins.fromJSON (lib.versions.minor buildCompiler.version) + 70) + ".1";
}
else throw ("Unrecognised build compiler " + buildCompiler.name)); let

buildStatus = getBuildStatus "dmd" version stdenv.system;

pathConfig = runCommand "phobos-tzdata-curl-paths" {} ''
Expand Down Expand Up @@ -85,20 +104,20 @@
then "druntime"
else "dmd/druntime";

commonBuildFlags =
commonBuildFlags = {forMake}:
[
"-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}"
"HOST_DMD=${ buildCompilerPath }"
"PIC=1"
"BUILD=${buildMode}"
]
++ lib.optional forMake "-fposix.mak"
# 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 @@ -109,8 +128,7 @@
++ lib.optional enableProfile "ENABLE_PROFILE=1"
++ lib.optional enableUnittest "ENABLE_UNITTEST=1"
++ lib.optional enableCoverage "ENABLE_COVERAGE=1";
in
stdenv.mkDerivation rec {
in stdenv.mkDerivation rec {
pname = "dmd";
inherit version;

Expand Down Expand Up @@ -210,7 +228,13 @@ in
];

postPatch =
# Older compilers use -dip25 in their build flags, but if the build
# compiler is 2.092 or newer it doesn't need it anymore, and from
# 2.103 on using the flag is a deprecation error.
lib.optionalString (lib.versionAtLeast buildFrontendVersion "2.092.0") ''
substituteInPlace ${dmdPrefix}/src/build.d --replace '"-dip25"' ""
''
+ ''
patchShebangs ${dmdPrefix}/test/{runnable,fail_compilation,compilable,tools}{,/extra-files}/*.sh
# Grep'd string changed with gdb 12
Expand Down Expand Up @@ -248,7 +272,7 @@ in

dontConfigure = true;

buildFlags = commonBuildFlags;
buildFlags = commonBuildFlags {forMake=true;};

# Build and install are based on http://wiki.dlang.org/Building_DMD
buildPhase = ''
Expand All @@ -275,7 +299,8 @@ in

checkInputs = lib.optional stdenv.isDarwin Foundation;

checkFlags = commonBuildFlags ++ ["N=$(checkJobs)"];
checkFlagsMake = commonBuildFlags {forMake=true;} ++ ["N=$(checkJobs)"];
checkFlagsRunD = commonBuildFlags {forMake=false;};

# many tests are disbled because they are failing
# NOTE: Purity check is disabled for checkPhase because it doesn't fare well
Expand All @@ -295,16 +320,16 @@ in
# This will also test DRuntime for versions without
# a separate DRuntime repo
NIX_ENFORCE_PURITY= \
make -C dmd test $checkFlags
(NIX_ENFORCE_PURITY= \
cd ${dmdPrefix}/test && env $checkFlagsRunD ${buildCompiler + /bin/rdmd} run.d -j $checkJobs all)
${lib.optionalString druntimeRepo ''
NIX_ENFORCE_PURITY= \
make -C druntime unittest $checkFlags
make -C druntime unittest $checkFlagsMake
''}
NIX_ENFORCE_PURITY= \
make -C phobos unittest $checkFlags DFLAGS="${phobosDflags}"
make -C phobos unittest $checkFlagsMake DFLAGS="${phobosDflags}"
runHook postCheck
'';
Expand Down

0 comments on commit c83ca1b

Please sign in to comment.