-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
add build target support #120249
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
add build target support #120249
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -196,6 +196,16 @@ rec { | |
| appendPatch = drv: x: appendPatches drv [x]; | ||
| appendPatches = drv: xs: overrideCabal drv (drv: { patches = (drv.patches or []) ++ xs; }); | ||
|
|
||
| /* Set a specific build target instead of compiling all targets in the package. | ||
| * For example, imagine we have a .cabal file with a library, and 2 executables "dev" and "server". | ||
| * We can build only "server" and not wait on the compilation of "dev" by using setBuildTarget as follows: | ||
| * | ||
| * setBuildTarget (callCabal2nix "thePackageName" thePackageSrc {}) "server" | ||
| * | ||
| */ | ||
| setBuildTargets = drv: xs: overrideCabal drv (drv: { buildTarget = lib.concatStringsSep " " xs; }); | ||
|
||
| setBuildTarget = drv: x: setBuildTargets drv [x]; | ||
|
|
||
| doHyperlinkSource = drv: overrideCabal drv (drv: { hyperlinkSource = true; }); | ||
| dontHyperlinkSource = drv: overrideCabal drv (drv: { hyperlinkSource = false; }); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| module Main where | ||
|
|
||
| main :: IO () | ||
| main = putStrLn "Hello, Bar!" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| module Main where | ||
|
|
||
| main :: IO () | ||
| main = putStrLn "Hello, Foo!" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import Distribution.Simple | ||
| main = defaultMain |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| { pkgs, haskellPackages }: | ||
|
|
||
| let | ||
| # This can be regenerated by running `cabal2nix .` in the current directory. | ||
| pkgDef = | ||
| { mkDerivation, base, lib }: | ||
| mkDerivation { | ||
| pname = "haskell-setBuildTarget"; | ||
| version = "0.1.0.0"; | ||
| src = ./.; | ||
| isLibrary = false; | ||
| isExecutable = true; | ||
| executableHaskellDepends = [ base ]; | ||
| license = lib.licenses.bsd3; | ||
| }; | ||
|
|
||
| drv = haskellPackages.callPackage pkgDef {}; | ||
|
|
||
| test = target: excluded: | ||
| let only = pkgs.haskell.lib.setBuildTarget drv target; | ||
| in '' | ||
| if [[ ! -f "${only}/bin/${target}" ]]; then | ||
| echo "${target} was not built" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ -f "${only}/bin/${excluded}" ]]; then | ||
| echo "${excluded} was built, when it should not have been" | ||
| exit 1 | ||
| fi | ||
| ''; | ||
|
|
||
| in pkgs.runCommand "test haskell.lib.setBuildTarget" {} '' | ||
| ${test "foo" "bar"} | ||
| ${test "bar" "foo"} | ||
| touch "$out" | ||
| '' | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| cabal-version: >=1.10 | ||
| name: haskell-setBuildTarget | ||
| version: 0.1.0.0 | ||
| author: Isaac Shapira | ||
| maintainer: fresheyeball@protonmail.com | ||
| build-type: Simple | ||
|
|
||
| executable foo | ||
| main-is: Foo.hs | ||
| build-depends: base | ||
| default-language: Haskell2010 | ||
|
|
||
| executable bar | ||
| main-is: Bar.hs | ||
| build-depends: base | ||
| default-language: Haskell2010 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cdepillabout This line is what should preserve existing packages without rebuilds.