Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bindgen does not emit functions for wasm/emscripten #1681

Closed
tangmi opened this issue Nov 18, 2019 · 1 comment
Closed

bindgen does not emit functions for wasm/emscripten #1681

tangmi opened this issue Nov 18, 2019 · 1 comment

Comments

@tangmi
Copy link

tangmi commented Nov 18, 2019

It seems like bindgen doesn't produce bindings for functions when building with cargo-web for wasm32-unknown-emscripten.

Input C/C++ Header

#pragma once

int add(int a, int b) {
    return a + b;
}

Bindgen Invocation

PS> E:\bin\emsdk\emsdk_env.ps1;
Adding directories to PATH:
PATH += E:\bin\emsdk
PATH += E:\bin\emsdk\clang\e1.38.16_64bit
PATH += E:\bin\emsdk\node\8.9.1_64bit\bin
PATH += E:\bin\emsdk\python\2.7.13.1_64bit\python-2.7.13.amd64
PATH += E:\bin\emsdk\java\8.152_64bit\bin
PATH += E:\bin\emsdk\emscripten\1.38.16

Setting environment variables:
EMSDK = E:/bin/emsdk

PS> bindgen input.h -o bindings.rs -- --target=wasm32-unknown-emscripten
...

Actual Results

Output of bindings.rs:

/* automatically generated by rust-bindgen */

Output of RUST_LOG=bindgen: (note it's finding my system clang, but using the emsdk one?)

[2019-11-18T20:23:45Z INFO  bindgen] Clang Version: clang version 8.0.1 (tags/RELEASE_801/final)
[2019-11-18T20:23:45Z WARN  bindgen] Using clang (8, 0), expected (3, 9)
[2019-11-18T20:23:45Z DEBUG bindgen] Generating bindings, libclang at C:\Program Files\LLVM\bin\libclang.dll
[2019-11-18T20:23:45Z DEBUG bindgen] Trying to find clang with flags: ["--target=wasm32"]
[2019-11-18T20:23:45Z DEBUG bindgen] Found clang: Clang { path: "E:\\bin\\emsdk\\clang\\e1.38.16_64bit\\clang.exe", version: Some(CXVersion { Major: 6, Minor: 0, Subminor: 1 }), c_search_paths: None, cpp_search_paths: None }
...

Output of clang --version

PS> clang --version
clang version 6.0.1  (emscripten 1.38.16 : 1.38.16)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: E:\bin\emsdk\clang\e1.38.16_64bit

Expected Results

Something similar to the non-wasm build, however it seems the link_name is different across msvc and emscripten...

extern "C" {
    #[link_name = "_Z3addii"] // Note: I found this by poking around the clang-compiled `.o` file targetting wasm32.
    pub fn add(a: ::std::os::raw::c_int, b: ::std::os::raw::c_int) -> ::std::os::raw::c_int;
}

I've also tried some of the things in the discussion after #730 was closed:

Thanks for your time!

@emilio
Copy link
Contributor

emilio commented Nov 19, 2019

Yeah this is #751. But poking at it I found a fix, will comment there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants