Skip to content

Commit

Permalink
[feat] Support gc
Browse files Browse the repository at this point in the history
Signed-off-by: csh <[email protected]>
  • Loading branch information
L-jasmine committed Feb 29, 2024
1 parent a6220e9 commit 94f17fe
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
5 changes: 5 additions & 0 deletions crates/wasmedge-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ fn main() {
let success = std::process::Command::new(bindgen_path)
.arg("--no-prepend-enum-name") // The API already prepends the name.
.arg("--dynamic-link-require-all")
.arg("--allowlist-item")
.arg("WasmEdge.*")
.arg("--no-layout-tests")
.arg("--formatter=none")
.arg("-o")
.arg(out_file)
Expand All @@ -136,6 +139,8 @@ fn main() {
.clang_arg(format!("-I{inc_dir}"))
.prepend_enum_name(false)
.dynamic_link_require_all(true)
.allowlist_item("WasmEdge.*")
.layout_tests(false)
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.generate()
.expect("failed to generate bindings")
Expand Down
29 changes: 29 additions & 0 deletions crates/wasmedge-sys/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,26 @@ impl Config {
unsafe { ffi::WasmEdge_ConfigureHasProposal(self.inner.0, ffi::WasmEdge_Proposal_Threads) }
}

/// Enables or disables the GC option. By default, the option is disabled.
///
/// # Argument
///
/// * `enable` - Whether the option turns on or not.
pub fn gc(&mut self, enable: bool) {
unsafe {
if enable {
ffi::WasmEdge_ConfigureAddProposal(self.inner.0, ffi::WasmEdge_Proposal_GC)
} else {
ffi::WasmEdge_ConfigureRemoveProposal(self.inner.0, ffi::WasmEdge_Proposal_GC)
}
}
}

/// Checks if the GC option turns on or not.
pub fn gc_enabled(&self) -> bool {
unsafe { ffi::WasmEdge_ConfigureHasProposal(self.inner.0, ffi::WasmEdge_Proposal_GC) }
}

/// Enables or disables the ExceptionHandling option. By default, the option is disabled.
///
/// # Argument
Expand Down Expand Up @@ -760,6 +780,7 @@ mod tests {
assert!(config.simd_enabled());
assert!(!config.tail_call_enabled());
assert!(!config.threads_enabled());
assert!(!config.gc_enabled());
assert!(!config.is_cost_measuring());
#[cfg(feature = "aot")]
assert!(!config.dump_ir_enabled());
Expand Down Expand Up @@ -798,6 +819,7 @@ mod tests {
config.simd(false);
config.tail_call(true);
config.threads(true);
config.gc(true);
config.measure_cost(true);
config.measure_time(true);
#[cfg(feature = "aot")]
Expand All @@ -822,6 +844,7 @@ mod tests {
assert!(!config.simd_enabled());
assert!(config.tail_call_enabled());
assert!(config.threads_enabled());
assert!(config.gc_enabled());
assert!(config.is_cost_measuring());
#[cfg(feature = "aot")]
assert!(config.dump_ir_enabled());
Expand Down Expand Up @@ -869,6 +892,7 @@ mod tests {
assert!(config.simd_enabled());
assert!(!config.tail_call_enabled());
assert!(!config.threads_enabled());
assert!(!config.gc_enabled());
assert!(!config.is_cost_measuring());
#[cfg(feature = "aot")]
assert!(!config.dump_ir_enabled());
Expand Down Expand Up @@ -899,6 +923,7 @@ mod tests {
config.simd(false);
config.tail_call(true);
config.threads(true);
config.gc(true);
config.measure_cost(true);
config.measure_time(true);
#[cfg(feature = "aot")]
Expand All @@ -918,6 +943,7 @@ mod tests {
assert!(!config.simd_enabled());
assert!(config.tail_call_enabled());
assert!(config.threads_enabled());
assert!(config.gc_enabled());
assert!(config.is_cost_measuring());
#[cfg(feature = "aot")]
assert!(config.dump_ir_enabled());
Expand Down Expand Up @@ -954,6 +980,7 @@ mod tests {
assert!(config.simd_enabled());
assert!(!config.tail_call_enabled());
assert!(!config.threads_enabled());
assert!(!config.gc_enabled());
assert!(!config.is_cost_measuring());
#[cfg(feature = "aot")]
assert!(!config.dump_ir_enabled());
Expand Down Expand Up @@ -985,6 +1012,7 @@ mod tests {
config_mut.simd(false);
config_mut.tail_call(true);
config_mut.threads(true);
config_mut.gc(true);
config_mut.measure_cost(true);
config_mut.measure_time(true);
#[cfg(feature = "aot")]
Expand All @@ -1004,6 +1032,7 @@ mod tests {
assert!(!config.simd_enabled());
assert!(config.tail_call_enabled());
assert!(config.threads_enabled());
assert!(config.gc_enabled());
assert!(config.is_cost_measuring());
#[cfg(feature = "aot")]
assert!(config.dump_ir_enabled());
Expand Down
13 changes: 13 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl ConfigBuilder {
inner.simd(self.common_config.simd);
inner.multi_memories(self.common_config.multi_memories);
inner.threads(self.common_config.threads);
inner.gc(self.common_config.gc);
inner.tail_call(self.common_config.tail_call);
inner.function_references(self.common_config.function_references);
inner.interpreter_mode(self.common_config.interpreter_mode);
Expand Down Expand Up @@ -307,6 +308,7 @@ pub struct CommonConfigOptions {
simd: bool,
multi_memories: bool,
threads: bool,
gc: bool,
tail_call: bool,
function_references: bool,
interpreter_mode: bool,
Expand All @@ -324,6 +326,7 @@ impl CommonConfigOptions {
/// * simd: true,
/// * multi_memories: false,
/// * threads: false,
/// * gc: false,
/// * tail_call: false,
/// * function_references: false,
/// * interpreter_mode: false,
Expand All @@ -338,6 +341,7 @@ impl CommonConfigOptions {
simd: true,
multi_memories: false,
threads: false,
gc: false,
tail_call: false,
function_references: false,
interpreter_mode: false,
Expand Down Expand Up @@ -452,6 +456,15 @@ impl CommonConfigOptions {
}
}

/// Enables or disables the GC option.
///
/// # Argument
///
/// - `enable` specifies if the option turns on or not.
pub fn gc(self, enable: bool) -> Self {
Self { gc: enable, ..self }
}

/// Enables or disables the TailCall option.
///
/// # Argument
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Defines the general types.
use wasmedge_sys::WasmValue;
use wasmedge_types::{self};
use wasmedge_types;

/// Defines runtime values that a WebAssembly module can either consume or produce.
#[derive(Debug, Clone)]
Expand Down

0 comments on commit 94f17fe

Please sign in to comment.