ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/App-Staticperl/staticperl.pod
(Generate patch)

Comparing App-Staticperl/staticperl.pod (file contents):
Revision 1.40 by root, Sun May 1 09:29:47 2011 UTC vs.
Revision 1.48 by root, Sun Jul 10 01:37:56 2011 UTC

39file that contains perl interpreter, libc, all the modules you need, all 39file that contains perl interpreter, libc, all the modules you need, all
40the libraries you need and of course your actual program. 40the libraries you need and of course your actual program.
41 41
42With F<uClibc> and F<upx> on x86, you can create a single 500kb binary 42With F<uClibc> and F<upx> on x86, you can create a single 500kb binary
43that contains perl and 100 modules such as POSIX, AnyEvent, EV, IO::AIO, 43that contains perl and 100 modules such as POSIX, AnyEvent, EV, IO::AIO,
44Coro and so on. Or any other choice of modules. 44Coro and so on. Or any other choice of modules (and some other size :).
45 45
46To see how this turns out, you can try out smallperl and bigperl, two 46To see how this turns out, you can try out smallperl and bigperl, two
47pre-built static and compressed perl binaries with many and even more 47pre-built static and compressed perl binaries with many and even more
48modules: just follow the links at L<http://staticperl.schmorp.de/>. 48modules: just follow the links at L<http://staticperl.schmorp.de/>.
49 49
84With F<staticperl>, the burden is mostly with the developer - only direct 84With F<staticperl>, the burden is mostly with the developer - only direct
85compile-time dependencies and L<AutoLoader> are handled automatically. 85compile-time dependencies and L<AutoLoader> are handled automatically.
86This means the modules to include often need to be tweaked manually. 86This means the modules to include often need to be tweaked manually.
87 87
88All this does not preclude more permissive modes to be implemented in 88All this does not preclude more permissive modes to be implemented in
89the future, but right now, you have to resolve state hidden dependencies 89the future, but right now, you have to resolve hidden dependencies
90manually. 90manually.
91 91
92=item * PAR works out of the box, F<staticperl> does not. 92=item * PAR works out of the box, F<staticperl> does not.
93 93
94Maintaining your own custom perl build can be a pain in the ass, and while 94Maintaining your own custom perl build can be a pain in the ass, and while
202=item F<staticperl cpan> [args...] 202=item F<staticperl cpan> [args...]
203 203
204Starts an interactive CPAN shell that you can use to install further 204Starts an interactive CPAN shell that you can use to install further
205modules. Installs the perl first if necessary, but apart from that, 205modules. Installs the perl first if necessary, but apart from that,
206no magic is involved: you could just as well run it manually via 206no magic is involved: you could just as well run it manually via
207F<~/.staticperl/perl/bin/cpan>. 207F<~/.staticperl/perl/bin/cpan>, except that F<staticperl> additionally
208sets the environment variable C<$PERL> to the path of the perl
209interpreter, which is handy in subshells.
208 210
209Any additional arguments are simply passed to the F<cpan> command. 211Any additional arguments are simply passed to the F<cpan> command.
210 212
211=item F<staticperl instcpan> module... 213=item F<staticperl instcpan> module...
212 214
547 549
548Just like C<--add>, except that it treats the file as binary and adds it 550Just like C<--add>, except that it treats the file as binary and adds it
549without any postprocessing (perl files might get stripped to reduce their 551without any postprocessing (perl files might get stripped to reduce their
550size). 552size).
551 553
552If you specify an alias you should probably add a C<&> prefix to avoid 554If you specify an alias you should probably add a C</> prefix to avoid
553clashing with embedded perl files (whose paths never start with C<&>), 555clashing with embedded perl files (whose paths never start with C</>),
554and/or use a special directory prefix, such as C<&res/name>. 556and/or use a special directory prefix, such as C</res/name>.
555 557
556You can later get a copy of these files by calling C<staticperl::find 558You can later get a copy of these files by calling C<staticperl::find
557"alias">. 559"alias">.
558 560
559An alternative way to embed binary files is to convert them to perl and 561An alternative way to embed binary files is to convert them to perl and
560use C<do> to get the contents - this method is a bit cumbersome, but works 562use C<do> to get the contents - this method is a bit cumbersome, but works
561both inside and outside of a staticperl bundle: 563both inside and outside of a staticperl bundle, without extra ado:
562 564
563 # a "binary" file, call it "bindata.pl" 565 # a "binary" file, call it "bindata.pl"
564 <<'SOME_MARKER' 566 <<'SOME_MARKER'
565 binary data NOT containing SOME_MARKER 567 binary data NOT containing SOME_MARKER
566 SOME_MARKER 568 SOME_MARKER
567 569
568 # load the binary 570 # load the binary
569 chomp (my $data = do "bindata.pl"); 571 chomp (my $data = do "bindata.pl");
572
573=item C<--allow-dynamic>
574
575By default, when F<mkbundle> hits a dynamic perl extension (e.g. a F<.so>
576or F<.dll> file), it will stop with a fatal error.
577
578When this option is enabled, F<mkbundle> packages the shared
579object into the bundle instead, with a prefix of F<!>
580(e.g. F<!auto/List/Util/Util.so>). What you do with that is currently up
581to you, F<staticperl> has no special support for this at the moment, apart
582from working around the lack of availability of F<PerlIO::scalar> while
583bootstrapping, at a speed cost.
584
585One way to deal with this is to write all files starting with F<!> into
586some directory and then C<unshift> that path onto C<@INC>.
587
588#TODO: example
570 589
571=back 590=back
572 591
573=item Step 2: filter all files using C<--include> and C<--exclude> options. 592=item Step 2: filter all files using C<--include> and C<--exclude> options.
574 593
882=item C<STATICPERL> 901=item C<STATICPERL>
883 902
884The directory where staticperl stores all its files 903The directory where staticperl stores all its files
885(default: F<~/.staticperl>). 904(default: F<~/.staticperl>).
886 905
887=item C<PERL_MM_USE_DEFAULT>, C<EV_EXTRA_DEFS>, ... 906=item C<DLCACHE>
888 907
889Usually set to C<1> to make modules "less inquisitive" during their 908The path to a directory (will be created if it doesn't exist) where
890installation, you can set any environment variable you want - some modules 909downloaded perl sources are being cached, to avoid downloading them
891(such as L<Coro> or L<EV>) use environment variables for further tweaking. 910again. The default is empty, which means there is no cache.
892 911
893=item C<PERL_VERSION> 912=item C<PERL_VERSION>
894 913
895The perl version to install - default is currently C<5.12.3>, but C<5.8.9> 914The perl version to install - default is currently C<5.12.3>, but C<5.8.9>
896is also a good choice (5.8.9 is much smaller than 5.12.3, while 5.10.1 is 915is also a good choice (5.8.9 is much smaller than 5.12.3, while 5.10.1 is
897about as big as 5.12.3). 916about as big as 5.12.3).
917
918=item C<PERL_MM_USE_DEFAULT>, C<EV_EXTRA_DEFS>, ...
919
920Usually set to C<1> to make modules "less inquisitive" during their
921installation. You can set (and export!) any environment variable you want
922- some modules (such as L<Coro> or L<EV>) use environment variables for
923further tweaking.
898 924
899=item C<PERL_PREFIX> 925=item C<PERL_PREFIX>
900 926
901The prefix where perl gets installed (default: F<$STATICPERL/perl>), 927The prefix where perl gets installed (default: F<$STATICPERL/perl>),
902i.e. where the F<bin> and F<lib> subdirectories will end up. 928i.e. where the F<bin> and F<lib> subdirectories will end up.
1115 1141
1116=back 1142=back
1117 1143
1118=head1 RUNTIME FUNCTIONALITY 1144=head1 RUNTIME FUNCTIONALITY
1119 1145
1120Binaries created with C<mkbundle>/C<mkperl> contain extra functions, which 1146Binaries created with C<mkbundle>/C<mkperl> contain extra functionality,
1121are required to access the bundled perl sources, but might be useful for 1147mostly related to the extra files bundled in the binary (the virtual
1122other purposes. 1148filesystem). All of this data is statically compiled into the binary, and
1149accessing means copying it from a read-only section of your binary. Data
1150pages in this way is usually freed by the operating system, as it isn't
1151use more the onace.
1152
1153=head2 VIRTUAL FILESYSTEM
1154
1155Every bundle has a virtual filesystem. The only information stored in it
1156is the path and contents of each file that was bundled.
1157
1158=head3 LAYOUT
1159
1160Any path starting with an ampersand (F<&>) or exclamation mark (F<!>) are
1161reserved by F<staticperl>. They must only be used as described in this
1162section.
1163
1164=over 4
1165
1166=item !
1167
1168All files that typically cannot be loaded from memory (such as dynamic
1169objects or shared libraries), but have to reside in the filesystem, are
1170prefixed with F<!>. Typically these files get written out to some
1171(semi-)temporary directory shortly after program startup, or before being
1172used.
1173
1174=item !boot
1175
1176The bootstrap file, if specified during bundling.
1177
1178=item !auto/
1179
1180Shared objects or dlls corresponding to dynamically-linked perl extensions
1181are stored with an F<!auto/> prefix.
1182
1183=item !lib/
1184
1185External shared libraries are stored in this directory.
1186
1187=item any letter
1188
1189Any path starting with a letter is a perl library file. For example,
1190F<Coro/AIO.pm> corresponds to the file loaded by C<use Coro::AIO>, and
1191F<Coro/jit.pl> corresponds to C<require "Coro/jit.pl">.
1192
1193Obviously, module names shouldn't start with any other characters than
1194letters :)
1195
1196=back
1197
1198=head3 FUNCTIONS
1199
1200=over 4
1201
1202=item $file = staticperl::find $path
1203
1204Returns the data associated with the given C<$path>
1205(e.g. C<Digest/MD5.pm>, C<auto/POSIX/autosplit.ix>).
1206
1207Returns C<undef> if the file isn't embedded.
1208
1209=item @paths = staticperl::list
1210
1211Returns the list of all paths embedded in this binary.
1212
1213=back
1214
1215=head2 EXTRA FEATURES
1123 1216
1124In addition, for the embedded loading of perl files to work, F<staticperl> 1217In addition, for the embedded loading of perl files to work, F<staticperl>
1125overrides the C<@INC> array. 1218overrides the C<@INC> array.
1126
1127=over 4
1128
1129=item $file = staticperl::find $path
1130
1131Returns the data associated with the given C<$path>
1132(e.g. C<Digest/MD5.pm>, C<auto/POSIX/autosplit.ix>), which is basically
1133the UNIX path relative to the perl library directory.
1134
1135Returns C<undef> if the file isn't embedded.
1136
1137=item @paths = staticperl::list
1138
1139Returns the list of all paths embedded in this binary.
1140
1141=back
1142 1219
1143=head1 FULLY STATIC BINARIES - UCLIBC AND BUILDROOT 1220=head1 FULLY STATIC BINARIES - UCLIBC AND BUILDROOT
1144 1221
1145To make truly static (Linux-) libraries, you might want to have a look at 1222To make truly static (Linux-) libraries, you might want to have a look at
1146buildroot (L<http://buildroot.uclibc.org/>). 1223buildroot (L<http://buildroot.uclibc.org/>).
1155good experiences with GCC 4.4.x but not GCC 4.5. 1232good experiences with GCC 4.4.x but not GCC 4.5.
1156 1233
1157To minimise code size, I used C<-pipe -ffunction-sections -fdata-sections 1234To minimise code size, I used C<-pipe -ffunction-sections -fdata-sections
1158-finline-limit=8 -fno-builtin-strlen -mtune=i386>. The C<-mtune=i386> 1235-finline-limit=8 -fno-builtin-strlen -mtune=i386>. The C<-mtune=i386>
1159doesn't decrease codesize much, but it makes the file much more 1236doesn't decrease codesize much, but it makes the file much more
1160compressible. 1237compressible (and the execution a lot slower...).
1161 1238
1162If you don't need Coro or threads, you can go with "linuxthreads.old" (or 1239If you don't need Coro or threads, you can go with "linuxthreads.old" (or
1163no thread support). For Coro, it is highly recommended to switch to a 1240no thread support). For Coro, it is highly recommended to switch to a
1164uClibc newer than 0.9.31 (at the time of this writing, I used the 20101201 1241uClibc newer than 0.9.31 (at the time of this writing, I used the 20101201
1165snapshot) and enable NPTL, otherwise Coro needs to be configured with the 1242snapshot) and enable NPTL, otherwise Coro needs to be configured with the
1167twice the address space needed for stacks). 1244twice the address space needed for stacks).
1168 1245
1169If you use C<linuxthreads.old>, then you should also be aware that 1246If you use C<linuxthreads.old>, then you should also be aware that
1170uClibc shares C<errno> between all threads when statically linking. See 1247uClibc shares C<errno> between all threads when statically linking. See
1171L<http://lists.uclibc.org/pipermail/uclibc/2010-June/044157.html> for a 1248L<http://lists.uclibc.org/pipermail/uclibc/2010-June/044157.html> for a
1172workaround (And L<https://bugs.uclibc.org/2089> for discussion). 1249workaround (and L<https://bugs.uclibc.org/2089> for discussion).
1173 1250
1174C<ccache> support is also recommended, especially if you want 1251C<ccache> support is also recommended, especially if you want
1175to play around with buildroot options. Enabling the C<miniperl> 1252to play around with buildroot options. Enabling the C<miniperl>
1176package will probably enable all options required for a successful 1253package will probably enable all options required for a successful
1177perl build. F<staticperl> itself additionally needs either C<wget> 1254perl build. F<staticperl> itself additionally needs either C<wget>
1185it from working properly in a chroot - either use dash (and link it to 1262it from working properly in a chroot - either use dash (and link it to
1186F</bin/sh> inside the chroot) or link busybox to F</bin/sh>, using it's 1263F</bin/sh> inside the chroot) or link busybox to F</bin/sh>, using it's
1187built-in ash shell. 1264built-in ash shell.
1188 1265
1189Finally, you need F</dev/null> inside the chroot for many scripts to work 1266Finally, you need F</dev/null> inside the chroot for many scripts to work
1190- F<cp /dev/null output/target/dev> or bind-mounting your F</dev> will 1267- either F<cp /dev/null output/target/dev> or bind-mounting your F</dev>
1191both provide this. 1268will provide this.
1192 1269
1193After you have compiled and set up your buildroot target, you can copy 1270After you have compiled and set up your buildroot target, you can copy
1194F<staticperl> from the C<App::Staticperl> distribution or from your 1271F<staticperl> from the C<App::Staticperl> distribution or from your
1195perl f<bin> directory (if you installed it) into the F<output/target> 1272perl F<bin> directory (if you installed it) into the F<output/target>
1196filesystem, chroot inside and run it. 1273filesystem, chroot inside and run it.
1197 1274
1198=head1 RECIPES / SPECIFIC MODULES 1275=head1 RECIPES / SPECIFIC MODULES
1199 1276
1200This section contains some common(?) recipes and information about 1277This section contains some common(?) recipes and information about

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines