Cross compilation: Difference between revisions

From Rosetta Code
Content added Content deleted
m (sp)
m (→‎{{header|Phix}}: sp, more)
Line 14: Line 14:
The compiler tries hard to avoid emitting unnecessary binary, which is likely to be more successful when those routines are used as plainly as possible, without any and/or parts to the conditional. Likewise #ilASM{} aka inline assembly can contain guards
The compiler tries hard to avoid emitting unnecessary binary, which is likely to be more successful when those routines are used as plainly as possible, without any and/or parts to the conditional. Likewise #ilASM{} aka inline assembly can contain guards
such as [32] to emit (only) the relevant code for different target architectures, see
such as [32] to emit (only) the relevant code for different target architectures, see
[[Conditional_structures#ilASM]] and [[Pragmatic_directives#Phix]] for more details and examples.
[[Conditional_structures#ilASM]] and [[Pragmatic_directives#Phix]] for more.


The requires() routine can help ensure time is not needlessly wasted trying to get things to work on
The requires() routine can help ensure time is not needlessly wasted trying to get things to work on
platform(s) where it currently simply does not.
platform(s) where it currently simply does not.


Lastly, pwa.p2js can be used to transpile Phix code to Javascript for running in a web browser, with the
Lastly, pwa/p2js can be used to transpile Phix code to Javascript for running in a web browser, with the
compiler directive "with javascript_semantics" explicitly stating that is possible, and the "without"
compiler directive "with javascript_semantics" explicitly stating that is possible, and the "without"
variant explicitly blocking it, with similar implications as requires().
variant explicitly blocking it, with similar implications as requires().

Revision as of 09:33, 26 June 2022

Cross compilation is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Explain the process of creating, for example, a Linux executable binary on a Windows machine, and vice versa.
Include details of any and all compilation and runtime options for incorporating platform-specific elements.
If your language cannot create executable files or is not cross-platform it should be omitted from this task.

Phix

A simple format directive in the source allows for easy cross-compilation to any other supported system, for instance the Linux binaries of Phix are always compiled on Windows by throwing the following at "p -c -norun p32.exu" (with a similar p64.exu for 64bit, and formats PE32 and PE64 for the reverse trick):

format ELF32
include p.exw

The platform() and machine_bits() builtins can be explictly used as runtime tests to vary code by platform. The compiler tries hard to avoid emitting unnecessary binary, which is likely to be more successful when those routines are used as plainly as possible, without any and/or parts to the conditional. Likewise #ilASM{} aka inline assembly can contain guards such as [32] to emit (only) the relevant code for different target architectures, see Conditional_structures#ilASM and Pragmatic_directives#Phix for more.

The requires() routine can help ensure time is not needlessly wasted trying to get things to work on platform(s) where it currently simply does not.

Lastly, pwa/p2js can be used to transpile Phix code to Javascript for running in a web browser, with the compiler directive "with javascript_semantics" explicitly stating that is possible, and the "without" variant explicitly blocking it, with similar implications as requires(). The former also triggers runtime errors on desktop/Phix should incompatible operations be attempted, most notably use of copy-on-write semantics, and hence effectively Javascript's pass by sharing, and also populates rosettacode with the otherwise hidden tags "(phixonline)" when javascript compatible and "(notonline)" when not, the results of searching for which can be seen here and here respectively.