Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
common --enable_bzlmod
33 changes: 29 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ on:
jobs:
build_ubuntu:
runs-on: ubuntu-24.04
env:
CGO_ENABLED: 1
USE_BAZEL_VERSION: 7.4.1
strategy:
matrix:
go: [ '1.22.x', '1.23.x' ]
name: Build WasmEdge-go on Ubuntu 24.04 x86_64 with Go ${{ matrix.go }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6
- name: Install go
uses: actions/setup-go@v2
uses: actions/setup-go@v6
with:
go-version: ${{ matrix.go }}
- name: Check go version
Expand All @@ -36,17 +39,29 @@ jobs:
run: |
source $HOME/.wasmedge/env
go build ./wasmedge/
- name: Bazel Test
run: |
bazel test //... \
--test_output=errors \
--copt="-I$HOME/.wasmedge/include" \
--linkopt="-L$HOME/.wasmedge/lib" \
--action_env=LD_LIBRARY_PATH=$HOME/.wasmedge/lib \
--action_env=DYLD_LIBRARY_PATH=$HOME/.wasmedge/lib \
--@io_bazel_rules_go//go/config:pure=false

build_macos:
runs-on: macos-14
env:
CGO_ENABLED: 1
USE_BAZEL_VERSION: 7.4.1
strategy:
matrix:
go: [ '1.22.x', '1.23.x' ]
name: Build WasmEdge-go on MacOS 14 x86_64 with Go ${{ matrix.go }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6
- name: Install go
uses: actions/setup-go@v2
uses: actions/setup-go@v6
with:
go-version: ${{ matrix.go }}
- name: Check go version
Expand All @@ -58,3 +73,13 @@ jobs:
run: |
source $HOME/.wasmedge/env
go build ./wasmedge/

- name: Bazel Test
run: |
bazel test //... \
--test_output=errors \
--copt="-I$HOME/.wasmedge/include" \
--linkopt="-L$HOME/.wasmedge/lib" \
--action_env=LD_LIBRARY_PATH=$HOME/.wasmedge/lib \
--action_env=DYLD_LIBRARY_PATH=$HOME/.wasmedge/lib \
--@io_bazel_rules_go//go/config:pure=false
2 changes: 2 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
load("@gazelle//:def.bzl", "gazelle")
gazelle(name = "gazelle")
47 changes: 47 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module(
name = "wasmedge_go",
version = "0.14.0",
)

bazel_dep(name = "platforms", version = "0.0.11")
bazel_dep(name = "rules_go", version = "0.50.1", repo_name = "io_bazel_rules_go")
bazel_dep(name = "gazelle", version = "0.38.0")

go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.23.0")
use_repo(go_sdk, "go_toolchains")

register_toolchains("@go_toolchains//:all")

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "wasmedge_c",
build_file_content = """
cc_library(
name = "wasmedge_c",
srcs = select({
"@platforms//os:linux": glob(["**/libwasmedge.so*"], allow_empty = True),
"@platforms//os:macos": glob(["**/libwasmedge.dylib*"], allow_empty = True),
"@platforms//os:windows": glob(["**/wasmedge.lib"], allow_empty = True),
"//conditions:default": glob(["**/libwasmedge.so*"], allow_empty = True),
}),
hdrs = glob(["**/include/**/*"], allow_empty = True),
includes = [
"WasmEdge-0.14.0-Linux/include",
"WasmEdge-0.14.0-Darwin/include",
"WasmEdge-0.14.0-Windows/include",
"include",
".",
],
visibility = ["//visibility:public"],
)
""",
urls = [
"https://github.com/WasmEdge/WasmEdge/releases/download/0.14.0/WasmEdge-0.14.0-ubuntu20.04_x86_64.tar.gz",
"https://github.com/WasmEdge/WasmEdge/releases/download/0.14.0/WasmEdge-0.14.0-darwin_aarch64.tar.gz",
"https://github.com/WasmEdge/WasmEdge/releases/download/0.14.0/WasmEdge-0.14.0-windows_x86_64.zip",
],
)
115 changes: 115 additions & 0 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,27 @@ For examples, please refer to the [example repository](https://github.com/second
## WasmEdge-go Documentation

Please refer to the [API Documentation](https://wasmedge.org/docs/embed/go/reference/latest) for details.

## Bazel Support on Windows
Comment thread
hydai marked this conversation as resolved.

To use this library with Bazel on Windows, you can define the WasmEdge C library as a local dependency. Below is an example of how to configure this in your project.

### Example Configuration

```starlark
load("@bazel_tools//tools/build_defs/cc:cc_import.bzl", "cc_import")

cc_import(
name = "libwasmedge",
shared_library = "C:/wasmedge/bin/wasmedge.dll",
interface_library = "C:/wasmedge/lib/wasmedge.lib",
system_provided = False,
)

cc_library(
name = "wasmedge_c",
hdrs = [":wasmedge_headers"],
deps = [":libwasmedge"],
includes = ["C:/wasmedge/include"],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Standard Bazel Workspace Root
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/second-state/WasmEdge-go

go 1.16
go 1.21

// Lost header in v0.9.1 version. Please use the WasmEdge-go v0.9.2 for WasmEdge 0.9.1.
retract v0.9.1
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"fmt"
"github.com/second-state/WasmEdge-go/wasmedge"
)

func main() {
wasmedge.SetLogOff()
conf := wasmedge.NewConfigure(wasmedge.WasmEdge_Configure_Default)
conf.Release()
fmt.Println("Success")
}

40 changes: 40 additions & 0 deletions wasmedge/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = [
"ast.go",
"async.go",
"callframe.go",
"cgo.go",
"chostfunc.go",
"cli.go",
"compiler.go",
"configure.go",
"executor.go",
"hostfunc.go",
"instance.go",
"limit.go",
"loader.go",
"log.go",
"plugin.go",
"result.go",
"statistics.go",
"store.go",
"string.go",
"validator.go",
"value.go",
"version.go",
"vm.go",
],
cgo = True,
clinkopts = ["-lwasmedge"],
importpath = "github.com/second-state/WasmEdge-go/wasmedge",
visibility = ["//visibility:public"],
)

go_test(
name = "go_default_test",
srcs = ["limit_test.go"],
embed = [":go_default_library"],
)
Loading