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

Since the bindings all use usize dont discriminate between 64 and 32 bits #82

Merged
merged 1 commit into from
May 9, 2024

Conversation

hansl
Copy link
Contributor

@hansl hansl commented May 9, 2024

This now builds with "cross build --target armv7-unknown-linux-gnueabihf".

In Rust, usize is u32 in 32-bits and u64 is 64-bits, so theres no need to make a distinction. The extra typings added in this PR will make sure this would compile for the desired target.

…2 bits

This now builds with "cross build --target armv7-unknown-linux-gnueabihf".

In Rust, usize is u32 in 32-bits and u64 is 64-bits, so theres no need to make a
distinction. The extra typings added in this PR will make sure this would compile
for the desired target.
@hansl
Copy link
Contributor Author

hansl commented May 9, 2024

Previously the errors given when cross-compiling for armv7 was:

   Compiling quickjs_runtime v0.13.3 (/Volumes/Sources/hansl/quickjs_es_runtime)
error[E0308]: mismatched types
    --> src/quickjs_utils/typedarrays.rs:98:9
     |
95   |     let raw = q::JS_NewArrayBuffer(
     |               -------------------- arguments to this function are incorrect
...
98   |         length,
     |         ^^^^^^ expected `usize`, found `u32`
     |
note: function defined here
    --> /target/armv7-unknown-linux-gnueabihf/debug/build/hirofa-quickjs-sys-005e3236c5a418e6/out/bindings.rs:2924:12
     |
2924 |     pub fn JS_NewArrayBuffer(
     |            ^^^^^^^^^^^^^^^^^
help: you can convert a `u32` to a `usize` and panic if the converted value doesn't fit
     |
98   |         length.try_into().unwrap(),
     |               ++++++++++++++++++++

error[E0308]: mismatched types
    --> src/quickjs_utils/typedarrays.rs:168:59
     |
168  |     let raw = q::JS_NewArrayBufferCopy(ctx, buf.as_ptr(), length);
     |               ------------------------                    ^^^^^^ expected `usize`, found `u32`
     |               |
     |               arguments to this function are incorrect
     |
note: function defined here
    --> /target/armv7-unknown-linux-gnueabihf/debug/build/hirofa-quickjs-sys-005e3236c5a418e6/out/bindings.rs:2934:12
     |
2934 |     pub fn JS_NewArrayBufferCopy(ctx: *mut JSContext, buf: *const u8, len: usize) -> JSValue;
     |            ^^^^^^^^^^^^^^^^^^^^^
help: you can convert a `u32` to a `usize` and panic if the converted value doesn't fit
     |
168  |     let raw = q::JS_NewArrayBufferCopy(ctx, buf.as_ptr(), length.try_into().unwrap());
     |                                                                 ++++++++++++++++++++

error[E0308]: mismatched types
    --> src/quickjs_utils/typedarrays.rs:221:45
     |
221  |         let ptr = q::JS_GetArrayBuffer(ctx, &mut len, *array_buffer.borrow_value());
     |                   --------------------      ^^^^^^^^ expected `*mut usize`, found `&mut u32`
     |                   |
     |                   arguments to this function are incorrect
     |
     = note:    expected raw pointer `*mut usize`
             found mutable reference `&mut u32`
note: function defined here
    --> /target/armv7-unknown-linux-gnueabihf/debug/build/hirofa-quickjs-sys-005e3236c5a418e6/out/bindings.rs:2940:12
     |
2940 |     pub fn JS_GetArrayBuffer(ctx: *mut JSContext, psize: *mut usize, obj: JSValue) -> *mut u8;
     |            ^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
    --> src/quickjs_utils/typedarrays.rs:273:45
     |
273  |         let ptr = q::JS_GetArrayBuffer(ctx, &mut len, *array_buffer.borrow_value());
     |                   --------------------      ^^^^^^^^ expected `*mut usize`, found `&mut u32`
     |                   |
     |                   arguments to this function are incorrect
     |
     = note:    expected raw pointer `*mut usize`
             found mutable reference `&mut u32`
note: function defined here
    --> /target/armv7-unknown-linux-gnueabihf/debug/build/hirofa-quickjs-sys-005e3236c5a418e6/out/bindings.rs:2940:12
     |
2940 |     pub fn JS_GetArrayBuffer(ctx: *mut JSContext, psize: *mut usize, obj: JSValue) -> *mut u8;
     |            ^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0308`.
error: could not compile `quickjs_runtime` (lib) due to 4 previous errors

@andrieshiemstra andrieshiemstra merged commit 2210d3f into HiRoFa:master May 9, 2024
1 check failed
@hansl hansl deleted the usize-is-usize branch May 9, 2024 21:17
@andrieshiemstra
Copy link
Member

Thanks @hansl !

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

Successfully merging this pull request may close these issues.

2 participants