Skip to content

Commit dd05f67

Browse files
committed
updated docs and changes (reworked script execution into EMBEDDED SCRIPTS section and added install_modules info), added @csdvrx suggestions
1 parent 3aecd75 commit dd05f67

File tree

2 files changed

+103
-28
lines changed

2 files changed

+103
-28
lines changed

Changes

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
Revision history for Perl-Dist-APPerl
2-
v0.X.X 2023-XX-XX
3-
Add setting fallback script to run if argv[0] script execution
4-
fails, set `default_script` in your config.
2+
v0.3.0 2023-01-XX
3+
Added running scripts from APPERL_SCRIPTNAME environment
4+
variable
5+
Added setting fallback script to run if argv[0] script
6+
execution fails, set `default_script` in your config
7+
Added installing CPAN distributions from tarball or directory
8+
on disk via "install_modules" in project config.
9+
full, small, and vista variant configs:
10+
Removed version from privlib archlib sitelib sitearch
11+
Updated Cosmopolitan source
12+
Update Perl source
13+
Added dbg config: gdb not working for me, YYMV
14+
Updated docs with new info.
515

616
v0.2.1 2022-12-03
717
Remove dependency on Env module.

lib/Perl/Dist/APPerl.pm

Lines changed: 90 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ sub _load_apperl_config {
14001400
if($key =~ /^(\+|\-)(.+)/) {
14011401
my $append = $1 eq '+';
14021402
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";
14041404
my $rtype = ref($itemconfig{$realkey});
14051405
$rtype or die("not ref");
14061406
if($append) {
@@ -1435,8 +1435,8 @@ sub _load_apperl_config {
14351435
foreach my $destdir (keys %{$itemconfig{zip_extra_files}}) {
14361436
foreach my $path (@{$itemconfig{zip_extra_files}{$destdir}}) {
14371437
$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";
14401440
}
14411441
}
14421442

@@ -1592,7 +1592,7 @@ To start an APPerl project from an existing APPerl and build it:
15921592
To start an APPerl project and build from scratch:
15931593
15941594
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
15961596
apperlm configure
15971597
apperlm build
15981598
@@ -1677,30 +1677,57 @@ the current environment.
16771677
For the most part, APPerl works like normal perl, however it has a
16781678
couple additional features.
16791679
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+
16801693
=over 4
16811694
16821695
=item *
16831696
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>.
16891701
1690-
./perl.com /zip/bin/perldoc perlcosmo
1702+
APPERL_SCRIPTNAME=perldoc ./perl.com perlcosmo
16911703
16921704
=item *
16931705
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!
16981711
16991712
ln -s perl.com perldoc.com
17001713
./perldoc.com perlcosmo
17011714
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+
17021726
=back
17031727
1728+
If a valid target is not found via the script execution methods, the
1729+
perl interpreter is invoked like normal.
1730+
17041731
=head1 CREATING APPLICATIONS WITH APPERL
17051732
17061733
=head2 RATONALE
@@ -1784,27 +1811,65 @@ permissively already.
17841811
17851812
=head2 BUILDING AN APPLICATION FROM SCRATCH
17861813
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.
17941824
17951825
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.
17971827
17981828
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
18001830
apperlm checkout my_src_build_config
18011831
apperlm configure
18021832
apperlm build
18031833
18041834
If all goes well you should have compiled APPerl from source!
18051835
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.
18081873
18091874
Now let's create a very basic C extension.
18101875

0 commit comments

Comments
 (0)