Add support for logging in SwiftWasm (via WASILibc)#177
Add support for logging in SwiftWasm (via WASILibc)#177ktoso merged 9 commits intoapple:mainfrom helje5:features/hh-wasm-1
WASILibc)#177Conversation
There is no threading on WASI (yet? ever?).
The WASILibc doesn't provide much C yet, apparently. Not even FILE.
WASILibc doesn't have stdio, e.g. no `FILE`. But it does have `print`, so let's just use that instead for both, regular and error logging.
WASILibc doesn't have `strftime`, but it does come w/ a working `DateFormatter`/`Date`. Use that instead.
Instead do not compile the locks on WASILibc and comment them out on the calling site.
|
Can one of the admins verify this patch? |
5 similar comments
|
Can one of the admins verify this patch? |
|
Can one of the admins verify this patch? |
|
Can one of the admins verify this patch? |
|
Can one of the admins verify this patch? |
|
Can one of the admins verify this patch? |
|
@swift-server-bot test this please |
weissi
left a comment
There was a problem hiding this comment.
I'm mostly happy with this but it does seem to add a Foundation dependency.
|
OK, lets put that on hold. Of course I tried w/ importing WASILibc first (obviously). As mentioned it didn't carry either If those do work, 95% of my modifications do not make any sense. |
Not sure what went wrong in my first try.
|
|
For WASI the Lock is not used at all, drop the local modifications I had in place before.
As per swiftwasm/swift#2480 (comment) `FILE` is not available in SwiftWasm, but `stdio` is. FILE pointers are exposed as OpaquePointer's in that environment. Also import the whole libc, like it is done with the other runtimes.
|
OK, I had another look at this, this is much simpler now:
I didn't do the This should be worth another review, I tried it and it works w/ the SwiftWasm 5.3.1 toolchain. |
|
@swift-server-bot test this please |
|
@swift-server-bot add to allowlist |
You can do |
Yes, but do you really want to add that much |
fine by me |
|
@MaxDesiatov Is this good now from your perspective? (if so, please mark things as resolved so that the PR can be merged) |
|
// Had some ancient review comment from the time of the initial commit still there; deleted, ignore that :) |
This is a port of Logging to the SwiftWasm
WASILibc.Motivation:
I'd like to log things in Wasm as well.
Modifications:
import Glibcas a fallback (you might want to consider to move tocanImport). Added additional checks forWASILibcand emit an#errorwhen no known runtime is available.WASILibc(well, WASI) doesn't support threading and hence locks.#ifguarded the Locks.swift file to not build the Lock classes w/ WASILibc. Then adjust the few invocations on the callsites to not use locks on WASILibc.WASILibcdoesn't have stdio, but it does have Foundationprint. Defines aTextOutputStreamusing that when on WASILibc, and do not use the Stdio variant. (implies using the same stream for both stdout/err)WASILibcdoesn't havestrftime, but it does have a working FoundationDateFormatter/Date. Use that instead of timestamp formatting.Result:
swift-log can be used in Wasm environments.
Source: