danielhstahl / black_scholes_rust

Rust for black scholes
https://danielhstahl.github.io/black_scholes_rust/dev/bench/
23 stars 8 forks source link

WASM support #23

Closed mcdallas closed 1 year ago

mcdallas commented 1 year ago

building for the wasm32-unknown-unknown target I get the following error

cargo build --target wasm32-unknown-unknown                                             
  Downloaded serde_derive v1.0.148
  Downloaded serde v1.0.148
  Downloaded syn v1.0.104
  Downloaded 3 crates (368.9 KB) in 1.11s
   Compiling autocfg v1.1.0
   Compiling proc-macro2 v1.0.47
   Compiling unicode-ident v1.0.5
   Compiling quote v1.0.21
   Compiling syn v1.0.104
   Compiling serde_derive v1.0.148
   Compiling libc v0.2.137
   Compiling serde v1.0.148
   Compiling num-traits v0.2.15
   Compiling num-integer v0.1.45
   Compiling num-bigint v0.2.6
   Compiling num-complex v0.2.4
   Compiling num-rational v0.2.4
   Compiling num-iter v0.1.43
   Compiling special v0.8.1
error[E0432]: unresolved imports `libc::c_double`, `libc::c_int`
 --> /Users/mike/.cargo/registry/src/github.com-1ecc6299db9ec823/special-0.8.1/src/math.rs:3:12
  |
3 | use libc::{c_double, c_int};
  |            ^^^^^^^^  ^^^^^ no `c_int` in the root
  |            |
  |            no `c_double` in the root

error[E0425]: cannot find function `lgamma` in module `math`
   --> /Users/mike/.cargo/registry/src/github.com-1ecc6299db9ec823/special-0.8.1/src/gamma.rs:205:36
    |
205 |         let value = unsafe { math::lgamma(self as f64, &mut sign) as Self };
    |                                    ^^^^^^ help: a function with a similar name exists: `tgamma`
...
246 | implement!(f32);
    | --------------- in this macro invocation
    |
   ::: /Users/mike/.cargo/registry/src/github.com-1ecc6299db9ec823/special-0.8.1/src/math.rs:8:5
    |
8   |     pub fn tgamma(x: c_double) -> c_double;
    |     --------------------------------------- similarly named function `tgamma` defined here
    |
    = note: this error originates in the macro `implement` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0425]: cannot find function `lgamma` in module `math`
   --> /Users/mike/.cargo/registry/src/github.com-1ecc6299db9ec823/special-0.8.1/src/gamma.rs:205:36
    |
205 |         let value = unsafe { math::lgamma(self as f64, &mut sign) as Self };
    |                                    ^^^^^^ help: a function with a similar name exists: `tgamma`
...
247 | implement!(f64);
    | --------------- in this macro invocation
    |
   ::: /Users/mike/.cargo/registry/src/github.com-1ecc6299db9ec823/special-0.8.1/src/math.rs:8:5
    |
8   |     pub fn tgamma(x: c_double) -> c_double;
    |     --------------------------------------- similarly named function `tgamma` defined here
    |
    = note: this error originates in the macro `implement` (in Nightly builds, run with -Z macro-backtrace for more info)

Some errors have detailed explanations: E0425, E0432.
For more information about an error, try `rustc --explain E0425`.
error: could not compile `special` due to 3 previous errors
warning: build failed, waiting for other jobs to finish...

which comes from the special = 0.8 dependency. This dependency is used in one function call here https://github.com/danielhstahl/black_scholes_rust/blob/d68fc55355cbedf7bf9b1db580287b43dec4629d/src/lib.rs#L8 and simply removing the .error() the library compiles fine.

I am wondering how critical this dependency is and maybe we could get rid of it or at least but it behind a feature flag

danielhstahl commented 1 year ago

This should be fixed, see https://github.com/danielhstahl/black_scholes_rust/actions/runs/3579683114/jobs/6021116491.

mcdallas commented 1 year ago

Awesome, thanks for the quick response 🙏