compiler

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBytecodeNil        = errors.New("wasm bytecode is nil")
	ErrContentNil         = errors.New("wasm content is nil")
	ErrExecCreationFailed = errors.New("unable to create wasm executable")
	ErrValidationFailed   = errors.New("wasm script validation error")
)
View Source
var ErrExecutableClosed = errors.New("executable is closed")

Functions

This section is empty.

Types

type Compiler

type Compiler struct {
	// contains filtered or unexported fields
}

Compiler implements the script.Compiler interface for WASM modules

func New

func New(opts ...FunctionalOption) (*Compiler, error)

New creates a new Extism WASM Compiler instance with the provided options.

func (*Compiler) Compile

func (c *Compiler) Compile(scriptReader io.ReadCloser) (script.ExecutableContent, error)

Compile implements script.Compiler TODO: Some error paths are difficult to test with the current design Consider adding integration tests for hard-to-reach error cases.

func (*Compiler) GetEntryPointName

func (c *Compiler) GetEntryPointName() string

GetEntryPointName is a getter for the func name entrypoint

func (*Compiler) String

func (c *Compiler) String() string

type Executable

type Executable struct {
	ByteCode adapters.CompiledPlugin
	// contains filtered or unexported fields
}

Executable implements script.ExecutableContent for Extism WASM modules

func NewExecutable

func NewExecutable(
	scriptBytes []byte,
	byteCode adapters.CompiledPlugin,
	entryPoint string,
) *Executable

NewExecutable creates a new Executable instance

func (*Executable) Close

func (e *Executable) Close(ctx context.Context) error

Close implements io.Closer

func (*Executable) GetByteCode

func (e *Executable) GetByteCode() any

GetByteCode returns the compiled plugin as a generic interface

func (*Executable) GetEntryPoint

func (e *Executable) GetEntryPoint() string

GetEntryPoint returns the name of the entry point function

func (*Executable) GetExtismByteCode

func (e *Executable) GetExtismByteCode() adapters.CompiledPlugin

GetExtismByteCode returns the compiled plugin with its proper type

func (*Executable) GetMachineType

func (e *Executable) GetMachineType() machineTypes.Type

GetMachineType returns the Extism machine type

func (*Executable) GetSource

func (e *Executable) GetSource() string

GetSource returns the original script content

type FunctionalOption

type FunctionalOption func(*Compiler) error

FunctionalOption is a function that configures a Compiler instance

func WithContext

func WithContext(ctx context.Context) FunctionalOption

WithContext creates an option to set a custom context for the Extism compiler.

func WithEntryPoint

func WithEntryPoint(entryPoint string) FunctionalOption

WithEntryPoint creates an option to set the entry point for Extism WASM modules

func WithHostFunctions

func WithHostFunctions(funcs []extismSDK.HostFunction) FunctionalOption

WithHostFunctions creates an option to set additional host functions

func WithLogHandler

func WithLogHandler(handler slog.Handler) FunctionalOption

WithLogHandler creates an option to set the log handler for Extism compiler. This is the preferred option for logging configuration as it provides more flexibility through the slog.Handler interface.

func WithLogger

func WithLogger(logger *slog.Logger) FunctionalOption

WithLogger creates an option to set a specific logger for Extism compiler. This is less flexible than WithLogHandler but allows users to customize their logging group configuration.

func WithRuntimeConfig

func WithRuntimeConfig(config wazero.RuntimeConfig) FunctionalOption

WithRuntimeConfig creates an option to set a custom wazero runtime configuration

func WithWASIEnabled

func WithWASIEnabled(enabled bool) FunctionalOption

WithWASIEnabled creates an option to enable or disable WASI support

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL