tbox
tbox copied to clipboard
WASM: file system support
Is your feature request related to a problem? Please describe.
We are using tbox to implement the file system related API in lolly: https://github.com/XmacsLabs/lolly/blob/main/System/Files/file.cpp
And we find the APIs are not working as expected on WASM.
Describe the solution you'd like
In https://emscripten.org/docs/porting/files/file_systems_overview.html:
Emscripten provides a virtual file system that simulates the local file system, so that native code using synchronous file APIs can be compiled and run with little or no change.
I guess if we implement it in posix api, it should work fine.
The only thing we need to do is to tune the macros in tbox (I guess).
And here is a list of routines we are using and I will try to make it work on wasm:
- [ ] tb_file_info
- [ ] tb_file_access
- [ ] tb_directory_current
- ...
Describe alternatives you've considered
None
Additional context
None
I guess it is related to https://github.com/xmake-io/xmake/issues/4173, if I set the emcc toolchain proper, it should work!
If I run xmake config -p wasm
without setting the PATH for emcc, TB_CONFIG_POSIX_HAVE_OPEN will not be defined.
/* #undef TB_CONFIG_POSIX_HAVE_OPEN */
Using an elvish script like below:
#!/usr/bin/env elvish
xrepo install -y "emscripten 3.1.42"
var pkg_info = (xrepo fetch --json emscripten | from-json)
var emsdk_path = $pkg_info[0][artifacts][installdir]
set-env EMSDK $emsdk_path
xmake config --yes -p wasm -vD
If we set the EMSDK environment variable, TB_CONFIG_POSIX_HAVE_OPEN
will be defined.
And the behavior of the related API still need to be checked!
And checked the tbox.config.h
in xrepo, TB_CONFIG_POSIX_HAVE_OPEN
is not defined.
这是因为 tbox 默认用的也是全局的 configvar_check_cfuncs,而 wasm 新加的 target 粒度 toolchain 绑定,暂时我也没空改成 target 粒度 check 。。
你可以走 xmake f -p wasm --sdk=/wasm/sdk
全局切 emcc sdk,走全局检测去编译 tbox ,就行了
Bot detected the issue body's language is not English, translate it automatically.
This is because tbox also uses the global configvar_check_cfuncs by default, and wasm’s newly added target granularity toolchain binding, I have no time to change to target granularity check for the time being. .
You can run xmake f -p wasm --sdk=/wasm/sdk
to globally switch to emcc sdk, and run global detection to compile tbox, and that's it.
等这个 patch https://github.com/tboox/tbox/pull/235
初步可以了,先试试 check 分支
Bot detected the issue body's language is not English, translate it automatically.
It's okay initially, try the check branch first