25 ms·
Actually Portable Perl
- idop 4y agoI was waiting for this, but it doesn't mention which version of Perl 5 this is.
- simonhamp 4y agoHas anyone done one of these (or wants to) for PHP?
- skor 4y agoYeah, I’ve wanted this for a long time. I’m going to try but can’t promise anything.
- notpushkin 4y agoSame but for Python. I'll probably look into it when I'm sufficiently bored with my current projects.
- tmtvl 4y agoTo quote the blogpost: After stumbling upon Gautham's APE Python port (https://ahgamut.github.io/2021/07/13/ape-python/) [...]
- deleted 4y ago[deleted]
- eesmith 4y ago5 months ago on HN, "Python is Actually Portable", https://news.ycombinator.com/item?id=32245430 https://news.ycombinator.com/item?id=32245430 (120 comments)
- jart 4y agoWe managed to get it to build I think last year. https://github.com/ahgamut/php-src/tree/cosmo_php73 https://github.com/ahgamut/php-src/tree/cosmo_php73 See also https://github.com/shmup/awesome-cosmopolitan https://github.com/shmup/awesome-cosmopolitan
- ahgamut 4y agoAdding on to jart's answer -- I ported PHP 7.3 back in July 2021 (building on alganet's work), and got up to a simple "hello-world". Have never used PHP, so I didn't know what else could be done with it at the time. However, the libc has grown a lot over the last year (Cosmo has a pthreads API now!) -- the updated libc enabled a quick experimental port of Python 3.11.0rc1 back in August (https://github.com/ahgamut/cpython/tree/cosmo_py311 https://github.com/ahgamut/cpython/tree/cosmo_py311), so I would expect that a newer version of PHP can be ported similarly. Let's see....
- ahgamut 4y agoah, here we are: https://github.com/ahgamut/php-src/tree/cosmo_php81 https://github.com/ahgamut/php-src/tree/cosmo_php81 (note it's an experimental port, I just put it together).
- skor 4y agoreally cool, thanks!!
- benatkin 4y agoOne file is nice, but I like being able to run on Alpine Linux. A lot of stuff like Deno depends on glibc. That's one thing I think about when I think "Actually Portable". Does this support musl?
- kissgyorgy 4y agoIt doesn't depend on anything, completely static. Here you can read more about Actually Portable Executables: https://justine.lol/ape.html https://justine.lol/ape.html
- jart 4y agoCosmopolitan Libc uses a musl-cross-make toolchain. https://github.com/jart/cosmopolitan/tree/master/third_party/gcc https://github.com/jart/cosmopolitan/tree/master/third_party... Its primary developer also runs Alpine. Cosmopolitan is closely related to Musl as far as C libraries go. You could think of Cosmo as a Musl that's twice as fast on x86 and runs on more than just Linux.
- jb1991 4y agoPerl is really one of the best languages and in modern times is underrated. I've been using it in production for most of my critical services since about 2012. I've used many other languages since then but always keep coming back to perl. It's a true gem of a language.
- G3rn0ti 4y agoIt's grand child, Raku, also seems to be an impressive language actually. Hated by Perlers and non-Perlers alike, it actually would be a great environment to build powerful programs in: https://www.oreilly.com/library/view/learning-perl-6/9781491977675/ https://www.oreilly.com/library/view/learning-perl-6/9781491...
- lizmat 4y agohttps://raku.org https://raku.org
- kamaal 4y ago>>Hated by Perlers and non-Perlers alike Wrong. Perlers still cheer for it. But for some reasons it hasn't wide spread adoption yet. We hope to use it some day in production.
- counterpartyrsk 4y ago
- G3rn0ti 4y agoThat's what I meant when I said Perlers hate Rakuans. It's an intersting example of "The People's Front of Judea" vs. "The Judean People's Front". I hope you gain inner peace one day again.
- newaccount2021 4y ago
- 4y ago
- HeckFeck 4y ago> a distribution of Perl the runs on several x86_64 operating systems (most Unix-like and Windows) via the same binary Unix and Windows in the same binary?? Sacrilege! Haven't we still laws against witchcraft?
- ptspts 4y agoShameless plug: my earlier project StaticPerl, statically linked Perl 5.10 for i386 Linux and FreeBSD: https://github.com/pts/staticperl https://github.com/pts/staticperl Differences: * Actually Portable Perl runs on more operating systems, StaticPerl runs on Linux i386 (requiring i686 or newer processor), Linux amd64 and FreeBSD with Linux emulation. * Actually Portable Perl has more of the standard Perl modules and C extensions bundled. StaticPerl contains only a few modules, simplified, with documentation and non-Linux support removed. StaticPerl is unlikely to work with existing Perl scripts with many use calls, but it is useful to write new Perl scripts from scratch, and these scripts will work with both StaticPerl and regular Perl. * Actually Portable Perl executable programs are larger (5 MB minimum, StaticPerl is ~1 MB) because they are compiled for amd64 rather than i386, and they contain more Perl and C code. * The first time an Actually Portable Perl executable program is run, it modifies a few bytes at the beginning of the program file (except on Windows). Thus these programs don't work on read-only filesystems unless they have been run on a read-write filesystem first. StaticPerl doesn't have this limitation.
- G4Vi 4y agoAuthor here. Nice comparison. By default (and the released) APPerl binaries do not self-modify (they use the non-self modifying ape loader) however on unix-like they install the APE loader to`$HOME/.ape`and use that ELF executable to run the APE. To skip the fork+exec to the ape loader, they can be assimilated with `--assimilate`, that does turn the APE executable into ELF. There is a kernel patch to add APE (Actually Portable Executable) support to Linux removing the need for the the apeloader or assimilating. I'm not sure what the status is on that.
- G4Vi 4y agoI forgot to mention APPerl and StaticPerl have many overlapping use cases, but APPerl is more tailored to application packaging. APPerl is built with a patch to Perl adding argv[0] script execution, allowing the APPerl binary to turn into a binary for any of the embedded scripts, with a rename or symlink rather then needing to pass flags the Perl executable to load modules.
- 4y ago
- jgilias 4y agoNice to see Cosmopolitan libc starting to be used more widely!
- benreesman 4y agoGod I must have written 200k lines of Perl5, and I hate it as only an experienced user can. But the fact is: it gets shit done. It’s pretty good at dealing with strings and byte sequences, and even more importantly, it’s always fucking installed, The “best” software helps you nothing if you’re machine isn’t running it.
- creeble 4y ago> It’s pretty good at dealing with strings and byte sequences, Ugh. Close to half the bugs I’ve chased in Perl in the last 10 years are encode/decode string bugs (or more specifically, the lack of doing encode/decode where necessary). After just one ‘downgrade_utf8()’ use, you get sick of Perl pretty fast.
- jamal-kumar 4y agoThis to me is where Perl ends up super short. Basically try using it outside of the anglosphere in the world of Unicode and support falls apart. Sure is excellent if you need to do something like extract a bunch of 1980s database files encoded in LATIN-1 though!
- yjftsjthsd-h 4y ago> Sure is excellent if you need to do something like extract a bunch of 1980s database files encoded in LATIN-1 though Or, y'know, a bunch of 2010s database files encoded in latin1. Fun fact: Did you know that MySQL 5.7 is still a supported version in 2022?
- Longhanks 4y agoIf you don’t (need to) care about Unicode, maybe. If you think pythons package management is not disastrous enough, maybe. If you do not (need to) consider Windows, maybe. Even then, I’d rather choose Python.
- bloblaw 4y ago> If you don’t (need to) care about Unicode, maybe Perl has had strong unicode support since Perl v5.12 (~2010). references: 1. http://xahlee.info/perl/perl_unicode.html http://xahlee.info/perl/perl_unicode.html 2. https://stackoverflow.com/a/6163129/12458 https://stackoverflow.com/a/6163129/12458 > If you think pythons package management is not disastrous enough, maybe. Huh? I've used PAR::Packer with great success since 2005. > If you do not (need to) consider Windows, maybe. Microsoft used to ship Perl scripts to work with COM and WMI with their NT4 and Windows 2000 resource kits. Perl works *extremely* well with Windows. I mean, there are lots of reasons to choose Python over Perl, but IMHO, these are not those reasons. I use Perl as a better-bash. If I was writing a modern website, a large application, or any ML related work...I'd choose Python. But for complex system administration, I'm picking Perl. YMMV
- dilDDoS 4y agoMaybe a little off topic, but I'm curious -- why are all of the Actually Portable programs always named with ".com" at the end? Does this have any special purpose?
- johannes1234321 4y agoA .com file is an old form of DOS executables with only code and data. No fancy headers or anything. Only thing specified is that execution will start at a specific address (0100h) and if you put a JMP you got enough space to put other headers around it. A com file is different from a typical dos/Windows exe, which requires a specific file header. Each exe begins with the two bytes MZ followed by specific information on page sizes etc. and there is no way around. The challenge a program like APP has is that it should be recognized by all operating systems, so to Linux it should look like an ELF executable, on Windows like a windows executable, etc. Now if you take this APP perl.com file and load it with Linux, Linux will read the ELF header and be happy. If you load it into Windows, it will see the .com ending and thus just put the code into memory, jump to address 0100h and start executing. The program then can ignore the elf header. And if you open it with some (unzip) Programm such a Programm will look at the end of the file, where it will find a zip file header info and will think it's an zip archive. (Zip files have the header at the end mostly for historic reasons, as all information was only available once compression was done, but as you span multiple disks you can't reach the front anymore) In the end it is a trick to make it look like different kind of file, depending on who looks at it.
- ploxiln 4y agoIt's a legacy type of windows executable that it uses as part of its multi-OS trick, and other OSes don't care about that extension.
- G4Vi 4y agoAPPerl creator here. I appreciate all the feedback and hope it comes in handy. It's linked from the page, but thought I'd point out if you're curious what went into making APPerl, check out the blogpost (self-plug): https://computoid.com/posts/Perl-is-Actually-Portable.html https://computoid.com/posts/Perl-is-Actually-Portable.html
- kal247 4y agoIf it does what I think it does, then you've found the holy grail.
- marttt 4y agoI wonder why microperl or miniperl didn't really take off. Would be a nice thing to have -- just a single-executable-perl with the basics and file i/o, alongside awk, Lua or any other tiny language. An interesting effort and article from around 2001: https://www.foo.be/docs/tpj/issues/vol5_3/tpj0503-0003.html https://www.foo.be/docs/tpj/issues/vol5_3/tpj0503-0003.html And an old Perlmonks discussion on a 850kb Perl: https://www.perlmonks.org/?node_id=222465 https://www.perlmonks.org/?node_id=222465 There is a newer github project as well -- it did work for a simple project with core modules for me: https://github.com/bentxt/microperl-standalone https://github.com/bentxt/microperl-standalone
- jandrese 4y agoThis is really interesting. I had to give up on Perl on Windows because Windows Defender was forever flagging anything compiled with Par::Packer as a virus and deleting it. Shame there isn't a portable windowing toolkit you could use with this. I'm pretty sure it's not possible to get the Qt or GTK bindings to work across all platforms from a single install, even if you are using the toolkit's widgets instead of trying to use the platform native widgets.