duktape icon indicating copy to clipboard operation
duktape copied to clipboard

[docs] Add a note on website and docs that duktape requires an OS to run

Open alexhutcheson opened this issue 4 years ago • 2 comments

I found duktape.org while I was looking for a Javascript interpreter that could run on a microcontroller. It took me a couple minutes of digging to find https://wiki.duktape.org/portability and https://wiki.duktape.org/howtobaremetal, and the details there still left me a bit confused over exactly what the minimum system requirements (e.g. compiler standard, MMU, RTOS vs. bare metal) would be to run duktape on a microcontroller.

It would be nice if this were more explicit and obvious. Embedded developers are often looking for the "checklist" of specific libraries/features/etc. to determine whether a library will run on the specific chip they are using, and right now that is difficult to piece together. I would suggest the following changes:

  • Add a list item to "Main features" on the home page that says something like "Works on a wide range of operating systems, compilers, and architectures", with a link to https://wiki.duktape.org/portability.
  • Add a "bare metal" section to https://wiki.duktape.org/portability, with a link to https://wiki.duktape.org/howtobaremetal and a list of bare metal platform/libc/compiler combinations that have been successfully tested.
  • Add a note to both https://wiki.duktape.org/portability and https://wiki.duktape.org/howtobaremetal detailing whether a RTOS is a requirement, or whether it's possible to embed duktape in a bare-metal microcontroller program with no RTOS.
  • Add a "System requirements" section near the top of https://duktape.org/guide.html, which lists what the system would need to run duktape (e.g. a C99 compiler, a libc that supports X, Y, and Z APIs/standards), along with links to https://wiki.duktape.org/portability and https://wiki.duktape.org/howtobaremetal as necessary.

These are just suggestions, and there would be other ways to present this information.

alexhutcheson avatar Jan 19 '21 14:01 alexhutcheson

I agree the documentation is scattered and could be improved. The main requirements are:

  • C89 compiler, C99 preferred
  • A custom allocator, or fall back to malloc(), free(), realloc()
  • A small set of standard library functions like setjmp(), longjmp(), s(n)printf(); I don't have an exact list at hand (this should be in the check list)
  • Exact IEEE double (and single) math, and math functions; again I don't have an exact list but things like fmod(), fabs(), floor(), ceil(), sin(), cos(), etc
  • Working integer/double casts (unfortunately not always a given)
  • Something to provide current date and time (this often needs manual replacement)

All these are provided via duk_config.h wrappers, e.g. no direct calls to any of the standard library functions are made. So the providers don't need to be from platform libraries themselves. For example, if something is broken in the platform libraries, you don't necessarily need to fix the platform but can just work around the specific dependency (e.g. replace a broken fmod() with a working one called my_fixed_fmod).

Because no dependencies should go around duk_config.h you can also get a sense what is expected of the platform by looking at what gets defined.

svaarala avatar Jan 19 '21 21:01 svaarala

I think, it is pretty easy to impement Duktape. It does not need to run under any OS, or RTOS, but it augments it a lot. Although I have to add, that it is not something that is terribly fast (which embedded JS should not be), but it runs.

I'm running it on my ESP32, 2cores, 1 core only runs Duktape, everything else runs on the other core.

VaderMester avatar Jan 22 '21 17:01 VaderMester