1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# 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
tools.
* 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
pkg-config-libraries:
- name: library1
pkg-config-libdir: library1/lib
libraries:
- name: library2
libdir: library2/lib
includedir: library2/include
binaries:
- 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 triplet
format (e.g. lib/arm-linux-gnueabihf) albeit libdirs themselves also searched.
### 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
tools.
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
or:
snapcraft --shared run make
where make is the preferred command to build the project. The build environment
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 `-L/path/to/library2
-llibrary2`
* if a static build is selected, the above variables will be adjusted
accordingly.
Lastly, dependent files such as libraries, helpers, data files etc. are copied
into the target application directory:
snapcraft populate-root --target=runtime-files/
this copies files listed in the populate-root-files section from all installed
devpacks into the target directory.
## Open questions / TODO
* No multiarch binaries support to distribute e.g. bin/arm-linux-gnueabihf/xyz.
* 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 devpack
libs?
* populate-root script and/or inspection tool to copy just the required libs
|