Skip to content

Commit 0f78a86

Browse files
committed
Remove the explicit gc feature from the wasmtime dependency in the c-api crate
1 parent e982010 commit 0f78a86

17 files changed

Lines changed: 171 additions & 40 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ jobs:
414414
-p wasmtime-c-api --no-default-features
415415
-p wasmtime-c-api --no-default-features --features wat
416416
-p wasmtime-c-api --no-default-features --features wasi
417+
-p wasmtime-c-api --no-default-features --features gc
417418
418419
- name: wasmtime-wasi-http
419420
checks: |

crates/c-api-macros/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,15 @@ pub fn declare_ref(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
135135

136136
#[doc = #as_ref_docs]
137137
#[unsafe(no_mangle)]
138+
#[cfg(feature = "gc")]
138139
pub extern fn #as_ref(a: &#ty) -> Box<crate::wasm_ref_t> {
139140
eprintln!("`{}` is not implemented", stringify!(#as_ref));
140141
std::process::abort();
141142
}
142143

143144
#[doc = #as_ref_const_docs]
144145
#[unsafe(no_mangle)]
146+
#[cfg(feature = "gc")]
145147
pub extern fn #as_ref_const(a: &#ty) -> Box<crate::wasm_ref_t> {
146148
eprintln!("`{}` is not implemented", stringify!(#as_ref_const));
147149
std::process::abort();

crates/c-api/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ doctest = false
2121

2222
[dependencies]
2323
env_logger = { workspace = true, optional = true }
24-
wasmtime = { workspace = true, features = ['runtime', 'gc', 'std'] }
24+
wasmtime = { workspace = true, features = ['runtime', 'std'] }
2525
wasmtime-c-api-macros = { workspace = true }
2626
log = { workspace = true }
2727
tracing = { workspace = true }

crates/c-api/include/wasmtime/config.hh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,15 @@ class Config {
303303
wasmtime_config_wasm_tail_call_set(ptr.get(), enable);
304304
}
305305

306+
#ifdef WASMTIME_FEATURE_GC
306307
/// \brief Configures whether the WebAssembly reference types proposal is
307308
/// enabled
308309
///
309310
/// https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.wasm_reference_types
310311
void wasm_reference_types(bool enable) {
311312
wasmtime_config_wasm_reference_types_set(ptr.get(), enable);
312313
}
314+
#endif // WASMTIME_FEATURE_GC
313315

314316
/// \brief Configures whether the WebAssembly simd proposal is enabled
315317
///
@@ -361,11 +363,13 @@ class Config {
361363
wasmtime_config_wasm_memory64_set(ptr.get(), enable);
362364
}
363365

366+
#ifdef WASMTIME_FEATURE_GC
364367
/// \brief Configures whether the WebAssembly Garbage Collection proposal will
365368
/// be enabled
366369
///
367370
/// https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.wasm_gc
368371
void wasm_gc(bool enable) { wasmtime_config_wasm_gc_set(ptr.get(), enable); }
372+
#endif // WASMTIME_FEATURE_GC
369373

370374
/// \brief Configures whether the WebAssembly function references proposal
371375
/// will be enabled
@@ -383,13 +387,15 @@ class Config {
383387
wasmtime_config_wasm_wide_arithmetic_set(ptr.get(), enable);
384388
}
385389

390+
#ifdef WASMTIME_FEATURE_GC
386391
/// \brief Configures whether the WebAssembly exceptions proposal will be
387392
/// enabled
388393
///
389394
/// https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.wasm_exceptions
390395
void wasm_exceptions(bool enable) {
391396
wasmtime_config_wasm_exceptions_set(ptr.get(), enable);
392397
}
398+
#endif // WASMTIME_FEATURE_GC
393399

394400
/// \brief Configures whether the WebAssembly custom-page-sizes proposal will
395401
/// be enabled

crates/c-api/include/wasmtime/func.hh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ NATIVE_WASM_TYPE(double, F64, f64)
8181

8282
#undef NATIVE_WASM_TYPE
8383

84+
#ifdef WASMTIME_FEATURE_GC
8485
/// Type information for `externref`, represented on the host as an optional
8586
/// `ExternRef`.
8687
template <> struct WasmType<std::optional<ExternRef>> {
@@ -102,8 +103,9 @@ template <> struct WasmType<std::optional<ExternRef>> {
102103
p->externref = 0;
103104
}
104105
}
106+
105107
static std::optional<ExternRef> load(Store::Context cx,
106-
wasmtime_val_raw_t *p) {
108+
wasmtime_val_raw_t *p) {
107109
if (p->externref == 0) {
108110
return std::nullopt;
109111
}
@@ -112,6 +114,7 @@ template <> struct WasmType<std::optional<ExternRef>> {
112114
return ExternRef(val);
113115
}
114116
};
117+
#endif // WASMTIME_FEATURE_GC
115118

116119
/// Type information for the `V128` host value used as a wasm value.
117120
template <> struct WasmType<V128> {

crates/c-api/include/wasmtime/store.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ WASM_API_EXTERN void wasmtime_context_set_data(wasmtime_context_t *context,
144144
*
145145
* The `context` argument must not be NULL.
146146
*/
147+
#ifdef WASMTIME_FEATURE_GC
147148
WASM_API_EXTERN wasmtime_error_t *
148149
wasmtime_context_gc(wasmtime_context_t *context);
150+
#endif
149151

150152
/**
151153
* \brief Set fuel to this context's store for wasm to consume while executing.

crates/c-api/include/wasmtime/store.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public:
9494
/// Creates a context referencing the provided `Caller`.
9595
Context(Caller *caller);
9696

97+
#ifdef WASMTIME_FEATURE_GC
9798
/// Runs a garbage collection pass in the referenced store to collect loose
9899
/// `externref` values, if any are available.
99100
Result<std::monostate> gc() {
@@ -103,6 +104,7 @@ public:
103104
}
104105
return std::monostate();
105106
}
107+
#endif
106108

107109
/// Injects fuel to be consumed within this store.
108110
///
@@ -253,9 +255,11 @@ public:
253255
/// Explicit function to acquire a `Context` from this store.
254256
Context context() { return this; }
255257

258+
#ifdef WASMTIME_FEATURE_GC
256259
/// Runs a garbage collection pass in the referenced store to collect loose
257260
/// GC-managed objects, if any are available.
258261
Result<std::monostate> gc() { return context().gc(); }
262+
#endif
259263

260264
private:
261265
template <typename F>

crates/c-api/include/wasmtime/val.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ typedef struct wasmtime_anyref {
5656
void *__private3;
5757
} wasmtime_anyref_t;
5858

59+
#ifdef WASMTIME_FEATURE_GC
5960
/// \brief Helper function to initialize the `ref` provided to a null anyref
6061
/// value.
6162
static inline void wasmtime_anyref_set_null(wasmtime_anyref_t *ref) {
@@ -71,6 +72,7 @@ static inline bool wasmtime_anyref_is_null(const wasmtime_anyref_t *ref) {
7172
return ref->store_id == 0;
7273
}
7374

75+
7476
/**
7577
* \brief Creates a new reference pointing to the same data that `anyref`
7678
* points to (depending on the configured collector this might increase a
@@ -201,6 +203,8 @@ WASM_API_EXTERN bool wasmtime_anyref_i31_get_s(wasmtime_context_t *context,
201203
* `wasmtime_externref_set_null`. Null can be tested for with the
202204
* `wasmtime_externref_is_null` function.
203205
*/
206+
#endif // WASMTIME_FEATURE_GC
207+
204208
typedef struct wasmtime_externref {
205209
/// Internal metadata tracking within the store, embedders should not
206210
/// configure or modify these fields.
@@ -213,6 +217,7 @@ typedef struct wasmtime_externref {
213217
void *__private3;
214218
} wasmtime_externref_t;
215219

220+
#ifdef WASMTIME_FEATURE_GC
216221
/// \brief Helper function to initialize the `ref` provided to a null externref
217222
/// value.
218223
static inline void wasmtime_externref_set_null(wasmtime_externref_t *ref) {
@@ -313,6 +318,7 @@ WASM_API_EXTERN void wasmtime_externref_from_raw(wasmtime_context_t *context,
313318
*/
314319
WASM_API_EXTERN uint32_t wasmtime_externref_to_raw(
315320
wasmtime_context_t *context, const wasmtime_externref_t *ref);
321+
#endif // WASMTIME_FEATURE_GC
316322

317323
/**
318324
* \typedef wasmtime_exnref_t
@@ -397,6 +403,7 @@ typedef uint8_t wasmtime_valkind_t;
397403
/// stored in little-endian order.
398404
typedef uint8_t wasmtime_v128[16];
399405

406+
400407
/**
401408
* \typedef wasmtime_valunion_t
402409
* \brief Convenience alias for #wasmtime_valunion

crates/c-api/include/wasmtime/val.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class EqRef;
1717
class StructRef;
1818
class ArrayRef;
1919

20+
#ifdef WASMTIME_FEATURE_GC
2021
/**
2122
* \brief Representation of a WebAssembly `externref` value.
2223
*
@@ -103,9 +104,12 @@ public:
103104
return wasmtime_externref_to_raw(cx.capi(), &val);
104105
}
105106
};
107+
#endif // WASMTIME_FEATURE_GC
106108

107109
class EqRef;
108110

111+
112+
#ifdef WASMTIME_FEATURE_GC
109113
/**
110114
* \brief Representation of a WebAssembly `anyref` value.
111115
*/
@@ -204,6 +208,7 @@ public:
204208
/// \brief Downcast to arrayref. Returns null arrayref if not an arrayref.
205209
inline std::optional<ArrayRef> as_array(Store::Context cx) const;
206210
};
211+
#endif // WASMTIME_FEATURE_GC
207212

208213
/// \brief Container for the `v128` WebAssembly type.
209214
struct V128 {

crates/c-api/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,13 @@ pub extern "C" fn wasmtime_config_wasm_tail_call_set(c: &mut wasm_config_t, enab
9090
}
9191

9292
#[unsafe(no_mangle)]
93+
#[cfg(feature = "gc")]
9394
pub extern "C" fn wasmtime_config_wasm_reference_types_set(c: &mut wasm_config_t, enable: bool) {
9495
c.config.wasm_reference_types(enable);
9596
}
9697

9798
#[unsafe(no_mangle)]
99+
#[cfg(feature = "gc")]
98100
pub extern "C" fn wasmtime_config_wasm_function_references_set(
99101
c: &mut wasm_config_t,
100102
enable: bool,
@@ -103,6 +105,7 @@ pub extern "C" fn wasmtime_config_wasm_function_references_set(
103105
}
104106

105107
#[unsafe(no_mangle)]
108+
#[cfg(feature = "gc")]
106109
pub extern "C" fn wasmtime_config_wasm_gc_set(c: &mut wasm_config_t, enable: bool) {
107110
c.config.wasm_gc(enable);
108111
}
@@ -476,6 +479,7 @@ pub extern "C" fn wasmtime_config_wasm_wide_arithmetic_set(c: &mut wasm_config_t
476479
}
477480

478481
#[unsafe(no_mangle)]
482+
#[cfg(feature = "gc")]
479483
pub extern "C" fn wasmtime_config_wasm_exceptions_set(c: &mut wasm_config_t, enable: bool) {
480484
c.config.wasm_exceptions(enable);
481485
}

0 commit comments

Comments
 (0)