source: project/wiki/eggs tutorial @ 32627

Last change on this file since 32627 was 32627, checked in by Jeremy Steward, 6 years ago

Fixes broken link to bitbucket in eggs tutorial

File size: 10.8 KB
1== Eggs Tutorial
4[[tags:tutorials eggs]]
6== Introduction
8This document explains how to create an official CHICKEN Extension.
10[[eggs|CHICKEN extensions]] can greatly enhance the functionality available in CHICKEN.
11They can define and export new convenient functions, wrap and make available libraries written in other languages (typically C) or even extend the basic language.
13A good way to start getting involved in the CHICKEN community is to contribute new eggs.
14Not only this will benefit other users, who will now be able to use your egg, it will also benefit you as you'll gain access to all the infrastructure for managing eggs (eg. you will be able to install your eggs using {{chicken-install}}) and other users might start helping improve your eggs. You can create an egg from software you've written yourself, or else with free software libraries you've ported from other Schemes (or even other languages).
16We will assume your extension is called ''mpeg3''.  Replace occurences of that string throughout this file with the actual name of your extension.
18== Programming your extension
20=== Code layout
22You should always use the module system for extensions to avoid creating name-conflicts
23if one of your exported toplevel identifiers clashes with an already existing definition.
24Modules also allow to export syntax definitions in a clean and easy-to-use way.
27== Additional files
30=== Documentation
32Providing good documentation for your eggs is a fundamental part of their overall quality.  Documentation for eggs is stored in wiki format in the CHICKEN subversion repository (see [[/contribute#create-eggseggs|this document]] for information on how to request an account).
34You can enter your entire documentation for your egg into this wiki. This has the advantage of inviting other members of the CHICKEN community to help improve the documentation for your eggs.  Also, eggs documented in the CHICKEN wiki are automatically indexed by our [[|API browser]].
36You can either use your favourite text editor to edit wiki files (then commit your changes to the subversion repository) or point your browser to and use it to edit the wiki contents.
38If you decide to edit the wiki files locally using a text editor then commiting to the repository, you'll need to ckeck out a copy of the subversion repository for wiki files:
40  $ svn co
42==== Sections
44We recommend that each page for an egg is given at least the following sections:
46; Your egg's name: The very first section of the documentation is taken as the title for your wiki page.  Your egg's name is usually a good page title.
47; Description : Must briefly describe and state the purpose of the egg.
48; Authors : The egg authors and maintainers
49; Requirements : Should list other eggs that are required to build (compile-time) or load (runtime) this egg.  Each entry should be linked to the respective egg.
50; API : The API description.  Be sure to semantically format the procedures, macros, parameters, classes etc (see the ''Extensions for CHICKEN documentation'' section at the [[/edit-help|Editing help]] page).
51; Examples : Must provide simple examples of the most important functions in the egg.  Note that all examples should be entirely self-contained; basically, pasting them in {{csi}} should work, which means, among other things, that they should include the {{use}} or {{require-extension}} lines loading the egg.  Each example should be its own subsection and the actual code should follow a brief explanation of what it does.
52; License : The license for your egg (see the [[eggs-licensing|Eggs Licensing]] page)
53; Version History : Should list all releases of the egg and a description of their differences with the previous versions.
56=== The setup file
58In order for {{chicken-install}} to install your extension, we recommend that you create a {{mpeg3.setup}} file with information about your egg.
59{{chicken-install}} will load this file. {{chicken-install}} adds some new procedures to the environment, which are documented in [[/man/4/Extensions#procedures-and-macros-available-in-setup-scripts|the "Extensions" section of the manual]].
61If your egg does not contain macros, your setup file should look similar to the following:
63<enscript highlight=scheme>
64;; These two instructions will produce statically and dynamically linkable object files "mpeg3.o" and "" respectively.
65(compile -s -O3 -d1 mpeg3.scm -j mpeg3)
66(compile -s mpeg.import.scm -O3 -d0)
69 ;; Name of your extension:
70 'mpeg3
71 ;; Files to install for your extension:
72 '("" "")
73 ;; Assoc list with properties for your extension:
74 '((version "1.2")))
77The first line will cause {{mpeg3.scm}} to be compiled into
78{{}} (a shared library for dynamic loading), which is installed by {{install-extension}}.
79The {{-j}} option will make sure that an ''import library'' is generated for your module(s) which, after compilation,
80provide module meta-information and exported syntax. Alternatively you can use {{-J}} without any arguments to generate import libraries for all defined modules.
82The second line will compile the generated import library.
84If your egg requires your code to be linked against a specific library or certain flags (eg. {{-l}}) to be passed to the C compiler, you should specify them here.
86Note that version is represented by a string.  That's because numbers can be tricky to represent versions.  Integers are usually not enough to represent minor/major changes, and floating point numbers require you to determine the number of minor releases a priori, otherwise you'll inevitably end up with version 1.10, which is numerically equivalent to 1.1, and that would cause problems when chicken-install tries to match versions to determine dependencies.
88=== The meta file
90Finally, you will need to create {{mpeg3.meta}}, with information about your egg.
91This file is used by the process that releases and uploads new eggs.
92It should contain a single s-expr as follows:
94<enscript highlight=scheme>(
95; Your egg's license:
96(license "BSD")
98; Pick one from the list of categories (see below) for your egg and enter it
99; here.
100(category web)
102; A list of eggs mpeg3 depends on.  If none, you can omit this declaration
103; altogether. `depends' is an alias to `needs'.
104; Notice that you should NOT put CHICKEN units (e.g., srfi-1, srfi-13
105; and many others) in `needs' or in `depends'.
106(needs sandbox syntax-case)
108; A list of eggs required for TESTING ONLY.  See the `Tests' section.
109; Just like `needs' and `depends', `test-depends' should NOT contain
110; CHICKEN units.
111(test-depends test)
113(author "Your Name Goes Here")
114(synopsis "A basic description of the purpose of the egg."))
117For the category entry you can use any of the following:
119;code-generation: Code generation
120;crypt: Cryptography
121;data: Algorithms and data-structures
122;db: Databases
123;debugging: Debugging tools
124;doc-tools: Documentation tools
125;egg-tools: Egg tools
126;ffi: Interfacing to other languages
127;graphics: Graphics
128;io: Input/Output
129;lang-exts: Language extensions
130;logic: Logic programming
131;macros: Macros and meta-syntax
132;math: Mathematical libraries
133;misc: Miscellaneous
134;net: Networking
135;oop: Object-oriented programming
136;os: OS interface
137;parsing: Data formats and parsing
138;sound: Sound related stuff
139;testing: Unit-testing
140;tools: Command line tools
141;ui: User interface toolkits
142;web: Web programming
143;xml: XML processing
144;hell: Concurrency and parallelism
145;uncategorized: Uncategorized
146;obsolete: Unsupported or redundant
148Make sure you read [[Eggs Licensing]]!
150More information about extension meta properties can be found here at
151the [[Metafile reference]].
153=== Tests
155[[/man/4/Extensions|chicken-install]] can automatically run a test suite on a freshly installed egg, if the egg directory
156contains a directory named {{tests}}, which should include a Scheme source file named {{run.scm}}.
157When {{chicken-install}} is invoked with the {{-test}} option, then this file will be executed
158(with {{test}} being the current working directory). It is recommended to add a test suite
159to your extension, as it allows some sort of automated testing of installed extensions. '''If "run.scm" never calls "error" during the execution then the test is considered successful.'''
161If your tests depend on extra eggs, '''do not''' use {{needs}}/{{depends}} to require them.  Use {{test-depends}} instead, so they'll only be required when {{chicken-install}} is used with the {{-test}} option.
163For proper integration to the [[|test infrastructure]],
164{{run.scm}} should exit {{0}} (zero) when all tests
165pass or any other number in case some test fails.  If you are using
166the [[/egg/test|test]] egg, a call to {{test-exit}} makes {{run.scm}}
167exit properly.
169With regard to the test infrastructure, notice that only the latest released egg versions are tested.
171==== Testing your extension
173Before publishing your egg, it is recommended to run [[/egg/salmonella|salmonella]] on it to try to catch some common mistakes in advance.  Here's how you can do that:
175  $ chicken-install salmonella # in case you don't have salmonella installed
176  $ cd egg-dir # the directory where yor egg code is stored
177  $ salmonella
179Salmonella will report to the standard output a summary of the tests it performs.  It also generates a detailed log file containing all the data generated along the tests execution.  You can use {{salmonella-log-viewer}} to see details about the whole test procedure:
181  $ salmonella-log-viewer salmonella.log
183See the [[/egg/salmonella|salmonella documentation]] for more information on how to test eggs.
185If your egg installs an executable file and tests call that file, take a look at [[|this caveat]].
187== Managing and hosting eggs
189CHICKEN currently supports distributing eggs hosted on remote
190repositories (in the past, we had a [[chicken-svn-for-eggs|central
191Subversion repository]] which is now deprecated for new eggs).  So,
192you can host your egg code on popular repository providers like
193[[|github]], [[|bitbucket]] etc,
194or even using your own server.
196See the [[/releasing-your-egg|Releasing your egg]] document for
197information on how to host egg code and manage releases.
199== Caveats
201=== License
203This may seem a bit annoying but since we have had this a couple of times on our mailing list, please make sure that your egg's license is compatible with the licenses of its dependencies.
205== Post check in notes
207Once your code hits the eggs repository, it'll be daily tested by [[/egg/salmonella|salmonella]] to check if it can be installed by {{chicken-install}}.  See [[]] for more information.
209Strive to keep the documentation for your eggs in good shape and up to date. It highly influences the quality of your eggs.
Note: See TracBrowser for help on using the repository browser.