[RFC] Snapcraft devpacks

Loïc Minier loic.minier at ubuntu.com
Mon Mar 30 23:56:29 UTC 2015


based on the snapcraft idea floated by Alexander to manage build
environments and SDKs, this is a draft proposal for a new devpack type to
allow developers to distribute libraries and dev tools, particularly aimed
at C/C++ libraries to be embedded in one's application.

Text below and branch at:

# Devpacks
## Definition
Devpacks are a specific type of Snap packages part of the development
workflow. Devpacks are only available at build time.

* Devpacks are mainly a transport mechanism for software libraries and build
* Devpacks typically permit embedding a copy of the provided software
  libraries in an application during build.
* Like apps, devpacks may support one, multiple or all architectures.
* Devpacks are self-contained and do not depend on other devpacks.
* One devpack may provide multiple tools or multiple libraries.
* Devpacks must be coinstallable.

Devpacks are not installed at runtime. Apps must carry all the relevant
runtime bits.

## Usage
### devpack yaml

When creating devpacks, meta/packaging.yaml would contain something like:

    name: foo
    version: 1.2.3
    architecture: host-arch1, host-arch2
    build-architecture: build-arch1, build-arch2
    link-type: shared, static
    type: devpack
      - name: library1
        pkg-config-libdir: library1/lib
      - name: library2
        libdir: library2/lib
        includedir: library2/include
      - name: bin/build-tool
        description: "Description of build tool"
    populate-root-files: "lib/*", "share/"

This devpack is to build apps that will run on host-arch1 or host-arch2 (if
unspecified, arch: all is assumed). It provides an additional build tool
described in the `binaries` section that will only work if the build is run
on `build-arch1` or `build-arch2` (by default arch: all is assumed).

This devpack offers two independent libraries; library1 is defined in
pkg-config form; library2 is provided directly.

`link-type: shared, static` indicates that both static and shared libraries
are provided. link-type may also just have the value `shared` or
`static` when only one type of libraries is supported.

The layout of pkg-config-libdir and libdir is in the usual multi-arch
format (e.g. lib/arm-linux-gnueabihf) albeit libdirs themselves also

### Using devpacks

Developers install devpacks into their build environment. Typically a clean
environment is created with snapcraft:
    snapcraft create env1 --base 15.04

This is a container which is started / stopped as needed by snapcraft when
using the environment. By default, this uses a multiarch chroot of the
architecture of the developer system and with support for the default set of
target architectures (e.g. amd64 and armhf) and with some basic development

Devpacks containing libraries and/or build tools are installed on top with:
    snapcraft addpack env1 foo-devpack

Additional build tools may be installed from Ubuntu with:
    snapcraft run apt-get install make

The build is achieved with:
    snapcraft --static run make
    snapcraft --shared run make
where make is the preferred command to build the project. The build
is setup before the build and teared down after the build.

Snapcraft makes some environment variables available to the build process
based on the selected devpacks:

* SNAP_CFLAGS, and LDFLAGS are set from flags for library1 and library2
* flags for library1 are generated by running `pkg-config
  --cflags library1` and `pkg-config --libs library1`
* flags for library2 are `-I/path/to/library1/headers` and
* if a static build is selected, the above variables will be adjusted

Lastly, dependent files such as libraries, helpers, data files etc. are
into the target application directory:
    snapcraft populate-root --target=runtime-files/
this copies files listed in the populate-root-files section from all
devpacks into the target directory.

## Open questions / TODO

* No multiarch binaries support to distribute e.g.
* Build for multiple architectures in one pass?
* Multiple set of CFLAGS/LDFLAGS
* Install into /usr/local/lib or some other dir to ease consumption of
* populate-root script and/or inspection tool to copy just the required libs

Loïc Minier
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/snappy-devel/attachments/20150331/de9e050c/attachment.html>

More information about the snappy-devel mailing list