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

WASM compatibility #131

Open
tpbraun96 opened this issue Apr 24, 2022 · 4 comments
Open

WASM compatibility #131

tpbraun96 opened this issue Apr 24, 2022 · 4 comments

Comments

@tpbraun96
Copy link

In the conversation thread here, we discussed how to make oqs's C library compile to WASM. The build script and anything else internal should be modified to support compilation to the common WASM targets here for the rust crate, that way no modification is needed for users of this library.

@thomwiggers
Copy link
Contributor

I've got some WASM support in the pqcrypto crates since PR rustpq/pqcrypto#26. I have no idea how WASM works though, so I would appreciate it if those that would like to see it open a PR and propose some suggestions for testing it in CI (so I don't break it accidentally).

@thomwiggers thomwiggers changed the title WASM WASM compatibility Apr 26, 2022
@enenum
Copy link

enenum commented Jun 19, 2024

Plus one on this

@enenum
Copy link

enenum commented Jul 1, 2024

So far, got liboqs rust to build with cargo build --target=wasm32-unknown-emscripten after supplying a few -I include paths - which I guessed, and might be part of the trouble. I used musl ones in emscripted compiler version 3.1.61 (on mac).
Then I setup a project to build with liboqs rust and get the benefit of all the brains behind the rust bindings.
I took the .a from the step above and made a liboqs.pc for a static link.

Here is where problems begin - and they are first compile problems.

When I build with target=wasm32-unknown-unknown (even using nightly and --Z wasm_c_abi=spec, I get

.../out/sig_bindings.rs:261:52
261 |     pub fn OQS_SIG_new(method_name: *const ::libc::c_char) -> *mut OQS_SIG;
    |                                                    ^^^^^^ not found in `libc`

with the suggestion

help: consider importing this type alias
   --> /.../oqs-sys-0.9.1+liboqs-0.9.0/src/lib.rs:35:5
    |
35  +     use core::ffi::c_char;

In addition, there are also errors like

error[E0308]: mismatched types
    --> /.../.cargo/registry/src/index.crates.io-6f17d22bba15001f/oqs-0.9.0/src/kem.rs:229:44
     |
229  |         let cstr = unsafe { CStr::from_ptr(kem.alg_version) };
     |                             -------------- ^^^^^^^^^^^^^^^ expected `*const u8`, found `*const i8`
     |                             |
     |                             arguments to this function are incorrect
     |
     = note: expected raw pointer `*const u8`
                found raw pointer `*const i8`
note: associated function defined here
    --> /.../.cargo/registry/src/index.crates.io-6f17d22bba15001f/cstr_core-0.2.6/src/lib.rs:1025:19
     |
1025 |     pub unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr {
     |                   ^^^^^^^^

which involve library crates - code I cannot edit, so I imagine there is configuration that can help.

With wasm32-unknown-emscripten only the second error shows up. Following the suggestion for the first error to use the alias solves the instances that I can affect (files in the target folder, but also has the errors indicated for some crate files.

@enenum
Copy link

enenum commented Jul 1, 2024

According to lib.rs in libc it seems c_int and friends are defined for emscripten only, but c_char is not defined (and appears to default to i8 instead of u8.

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

3 participants