-
Notifications
You must be signed in to change notification settings - Fork 86
adaptation: allow compiling out WASM support altogether. #253
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that calling it
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh! good call, forgot that |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| //go:build nri_no_wasm | ||
|
|
||
| /* | ||
| Copyright The containerd Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package adaptation | ||
|
|
||
| import ( | ||
| "github.com/containerd/nri/pkg/api" | ||
| ) | ||
|
|
||
| func getWasmService() (*api.PluginPlugin, error) { | ||
| return nil, ErrWasmDisabled | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| //go:build !nri_no_wasm | ||
|
|
||
| /* | ||
| Copyright The containerd Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package adaptation | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/containerd/nri/pkg/api" | ||
| "github.com/tetratelabs/wazero" | ||
| "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" | ||
| ) | ||
|
|
||
| func getWasmService() (*api.PluginPlugin, error) { | ||
| wasmWithCloseOnContextDone := func(ctx context.Context) (wazero.Runtime, error) { | ||
| var ( | ||
| cfg = wazero.NewRuntimeConfig().WithCloseOnContextDone(true) | ||
| r = wazero.NewRuntimeWithConfig(ctx, cfg) | ||
| ) | ||
| if _, err := wasi_snapshot_preview1.Instantiate(ctx, r); err != nil { | ||
| return nil, err | ||
| } | ||
| return r, nil | ||
| } | ||
|
|
||
| wasmPlugins, err := api.NewPluginPlugin( | ||
| context.Background(), | ||
| api.WazeroRuntime(wasmWithCloseOnContextDone), | ||
| ) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("unable to initialize WASM service: %w", err) | ||
| } | ||
|
|
||
| return wasmPlugins, nil | ||
| } |
There was a problem hiding this comment.
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
WithWASMServicewas created (that would either return an error, ornil).