Skip to content
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

Error compiling to WASM because of readline #125

Open
vasilev opened this issue Feb 18, 2025 · 0 comments
Open

Error compiling to WASM because of readline #125

vasilev opened this issue Feb 18, 2025 · 0 comments

Comments

@vasilev
Copy link

vasilev commented Feb 18, 2025

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!

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

No branches or pull requests

1 participant