-
Notifications
You must be signed in to change notification settings - Fork 733
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
wasm32 target does not generate class functions. #751
Comments
Note: |
I think the target should be |
So this is because clang reports a It's unclear to me whether that's a bug on clang itself, or the symbol is really unusable. Commenting out that check makes the file getting generated properly. @kkimdev, could you try with that check commented out and see if you can call that method or something? We can whitelist the wasm target, I guess, but I'm not super-happy about it. |
@emilio Yes I commented out them and now I can link and call the method. I guess we should file a bug to libclang? Below are the steps to reproduce: test.hpp int add_one(int x); test.cpp int add_one(int x) { return x + 1; } main.rs mod test;
fn main() {
unsafe {
let x = test::add_one(3);
println!("{}", x);
}
} Commands rustc main.rs --target=wasm32-unknown-emscripten -o main.bc
bindgen test.hpp -o test.rs -- -target wasm32
emcc test.cpp -o test.bc
emcc main.bc test.bc -o test.html
python -m SimpleHTTPServer
# Navigate http://localhost:8000/test.html |
Yes, a bug against llvm or https://github.com/kripken/emscripten would be the best way to proceed I think. I'm not sure where the bug lies exactly, I could dig next week (busy today). |
Any update on this? I'm currently facing the same problem actually. |
I'm pretty sure this is not our bug, but I can land a workaround, I guess... |
The problem here may be that clang seems to be assuming A workaround for this is to explicitly set the clang arg You can do this from a typical build.rs script by modifying it to include something like:
Alternatively, if you have control over the C headers that you are running bindgen on, you could set an explicit visibility for those functions that you want to export to wasm:
At which point the |
Ah, I just poked at #1681 before reading this again, and was going to comment that indeed, the best alternative is passing This is not a bindgen bug, so closing. But maybe some docs on this would be useful in the book? A PR for that would be appreciated :) |
I believe that there may be some lingering issue (that may be related to bindgen). It looks like Edit: I forgot to say thank you @emilio for finding this |
What issue does the wasm build have? Could you file a new issue with a detailed error message? That is needed to avoid mangling by rustc itself, but maybe wasm is undoing that? There's |
I get a lot of
I am building my C++ code using the |
@tangmi Have you found a solution for your problem? I'm having the same issue. |
Apologies because my memory is a bit hazy, I believe I just added a part to my |
@tangmi Thank you for the quick reply. I managed to compile using Rust nightly. 🤔 |
I think my case was some (non-bindgen) part of the compile chain wasn't respecting the fact that LLVM uses Maybe this has been fixed in a newer version of clang? I'm glad nightly works for you, I hope it's a sufficient solution for you! |
Input C/C++ Header
Bindgen Invocation
Actual Results
Expected Results
Something similar to the following. Generated with
$ bindgen test.h -- -x c++
on x86_64.RUST_LOG=bindgen
OutputThe text was updated successfully, but these errors were encountered: