Build.dhall
1 {- Build.dhall 2 3 Build target definition with coeffects. 4 -} 5 6 let Resource = ./Resource.dhall 7 let Toolchain = ./Toolchain.dhall 8 let Triple = ./Triple.dhall 9 10 -- Dependency reference 11 let Dep 12 : Type 13 = < -- Local target (same repo) 14 Local : Text -- ":foo" or "//pkg:foo" 15 -- External (content-addressed) 16 | External : { hash : Text, name : Text } 17 -- Pkg-config 18 | PkgConfig : Text -- "openssl", "zlib" 19 -- Nix flake reference (resolved at graph construction) 20 | Flake : Text -- "nixpkgs#openssl", ".#libfoo", "github:owner/repo#pkg" 21 > 22 23 -- Source specification 24 let Src 25 : Type 26 = < -- Local files 27 Files : List Text 28 -- Content-addressed fetch 29 | Fetch : { url : Text, hash : Text } 30 -- Git 31 | Git : { url : Text, rev : Text, hash : Text } 32 > 33 34 -- Build target 35 let Target 36 : Type 37 = { name : Text 38 , srcs : Src 39 , deps : List Dep 40 , toolchain : Toolchain.Toolchain 41 , requires : Resource.Resources -- coeffects (what this build needs) 42 } 43 44 -- Convenience constructor 45 let target 46 : Target → Target 47 = λ(t : Target) → t 48 49 -- C/C++ library 50 let cxx-library 51 : { name : Text 52 , srcs : List Text 53 , deps : List Dep 54 , toolchain : Toolchain.Toolchain 55 , requires : Resource.Resources 56 } → Target 57 = λ(cfg : { name : Text 58 , srcs : List Text 59 , deps : List Dep 60 , toolchain : Toolchain.Toolchain 61 , requires : Resource.Resources 62 }) → 63 { name = cfg.name 64 , srcs = Src.Files cfg.srcs 65 , deps = cfg.deps 66 , toolchain = cfg.toolchain 67 , requires = cfg.requires 68 } 69 70 -- C/C++ binary 71 let cxx-binary 72 : { name : Text 73 , srcs : List Text 74 , deps : List Dep 75 , toolchain : Toolchain.Toolchain 76 , requires : Resource.Resources 77 } → Target 78 = λ(cfg : { name : Text 79 , srcs : List Text 80 , deps : List Dep 81 , toolchain : Toolchain.Toolchain 82 , requires : Resource.Resources 83 }) → 84 { name = cfg.name 85 , srcs = Src.Files cfg.srcs 86 , deps = cfg.deps 87 , toolchain = cfg.toolchain 88 , requires = cfg.requires 89 } 90 91 -- Fetch from URL (content-addressed) 92 let fetch 93 : { url : Text, hash : Text } → Src 94 = Src.Fetch 95 96 -- Git source 97 let git 98 : { url : Text, rev : Text, hash : Text } → Src 99 = Src.Git 100 101 -- Dependency constructors 102 let dep = 103 { local = Dep.Local 104 , pkgconfig = Dep.PkgConfig 105 , external = λ(hash : Text) → λ(name : Text) → 106 Dep.External { hash, name } 107 , flake = Dep.Flake 108 , nixpkgs = λ(pkg : Text) → Dep.Flake "nixpkgs#${pkg}" 109 , nixpkgsMusl = λ(pkg : Text) → Dep.Flake "nixpkgs#pkgsMusl.${pkg}" 110 , nixpkgsStatic = λ(pkg : Text) → Dep.Flake "nixpkgs#pkgsStatic.${pkg}" 111 } 112 113 in { Dep 114 , Src 115 , Target 116 , target 117 , cxx-library 118 , cxx-binary 119 , fetch 120 , git 121 , dep 122 , Resource = Resource 123 , Toolchain = Toolchain 124 , Triple = Triple 125 }