Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: --granular-output flag #624

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft

Conversation

mrcjkb
Copy link
Member

@mrcjkb mrcjkb commented Jun 3, 2024

This adds a --granular-output flag that allows to split a package into multiple derivations (where executable/test/benchmark targets depend on the libraries). The behaviour without the flag is unchanged.

See also: NixOS/nixpkgs#315129

Example output:

cabal2nix cabal2nix/test/golden-test-cases/ttrie.cabal --granular-output
{ mkDerivation, async, atomic-primops, base, bifunctors, containers
, criterion-plus, deepseq, hashable, lib, mwc-random, primitive
, QuickCheck, stm, stm-containers, stm-stats, test-framework
, test-framework-quickcheck2, text, transformers
, unordered-containers, vector
}:
let
  ttrie = mkDerivation {
            pname = "ttrie";
            version = "0.1.2.1";
            sha256 = "deadbeef";
            libraryHaskellDepends = [
              atomic-primops base hashable primitive stm
            ];
            doCheck = false;
            buildTarget = "ttrie";
            homepage = "http://github.com/mcschroeder/ttrie";
            description = "Contention-free STM hash map";
            license = lib.licenses.mit;
          };
in {
  libraries = {inherit ttrie;};
  exes = { };
  testExes = {
     map-properties = mkDerivation {
                        pname = "map-properties";
                        version = "0.1.2.1";
                        sha256 = "deadbeef";
                        isLibrary = false;
                        isExecutable = true;
                        testHaskellDepends = [
                          base containers hashable QuickCheck stm test-framework
                          test-framework-quickcheck2 ttrie
                        ];
                        buildTarget = "map-properties";
                        homepage = "http://github.com/mcschroeder/ttrie";
                        description = "Contention-free STM hash map";
                        license = lib.licenses.mit;
                      };
  };
  benchExes = {
      bench = mkDerivation {
                pname = "bench";
                version = "0.1.2.1";
                sha256 = "deadbeef";
                isLibrary = false;
                isExecutable = true;
                benchmarkHaskellDepends = [
                  async base bifunctors containers criterion-plus deepseq mwc-random
                  primitive stm stm-containers stm-stats text transformers ttrie
                  unordered-containers vector
                ];
                doBenchmark = true;
                buildTarget = "bench";
                homepage = "http://github.com/mcschroeder/ttrie";
                description = "Contention-free STM hash map";
                license = lib.licenses.mit;
              };
   };
}

I've hit a dead end with this, which is why I'm opening this as a draft PR to find out if it's worth pursuing this idea further:

Even if an executable derivation has the library/libraries in its *HaskellDepends, cabal will prioritise building the library from source, essentially rendering this feature useless.
I've tried getting this to work with incremental builds (setting doInstallIntermediates and enableSeparateIntermediatesOutput in the libraries and passing them to the exes via previousIntermediates), but this doesn't seem to help.

Maybe someone here has an idea how to solve that problem?

Important

In the current state, the *Exes targets don't work if the source is hackage.

@mrcjkb mrcjkb marked this pull request as draft June 3, 2024 09:19
@mrcjkb mrcjkb force-pushed the granular-output branch from 67bbd9f to 761250c Compare June 3, 2024 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant