Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

APPerl: "osname=cosmo" problem

by kcott (Archbishop)
on Jun 08, 2023 at 05:18 UTC ( #11152689=perlquestion: print w/replies, xml ) Need Help??

kcott has asked for the wisdom of the Perl Monks concerning the following question:

Background

I don't know how much of this is useful. I've kept it very brief. Ask for more details if you need them.

  1. cpan install Perl::Dist::APPerl v0.3.0 (on openSUSE Leap 15.4 with Perl v5.26.1)
  2. $ apperlm install-build-deps $ apperlm init --name initial_build_config --base full $ apperlm checkout initial_build_config $ apperlm configure $ apperlm build
  3. $ ./perl.com -v This is perl 5, version 36, subversion 0 (v5.36.0) built for x86_64-co +smo (with 6 registered patches, see perl -V for more detail) ... $ ./perl.com -V Summary of my perl5 (revision 5 version 36 subversion 0) configuration +: Commit id: ca87f329eeb075c0fe7ac803eb933f36af45a69b Platform: osname=cosmo ...
  4. Copied perl.com to Win10 platform with Strawberry Perl v5.26.3. Renamed to apperl.com to avoid conflict with (Strawberry) perl.exe.
    C:\Users\ken\tmp>apperl -v This is perl 5, version 36, subversion 0 (v5.36.0) built for x86_64-co +smo (with 6 registered patches, see perl -V for more detail) ... C:\Users\ken\tmp>apperl -V Summary of my perl5 (revision 5 version 36 subversion 0) configuration +: Commit id: ca87f329eeb075c0fe7ac803eb933f36af45a69b Platform: osname=cosmo ...
  5. Copied perl.com to Cygwin platform with Perlbrew Perl v5.36.0.
    $ ./perl.com -v This is perl 5, version 36, subversion 0 (v5.36.0) built for x86_64-co +smo (with 6 registered patches, see perl -V for more detail) ... $ ./perl.com -V Summary of my perl5 (revision 5 version 36 subversion 0) configuration +: Commit id: ca87f329eeb075c0fe7ac803eb933f36af45a69b Platform: osname=cosmo ...

Problem

From "Perl::Dist::APPerl - USAGE":

"APPerl doesn't need to be installed, the output perl.com binary can be copied between computers and ran without installation."

This generally seemed to be the case. I ran various checks (on all platforms): 'use v5.36;' enables the strict and warnings pragmata, and features are enabled or disabled in line with :5.36 bundle; an arbitrary selection of core modules had correct versions.

However, $^O reported cosmo (presumably short for Cosmopolitan Libc) on all platforms. This will cause problems with modules which provide different functionality based on $^O. File::Spec gave good examples of this.

Linux:

$ perl -E 'say $^O' linux $ ./perl.com -E 'say $^O' cosmo $ perl -E 'use File::Spec; say for @File::Spec::ISA;' File::Spec::Unix $ ./perl.com -E 'use File::Spec; say for @File::Spec::ISA;' File::Spec::Unix

Win10:

C:\Users\ken\tmp>perl -E "say $^O" MSWin32 C:\Users\ken\tmp>apperl -E "say $^O" cosmo C:\Users\ken\tmp>perl -E "use File::Spec; say for @File::Spec::ISA;" File::Spec::Win32 C:\Users\ken\tmp>apperl -E "use File::Spec; say for @File::Spec::ISA;" File::Spec::Unix

Cygwin:

$ perl -E 'say $^O' cygwin $ ./perl.com -E 'say $^O' cosmo $ perl -E 'use File::Spec; say for @File::Spec::ISA;' File::Spec::Cygwin $ ./perl.com -E 'use File::Spec; say for @File::Spec::ISA;' File::Spec::Unix

In all of those cases, you really want the perl.com -E ... output to match the perl -E ... output; but all defaulted to File::Spec::Unix.

"Perl::Dist::APPerl - USAGE" goes on to say:

"However, in certain cases such as magic (modifying $0, etc.) The binary must be assimilated for it to work properly. ... cp perl.com perl ./perl --assimilate"

In case that was needed, I tried:

# Win10 C:\Users\ken\tmp>apperl --assimilate Unrecognized switch: --assimilate (-h will show valid options). # Cygwin $ ./perl.com --assimilate Unrecognized switch: --assimilate (-h will show valid options).

I haven't worked with APPerl previously; there's a lot of documentation; it's entirely possible that I've missed a step; misread an instruction; or made some other mistake. I've been over what I've done a number of times but I can't see where I might have gone wrong. It could, of course, be bugs or shortcomings in APPerl itself.

If anyone can shed any light on this it would be greatly appreciated. Thankyou.

— Ken

Replies are listed 'Best First'.
Re: APPerl: "osname=cosmo" problem
by Corion (Patriarch) on Jun 08, 2023 at 05:23 UTC

    APPerl / APE binaries run on the "Cosmopolitan" compatibility wrapper, which emulates some Linux API. Hence it makes some sense that it identifies as its own OS instead of the native OS.

    I'm not sure what actual use case you want, but I guess you will have to submit patches for all the relevant modules to recognize/handle cosmo as OS. In the case of File::Spec, I think File::Spec::Unix is what you actually want, as I don't know if Cosmopolitan provides a Cygwin-like wrapper for filenames.

      G'day Corion,

      ++ Thanks for the very quick response.

      This is an evaluation for $work. Various Linux and MSWin platforms are in general use; I only used Cygwin because it was a handy, third platform to test.

      I'll wait to see what others might have to say; however, based on your comments, I suspect this may be inappropriate for $work.

      — Ken

        Depending how close you have to get to the OS and how much the existing scripts rely on OS features (Windows newline translation etc.), yes, I think further work is needed on the Perl side.</>

Re: APPerl: "osname=cosmo" problem
by Anonymous Monk on Jun 08, 2023 at 14:15 UTC

    Probably not appropriate for $work, but:

    You can get some indication of the system from POSIX::uname(). The docs for this are hedged about with caveats, but if it returns something germaine you can in theory derive an appropriate value from this and assign it to $^O itself, which (believe it or not) can be modified. This modification must be done at compile time, before any of the affected modules are loaded.

      ++ Thanks for the tip. I had a quick look: you're right about the caveats.

      I'll check this out tomorrow (actually, later today; it's 2am here). Perhaps a pragma:

      use cosmonaut;

      — Ken

        I'll check this out tomorrow (actually, later today; it's 2am here)

        G'Day kcott,

        Another natural nightowl!

        I have set Alexa to turn off my desk light at half past midnight as a very (in)visible reminder that I need to stop working, start reading physical paper (usually a physical magazine) and get away from screens and head for bed.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11152689]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2023-12-04 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (25 votes). Check out past polls.

    Notices?