source: project/wiki/eggs tutorial @ 8072

Last change on this file since 8072 was 8072, checked in by svnwiki, 12 years ago

Changes applied for sjamaan ( through svnwiki:

Point to the documentation for chicken-setup so people know where these new procedures come from.

File size: 11.2 KB
2[[tags:tutorials eggs]]
4== Introduction
6This document explains how to create an official Chicken Extension.
8[[eggs|Chicken extensions]] can greatly enhance the functionality available in Chicken.
9They can define and export new convenient functions, wrap and make available libraries written in other languages (typically C) or even extend the basic language.
11A good way to start getting involved in the Chicken community is to contribute new eggs.
12Not 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-setup}}) and other users might start helping improve your eggs.
14We will assume your extension is called ''mpeg3'' (which is the name of an already existing [[mpeg3|egg]]).  Replace occurences of that string throughout this file with the actual name of your extension.
16== Programming your extension
18=== Code layout
20You should write the code for your extension in the following files:
22* If your extension doesn't contain macros (and thus it doesn't need to be available at compile time), as is the case with most, write all your code in {{mpeg3.scm}}.  It should contain all the symbols in your extension that you want to compile and make available to user programs at run-time.
23* Otherwise:
24** Write your macros and any code that needs to be available at compile time in {{mpeg3.scm}}.  You'll soon setup your egg in such a way that this file won't get compiled (but rather {{load}}ed during compilation of programs that use your extension).
25** Write your function definitions and any code that should be available at run-time in {{mpeg3-base.scm}}.  This file will be compiled into {{}}, which will be loaded at runtime.
27We strongly recommend that you add a {{(declare (export ...))}} declaration to your runtime file explicitly listing all the symbols that should be exported to programs using your egg.
28This not only avoids name clashes, but it also serves as some implicit sort of documentation as to what the public interface exported by the egg is (which should not, ever, replace your standard documentation!).
30=== Testing your extension
32To test your extension the best practice seems to be to {{load}} it directly from the source code (unless it uses foreign code, in which case you'll need to compile it and load your {{.so}} file).
34== Additional files
36=== Documentation
38There are basically two alternative options to provide documentation for your egg.
39Which you choose is up to you.
40The following sections describes them.
42==== Hand written HTML
44==== Using eggdoc
46The [[eggdoc]] extension translates an SXML dialect into HTML. The
47best way to learn about eggdoc is to study one of the many existing
48examples in the extension repository.
50==== Using the wiki
52You can enter your entire documentation for your egg into this wiki.
53You'll use a file called {{mpeg3}} at the root of this wiki.
54The following are some examples:
56* [[stream-ext]] egg
57* [[stream-wiki]] egg
59This has the advantage of inviting other members of the Chicken community to help improve the documentation for your egg.
61Whenever a new release for your egg is made, its associated file from the wiki will be converted to HTML and shipped with it (as {{mpeg3.html}}) as well as uploaded to <>.
63If you follow this route, it would be a good idea to consult the [[eggs guidelines|guidelines for documenting eggs in the wiki]].
65=== The setup file
67In order for {{chicken-setup}} to install your extension, we recommend that you create a {{mpeg3.setup}} file with information about your egg.
68{{chicken-setup}} will load this file. {{chicken-setup}} adds some new procedures to the environment, which are documented in [[chicken-setup#procedures-and-macros-available-in-setup-scripts|the chicken-setup section of the manual]].
70If your egg does not contain macros, your setup file should look similar to the following:
72<enscript highlight=scheme>
73; These two instructions will produce statically and dynamically linkable object files "mpeg3.o" and "" respectively.
74(compile -c -O2 -d1 mpeg3.scm -unit mpeg3)
75(compile -s -O2 -d1 mpeg3.scm)
78  ; Name of your extension:
79  'mpeg3
80  ; Files to install for your extension:
81  '("mpeg3.o" "" "mpeg3.html")
82  ; Assoc list with properties for your extension:
83  '((version 1.2)
84    (static "mpeg3.o") ;; for static linking
85    (documentation "mpeg3.html")))</enscript>
87Note that the first line will cause {{mpeg3.scm}} to be compiled into
88{{mpeg3.o}}, which is installed by {{install-extension}}.
90Note that the second line will cause {{mpeg3.scm}} to be compiled into
91{{}}, which is installed by {{install-extension}}.
93If your extension includes syntax it should:
95# Compile {{mpeg3-base.scm}} (instead of {{mpeg3.scm}}), according to the semantics for those files.
96# List both {{mpeg3.scm}} (macros) and {{}} in the list of files to install.
97# In the list of properties it should include {{(syntax)}} and {{(require-at-runtime mpeg3)}}.
99If 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.
101If you are using the wiki for your documentation, {{mpeg3.html}}
102will be created as part of the process that uploads your egg to
103That means that testing your setup script will fail, as it won't find it.
104For that reason, you will need to create a dummy {{mpeg3.html}} file temporarily, which you won't be releasing nor uploading to the Subversion repository for eggs (described below).
106=== The meta file
108Finally, you will need to create {{mpeg3.meta}}, with information about your egg.
109This file is used by the process that releases and uploads new eggs.
110It should contain a single s-expr as follows:
112<enscript highlight=scheme>((egg "mpeg3.egg") ; This should never change
114 ; List here all the files that should be bundled as part of your egg.  Note
115 ; that (1) mpeg3.meta does not need to be listed here and (2) you might
116 ; want to include mpeg3-base.scm (if it exists).
118 (files "mpeg3.scm" "mpeg3.html" "mpeg3.setup")
120 ; The following should only be present if the egg's documentation should be
121 ; generated from the wiki:
123 (doc-from-wiki)
125 ; Your egg's license:
127 (license "GPL")
129 ; Pick one from the list of categories (see below) for your egg and enter it
130 ; here.
132 (category web)
134 ; A list of eggs mpeg3 depends on.  If none, you can omit this declaration
135 ; altogether:
137 (needs sandbox syntax-case)
139 (author "Your Name Goes Here")
140 (synopsis "A basic description of the purpose of the egg."))</enscript>
142For the category entry you can use any of the following:
144;code-generation: Code generation
145;crypt: Cryptography
146;data: Algorithms and data-structures
147;db: Databases
148;debugging: Debugging tools
149;doc-tools: Documentation tools
150;egg-tools: Egg tools
151;ffi: Interfacing to other languages
152;graphics: Graphics
153;io: Input/Output
154;lang-exts: Language extensions
155;logic: Logic programming
156;macros: Macros and meta-syntax
157;math: Mathematical libraries
158;misc: Miscellaneous
159;net: Networking
160;oop: Object-oriented programming
161;os: OS interface
162;parsing: Data formats and parsing
163;sound: Sound related stuff
164;testing: Unit-testing
165;tools: Command line tools
166;ui: User interface toolkits
167;web: Web programming
168;xml: XML processing
170More information about extension meta properties can be found here at
171the [[Metafile reference]].
173=== Tests
175[[chicken-setup]] can automatically run a test suite on a freshly installed egg, if the egg directory
176contains a directory named {{tests}}, which should include a Scheme source file named {{run.scm}}.
177When {{chicken-setup}} is invoked with the {{-test}} option, then this file will be executed
178(with {{test}} being the current working directory). It is recommended to add a test suite
179to 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.'''
181== Managing eggs in the repository
183=== Obtaining an account in the repository
185We keep all Chicken Extensions in the following [[|Subversion]]
190You can see a graph of some stats about it here:
194In order to create your extensions you will need access to this repository.
195Send an email to the Chicken Users mailing list and state:
197* A brief description of the purpose of your extension
198* The name you want to use for your extension
199* The username you want to use to access the repository (unless you already have one).
201With this information we will create a directory for your extension and create you an account with the appropriate access rights.
203To checkout this directory run the following command:
205 svn checkout
207=== Directory structure
209The directory for your egg will have the following subdirectories:
211; {{trunk}} : Here you can keep the latest (potentially unstable) development version for your egg.
212; {{tags}} : You should keep one subdirectory of this directory for every release for your egg.  The names of the directories here should correspond to the version number of their associated release.
213; {{branches}} : Contains, as subdirectories, any special branches of the code that need to be maintained apart of the trunk.
215Furthermore, there is a {{wiki}} directory at the top-level of the repository.
216It holds the entire contents for this wiki.
217This can be helpful if you decide to use it to document your egg.
219=== Importing your files
221You will initially copy your files to the {{trunk}} directory, add them manually and commit your changes.  For example:
223 svn add trunk/mpeg3.scm
224 svn add trunk/mpeg3.setup
225 svn add trunk/mpeg3.meta
226 svn commit -m "Importing mpeg3 extension."
228=== Making a new release
230Once the code in {{trunk}} is reasonably stable and you want to make a new release, copy it to a new directory under {{tags}}.
231The directory should be named after the software version.
232Software versions should have the form of a list of numbers separated by a dot
233(eg. “1.3.4” is a valid software version, whereas “1.3-0” or “1.3rc0” are not).
235For example, to make the 1.3 release for mpeg3, you would run the following commands (at the directory where you checked out your egg):
237 svn copy trunk tags/1.3
238 svn commit -m "Releasing version 1.3."
240Tagged extensions in the repository will have an additional file when wrapped up for upload
241to the CHICKEN website called {{version}} - this file contains the version number (the tag)
242of the packaged egg.
244Uploading the egg on the CHICKEN website for downloading via {{chicken-setup}} happens automatically -
245a background job periodically checks the source code repository for updates and wraps up the eggs, copying them
246to the call/ web-server (see also [[periodic-tasks]]). Should there be a problem (your egg doesn't show up, or whatever), send an email to any of the following persons asking them to help with uploading:
248* [[Felix Winkelmann]] <>
249* [[Alejandro Forero Cuervo]] <>
250* [[Mario Domenech Goulart]] <mario @ ucpel . tche . br>
Note: See TracBrowser for help on using the repository browser.