@@ -1400,7 +1400,7 @@ sub _load_apperl_config {
1400
1400
if ($key =~ / ^(\+ |\- )(.+)/ ) {
1401
1401
my $append = $1 eq ' +' ;
1402
1402
my $realkey = $2 ;
1403
- exists $itemconfig {$realkey } or die ( " cannot append without existing key" ) ;
1403
+ exists $itemconfig {$realkey } or die " cannot append without existing key: $realkey " ;
1404
1404
my $rtype = ref ($itemconfig {$realkey });
1405
1405
$rtype or die (" not ref" );
1406
1406
if ($append ) {
@@ -1435,8 +1435,8 @@ sub _load_apperl_config {
1435
1435
foreach my $destdir (keys %{$itemconfig {zip_extra_files }}) {
1436
1436
foreach my $path (@{$itemconfig {zip_extra_files }{$destdir }}) {
1437
1437
$path = abs_path($path );
1438
- $path or die ;
1439
- -e $path or die ( " missing file $path " ) ;
1438
+ $path or die " zip_extra_files: check that all files exist for destdir: $destdir " ;
1439
+ -e $path or die " zip_extra_files: missing file $path " ;
1440
1440
}
1441
1441
}
1442
1442
@@ -1592,7 +1592,7 @@ To start an APPerl project from an existing APPerl and build it:
1592
1592
To start an APPerl project and build from scratch:
1593
1593
1594
1594
apperlm install-build-deps
1595
- apperlm init --name your_config_name --base v5.36.0- small-v0.1.0
1595
+ apperlm init --name your_config_name --base small
1596
1596
apperlm configure
1597
1597
apperlm build
1598
1598
@@ -1677,30 +1677,57 @@ the current environment.
1677
1677
For the most part, APPerl works like normal perl, however it has a
1678
1678
couple additional features.
1679
1679
1680
+ =head2 EMBEDDED SCRIPTS
1681
+
1682
+ The APPerl binary is also a ZIP file. Paths starting with C</zip/ >
1683
+ refer to files compressed in the binary itself. At runtime the zip
1684
+ filesystem is readonly, but additional modules and scripts can be added
1685
+ just by adding them to the zip file. For example, perldoc and the other
1686
+ standard scripts are shipped inside of C</zip/bin >
1687
+
1688
+ ./perl.com /zip/bin/perldoc perlcosmo
1689
+
1690
+ For convenience, APPerl has some other ways of invoking embedded
1691
+ scripts:
1692
+
1680
1693
=over 4
1681
1694
1682
1695
=item *
1683
1696
1684
- C</zip/ > filesystem - The APPerl binary is also a ZIP file. Paths
1685
- starting with C</zip/ > refer to files compressed in the binary itself.
1686
- At runtime the zip filesystem is readonly, but additional modules and
1687
- scripts can be added just by adding them to the zip file. For example,
1688
- perldoc and the other standard scripts are shipped inside of /zip/bin
1697
+ C<APPERL_SCRIPTNAME > - When the environment variable C<APPERL_SCRIPTNAME >
1698
+ is set, APPerl attempts to load the basename of C<APPERL_SCRIPTNAME >
1699
+ without file extension from C</zip/bin > or opens the perl interpreter
1700
+ like normal if it is C<perl > .
1689
1701
1690
- ./perl.com /zip/bin/perldoc perlcosmo
1702
+ APPERL_SCRIPTNAME=perldoc ./perl.com perlcosmo
1691
1703
1692
1704
=item *
1693
1705
1694
- C<argv[0] > script execution - this allows making single binary perl
1695
- applications! APPerl built with the APPerl additions
1696
- (found in cosmo-apperl branches) attempts to load the argv[0] basename
1697
- without extension from /zip/bin
1706
+ C<argv[0] > - If C<APPERL_SCRIPTNAME > is not set, APPerl attempts to
1707
+ load the basename of C<argv[0] > without file extension from C</zip/bin >
1708
+ or opens the perl interpreter like normal if it is C<perl > . This
1709
+ enables making single binary perl applications, with a symlink, move,
1710
+ or copy!
1698
1711
1699
1712
ln -s perl.com perldoc.com
1700
1713
./perldoc.com perlcosmo
1701
1714
1715
+ =item *
1716
+
1717
+ C<APPERL_DEFAULT_SCRIPT > - If C<argv[0] > doesn't yield a valid target
1718
+ either, if the C<APPERL_DEFAULT_SCRIPT > field inside of the binary
1719
+ is set, APPerl will attempt to load that. This way is meant for APPerl
1720
+ application authors to protect against accidental rename messing up
1721
+ C<argv[0] > script execution. L</BUILDING AN APPLICATION FROM EXISTING APPERL>
1722
+ shows how to set it with C<"default_script" > , but you could also
1723
+ set/change it, by searching for C<APPERL_DEFAULT_SCRIPT > in a hex
1724
+ editor and modifying it.
1725
+
1702
1726
=back
1703
1727
1728
+ If a valid target is not found via the script execution methods, the
1729
+ perl interpreter is invoked like normal.
1730
+
1704
1731
=head1 CREATING APPLICATIONS WITH APPERL
1705
1732
1706
1733
=head2 RATONALE
@@ -1784,27 +1811,65 @@ permissively already.
1784
1811
1785
1812
=head2 BUILDING AN APPLICATION FROM SCRATCH
1786
1813
1787
- If your application requires non-standard C or XS extensions, APPerl
1788
- must be built from scratch as it does not support dynamic libraries,
1789
- only static linking. Note, this process can only be completed on
1790
- Linux as building the Cosmopolitan Libc from scratch is only supported
1791
- on Linux and APPerl uses the unix-like C<Configure > to configure perl.
1792
- This tutorial assumes you already have an APPerl project, possibly from
1793
- following the L</BUILDING AN APPLICATION FROM EXISTING APPERL> tutorial.
1814
+ If your application requires non-standard C or XS extensions, or you
1815
+ would like to install CPAN distributions through their standard
1816
+ mechanisms (C<Makefile.PL > or C<Build.PL > ), APPerl must be built from
1817
+ scratch as it only supports static linking and installing distributions
1818
+ may require adding in extensions. Note, this process can only be
1819
+ completed on Linux as building the Cosmopolitan Libc from scratch is
1820
+ only supported on Linux and APPerl uses the unix-like C<Configure > to
1821
+ configure perl. This tutorial assumes you already have an APPerl
1822
+ project, possibly from following the L</BUILDING AN APPLICATION FROM EXISTING APPERL>
1823
+ tutorial.
1794
1824
1795
1825
First install the APPerl build dependencies and create a new config
1796
- based on the current small config, checkout, configure, and build.
1826
+ based on the current full config, checkout, configure, and build.
1797
1827
1798
1828
apperlm install-build-deps
1799
- apperlm new-config --name my_src_build_config --base v5.36.0-small-v0.1.0
1829
+ apperlm new-config --name my_src_build_config --base full
1800
1830
apperlm checkout my_src_build_config
1801
1831
apperlm configure
1802
1832
apperlm build
1803
1833
1804
1834
If all goes well you should have compiled APPerl from source!
1805
1835
1806
- ./perl-small.com -V
1807
- stat perl-small.com
1836
+ ./perl.com -V
1837
+ stat perl.com
1838
+
1839
+ =head3 ADDING CPAN DISTRIBUTIONS
1840
+
1841
+ The recommended way of adding CPAN distributions or C or XS extensions
1842
+ is via the C<"install_modules" > mechanism.
1843
+
1844
+ Currently, no CPAN client is used, so you must download or make
1845
+ available or disk otherwise the needed distributions for C<apperlm >
1846
+ to be able to build and install them into your APPerl. It supports
1847
+ folder paths and paths to tarballs such as the one's directly
1848
+ downloaded from CPAN.
1849
+
1850
+ For example to install L<Geo::Calc:XS> , download its tarball from CPAN
1851
+ and add to to my_src_build_config in apperl-project.json:
1852
+
1853
+ "install_modules" : ["Geo-Calc-XS-0.33.tar.gz"]
1854
+
1855
+ Then, build and test it:
1856
+
1857
+ apperlm build
1858
+ ./perl.com -MGeo::Calc::XS -e 'print $Geo::Calc::XS::VERSION'
1859
+
1860
+ Distributions in C<"install_modules" > are installed in order, so
1861
+ modules with dependencies just need them to be installed before in
1862
+ order for them to be added.
1863
+
1864
+ =cut
1865
+
1866
+ =head3 ADDING VIA PERL BUILD
1867
+
1868
+ This method is B<NOT RECOMMENDED > as many modules/extensions cannot be
1869
+ built this way, it only works for modules that can be built with
1870
+ C<miniperl > , do not have dependencies, and requires reconfiguring Perl.
1871
+ The method listed in L</ADDING CPAN DISTRIBUTIONS> supersedes this
1872
+ method.
1808
1873
1809
1874
Now let's create a very basic C extension.
1810
1875
0 commit comments