mirror of
https://github.com/aljazceru/ark.git
synced 2026-01-29 08:14:20 +01:00
pkg/client-sdk/wasm: build wasm (#238)
Signed-off-by: tiero <3596602+tiero@users.noreply.github.com>
This commit is contained in:
1
pkg/client-sdk/.gitignore
vendored
Normal file
1
pkg/client-sdk/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
build
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package arksdkwasm
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package browser
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,4 +1,7 @@
|
||||
package arksdkwasm
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package browser
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,4 +1,7 @@
|
||||
package arksdkwasm
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package browser
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
@@ -1,4 +1,7 @@
|
||||
package arksdkwasm
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package browser
|
||||
|
||||
import (
|
||||
"context"
|
||||
43
pkg/client-sdk/wasm/build.go
Normal file
43
pkg/client-sdk/wasm/build.go
Normal 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
|
||||
20
pkg/client-sdk/wasm/main.go
Normal file
20
pkg/client-sdk/wasm/main.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user