Skip to content

Enable gc feature by default#12805

Open
tolumide-ng wants to merge 2 commits intobytecodealliance:mainfrom
tolumide-ng:fix/wasmtime-c-api-gc-update
Open

Enable gc feature by default#12805
tolumide-ng wants to merge 2 commits intobytecodealliance:mainfrom
tolumide-ng:fix/wasmtime-c-api-gc-update

Conversation

@tolumide-ng
Copy link
Copy Markdown

The c-api crate currently enables the gc feature on its wasmtime dependency, even though it exposes a gc feature to control this behaviour. This prevents downstream users from disabling gc, since Cargo.toml doesn't allow overriding it. However, structs like RootScope are only available when gc is enabled. Removing it from default features, without other options, would break internal implementations.

Changes

  1. Enable the gc feature via the wasmtime-c-api crate by default.
  2. Removes the explicitly set gc feature for the wasmtime dependency in c-api, thus enabling downstream users to specify this behaviour.

Closes #12783

@tolumide-ng tolumide-ng requested a review from a team as a code owner March 19, 2026 22:51
@tolumide-ng tolumide-ng requested review from cfallin and removed request for a team March 19, 2026 22:51
@github-actions github-actions bot added the wasmtime:c-api Issues pertaining to the C API. label Mar 20, 2026
@tolumide-ng tolumide-ng requested a review from a team as a code owner March 21, 2026 00:13
@tolumide-ng tolumide-ng force-pushed the fix/wasmtime-c-api-gc-update branch 2 times, most recently from 2569780 to ba53a43 Compare March 21, 2026 01:40
Copy link
Copy Markdown
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning now from vacation, thanks for your patience @tolumide-ng. Also I'll apologize that the scope of this issue is broadening to be a bit larger than I had originally anticipated. I thought there would be some minor edits required to get the c-api building without GC, but there's a number of API design decisions to make here which affect how exactly this works. I'm happy to help guide through these, but if you feel this is getting too broad in scope that's also totally fine.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an example file where when gc is disabled the entire module may wish to disappear vs having lots of #[cfg] internally.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not exactly sure what you mean here. There are some functions where the gc feature does not apply, and some other modules depend on the macros. I'd be happy to retry with more clarification.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah what I mean is placing #![cfg(feature = "gc")] at the top of this file to avoid compiling the entire file when the gc feature is disabled. Everything in here looks GC-related so should be fine to omit when gc is disabled. What are the errors you're seeing though about other modules depending on this? Perhaps those dependencies should also be #[cfg]'d?

Copy link
Copy Markdown
Author

@tolumide-ng tolumide-ng Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the clarification. The errors mostly emanate from:

  1. crates/c-api/src/table.rs:2:82 where wasm_ref_t is used
  2. crates/c-api/src/val.rs:3:43 where wasm_val_union has *mut wasm_ref_t in its fields.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For table.rs that's ok to exclude those functions when GC is disabled, and for val.rs the union will have fewer fields when GC is disabled and that's ok, too.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd update this right away, thank you

@tolumide-ng
Copy link
Copy Markdown
Author

Returning now from vacation, thanks for your patience @tolumide-ng. Also I'll apologize that the scope of this issue is broadening to be a bit larger than I had originally anticipated. I thought there would be some minor edits required to get the c-api building without GC, but there's a number of API design decisions to make here which affect how exactly this works. I'm happy to help guide through these, but if you feel this is getting too broad in scope that's also totally fine.

Welcome back from your holiday @alexcrichton, and thank you for the review.
I'm happy to continue with the expanded scope. It looks like an informative introduction to the codebase.
I'd definitely appreciate your guidance as questions come up.

@tolumide-ng tolumide-ng force-pushed the fix/wasmtime-c-api-gc-update branch 7 times, most recently from 395f1f3 to 75ac484 Compare April 1, 2026 23:06
@tolumide-ng tolumide-ng requested a review from alexcrichton April 2, 2026 22:22
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah what I mean is placing #![cfg(feature = "gc")] at the top of this file to avoid compiling the entire file when the gc feature is disabled. Everything in here looks GC-related so should be fine to omit when gc is disabled. What are the errors you're seeing though about other modules depending on this? Perhaps those dependencies should also be #[cfg]'d?

@tolumide-ng tolumide-ng force-pushed the fix/wasmtime-c-api-gc-update branch from 2864340 to a226ebf Compare April 3, 2026 20:54
@tolumide-ng tolumide-ng requested a review from alexcrichton April 6, 2026 12:02
Copy link
Copy Markdown
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like some merge conflicts have cropped up as well, I'd recommend rebasing and seeing how to resolve those as well.

void *__private3;
} wasmtime_anyref_t;

#ifdef WASMTIME_FEATURE_GC
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to make the definition of wasmtime_{any,extern}ref_t conditional based on WASMTIME_FEATURE_GC?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For table.rs that's ok to exclude those functions when GC is disabled, and for val.rs the union will have fewer fields when GC is disabled and that's ok, too.

@tolumide-ng tolumide-ng force-pushed the fix/wasmtime-c-api-gc-update branch from ae29880 to 344c5b9 Compare April 6, 2026 18:29
@tolumide-ng tolumide-ng force-pushed the fix/wasmtime-c-api-gc-update branch 4 times, most recently from 89143a5 to 44bff11 Compare April 6, 2026 20:33
@tolumide-ng tolumide-ng force-pushed the fix/wasmtime-c-api-gc-update branch from 44bff11 to c575d98 Compare April 6, 2026 21:06
@tolumide-ng tolumide-ng requested a review from alexcrichton April 6, 2026 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:c-api Issues pertaining to the C API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

c-api: gc feature unconditionally enabled in wasmtime crate

2 participants