pkg/client-sdk/wasm: build wasm (#238)

Signed-off-by: tiero <3596602+tiero@users.noreply.github.com>
This commit is contained in:
Marco Argentieri
2024-08-12 16:40:27 +02:00
committed by GitHub
parent 72a7f29bab
commit c559b91fec
17 changed files with 273 additions and 44 deletions

1
pkg/client-sdk/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
build

View File

@@ -18,4 +18,17 @@ vet:
## lint: lint codebase
lint:
@echo "Linting code..."
@golangci-lint run --fix
@golangci-lint run --fix --verbose
## wasm: compiles the client-sdk to wasm
WASM_DIR = wasm
BUILD_DIR = build
VERSION := $(shell git describe --tags --always --dirty)
GO_VERSION := $(shell go version | cut -d' ' -f3)
.PHONY: build-wasm
build-wasm:
@mkdir -p $(BUILD_DIR)
@echo "Version: $(VERSION)"
@GOOS=js GOARCH=wasm GO111MODULE=on go build -ldflags="-X 'main.Version=$(VERSION)'" -o $(BUILD_DIR)/client-sdk.wasm $(WASM_DIR)/main.go

View File

@@ -1,4 +1,7 @@
package arksdkwasm
//go:build js && wasm
// +build js,wasm
package browser
import (
"context"

View File

@@ -1,4 +1,7 @@
package arksdkwasm
//go:build js && wasm
// +build js,wasm
package browser
import (
"context"

View File

@@ -1,4 +1,7 @@
package arksdkwasm
//go:build js && wasm
// +build js,wasm
package browser
import (
"encoding/hex"

View File

@@ -1,4 +1,7 @@
package arksdkwasm
//go:build js && wasm
// +build js,wasm
package browser
import (
"context"

View File

@@ -0,0 +1,43 @@
//go:build js && wasm
// +build js,wasm
package main
import (
"fmt"
"runtime/debug"
)
var (
Version = "dev"
CommitSHA = "unknown"
BuildTime = "unknown"
)
func init() {
if info, available := debug.ReadBuildInfo(); available {
for _, setting := range info.Settings {
switch setting.Key {
case "vcs.revision":
CommitSHA = setting.Value
case "vcs.time":
BuildTime = setting.Value
}
}
}
}
// PrintBuildInfo prints the build information
func PrintBuildInfo() {
fmt.Printf("ARK SDK WebAssembly Module\n")
fmt.Printf("Version: %s\n", Version)
fmt.Printf("Commit: %s\n", CommitSHA)
fmt.Printf("Build Time: %s\n", BuildTime)
}
// GetVersion returns the version string
func GetVersion() string {
return Version
}
// You can add more build-related functions here as needed

View File

@@ -0,0 +1,20 @@
//go:build js && wasm
// +build js,wasm
package main
import (
"github.com/ark-network/ark/pkg/client-sdk/wasm/browser"
)
func main() {
c := make(chan struct{}, 0)
println("ARK SDK WebAssembly module initialized")
browser.InitWrapper()
<-c
}
func init() {
// You can add any additional initialization here if needed
// This runs before the main function
}