mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-18 04:34:19 +01:00
pkg/client-sdk/wasm: build wasm (#238)
Signed-off-by: tiero <3596602+tiero@users.noreply.github.com>
This commit is contained in:
55
.github/workflows/ark.artifacts.yaml
vendored
Normal file
55
.github/workflows/ark.artifacts.yaml
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
name: Build and Upload Binaries and WASM
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.21.0
|
||||
|
||||
- name: Build binaries
|
||||
run: make build-all
|
||||
|
||||
- name: Build WASM SDK
|
||||
run: |
|
||||
cd pkg/client-sdk
|
||||
make build-wasm
|
||||
|
||||
- name: Upload server binaries
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: server-binaries
|
||||
path: ./server/build
|
||||
if-no-files-found: error
|
||||
retention-days: 5
|
||||
compression-level: 6
|
||||
overwrite: true
|
||||
|
||||
- name: Upload client binaries
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: client-binaries
|
||||
path: ./client/build
|
||||
if-no-files-found: error
|
||||
retention-days: 5
|
||||
compression-level: 6
|
||||
overwrite: true
|
||||
|
||||
- name: Upload WASM SDK
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: wasm-sdk
|
||||
path: pkg/client-sdk/build
|
||||
if-no-files-found: error
|
||||
retention-days: 5
|
||||
compression-level: 0
|
||||
overwrite: true
|
||||
11
.github/workflows/ark.release.yaml
vendored
11
.github/workflows/ark.release.yaml
vendored
@@ -25,6 +25,7 @@ jobs:
|
||||
- name: Build binaries
|
||||
run: make build-all
|
||||
|
||||
# Server
|
||||
- name: Upload server binary (Linux, AMD64)
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
@@ -106,6 +107,16 @@ jobs:
|
||||
asset_name: ark-darwin-arm64
|
||||
asset_content_type: application/octet-stream
|
||||
|
||||
# WASM SDK
|
||||
- name: Upload WASM SDK
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ github.event.release.upload_url }}
|
||||
asset_path: pkg/client-sdk/build/client-sdk.wasm
|
||||
asset_name: client-sdk.wasm
|
||||
asset_content_type: application/wasm
|
||||
|
||||
# Docker
|
||||
|
||||
|
||||
7
.github/workflows/ark.unit.yaml
vendored
7
.github/workflows/ark.unit.yaml
vendored
@@ -4,12 +4,14 @@ on:
|
||||
push:
|
||||
paths:
|
||||
- "server/**"
|
||||
- "pkg/client-sdk/**"
|
||||
branches: [master]
|
||||
pull_request:
|
||||
branches:
|
||||
branches:
|
||||
- master
|
||||
paths:
|
||||
- "server/**"
|
||||
- "pkg/client-sdk/**"
|
||||
|
||||
jobs:
|
||||
test-server:
|
||||
@@ -38,6 +40,7 @@ jobs:
|
||||
- run: go get -v -t -d ./...
|
||||
- name: unit testing
|
||||
run: make test
|
||||
|
||||
test-sdk:
|
||||
name: sdk unit tests
|
||||
runs-on: ubuntu-latest
|
||||
@@ -60,4 +63,4 @@ jobs:
|
||||
args: '-severity high -quiet ./...'
|
||||
- run: go get -v -t -d ./...
|
||||
- name: unit testing
|
||||
run: make test
|
||||
run: make test
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,5 @@
|
||||
.DS_Store
|
||||
.vscode/
|
||||
|
||||
main.wasm
|
||||
*.wasm
|
||||
wasm_exec.js
|
||||
8
Makefile
8
Makefile
@@ -16,5 +16,9 @@ build-all-client:
|
||||
@echo "Building ark binary for all archs..."
|
||||
@bash ./client/scripts/build-all
|
||||
|
||||
build: build-server build-client
|
||||
build-all: build-all-server build-all-client
|
||||
build-wasm:
|
||||
@echo "Building wasm..."
|
||||
@$(MAKE) -C pkg/client-sdk build-wasm
|
||||
|
||||
build: build-server build-client build-wasm
|
||||
build-all: build-all-server build-all-client build-wasm
|
||||
|
||||
@@ -1,26 +1,36 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Get the parent directory path
|
||||
PARENT_PATH=$(dirname $(
|
||||
cd $(dirname $0)
|
||||
pwd -P
|
||||
cd $(dirname $0)
|
||||
pwd -P
|
||||
))
|
||||
|
||||
if [[ -z $GOOS ]]; then
|
||||
GOOS=$(eval "go env GOOS")
|
||||
fi
|
||||
# Set VERSION (you can modify this to get the version from a file or environment variable)
|
||||
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "unknown")
|
||||
|
||||
# Set GOOS and GOARCH if not already set
|
||||
if [[ -z $GOOS ]]; then
|
||||
GOOS=$(go env GOOS)
|
||||
fi
|
||||
if [[ -z $GOARCH ]]; then
|
||||
GOARCH=$(eval "go env GOARCH")
|
||||
GOARCH=$(go env GOARCH)
|
||||
fi
|
||||
|
||||
echo "Building for $GOOS $GOARCH"
|
||||
echo "Version: $VERSION"
|
||||
|
||||
# Change to the parent directory
|
||||
pushd $PARENT_PATH
|
||||
|
||||
# Create build directory if it doesn't exist
|
||||
mkdir -p build
|
||||
|
||||
# Build the binary with version information
|
||||
GO111MODULE=on go build -ldflags="-s -w -X 'main.Version=$VERSION'" -o build/ark-$GOOS-$GOARCH .
|
||||
|
||||
GO111MODULE=on go build -ldflags="-s -w" -o build/ark-$GOOS-$GOARCH .
|
||||
echo "Build complete: build/ark-$GOOS-$GOARCH"
|
||||
|
||||
popd
|
||||
# Return to the original directory
|
||||
popd
|
||||
@@ -1,21 +1,41 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Get the parent directory path
|
||||
PARENT_PATH=$(dirname $(
|
||||
cd $(dirname $0)
|
||||
pwd -P
|
||||
cd $(dirname $0)
|
||||
pwd -P
|
||||
))
|
||||
|
||||
# Define OS and ARCH arrays
|
||||
declare -a OS=("darwin" "linux")
|
||||
declare -a ARCH=("amd64" "arm64")
|
||||
|
||||
# Change to the parent directory
|
||||
pushd $PARENT_PATH
|
||||
|
||||
# Function to handle errors
|
||||
handle_error() {
|
||||
echo "Error occurred in build for $1 $2"
|
||||
echo "Build command: GOOS=$1 GOARCH=$2 ./scripts/build"
|
||||
echo "Exit code: $3"
|
||||
echo "You may want to run this build manually to see more detailed error messages."
|
||||
}
|
||||
|
||||
# Loop through OS and ARCH combinations
|
||||
for os in "${OS[@]}"; do
|
||||
for arch in "${ARCH[@]}"; do
|
||||
GOOS=$os GOARCH=$arch ./scripts/build
|
||||
done
|
||||
for arch in "${ARCH[@]}"; do
|
||||
echo "Building for $os $arch"
|
||||
if GOOS=$os GOARCH=$arch ./scripts/build; then
|
||||
echo "Build successful for $os $arch"
|
||||
else
|
||||
handle_error $os $arch $?
|
||||
fi
|
||||
echo "------------------------"
|
||||
done
|
||||
done
|
||||
|
||||
popd
|
||||
# Return to the original directory
|
||||
popd
|
||||
|
||||
echo "All builds completed."
|
||||
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
|
||||
}
|
||||
@@ -1,18 +1,32 @@
|
||||
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Get the parent directory path
|
||||
PARENT_PATH=$(dirname $(
|
||||
cd $(dirname $0)
|
||||
pwd -P
|
||||
cd $(dirname $0)
|
||||
pwd -P
|
||||
))
|
||||
|
||||
OS=$(eval "go env GOOS")
|
||||
ARCH=$(eval "go env GOARCH")
|
||||
# Set VERSION (you can modify this to get the version from a file or environment variable)
|
||||
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "unknown")
|
||||
|
||||
# Get OS and ARCH
|
||||
OS=$(go env GOOS)
|
||||
ARCH=$(go env GOARCH)
|
||||
|
||||
echo "Building arkd for $OS $ARCH"
|
||||
echo "Version: $VERSION"
|
||||
|
||||
# Change to the parent directory
|
||||
pushd $PARENT_PATH
|
||||
|
||||
# Create build directory if it doesn't exist
|
||||
mkdir -p build
|
||||
GO111MODULE=on go build -o build/arkd-$OS-$ARCH ./cmd/arkd
|
||||
popd
|
||||
|
||||
|
||||
# Build the binary with version information
|
||||
go build -ldflags="-s -w -X 'main.Version=$VERSION'" -o build/arkd-$OS-$ARCH ./cmd/arkd
|
||||
|
||||
echo "Build complete: build/arkd-$OS-$ARCH"
|
||||
|
||||
# Return to the original directory
|
||||
popd
|
||||
|
||||
@@ -1,23 +1,46 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Get the parent directory path
|
||||
PARENT_PATH=$(dirname $(
|
||||
cd $(dirname $0)
|
||||
pwd -P
|
||||
cd $(dirname $0)
|
||||
pwd -P
|
||||
))
|
||||
|
||||
# Set VERSION (you can modify this to get the version from a file or environment variable)
|
||||
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "unknown")
|
||||
|
||||
# Define OS and ARCH arrays
|
||||
declare -a OS=("darwin" "linux")
|
||||
declare -a ARCH=("amd64" "arm64")
|
||||
|
||||
# Change to the parent directory
|
||||
pushd $PARENT_PATH
|
||||
mkdir -p build
|
||||
|
||||
# Function to handle errors
|
||||
handle_error() {
|
||||
echo "Error occurred in build for $1 $2"
|
||||
echo "Build command: VERSION=$VERSION GOOS=$1 GOARCH=$2 ./scripts/build"
|
||||
echo "Exit code: $3"
|
||||
echo "You may want to run this build manually to see more detailed error messages."
|
||||
}
|
||||
|
||||
echo "Starting builds for version: $VERSION"
|
||||
|
||||
# Loop through OS and ARCH combinations
|
||||
for os in "${OS[@]}"; do
|
||||
for arch in "${ARCH[@]}"; do
|
||||
echo "Building for $os $arch"
|
||||
GOOS=$os GOARCH=$arch go build -o build/arkd-$os-$arch cmd/arkd/main.go
|
||||
done
|
||||
for arch in "${ARCH[@]}"; do
|
||||
echo "Building for $os $arch"
|
||||
if VERSION=$VERSION GOOS=$os GOARCH=$arch ./scripts/build; then
|
||||
echo "Build successful for $os $arch"
|
||||
else
|
||||
handle_error $os $arch $?
|
||||
fi
|
||||
echo "------------------------"
|
||||
done
|
||||
done
|
||||
|
||||
popd
|
||||
# Return to the original directory
|
||||
popd
|
||||
|
||||
echo "All builds completed for version $VERSION."
|
||||
Reference in New Issue
Block a user