Skip to content

Conversation

@klihub
Copy link
Member

@klihub klihub commented Dec 11, 2025

This PR introduces the "nri_no_wasm" build tag which now allows disabling WASM support altogether at compile time. This can be helpful in resource constrained or other environments, where WASM support is not needed and the related binary size increase penalty is considered difficult to justify.

socketPath: DefaultSocketPath,
syncLock: sync.RWMutex{},
wasmService: wasmPlugins,
wasmService: wasmService,
Copy link
Member

Choose a reason for hiding this comment

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

I was originally considering if this could be a functional option (WithWASMService); that could potentially allow the caller to either pass, or not pass the option.

Compile-time could still be an option for that if a stub WithWASMService was created (that would either return an error, or nil).

@thaJeztah
Copy link
Member

thaJeztah commented Dec 11, 2025

Oh, thanks! @robmry PTAL 🤗

The thing I was struggling with was that various of the WASM types are also deeply engrained in the API definition, but not sure if that caused the binary size to grow as well.

I started looking if we could somehow get that dependency out of the API definition, but didn't get very far; just a quick "let's see if this could work", but there were a lot of places and additional definitions; I pushed what I had here, but it very likely won't even compile;

edit: wrong link

@klihub klihub force-pushed the devel/nowasm-build-flag branch 2 times, most recently from 9b9b452 to b5c71f1 Compare December 11, 2025 11:34
@klihub
Copy link
Member Author

klihub commented Dec 11, 2025

Oh, thanks! @robmry PTAL 🤗

The thing I was struggling with was that various of the WASM types are also deeply engrained in the API definition, but not sure if that caused the binary size to grow as well.

Yeah, I'm unable to tell. But I tried the effect of this and compiling containerd main/HEAD now with BUILDTAGS=nri_nowasm results on x86_64 in a 45272408 binary size vs. 48184952 when compiling with WASM support enabled. A size reduction of 2912544 bytes.

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

thanks!

I think this change looks good; AFAICS, it doesn't paint us in a corner on considering some of the other options (functional option to add the plugin and looking further at what can be done for the API definitions).

I left one nit for the naming of the files, but not really blocking, just a suggestion.

LGTM

Copy link
Member

Choose a reason for hiding this comment

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

I think using underscores instead of hyphens is more common in Go; perhaps adaptation_wasm.go and adaptation_nowasm.go could work?

Copy link
Member Author

@klihub klihub Dec 11, 2025

Choose a reason for hiding this comment

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

I think that calling it adaptation_wasm.go would not work. It would break the builds, because wasm is a valid GOARCH, so it would be excluded from x86_64 and arm builds.

Copy link
Member

Choose a reason for hiding this comment

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

Oh! good call, forgot that wasm was a builtin... 😢

@klihub
Copy link
Member Author

klihub commented Dec 11, 2025

thanks!

I think this change looks good; AFAICS, it doesn't paint us in a corner on considering some of the other options (functional option to add the plugin and looking further at what can be done for the API definitions).

Yes, I also think we should explore your 'inject WASM support using a functional option' further, and see if we can sort everything out to get it working, and then take a look at what that would mean in terms of maintenance wrt. expected WASM runtime API stability/etc.

@robmry
Copy link

robmry commented Dec 11, 2025

Yeah, I'm unable to tell. But I tried the effect of this and compiling containerd main/HEAD now with BUILDTAGS=nri_nowasm results on x86_64 in a 45272408 binary size vs. 48184952 when compiling with WASM support enabled. A size reduction of 2912544 bytes.

Great - thank you! I tried it on a dockerd build and it saves about the same.

@klihub klihub requested a review from mikebrow December 11, 2025 13:10
@mikebrow
Copy link
Member

thanks!
I think this change looks good; AFAICS, it doesn't paint us in a corner on considering some of the other options (functional option to add the plugin and looking further at what can be done for the API definitions).

Yes, I also think we should explore your 'inject WASM support using a functional option' further, and see if we can sort everything out to get it working, and then take a look at what that would mean in terms of maintenance wrt. expected WASM runtime API stability/etc.

nod.. I wonder if functional would allow for variants per runtime type?

@klihub
Copy link
Member Author

klihub commented Dec 11, 2025

@saschagrunert Would you guys be okay with enabling WASM support behind a build flag and have it disabled by default (so the other way around than proposed in this PR) ?

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

The build tag seems inconsistent with existing ones

https://github.com/containerd/nri/pull/253/changes#r2612981454

@klihub
Copy link
Member Author

klihub commented Dec 12, 2025

thanks!
I think this change looks good; AFAICS, it doesn't paint us in a corner on considering some of the other options (functional option to add the plugin and looking further at what can be done for the API definitions).

Yes, I also think we should explore your 'inject WASM support using a functional option' further, and see if we can sort everything out to get it working, and then take a look at what that would mean in terms of maintenance wrt. expected WASM runtime API stability/etc.

nod.. I wonder if functional would allow for variants per runtime type?

If you mean plugging in other WASM implementations than wazero, then moving to a functional option to set up WASM support would make this theoretically/from a pure mechanics PoV possible. However, since our WASM support uses knqyf263/go-plugin to generate all the necessary bindings and other boilerplate to interact with WASM-compiled code from our protobuf definitions, and since go-plugin uses wazero, this would not really be possible in practice at the moment.

@saschagrunert
Copy link
Contributor

@saschagrunert Would you guys be okay with enabling WASM support behind a build flag and have it disabled by default (so the other way around than proposed in this PR) ?

Should be fine, yes.

@klihub klihub force-pushed the devel/nowasm-build-flag branch from b5c71f1 to e10f3bf Compare December 12, 2025 13:57
@klihub klihub requested a review from AkihiroSuda December 12, 2025 13:58
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda AkihiroSuda requested a review from dmcgowan December 16, 2025 05:55
@klihub
Copy link
Member Author

klihub commented Dec 16, 2025

@mikebrow @dmcgowan Could you guys chime in if we are fine with the current build tag semantics, IOW keeping WASM support on by default for backward compatibility and turning it off using the no_wasm tag ? If we are fine with it, I'll merge this as is, then tag a v0.11.0 release.

Copy link
Contributor

@marquiz marquiz left a comment

Choose a reason for hiding this comment

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

Looks good to me.

That said, if we think that disabling wasm support by default is desirable and a good thing, I think now would be a good time to do it (before we get to NRI v1.0). Put a big fat note in the release notes.

Copy link
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

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

LGTM

@klihub
Copy link
Member Author

klihub commented Dec 16, 2025

Looks good to me.

That said, if we think that disabling wasm support by default is desirable and a good thing, I think now would be a good time to do it (before we get to NRI v1.0). Put a big fat note in the release notes.

I think disabling WASM makes the most sense for those who consume and compile containerd themselves from sources and really count bytes, for instance k3s. I'd be fine with keeping it enabled by default.

Allow WASM support to be disabled at compile time using the
"nri_no_wasm" build tag.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
@klihub klihub force-pushed the devel/nowasm-build-flag branch from e10f3bf to ab88fe6 Compare December 16, 2025 19:16
@klihub klihub requested a review from AkihiroSuda December 16, 2025 19:18
@klihub
Copy link
Member Author

klihub commented Dec 16, 2025

@AkihiroSuda Updated the build tag according to the latest preference/review comment. Now I'd need one re-approval to be able to merge this.

@AkihiroSuda AkihiroSuda merged commit 1078130 into containerd:main Dec 17, 2025
16 checks passed
@klihub klihub deleted the devel/nowasm-build-flag branch December 17, 2025 07:38
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.

8 participants