Support wasm-targets
Currently, the library, unfortunately, does not support wasm
(Web Assembly) targets for the following issues:
-
For building the library it is also necessary to compile
atty
,clap
, andliner
(which cannot be compiled for wasm rn) and which are not actually required for the library -
The
decimal
andnum
dependencies both depend onrustc-serialize
which cannot be built for wasm targets
Possible solutions
-
This one is trivial: Just declare
atty
,clap
, andliner
as optional dependencies required only for the binary. I implemented this in the following patch: BafDyce/calc@c93cabb0 (Note that this now requires one to runcargo build --bin calc --features=binary
to build the cli application) -
This is a bit harder, especially since
calc
relies quite heavily on BigInts. For now, I based my work on a relatively old commit (right before calc switched to BigInts) and applied a patch to only use stdlib data types (removing thedecimal
andnum
dependencies). You can see that patch here: BafDyce/calc@45e2e587 (Note that this is quite an ugly (imo) hack, is almost untested, and probably only works for "small" numbers)
If you're interested, I would be more than happy to provide a MR (against the latest master) for number 1 and also for the second patch (maybe you are interested in supporting a wasm
-branch?). Maybe it would be even possible to support wasm-targets without using an outdated + hacked version of calc
?
PS: I applied both of my patches in a wasm-branch on my fork: https://gitlab.redox-os.org/BafDyce/calc/commits/wasm