Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

How to do a true cross compilation

by Joride (Initiate)
on Dec 18, 2021 at 16:16 UTC ( #11139704=perlquestion: print w/replies, xml ) Need Help??

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

Hi all, I've been scouring the web to understand Perl's build system, but I can't seem to find the info I am looking for. What I want to do: run a Perl-tool (exiftool by Phil Harvey to be exact) inside an iOS app. On macOS, I can create an app, spawn an new process that runs exiftool using C conventions or using Apple's NSTask, no problem. On iOS however, there is no system installed Perl, nor is it possible to install it (unless jailbroken, but I am not going there). So, no big deal, I read about perlembed (https://perldoc.perl.org/perlembed), and I thought that looks exactly like what I need so let's get it done. But! As I understand, 'cross compiling' Perl means the following, using some custom autotools configure settings: 1. build 'miniperl' in the target architecture (in my case, for iOS that would be arm64 for devices, and arm64 or x86_64 for the simulator that runs on macOS) 2 Miniperl will build the actual library (.a file), and is expected to do so on the target device . This last step is problemematic: on iOS there is no toolchain present, and no way to SSH into it and run miniperl. So, the challenge: how to compile Perl for arm64 (for iOS devices), and x86_64 / arm64 (for Intel or M1 macOS devices respectively, running the simulator), on macOS without SSH (or any other) access to the target machine for building?

Replies are listed 'Best First'.
Re: How to do a true cross compilation
by talexb (Chancellor) on Dec 18, 2021 at 17:07 UTC
      But! As I understand, 'cross compiling' Perl means the following, using some custom autotools configure settings: 1. build 'miniperl' in the target architecture (in my case, for iOS that would be arm64 for devices, and arm64 or x86_64 for the simulator that runs on macOS) 2 Miniperl will build the actual library (.a file), and is expected to do so on the target device.

    I believe your understanding of cross-compiling is flawed. What it actually means is that you compile code for a target that's different than the native architecture. For example, I wrote C on a VAX 11/780 that was cross-compiled to 68000 assembler, and then downloaded to the target system (yeah, OK, it was the early 80's).

    If you're compiling on the local system for use on that system .. that's not cross-compiling.

    I imagine that there are tools that will cross-compile for iOS on other architectures -- then all you need to do is to load that executable on the target system, possibly by creating an iOS app. I don't actually know about any of this -- I'm just hand-waving at this point.

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

      I see what you are saying Alex, thank you for your quick response. Your description of cross compiling matches my understanding (but I can see how my write up could have been more clear). However, my understanding of Perl's way of 'cross compiling' is different, and consists of 2 steps: First, build something called 'miniperl'. This miniperl is then supposed to be transferred to the target machine, where miniperl will then build actual Perl. Of course, in your explanation, only the first step would be cross-compiling: building on macos (x86_64) for a machine (iPhone) running arm64. So I am hoping there is a way to cross-compile Perl in the way you described, without having to transfer minperl (or any access at all before building) to the target machine/system. And maybe my understanding of Perl-specific cross compilation is flawed of incomplete too, I found quite some information on the topic, but mostly not in agreement with each other.
Re: How to do a true cross compilation
by Anonymous Monk on Dec 18, 2021 at 20:11 UTC
      I had not seen that piece of information yet, thank you for sharing. In the linked documentation, it says "Configure understands -Dusecrosscompile option. This option arranges for building miniperl for TARGET machine, so this miniperl is assumed then to be copied to TARGET machine and used as a replacement of full perl executable. "
      Do I understand correctly, that 'miniperl' is an actual Perl build that I can use to run Perl scripts? Or, is 'miniperl' an intermediate step in compiling, and miniperl's only goal in life is to build an actual Perl exectuable?
      In the former case, I 'only' have to get miniperl to be built in the target architecture (in my case arm64 or x86_64, as I am planning on embedding into iOS), right?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2022-06-29 12:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (96 votes). Check out past polls.

    Notices?