source: project/wiki/eggs tutorial @ 33367

Last change on this file since 33367 was 33367, checked in by wasamasa, 4 years ago

Fix typo

File size: 10.8 KB
Line 
1== Eggs Tutorial
2
3[[toc:]]
4[[tags:tutorials eggs]]
5
6== Introduction
7
8This document explains how to create an official CHICKEN Extension.
9
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.
12
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).
15
16We will assume your extension is called ''mpeg3''.  Replace occurences of that string throughout this file with the actual name of your extension.
17
18== Programming your extension
19
20=== Code layout
21
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.
25
26
27== Additional files
28
29
30=== Documentation
31
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).
33
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 [[http://api.call-cc.org|API browser]].
35
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 http://wiki.call-cc.org/eggref/4/eggname-here and use it to edit the wiki contents.
37
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:
39
40  $ svn co https://code.call-cc.org/svn/chicken-eggs/wiki
41
42==== Sections
43
44We recommend that each page for an egg is given at least the following sections:
45
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.
54
55
56=== The setup file
57
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]].
60
61If your egg does not contain macros, your setup file should look similar to the following:
62
63<enscript highlight=scheme>
64;; These two instructions will produce statically and dynamically linkable object files "mpeg3.o" and "mpeg3.so" respectively.
65(compile -s -O3 -d1 mpeg3.scm -j mpeg3)
66(compile -s mpeg.import.scm -O3 -d0)
67
68(install-extension
69 ;; Name of your extension:
70 'mpeg3
71 ;; Files to install for your extension:
72 '("mpeg3.so" "mpeg3.import.so")
73 ;; Assoc list with properties for your extension:
74 '((version "1.2")))
75</enscript>
76
77The first line will cause {{mpeg3.scm}} to be compiled into
78{{mpeg3.so}} (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.
81
82The second line will compile the generated import library.
83
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.
85
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.
87
88=== The meta file
89
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:
93
94<enscript highlight=scheme>(
95; Your egg's license:
96(license "BSD")
97
98; Pick one from the list of categories (see below) for your egg and enter it
99; here.
100(category web)
101
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)
107
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)
112
113(author "Your Name Goes Here")
114(synopsis "A basic description of the purpose of the egg."))
115</enscript>
116
117For the category entry you can use any of the following:
118
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
147
148Make sure you read [[Eggs Licensing]]!
149
150More information about extension meta properties can be found here at
151the [[Metafile reference]].
152
153=== Tests
154
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.'''
160
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.
162
163For proper integration to the [[http://tests.call-cc.org|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.
168
169With regard to the test infrastructure, notice that only the latest released egg versions are tested.
170
171==== Testing your extension
172
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:
174
175  $ chicken-install salmonella # in case you don't have salmonella installed
176  $ cd egg-dir # the directory where your egg code is stored
177  $ salmonella
178
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:
180
181  $ salmonella-log-viewer salmonella.log
182
183See the [[/egg/salmonella|salmonella documentation]] for more information on how to test eggs.
184
185If your egg installs an executable file and tests call that file, take a look at [[http://wiki.call-cc.org/eggref/4/salmonella#testing-executable-files-installed-by-eggs|this caveat]].
186
187== Managing and hosting eggs
188
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[[http://github.com|github]], [[http://bitbucket.org|bitbucket]] etc,
194or even using your own server.
195
196See the [[/releasing-your-egg|Releasing your egg]] document for
197information on how to host egg code and manage releases.
198
199== Caveats
200
201=== License
202
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.
204
205== Post check in notes
206
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 [[http://tests.call-cc.org]] for more information.
208
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.