Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, I'm interested in extending the functionality of dbase-rs to make it runnable on the web. My use case is that I'm working on a hobby project that targets the web and needs to be able to read in shapefiles, which is a multifile format with a dbase component. Would you be happy to accept a PR enabling this?
Below is a more involved explanation of what this PR attempts to achieve. I don't have much knowledge in this domain so I might have made some mistakes. I've included some links for reference.
Running dbase-rs on the web can be achieved with WebAssembly but there seem to be 2 different compilation targets, neither of which target the web specifically:
wasm32-unknown-unknown
wasm32-wasi
/wasm32-wasip2
The former does not make any assumptions about the platform it will run on, and since dbase works with files it does not seem like the best fit. However, one could still use web_sys::File or similar to make it work on web.
The latter target assumes the target platform will provide the WebAssembly System Interface which includes a filesystem api. If my understanding is correct, this implies that dbase and std in general should work more or less out of the box. The WASI spec is still in the works and is not yet implemented by any browser, but there is a polyfill that makes wasi components executable on the web. One can also run them in a vm using a wasm runtime like wasmtime.
In this PR I've made some adjustments to make dbase-rs build on
wasm32-wasip2
as it seemed like the simpler and cleaner option.The only block preventing it from building was
std::fs::File::try_clone
. I've followed a workaround I found im some other repositories [1], [2] which is essentially to wrapstd::fs::File
in anArc
.The filesystem api was added in WASI preview 2, which has only recently been stabilised and added as a rustc tier 3 target. As a result rustup does not yet support it, but there is a cargo-component tool that translates binaries built for
wasm32-wasip1
intowasm32-wasip2
components.To test out whether this PR works, I've installed both cargo-component and wasmtime, and have managed to get the two dbase examples to run:
The above will
wasm32-wasip1
targetwasm-wasip1
binary into awasm-wasip2
component