Skip to content

wasm-pack libc error #121

@DevinBayly

Description

@DevinBayly

Hi there,

I understand that it's not exactly the aim of this package, but I'm trying to do linear algebra in the browser with a ndarray web assembly module. When I use wasm-pack build workflow to run the factorize examples I get a number of libc related errors that aren't present in the standard system build. What's strange (or not at all) is that the rest of the ndarray crate lends itself nicely to wasm conversion.

If you have a second, could you briefly glance over these errors, and help me determine whether there's any workaround? I'd love to be able to use the developing ndarray-linalg crate to handle the transformation, and factorization needs that folks may have.

If this is way out of the scope of your tool, then feel free to pass on this issue. Thanks!

//lib.rs
extern crate cfg_if;
extern crate wasm_bindgen;

mod utils;

use cfg_if::cfg_if;
use wasm_bindgen::prelude::*;

cfg_if! {
    // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
    // allocator.
    if #[cfg(feature = "wee_alloc")] {
        extern crate wee_alloc;
        #[global_allocator]
        static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
    }
}

extern crate ndarray;
extern crate ndarray_linalg;

use ndarray::*;
use ndarray_linalg::*;

// Solve `Ax=b`
fn solve() -> Result<(), error::LinalgError> {
    let a: Array2<f64> = random((3, 3));
    let b: Array1<f64> = random(3);
    let _x = a.solve(&b)?;
    println!("in solve {:?}",_x);
    Ok(())
}

// Solve `Ax=b` for many b with fixed A
fn factorize() -> Result<String, error::LinalgError> {
    let a: Array2<f64> = random((3, 3));
    let f = a.factorize_into()?; // LU factorize A (A is consumed)
    let mut ret_string = String::new();
    for _ in 0..10 {
        let b: Array1<f64> = random(3);
        let _x = f.solve_into(b)?; // solve Ax=b using factorized L, U
        ret_string += format!("in factorize {:?}",_x);
    }
    Ok(ret_string)
}

#[wasm_bindgen]
extern {
    fn alert(s: &str);
}

#[wasm_bindgen]
pub fn greet() -> String {
    match factorize() {
        Ok(st) => st,
        Err(e) => format!("broke something")
    }
}

//cargo.toml
[package]
name = "test-linalgwasm"
version = "0.1.0"
authors = [""]

[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = ["console_error_panic_hook"]

[dependencies]
cfg-if = "0.1.2"
ndarray= "0.12"
ndarray-linalg = { version = "0.10", features = ["openblas"] }
wasm-bindgen = "0.2"

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.1", optional = true }

# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
# compared to the default allocator's ~10K. It is slower than the default
# allocator, however.
#
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
wee_alloc = { version = "0.4.2", optional = true }

[dev-dependencies]
wasm-bindgen-test = "0.2"

[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s

build error


  [1/9] Checking `rustc` version...
  [2/9] Checking crate configuration...
  [3/9] Adding WASM target...
  info: component 'rust-std' for target 'wasm32-unknown-unknown' is up to date
  [4/9] Compiling to WASM...
      Updating crates.io index
     Compiling proc-macro2 v0.4.23
     Compiling unicode-xid v0.1.0
     Compiling wasm-bindgen-shared v0.2.28
     Compiling cfg-if v0.1.6
     Compiling num-traits v0.2.6
     Compiling lazy_static v1.2.0
     Compiling openblas-src v0.6.1
     Compiling matrixmultiply v0.1.15
     Compiling num-complex v0.2.1
     Compiling rawpointer v0.1.0
     Compiling ndarray v0.12.0
     Compiling libc v0.2.43
     Compiling rand_core v0.3.0
     Compiling either v1.5.0
     Compiling wasm-bindgen v0.2.28
     Compiling log v0.4.6
     Compiling cblas-sys v0.1.4
     Compiling lapacke-sys v0.1.4
  error[E0432]: unresolved imports `libc::c_char`, `libc::c_double`, `libc::c_float`, `libc::c_int`
    --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/cblas-sys-0.1.4/src/lib.rs:13:12
     |
  13 | use libc::{c_char, c_double, c_float, c_int};
     |            ^^^^^^  ^^^^^^^^  ^^^^^^^  ^^^^^ no `c_int` in the root
     |            |       |         |
     |            |       |         no `c_float` in the root
     |            |       no `c_double` in the root
     |            no `c_char` in the root
  
  error[E0412]: cannot find type `c_double` in module `libc`
    --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/cblas-sys-0.1.4/src/lib.rs:17:36
     |
  17 | pub type c_double_complex = [libc::c_double; 2];
     |                                    ^^^^^^^^ not found in `libc`
  
  error[E0412]: cannot find type `c_float` in module `libc`
    --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/cblas-sys-0.1.4/src/lib.rs:21:35
     |
  21 | pub type c_float_complex = [libc::c_float; 2];
     |                                   ^^^^^^^ not found in `libc`
  
  error: aborting due to 3 previous errors
  
  Some errors occurred: E0412, E0432.
  For more information about an error, try `rustc --explain E0412`.
  error: Could not compile `cblas-sys`.
  warning: build failed, waiting for other jobs to finish...
  error[E0432]: unresolved imports `libc::c_char`, `libc::c_double`, `libc::c_float`, `libc::c_int`
    --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/lapacke-sys-0.1.4/src/lib.rs:13:12
     |
  13 | use libc::{c_char, c_double, c_float, c_int};
     |            ^^^^^^  ^^^^^^^^  ^^^^^^^  ^^^^^ no `c_int` in the root
     |            |       |         |
     |            |       |         no `c_float` in the root
     |            |       no `c_double` in the root
     |            no `c_char` in the root
  
  error[E0412]: cannot find type `c_double` in module `libc`
    --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/lapacke-sys-0.1.4/src/lib.rs:17:36
     |
  17 | pub type c_double_complex = [libc::c_double; 2];
     |                                    ^^^^^^^^ not found in `libc`
  
  error[E0412]: cannot find type `c_float` in module `libc`
    --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/lapacke-sys-0.1.4/src/lib.rs:21:35
     |
  21 | pub type c_float_complex = [libc::c_float; 2];
     |                                   ^^^^^^^ not found in `libc`
  
  error: aborting due to 3 previous errors
  
  Some errors occurred: E0412, E0432.
  For more information about an error, try `rustc --explain E0412`.
  error: Could not compile `lapacke-sys`.
\ warning: build failed, waiting for other jobs to finish...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions