You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

283 lines
8.7 KiB

<h1 id="portability">Portability</h1>
<h2>Platforms and compilers</h2>
<p>The table below summarizes the platforms and compilers which Duktape is known
to work on, with portability notes where appropriate. This is <b>not an exhaustive
list</b> of supported/unsupported platforms, rather a list of what is known to work
(and not to work). Platform and compiler specific issues are discussed in more
detail below the table.</p>
<table>
<thead>
<tr>
<th>Operating system</th>
<th>Compiler</th>
<th>Processor</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<tr>
<td>Linux</td>
<td>GCC</td>
<td>x86</td>
<td>No known issues.</td>
</tr>
<tr>
<td>Linux</td>
<td>GCC</td>
<td>x64</td>
<td>No known issues.</td>
</tr>
<tr>
<td>Linux</td>
<td>GCC</td>
<td>ARM</td>
<td>No known issues.</td>
</tr>
<tr>
<td>Linux</td>
<td>GCC</td>
<td>MIPS</td>
<td>No known issues.</td>
</tr>
<tr>
<td>Linux</td>
<td>Clang</td>
<td>x86</td>
<td>No known issues.</td>
</tr>
<tr>
<td>Linux</td>
<td>Clang</td>
<td>x64</td>
<td>No known issues.</td>
</tr>
<tr>
<td>Linux</td>
<td>Clang</td>
<td>ARM</td>
<td>No known issues.</td>
</tr>
<tr>
<td>Linux</td>
<td>Clang</td>
<td>MIPS</td>
<td>No known issues.</td>
</tr>
<tr>
<td>Linux</td>
<td>TCC</td>
<td>x64</td>
<td>Zero sign issues (see below).</td>
</tr>
<tr>
<td>FreeBSD</td>
<td>Clang</td>
<td>x86</td>
<td>Aliasing issues with clang 3.3 on 64-bit FreeBSD, <code>-m32</code>, and packed <code>duk_tval</code> (see below).</td>
</tr>
<tr>
<td>FreeBSD</td>
<td>Clang</td>
<td>x64</td>
<td>No known issues.</td>
</tr>
<tr>
<td>NetBSD</td>
<td>GCC</td>
<td>x86</td>
<td>No known issues (NetBSD 6.0). There are some <code>pow()</code> function incompatibilities on NetBSD, but
there is a workaround for them.</td>
</tr>
<tr>
<td>OpenBSD</td>
<td>GCC</td>
<td>x86</td>
<td>No known issues (FreeBSD 5.4).</td>
</tr>
<tr>
<td>Windows</td>
<td>MinGW</td>
<td>x86</td>
<td><code>-std=c99</code> recommended, only ISO 8601 date format supported (no platform specific format).</td>
</tr>
<tr>
<td>Windows</td>
<td>MinGW-w64</td>
<td>x64</td>
<td><code>-m64</code>, <code>-std=c99</code> recommended, only ISO 8601 date format supported (no platform specific format).</td>
</tr>
<tr>
<td>Windows</td>
<td>MSVC<br />(Visual Studio Express 2010)</td>
<td>x86</td>
<td>Only ISO 8601 date format supported (no platform specific format).</td>
</tr>
<tr>
<td>Windows</td>
<td>MSVC<br />(Visual Studio Express 2013 for Windows Desktop)</td>
<td>x64</td>
<td>Only ISO 8601 date format supported (no platform specific format).</td>
</tr>
<tr>
<td>Android</td>
<td>GCC<br />(Android NDK)</td>
<td>ARM</td>
<td>No known issues.</td>
</tr>
<tr>
11 years ago
<td>OSX</td>
<td>Clang</td>
<td>x64</td>
<td>Tested on OSX 10.9.2 with XCode.</td>
</tr>
<tr>
<td>Darwin</td>
<td>GCC</td>
<td>x86</td>
<td>No known issues.</td>
</tr>
<tr>
<td>QNX</td>
<td>GCC</td>
<td>x86</td>
<td><code>-std=c99</code> recommended. Architectures other than x86 should also work.</td>
</tr>
<tr>
<td>AmigaOS</td>
<td>VBCC</td>
<td>M68K</td>
<td>Requires some preprocessor defines, datetime resolution limited to full seconds.</td>
</tr>
<tr>
<td>TOS<br />(Atari ST)</td>
<td>VBCC</td>
<td>M68K</td>
<td>Requires some preprocessor defines, datetime resolution limited to full seconds.</td>
</tr>
<tr>
<td>Emscripten</td>
<td>Emscripten</td>
<td>n/a</td>
<td>Requires additional options, see below. At least V8/NodeJs works.</td>
<tr>
<td>Adobe Flash Runtime</td>
<td>CrossBridge<br />(GCC-4.2 with Flash backend)</td>
<td>n/a</td>
<td><code>-std=c99</code> recommended, may need <code>-jvmopt=-Xmx1G</code> if running
32-bit Java. Tested with <a href="http://adobe-flash.github.io/crossbridge/">CrossBridge</a>
1.0.1 on 64-bit Windows 7.</td>
</tr>
</tbody>
</table>
<h3>Clang</h3>
<p>Clang 3.3 on FreeBSD has some aliasing issues (at least) when using
<code>-m32</code> and when Duktape ends up using a packed <code>duk_tval</code>
value representation type. You can work around the problem by defining
<code>DUK_OPT_NO_PACKED_TVAL</code> to disable packed value type. The
problem does not appear in all clang versions. Duktape self tests cover
this issue (define <code>DUK_OPT_SELF_TESTS</code> when compiling).
See internal test file <code>misc/clang_aliasing.c</code>.</p>
<h3>TCC</h3>
<p>TCC has zero sign handling issues; Duktape mostly works but zero sign is
not handled correctly. This results in Ecmascript non-compliance, for
instance <code>1/-0</code> evaluates to <code>Infinity</code>, not <code>-Infinity</code>
as it should.</p>
<h3>VBCC (AmigaOS / TOS)</h3>
<p>VBCC doesn't appear to provide OS or processor defines. To compile for
M68K AmigaOS or TOS you must:</p>
<ul>
<li>Define <code>__MC68K__</code> manually.</li>
<li>Define either <code>AMIGA</code> or <code>__TOS__</code> manually.</li>
</ul>
<p>Datetime resolution is limited to full seconds only when using VBCC on
AmigaOS or TOS.</p>
<h3>Emscripten</h3>
<p>Needs a set of <code>emcc</code> options. When executed with
V8, the following seem to work:</p>
<ul>
<li><code>-DEMSCRIPTEN</code>: <b>mandatory option</b>, needed by Duktape
to detect Emscripten. Without this Duktape may use unaligned accesses
which Emscripten does not allow. This results in odd and inconsistent
behavior, and is not necessarily caught by Duktape self tests.</li>
<li><code>-std=c99</code></li>
<li><code>-O2</code></li>
<li><code>-s ASM_JS=0</code></li>
<li><code>-s MAX_SETJMPS=1000</code></li>
<li><code>-s OUTLINING_LIMIT=20000</li>
</ul>
<p>Dukweb is compiled using Emscripten, so you can also check out the Duktape
git repository to see how Dukweb is compiled.</p>
<h2>Using Duktape from a C++ program</h2>
<p>To use Duktape from a C++ program, simply compile Duktape in plain C and use
<code>duktape.h</code> normally in your C++ program; <code>duktape.h</code>
contains the necessary glue to make this work. Specifically, it contains
<code>extern "C" { ... }</code> to avoid name mangling issues.</p>
<p>Currently Duktape itself cannot be compiled in C++ mode. This is under
work but is not a trivial issue because many of the compiler defines and
headers are different (especially for pre C99/C++11).</p>
<h2>Limitations</h2>
<ul>
<li>The <code>int</code> type is assumed to be at least 32 bits. This is
incorrect even on some platforms which provide a 32-bit type.</li>
<li>Pointer less-than/greater-than comparisons are expected to work like
pointers were unsigned. This is incorrect on some platforms.</li>
<li>On platforms requiring aligned accesses, Duktape guarantees 4-byte
alignment. In particular, 64-bit integers and IEEE double values are
not guaranteed to be 8-byte aligned. This is not always correct.</li>
</ul>
<h2>Troubleshooting</h2>
<ul>
<li>Compile in C mode if possible. Although C++ compilation now works,
it isn't as portable as C compilation.</li>
<li>Enable C99 mode if possible (<code>-std=c99</code> or similar). Type
detection without C99 is less reliable than with C99.</li>
<li>If Duktape compiles but doesn't seem to work correctly, enable
self tests with <code>DUK_OPT_SELF_TESTS</code>. Self tests
detect some compiler and platform issues which cannot be caught
compile time.</li>
<li>If the target platform has specific alignment requirements and Duktape
doesn't autodetect the platform correctly, you may need to provide
either <code>DUK_OPT_FORCE_ALIGN=4</code> or <code>DUK_OPT_FORCE_ALIGN=8</code>.
The alignment number should match whatever alignment is needed for IEEE
doubles and 64-bit integer values.</li>
<li>If compilation fails in endianness detection, Duktape probably doesn't
(yet) support the platform specific endianness headers of your platform.
Such headers are unfortunately non-standardized, so endianness detection
is a common (and usually trivial) portability issue on custom platforms.
Use <code>DUK_OPT_FORCE_BYTEORDER</code> to force endianness as a workaround.
If you know how the endianness detection should work on your platform,
please send an e-mail about the issue or contribute a patch.</li>
<li>Another typical portability issue on new platforms is the Date built-in,
which requires a few platform specific functions for dealing with date and
time. Often existing Date functions are sufficient but platform detection
in <code>duk_features.h</code> does not yet handle the target platform
correctly. This is usually trivial to fix; please contribute a patch if
you do so. At other times the platform has no standard time APIs (like
POSIX). In this case you'll need to add a few platform specific Date
functions into <code>duk_bi_date.c</code>, and implement platform detection
into <code>duk_features.h</code>; again, please contribute a patch if you
do so. You can look at <code>duk_bi_date.c</code> for POSIX and Windows
Date API examples.</li>
</ul>