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

refactor(lib): make Rust module compile-able under stable Rust #393

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions lib/ngx-wasm-rs/lib/backtrace/src/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ impl Drop for ngx_wasm_backtrace_name_table_t {

fn vec_into_wasm_byte_vec_t(bv: *mut wasm_byte_vec_t, v: Vec<u8>) {
unsafe {
let (ptr, len, _cap) = v.into_raw_parts();
(*bv).size = len;
(*bv).data = ptr;
// FIXME Update this when vec_into_raw_parts is stabilized
let mut v = mem::ManuallyDrop::new(v);
(*bv).size = v.len();
(*bv).data = v.as_mut_ptr();
}
}

Expand All @@ -63,22 +64,24 @@ pub unsafe extern "C" fn ngx_wasm_backtrace_get_name_table(

let mut names = Vec::<ngx_wasm_backtrace_name_t>::with_capacity(table.len());
for (idx, name) in table.drain(..) {
let (bytes, len, _cap) = name.into_raw_parts();
// FIXME Update this when vec_into_raw_parts is stabilized
let mut name = mem::ManuallyDrop::new(name);
let name_t = ngx_wasm_backtrace_name_t {
idx,
name: Box::new(wasm_byte_vec_t {
size: len,
data: bytes,
size: name.len(),
data: name.as_mut_ptr(),
}),
};

names.push(name_t);
}

let (bytes, len, _cap) = names.into_raw_parts();
// FIXME Update this when vec_into_raw_parts is stabilized
let mut names = mem::ManuallyDrop::new(names);
Some(Box::new(ngx_wasm_backtrace_name_table_t {
size: len,
table: bytes,
size: names.len(),
table: names.as_mut_ptr(),
}))
} else {
None
Expand Down
1 change: 0 additions & 1 deletion lib/ngx-wasm-rs/lib/backtrace/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#![feature(vec_into_raw_parts)]
pub(crate) mod backtrace;
pub mod c_api;
8 changes: 4 additions & 4 deletions lib/ngx-wasm-rs/lib/wat/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(vec_into_raw_parts)]
use ngx_wasm_c_api::*;
use regex::Regex;
use std::mem;
Expand Down Expand Up @@ -26,9 +25,10 @@ fn extract_message(err: &str) -> Option<String> {

fn vec_into_wasm_byte_vec_t(bv: *mut wasm_byte_vec_t, v: Vec<u8>) -> () {
unsafe {
let (ptr, len, _cap) = v.into_raw_parts();
(*bv).size = len;
(*bv).data = ptr;
// FIXME Update this when vec_into_raw_parts is stabilized
let mut v = mem::ManuallyDrop::new(v);
(*bv).size = v.len();
(*bv).data = v.as_mut_ptr();
}
}

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly
stable
thibaultcha marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 8 additions & 3 deletions util/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,14 @@ export RUSTFLAGS="$TEST_NGINX_CARGO_RUSTFLAGS"
eval cargo build \
--lib \
"${args[@]}" \
--target wasm32-wasi \
--out-dir $DIR_TESTS_LIB_WASM \
-Z unstable-options
thibaultcha marked this conversation as resolved.
Show resolved Hide resolved
--target wasm32-wasi

if [ "$TEST_NGINX_CARGO_PROFILE" = release ]; then
cp target/wasm32-wasi/release/*.wasm $DIR_TESTS_LIB_WASM

else
cp target/wasm32-wasi/debug/*.wasm $DIR_TESTS_LIB_WASM
fi

if [ $(uname -s) = Linux ]; then
export TEST_NGINX_EVENT_TYPE=epoll
Expand Down