MyNixOS website logo
Description

Build tool for C.

A build tool and package manager configured using Dhall.

cpkg

Hackage CI Hackage Dependencies of latest version on Hackage

cpkg is a build tool for C with a particular emphasis on cross compilation. It is configured using Dhall.

By considering a package to be a function taking a cpkg-supplied installation directory to a series of steps, we can effectively package C projects with diverse build systems and handle dependencies between them.

This tool provides reasonably good support for cross-compilation of C projects and packages. It is not a full-fledged package manager.

Installation

cabal new-install cpkg

Shell Completions

Add the following to your ~/.bashrc for shell completions:

eval "$(cpkg --bash-completion-script cpkg)"

Packages

To view available packages, use cpkg list

vanessa@thinkpad ~/programming/haskell/done/cpkg šŸŒø cpkg list

autoconf
    url: https://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.xz
    version: 2.69
    build dependencies: m4


automake
    url: https://ftp.gnu.org/gnu/automake/automake-1.16.1.tar.xz
    version: 1.16.1
    build dependencies: autoconf


at-spi2-atk
    url: http://ftp.gnome.org/pub/gnome/sources/at-spi2-atk/2.30/at-spi2-atk-2.30.0.tar.xz
    version: 2.30.0
    dependencies: at-spi2-core, atk, libxml2
    build dependencies: meson, ninja


at-spi2-core
    url: http://ftp.gnome.org/pub/gnome/sources/at-spi2-core/2.30/at-spi2-core-2.30.0.tar.xz
    version: 2.30.0
    dependencies: libXtst, glib
    build dependencies: meson, ninja


atk
    url: https://ftp.gnome.org/pub/gnome/sources/atk/2.30/atk-2.30.0.tar.xz
    version: 2.30.0
    build dependencies: gobject-introspection
ā‹®

Example

To install tar:

cpkg install tar

To install emacs:

cpkg install emacs

Configuration

Here is the configuration for Lua:

let prelude = https://raw.githubusercontent.com/vmchale/cpkg/master/dhall/cpkg-prelude.dhall
in

let lua =
  Ī»(v : List Natural) ā†’
    let printLuaOS =
      Ī»(os : types.OS) ā†’
        merge
          { FreeBSD   = Ī»(_ : {}) ā†’ "freebsd"
          , OpenBSD   = Ī»(_ : {}) ā†’ "bsd"
          , NetBSD    = Ī»(_ : {}) ā†’ "bsd"
          , Solaris   = Ī»(_ : {}) ā†’ "solaris"
          , Dragonfly = Ī»(_ : {}) ā†’ "bsd"
          , Linux     = Ī»(_ : {}) ā†’ "linux"
          , Darwin    = Ī»(_ : {}) ā†’ "macosx"
          , Windows   = Ī»(_ : {}) ā†’ "mingw"
          , Redox     = Ī»(_ : {}) ā†’ "generic"
          , Haiku     = Ī»(_ : {}) ā†’ "generic"
          , IOS       = Ī»(_ : {}) ā†’ "generic"
          , AIX       = Ī»(_ : {}) ā†’ "generic"
          , Hurd      = Ī»(_ : {}) ā†’ "generic"
          , Android   = Ī»(_ : {}) ā†’ "generic"
          , NoOs      = Ī»(_ : {}) ā†’ "c89"
          }
          os
    in

    let luaBuild =
      Ī»(cfg : types.BuildVars) ā†’
        let cc = prelude.mkCCArg cfg
        in

        let ldflags =
          (prelude.mkLDFlags cfg.linkDirs).value
        in

        let cflags =
          (prelude.mkCFlags cfg.includeDirs).value
        in

        let os =
          prelude.osCfg cfg
        in

        [ prelude.call (prelude.defaultCall ā«½ { program = "make"
                                              , arguments = cc # [ printLuaOS os, "MYLDFLAGS=${ldflags}", "MYCFLAGS=${cflags}", "MYLIBS=-lncurses" ]
                                              })
        ]
    in

    let luaInstall =
      Ī»(cfg : types.BuildVars) ā†’
        [ prelude.call (prelude.defaultCall ā«½ { program = "make"
                                              , arguments = [ "install", "INSTALL_TOP=${cfg.installDir}" ]
                                              }) ]
          # prelude.symlinkBinaries [ "bin/lua", "bin/luac" ]
    in

    prelude.simplePackage { name = "lua", version = v } ā«½
      { pkgUrl = "http://www.lua.org/ftp/lua-${prelude.showVersion v}.tar.gz"
      , configureCommand = prelude.doNothing
      , buildCommand = luaBuild
      , installCommand = luaInstall
      , pkgDeps = [ prelude.unbounded "readline"
                  , prelude.unbounded "ncurses"
                  ]
      }
in

lua [5,3,5]

Cabal Integration

After running

cpkg install libX11 --target=arm-linux-gnueabihf
cpkg install libXext --target=arm-linux-gnueabihf
cpkg install libXrandr --target=arm-linux-gnueabihf
cpkg install libXinerama --target=arm-linux-gnueabihf
cpkg install libXScrnSaver --target=arm-linux-gnueabihf

You can dump flags to be passed to cabal with

cpkg dump-cabal libX11 libXext libXrandr libXinerama libXScrnSaver --target=arm-linux-gnueabihf

which will produce something like

--extra-lib-dirs=/home/vanessa/.cpkg/arm-linux-gnueabihf/libX11-1.6.7-820c8166b4caadb/lib --extra-lib-dirs=/home/vanessa/.cpkg/arm-linux-gnueabihf/libXext-1.3.3-1bad0a89c6794a53/lib --extra-lib-dirs=/home/vanessa/.cpkg/arm-linux-gnueabihf/libXrandr-1.5.1-f58f951a622e5c2/lib --extra-lib-dirs=/home/vanessa/.cpkg/arm-linux-gnueabihf/libXinerama-1.1.4-516496f7e04d34be/lib --extra-lib-dirs=/home/vanessa/.cpkg/arm-linux-gnueabihf/libXScrnSaver-1.2.3-60f6993b79a87725/lib

This could be used, for example, to cross-compile xmonad, viz.

cabal new-install xmonad --with-ghc arm-linux-gnueabihf-ghc --with-ghc-pkg arm-linux-gnueabihf-ghc-pkg $(cpkg dump-cabal libX11 libXext libXrandr libXinerama libXScrnSaver --target=arm-linux-gnueabihf)

Dhall Prelude

There is a prelude available containing functions which simplify the process of writing package descriptions. As an example, we can install sed

let prelude = https://raw.githubusercontent.com/vmchale/cpkg/master/dhall/cpkg-prelude.dhall
in

let sed =
  Ī»(v : List Natural) ā†’
    prelude.makeGnuExe { name = "sed", version = v }
in

sed [4,5]

Known Deficiencies

Security

This tool is insecure.

Performance

This tool is not performant.

Dependency Solver

Currently, there is no dependency solver. It should be relatively easy to add a version-based dependency solver to the code.

Garbage Collection

Currently, there is no garbage collector Ć  la $ nix-collect-garbage. This will not be relatively easy to add, because it will require that the global package index be re-implemented (ideally using a proper database).

Contents

Lovingly provided by polyglot:

ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€
 Language             Files       Lines         Code     Comments       Blanks
ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€
 Bash                     4          58           49            3            6
 Cabal                    1         165          147            0           18
 Cabal Project            1           4            3            0            1
 Dhall                    5        6412         5724            0          688
 Haskell                 32        1999         1643           37          319
 Makefile                 1          12            8            0            4
 Markdown                 3         556          448            0          108
 YAML                     4         114          110            0            4
ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€
 Total                   51        9320         8132           40         1148
ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€
Metadata

Version

0.2.5.8

PlatformsĀ (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows