@@ -4,15 +4,16 @@ import (
4
4
"context"
5
5
"errors"
6
6
"fmt"
7
- observe "github.com/dylibso/observe-sdk/go"
8
- "github.com/tetratelabs/wazero"
9
- "github.com/tetratelabs/wazero/api"
10
- "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
11
7
"os"
12
8
"strconv"
13
9
"strings"
14
10
"sync/atomic"
15
11
"time"
12
+
13
+ observe "github.com/dylibso/observe-sdk/go"
14
+ "github.com/tetratelabs/wazero"
15
+ "github.com/tetratelabs/wazero/api"
16
+ "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
16
17
)
17
18
18
19
type CompiledPlugin struct {
@@ -55,6 +56,10 @@ type PluginConfig struct {
55
56
// When plugins are built using NewCompiledPlugin, the ModuleConfig has no
56
57
// effect because the instance is not created. Instead, the ModuleConfig is
57
58
// passed directly in calls to the CompiledPlugin.Instance method.
59
+ //
60
+ // NOTE: Module name and start functions are ignored as they are overridden by Extism, also if Manifest contains
61
+ // non-empty AllowedPaths, then FS is also ignored. If EXTISM_ENABLE_WASI_OUTPUT is set, then stdout and stderr are
62
+ // set to os.Stdout and os.Stderr respectively (ignoring user defined module config).
58
63
ModuleConfig wazero.ModuleConfig
59
64
}
60
65
@@ -96,27 +101,25 @@ func NewCompiledPlugin(
96
101
return nil , fmt .Errorf ("manifest can't be empty" )
97
102
}
98
103
99
- var cfg wazero.RuntimeConfig
100
- if config .RuntimeConfig == nil {
101
- cfg = wazero .NewRuntimeConfig ()
102
- } else {
103
- cfg = config .RuntimeConfig
104
+ runtimeConfig := config .RuntimeConfig
105
+ if runtimeConfig == nil {
106
+ runtimeConfig = wazero .NewRuntimeConfig ()
104
107
}
105
108
106
109
// Make sure function calls are cancelled if the context is cancelled
107
110
if manifest .Timeout > 0 {
108
- cfg = cfg .WithCloseOnContextDone (true )
111
+ runtimeConfig = runtimeConfig .WithCloseOnContextDone (true )
109
112
}
110
113
111
114
if manifest .Memory != nil {
112
115
if manifest .Memory .MaxPages > 0 {
113
- cfg = cfg .WithMemoryLimitPages (manifest .Memory .MaxPages )
116
+ runtimeConfig = runtimeConfig .WithMemoryLimitPages (manifest .Memory .MaxPages )
114
117
}
115
118
}
116
119
117
120
p := CompiledPlugin {
118
121
manifest : manifest ,
119
- runtime : wazero .NewRuntimeWithConfig (ctx , cfg ),
122
+ runtime : wazero .NewRuntimeWithConfig (ctx , runtimeConfig ),
120
123
observeAdapter : config .ObserveAdapter ,
121
124
observeOptions : config .ObserveOptions ,
122
125
enableHttpResponseHeaders : config .EnableHttpResponseHeaders ,
@@ -220,24 +223,28 @@ func (p *CompiledPlugin) Instance(ctx context.Context, config PluginInstanceConf
220
223
if moduleConfig == nil {
221
224
moduleConfig = wazero .NewModuleConfig ()
222
225
}
223
- moduleConfig = moduleConfig .WithName (strconv .Itoa (int (p .instanceCount .Add (1 ))))
224
226
225
- // NOTE: this is only necessary for guest modules because
226
- // host modules have the same access privileges as the host itself
227
- fs := wazero .NewFSConfig ()
228
- for host , guest := range p .manifest .AllowedPaths {
229
- if strings .HasPrefix (host , "ro:" ) {
230
- trimmed := strings .TrimPrefix (host , "ro:" )
231
- fs = fs .WithReadOnlyDirMount (trimmed , guest )
232
- } else {
233
- fs = fs .WithDirMount (host , guest )
234
- }
235
- }
227
+ moduleConfig = moduleConfig .WithName (strconv .Itoa (int (p .instanceCount .Add (1 ))))
236
228
237
229
// NOTE: we don't want wazero to call the start function, we will initialize
238
230
// the guest runtime manually.
239
231
// See: https://github.com/extism/go-sdk/pull/1#issuecomment-1650527495
240
- moduleConfig = moduleConfig .WithStartFunctions ().WithFSConfig (fs )
232
+ moduleConfig = moduleConfig .WithStartFunctions ()
233
+
234
+ if len (p .manifest .AllowedPaths ) > 0 {
235
+ // NOTE: this is only necessary for guest modules because
236
+ // host modules have the same access privileges as the host itself
237
+ fs := wazero .NewFSConfig ()
238
+ for host , guest := range p .manifest .AllowedPaths {
239
+ if strings .HasPrefix (host , "ro:" ) {
240
+ trimmed := strings .TrimPrefix (host , "ro:" )
241
+ fs = fs .WithReadOnlyDirMount (trimmed , guest )
242
+ } else {
243
+ fs = fs .WithDirMount (host , guest )
244
+ }
245
+ }
246
+ moduleConfig = moduleConfig .WithFSConfig (fs )
247
+ }
241
248
242
249
_ , wasiOutput := os .LookupEnv ("EXTISM_ENABLE_WASI_OUTPUT" )
243
250
if p .hasWasi && wasiOutput {
0 commit comments