Improve portability of building libprism#2171
Conversation
|
|
|
It looks like |
kddnewton
left a comment
There was a problem hiding this comment.
Thank you very much for your contributions here!
First, I think you are correct and we should enhance our build system. I've opened #2189 for context and tracking.
Second, thank you for finding the issue with our clang-analyzer and gcc-analyzer. I'll get those things fixed.
Third, I am fine with the inttypes.h change, that is great. As for the PRISM_NO_MEMORY_MAP macro, I was wondering if you could take the approach we had previously where if mmap(2) didn't exist we would instead malloc/free the associated memory by reading the file? You can see it was removed here: #1224. You can see how it was done in this file: https://github.com/ruby/prism/blob/f8a231e0acdd4f5b5f6deeef18ea877169ddc7bd/src/util/yp_string.c.
Do you have an example platform which is neither POSIX nor Windows? |
| <%# encoding: ASCII -%> | ||
| #include "prism/prettyprint.h" | ||
|
|
||
| #define __STDC_FORMAT_MACROS |
There was a problem hiding this comment.
I think this should move to https://github.com/ruby/prism/blob/main/include/prism/defines.h to ensure it's defined before any other system #include (otherwise these macros could be missing and the second include is noop).
I think it makes sense to also move the #include <inttypes.h> there.
He mentions this in |
|
Right, I see:
but that sounds like a processor/arch and doesn't tell me which operating system/libc it is, and why that would not have mmap. |
Lines 7 to 10 in f8a231e [edit] Sorry, I was wrong. It wouldn't work because some systems don't have only MMAP but also a filesystem. |
Systems without a filesystem cannot run CRuby and so cannot run the Prism test suite, so then it seems very hard/impossible to test if Prism works correctly there. On such systems, is read(2) not even declared in headers? Or does it fail at runtime? |
|
@eregon Arm Cortex-M0+ does not typically have a general purpose OS. It sometimes will have something like RTX or some other real-time operating system. picoruby supports compiling to these platforms using the standard C library, using a libc like glibc, Newlib or Newlib-nano. This information comes from the docs for the platform and runtime, respectively. You can learn more by reading them yourself. @hasumikin you shouldn't have to load the contents directly from a Ruby file. This should be enough to get you started: void parse(const uint8_t *source, size_t length) {
pm_parser_t parser;
pm_parser_init(&parser, source, length, NULL);
pm_node_t *root = pm_parse(&parser);
// do something here with root node
pm_node_destroy(&parser, root);
pm_parser_free(&parser);
}I'm happy to support a |
|
(Let me add some to Kevin's comment)
Yes, so the CORE implementation of mruby and PicoRuby doesn't depend on a filesystem.
No,
Generally, the compilation by gcc fails due to the lack of some functions.
Thanks, I could successfully compile my mruby/PicoRuby script on my Ubuntu :)
Glad to hear that!
(I mean this issue is kind of a decision of design including #2189 . So I think it would be better to have a meticulous discussion.) What do you say? |
|
@hasumikin yes, that makes sense. I've opened #2215 to take the |
|
I wonder if we can just check |
Background
I'm investigating the possibility of making a compiler for mruby and PicoRuby using Prism.
To do that, I think some additional considerations in the build process of libprism will be helpful.
Summary of the patch
PRISM_NO_MEMORY_MAPconstant macro to exclude the memory map interface such asmmap(2). This makes libprism more portable, especially for a non-POSIX platform<inttypes.h>and use their macros to cover format specifiers ofprintf()among various platforms. Without this, building libprism against 32bit architecture raises errors that look like the following: