Skip to content

Error compiling to WASM because of readline #125

Open
@vasilev

Description

Encountered an error while attempted to compile the embedded version of Starlet to Webassembly:

# github.com/chzyer/readline
/go/pkg/mod/github.com/chzyer/[email protected]/utils.go:81:29: undefined: State
/go/pkg/mod/github.com/chzyer/[email protected]/utils.go:241:9: undefined: State
/go/pkg/mod/github.com/chzyer/[email protected]/operation.go:234:4: undefined: ClearScreen
/go/pkg/mod/github.com/chzyer/[email protected]/readline.go:129:20: undefined: GetScreenWidth
/go/pkg/mod/github.com/chzyer/[email protected]/readline.go:132:22: undefined: DefaultIsTerminal
/go/pkg/mod/github.com/chzyer/[email protected]/readline.go:142:26: undefined: DefaultOnWidthChanged
/go/pkg/mod/github.com/chzyer/[email protected]/remote.go:324:2: undefined: DefaultOnWidthChanged
/go/pkg/mod/github.com/chzyer/[email protected]/remote.go:346:17: undefined: GetScreenWidth
/go/pkg/mod/github.com/chzyer/[email protected]/remote.go:362:16: undefined: DefaultIsTerminal
/go/pkg/mod/github.com/chzyer/[email protected]/terminal.go:51:2: undefined: SuspendMe
/go/pkg/mod/github.com/chzyer/[email protected]/terminal.go:51:2: too many errors
  • Go version: 1.24.0, but the same error in older compiler versions too.
  • Starlet version: latest published, v0.1.2
  • chzyer/readline versions: both latest, v1.5.1 and v0.0.0-20180603132655-2972be24d48e used in Starlet.

Reproduction steps

mkdir reproduce-error
cd reproduce-error
go mod init main
go get github.com/1set/starlet
cat > starlet.go << 'END'
package main

import (
	"github.com/1set/starlet"
)

func main() {
	const code = `
print('Hello from Starlet!')
`
	machine := starlet.NewWithBuiltins(nil, nil, nil)
	_, err := machine.RunScript([]byte(code), nil)
	if err != nil {
		panic(err)
	}
}
END

# works OK in console
go run starlet.go
# fails to compile to WASM
GOOS=js GOARCH=wasm go build -o starlet.wasm starlet.go
Same error against latest available version of chzyer/readline, 1.5.1 at the this time

readline versions available

Error:

# github.com/chzyer/readline
/go/pkg/mod/github.com/chzyer/[email protected]/utils.go:84:29: undefined: State
/go/pkg/mod/github.com/chzyer/[email protected]/utils.go:265:9: undefined: State
/go/pkg/mod/github.com/chzyer/[email protected]/operation.go:236:4: undefined: ClearScreen
/go/pkg/mod/github.com/chzyer/[email protected]/readline.go:131:20: undefined: GetScreenWidth
/go/pkg/mod/github.com/chzyer/[email protected]/readline.go:134:22: undefined: DefaultIsTerminal
/go/pkg/mod/github.com/chzyer/[email protected]/readline.go:144:26: undefined: DefaultOnWidthChanged
/go/pkg/mod/github.com/chzyer/[email protected]/remote.go:324:2: undefined: DefaultOnWidthChanged
/go/pkg/mod/github.com/chzyer/[email protected]/remote.go:346:17: undefined: GetScreenWidth
/go/pkg/mod/github.com/chzyer/[email protected]/remote.go:362:16: undefined: DefaultIsTerminal
/go/pkg/mod/github.com/chzyer/[email protected]/terminal.go:51:2: undefined: SuspendMe
/go/pkg/mod/github.com/chzyer/[email protected]/terminal.go:51:2: too many errors

Reproduction steps

mkdir reproduce-error-v1.5.1
cd reproduce-error-v1.5.1
go mod init main
go get github.com/1set/starlet
go get github.com/chzyer/[email protected]
cat > starlet.go << 'END'
package main

import (
	"github.com/1set/starlet"
)

func main() {
	const code = `
print('Hello from Starlet!')
`
	machine := starlet.NewWithBuiltins(nil, nil, nil)
	_, err := machine.RunScript([]byte(code), nil)
	if err != nil {
		panic(err)
	}
}
END

# works OK in console
go run starlet.go
# fails to compile to WASM
GOOS=js GOARCH=wasm go build -o starlet.wasm starlet.go

Why reporting to Starlet repo

  1. It appears the chzyer/readline is not actively maintained at this time.
  2. Starlet depends on fixed (and old) version of chzyer/readline.

Possible solutions on Starlet side

Have not analyzed the code of Starlet very deeply, but AFAICU one of the following fixes is possible:

  1. Move readline-related functionality to CLI, decoupling the core suitable for embedding from IO dependencies.
  2. Implement a conditional compilation to exclude readline-related code on selected platforms.

What do you think?

BTW thank you all for your work on Starlet!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions