<div dir="ltr">Hi,<div><br></div><div>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.</div><div><br></div><div>Text below and branch at:</div><div><a href="http://bazaar.launchpad.net/~lool/snappy/snappy.devpacks-definition/view/head:/devpacks.md">http://bazaar.launchpad.net/~lool/snappy/snappy.devpacks-definition/view/head:/devpacks.md</a><br></div><div><br></div><div>===============<br></div><div><div># Devpacks</div><div>## Definition</div><div>Devpacks are a specific type of Snap packages part of the development</div><div>workflow. Devpacks are only available at build time.</div><div><br></div><div>* Devpacks are mainly a transport mechanism for software libraries and build</div><div>  tools.</div><div>* Devpacks typically permit embedding a copy of the provided software</div><div>  libraries in an application during build.</div><div>* Like apps, devpacks may support one, multiple or all architectures.</div><div>* Devpacks are self-contained and do not depend on other devpacks.</div><div>* One devpack may provide multiple tools or multiple libraries.</div><div>* Devpacks must be coinstallable.</div><div><br></div><div>Devpacks are not installed at runtime. Apps must carry all the relevant</div><div>runtime bits.</div><div><br></div><div>## Usage</div><div>### devpack yaml</div><div><br></div><div>When creating devpacks, meta/packaging.yaml would contain something like:</div><div><br></div><div>    name: foo</div><div>    version: 1.2.3</div><div>    architecture: host-arch1, host-arch2</div><div>    build-architecture: build-arch1, build-arch2</div><div>    link-type: shared, static</div><div>    type: devpack</div><div>    pkg-config-libraries:</div><div>      - name: library1</div><div>        pkg-config-libdir: library1/lib</div><div>    libraries:</div><div>      - name: library2</div><div>        libdir: library2/lib</div><div>        includedir: library2/include</div><div>    binaries:</div><div>      - name: bin/build-tool</div><div>        description: "Description of build tool"</div><div>    populate-root-files: "lib/*", "share/"</div><div><br></div><div>This devpack is to build apps that will run on host-arch1 or host-arch2 (if</div><div>unspecified, arch: all is assumed). It provides an additional build tool</div><div>described in the `binaries` section that will only work if the build is run</div><div>on `build-arch1` or `build-arch2` (by default arch: all is assumed).</div><div><br></div><div>This devpack offers two independent libraries; library1 is defined in</div><div>pkg-config form; library2 is provided directly.</div><div><br></div><div>`link-type: shared, static` indicates that both static and shared libraries</div><div>are provided. link-type may also just have the value `shared` or</div><div>`static` when only one type of libraries is supported.</div><div><br></div><div>The layout of pkg-config-libdir and libdir is in the usual multi-arch triplet</div><div>format (e.g. lib/arm-linux-gnueabihf) albeit libdirs themselves also searched.</div><div><br></div><div>### Using devpacks</div><div><br></div><div>Developers install devpacks into their build environment. Typically a clean</div><div>environment is created with snapcraft:</div><div>    snapcraft create env1 --base 15.04</div><div><br></div><div>This is a container which is started / stopped as needed by snapcraft when</div><div>using the environment. By default, this uses a multiarch chroot of the</div><div>architecture of the developer system and with support for the default set of</div><div>target architectures (e.g. amd64 and armhf) and with some basic development</div><div>tools.</div><div><br></div><div>Devpacks containing libraries and/or build tools are installed on top with:</div><div>    snapcraft addpack env1 foo-devpack</div><div><br></div><div>Additional build tools may be installed from Ubuntu with:</div><div>    snapcraft run apt-get install make</div><div><br></div><div>The build is achieved with:</div><div>    snapcraft --static run make</div><div>or:</div><div>    snapcraft --shared run make</div><div>where make is the preferred command to build the project. The build environment</div><div>is setup before the build and teared down after the build.</div><div><br></div><div>Snapcraft makes some environment variables available to the build process</div><div>based on the selected devpacks:</div><div><br></div><div>* SNAP_CFLAGS, and LDFLAGS are set from flags for library1 and library2</div><div>* flags for library1 are generated by running `pkg-config</div><div>  --cflags library1` and `pkg-config --libs library1`</div><div>* flags for library2 are `-I/path/to/library1/headers` and `-L/path/to/library2</div><div>  -llibrary2`</div><div>* if a static build is selected, the above variables will be adjusted</div><div>  accordingly.</div><div><br></div><div>Lastly, dependent files such as libraries, helpers, data files etc. are copied</div><div>into the target application directory:</div><div>    snapcraft populate-root --target=runtime-files/</div><div>this copies files listed in the populate-root-files section from all installed</div><div>devpacks into the target directory.</div><div><br></div><div>## Open questions / TODO</div><div><br></div><div>* No multiarch binaries support to distribute e.g. bin/arm-linux-gnueabihf/xyz.</div><div>* Build for multiple architectures in one pass?</div><div>* Multiple set of CFLAGS/LDFLAGS</div><div>* Install into /usr/local/lib or some other dir to ease consumption of devpack</div><div>  libs?</div><div>* populate-root script and/or inspection tool to copy just the required libs</div></div><div>===============</div><div><div><br></div><div>Cheers,</div></div><div>-- </div><div>Loïc Minier</div></div>