提交 6cc219bd 编写于 作者: chai2010's avatar chai2010

3rdparty/wabt: 支持纯 Go 模式

上级 baa0b0c5
# 版权 @2019 凹语言 作者。保留所有权利。
hello:
go run main.go run _examples/hello
CGO_ENABLED=0 go run main.go run _examples/hello
hi:
go run main.go run _examples/hi
CGO_ENABLED=0 go run main.go run _examples/hi
prime:
go run main.go run _examples/prime
CGO_ENABLED=0 go run main.go run _examples/prime
wasm:
go run main.go ssa _examples/hi
go run main.go wasm _examples/hi
CGO_ENABLED=0 go run main.go ssa _examples/hi
CGO_ENABLED=0 go run main.go wasm _examples/hi
wasm2wat a.out.wasm -o a.out.wast
cd ./tools/wa-wasmer-run && go run main.go -file=../../a.out.wasm
......
......@@ -28,13 +28,15 @@
+------------+
```
安装和测试:
安装和测试(默认使用了 CGO,可选择关闭):
1. 安装 [Clang](https://clang.llvm.org), 确保本地 `clang` 命令有效
2. `go install github.com/wa-lang/wa@latest`
3. `wa init -name=_examples/hi`
4. `wa run _examples/hi`
> 如果本地安装了 `wabt` 工具,可以通过设置 `CGO_ENABLED` 环境变量为 `0` 关闭 CGO 特性,提升 `go build` 编译性能。
> 项目尚处于原型开源阶段,如果有共建和PR需求请 [入群交流](https://wa-lang.org/community/index.html)。
> [VS Code 插件支持](https://marketplace.visualstudio.com/items?itemName=xxxDeveloper.vscode-wa)
......
......@@ -4,6 +4,7 @@
package main
import (
"errors"
"flag"
"fmt"
"log"
......@@ -13,7 +14,6 @@ import (
"os"
"sort"
"text/template"
"errors"
)
func main() {
......
// 版权 @2022 凹语言 作者。保留所有权利。
//go:build !wabt_cgo
// +build !wabt_cgo
//go:build !cgo
// +build !cgo
package wabt
import (
"fmt"
"os"
"os/exec"
"runtime"
)
func Wat2WasmCmd(args ...string) {
const Version = "1.0.29"
func Wat2WasmCmd(args ...string) error {
exe := "wat2wasm"
if runtime.GOOS == "windows" {
exe += ".exe"
}
cmd := exec.Command(exe, args...)
stdoutStderr, err := cmd.CombinedOutput()
if len(stdoutStderr) != 0 {
fmt.Printf("%s\n", stdoutStderr)
}
if err != nil {
if len(stdoutStderr) != 0 {
fmt.Printf("%s\n", stdoutStderr)
}
fmt.Printf("ERROR: %v\n", err)
os.Exit(1)
return err
}
fmt.Printf("%s\n", stdoutStderr)
return nil
}
// 版权 @2022 凹语言 作者。保留所有权利。
// go build -tags="wabt_cgo"
//go:build wabt_cgo
// +build wabt_cgo
package wabt
import (
"fmt"
"os"
"github.com/wa-lang/wa/internal/3rdparty/wabt"
)
func Wat2WasmCmd(args ...string) {
if err := wabt.Wat2WasmCmd(args...); err != nil {
fmt.Printf("ERROR: %v\n", err)
os.Exit(1)
}
}
......@@ -11,9 +11,9 @@ import (
"runtime/debug"
"github.com/wa-lang/wa/internal/3rdparty/cli"
"github.com/wa-lang/wa/internal/3rdparty/wabt"
"github.com/wa-lang/wa/internal/app"
"github.com/wa-lang/wa/internal/config"
"github.com/wa-lang/wa/internal/wabt"
)
func main() {
......@@ -270,11 +270,15 @@ func main() {
},
},
{
Name: "wat2wasm",
Usage: "convert wat to the wasm",
Name: "wat2wasm",
Usage: "convert wat to the wasm",
Hidden: true,
Action: func(c *cli.Context) error {
wabt.Wat2WasmCmd(c.Args().Slice()...)
err := wabt.Wat2WasmCmd(c.Args().Slice()...)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
return nil
},
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册