-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Exprimental WASI support for ports/unix #13676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #13676 +/- ##
=======================================
Coverage 98.57% 98.57%
=======================================
Files 164 164
Lines 21349 21349
=======================================
Hits 21045 21045
Misses 304 304 ☔ View full report in Codecov by Sentry. |
ports/unix/mpconfigport.h
Outdated
@@ -154,8 +154,12 @@ typedef long mp_off_t; | |||
// Don't default sys.argv and sys.path because we do that in main. | |||
#define MICROPY_PY_SYS_PATH_ARGV_DEFAULTS (0) | |||
|
|||
#if defined(__wasi__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be done like
#ifndef MICROPY_PY_SYS_EXECUTABLE
#define MICROPY_PY_SYS_EXECUTABLE (1)
#endif
so it works generically, then make a separate mpconfigvariant_wasi.h where it gets set to 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
who would include mpconfigvariant_wasi.h?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be done automatically if you use make VARIANT=wasi
(though, my mistake, it should actually be unix/variants/wasi/mpconfigvariant.h). Likewise instead of build.sh you'd implement the specific makefile options in unix/variants/wasi/mpconfigvariant.mk. Check out the other variants for examples. Also I think to have any chance of merging this ulab should probably not be included unconditionally because this makes it harder to build out of the box; on the other hand if this only works with non-approved upstream wasi patches it's not super useful for others anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please make this a new variant. It should then be possible to build it via make VARIANT=wasi
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. i was not aware of the mechanism. thank you. let me try to adapt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I think to have any chance of merging this ulab should probably not be included unconditionally because this makes it harder to build out of the box; on the other hand if this only works with non-approved upstream wasi patches it's not super useful for others anyway.
sure.
wrt wasi patches, alternatively it's possible to put the setjmp/longjmp runtime within micropython itself. at least until when setjmp/longjmp gets ready in wasi. how do you think?
anyway, it won't be super useful until wasm EH is widely implemented in runtimes though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If building unix for wasi requires patches to wasi/binaryen then IMO this PR should stay as a draft until those patches are no longer needed. You could put the setjmp/longjmp code here, but I guess the other patches are still needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i adapted to use VARIANT. it simplify a lot. thank you.
i'm not sure what should be done for UNAME_S logic in Makefile though.
a build for WASI is actually a cross compile. but the existing CROSS_COMPILE seems geared to "arm-none-eabi-gcc" style cross toolchain, which doesn't seem suitable to wasi-sdk style cross toolchain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If building unix for wasi requires patches to wasi/binaryen then IMO this PR should stay as a draft until those patches are no longer needed. You could put the setjmp/longjmp code here, but I guess the other patches are still needed.
FYI, all toolchain patches have been merged in the upstream since then.
@@ -91,7 +91,11 @@ | |||
#define MICROPY_PY_OS_ERRNO (1) | |||
#define MICROPY_PY_OS_GETENV_PUTENV_UNSETENV (1) | |||
#define MICROPY_PY_OS_SEP (1) | |||
#if defined(__wasi__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comment as above: instead of modifying this variant it might be better to create it separately
See semi-related #11723, which gets |
af654be
to
31296b5
Compare
478f48d
to
ab9cc99
Compare
Code size report:
|
16efb82
to
b070ffc
Compare
b79d221
to
04ba2be
Compare
is there any TODO for this PR while waiting for LLVM 19? |
04c8cca
to
750c3a3
Compare
the last push is a conflict resolution |
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
VARIANT=wasi. Also remove hardcoded ulab. Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
Also, update comments. Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
To match the new name of the corresponding wasm-opt option. Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
Because it isn't too useful without network. This might be a bit controversial because actually you can use socket even with WASIp1 if you use one of non-standard runtime-specific mechanisms to create/pass an open socket. Anyway, it's easy to re-enable it if you want to use it. Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
Now WASI-SDK 25.0, which contains LLVM 19, has been released. Simplify the requirements by using it. Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
now wasi-sdk 25 has been released and this only requires released versions of the toolchain. |
the ci failure doesn't seem related to this PR.
|
FROZEN_MANIFEST ?= $(VARIANT_DIR)/manifest.py | ||
|
||
# WASI doesn't have FFI | ||
MICROPY_PY_FFI=0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have whitespace around the =
, likewise in rest of file
@@ -0,0 +1,28 @@ | |||
# Build for WASI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imo not needed to state the obvious.,
@@ -0,0 +1,3 @@ | |||
# include("$(PORT_DIR)/variants/manifest.py") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this file only has comments can it just be omitted?
#define HAS_SIGNAL 1 | ||
#endif | ||
|
||
#if HAS_SIGNAL != 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just #if HAS_SIGNAL
is good enough?
PROG=build-wasi/micropython | ||
|
||
# Unlike emscripten, WASI doesn't provide a way to scan GC roots | ||
# like WASM locals. Hopefully --spill-pointers can workaround it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try this with e.g. long-running scripts?
Apart from some cosmetic changes (see somments):
|
@stinos thank you for comments. i will take my time to digest. |
See comments in build-wasi.sh