Skip to content

Commit

Permalink
Add bazel support (bytecodealliance#28)
Browse files Browse the repository at this point in the history
* add bazel support

* add wasmtime cc_import

* rename BUILD to BUILD.bazel to avoid conflict

* test bazelisk

* install bazelisk by go get

* fix bazel test on windows

* try exclude wildcard

* try use cmd on bazel in windows

* fmt

* try abhinavsingh/setup-bazel

* with version v3.3.1

* try msys2 git

* fix matrix.os

* use bash shell

* mv git folder

* fix spelling

* use bazelisk back

* remove pwsh

* push again

* fix yml

* disable verify ssl to avoid reinstalling git

* use C:\git\cmd rather than bin

* specify target to ease problem

* use msys2

* fix shell type

* use mingw-gcc

* omit compiler in msys2

* install gcc

* add compiler option back

* use mingw-gcc

* remove gazelle
  • Loading branch information
c0mm4nd authored Jul 15, 2020
1 parent 1b3b541 commit 05d2c8a
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 2 deletions.
26 changes: 24 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,39 @@ jobs:
env:
GODEBUG: cgocheck=2
GOGC: 1
- name: Test bazel build on *nix
shell: bash
run: |
export GOOS=$(go env GOHOSTOS)
go get github.com/bazelbuild/bazelisk
export PATH=$PATH:$(go env GOPATH)/bin
bazelisk build :go_default_library
bazelisk test :go_default_test
if: matrix.os != 'windows-latest'
- name: Ready msys2
uses: msys2/setup-msys2@v1
with:
msystem: MINGW64
update: true
install: git mingw-w64-x86_64-toolchain
path-type: inherit
if: matrix.os == 'windows-latest'
- name: Test bazel build on Windows
shell: msys2 {0}
run: |
go get github.com/bazelbuild/bazelisk
bazelisk build --compiler=mingw-gcc :go_default_library
bazelisk test --compiler=mingw-gcc :go_default_test
if: matrix.os == 'windows-latest'

coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v1
with:
python-version: 3.8
- run: python ci/download-wasmtime.py

- uses: actions/setup-go@v1
with:
go-version: '1.14'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build
/bazel-*
155 changes: 155 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

cc_import(
name = "wasmtime",
static_library = select({
"@io_bazel_rules_go//go/platform:darwin": "build/macos-x86_64/libwasmtime.a",
"@io_bazel_rules_go//go/platform:linux_amd64": "build/linux-x86_64/libwasmtime.a",
"@io_bazel_rules_go//go/platform:windows_amd64": "build/windows-x86_64/libwasmtime.a",
}),
hdrs = glob(["build/include/*.h"]),
visibility = ["//visibility:public"]
)

go_library(
name = "go_default_library",
srcs = [
"config.go",
"doc.go",
"engine.go",
"error.go",
"exporttype.go",
"extern.go",
"externtype.go",
"ffi.go",
"freelist.go",
"func.go",
"functype.go",
"global.go",
"globaltype.go",
"importtype.go",
"instance.go",
"limits.go",
"linker.go",
"maybe_gc_no.go",
"memory.go",
"memorytype.go",
"module.go",
"shims.c",
"shims.h",
"slab.go",
"store.go",
"table.go",
"tabletype.go",
"trap.go",
"val.go",
"valtype.go",
"wasi.go",
"wat2wasm.go",
],
cgo = True,
clinkopts = select({
"@io_bazel_rules_go//go/platform:aix": [
"-lwasmtime -lm -ldl",
],
"@io_bazel_rules_go//go/platform:android": [
"-lwasmtime -lm -ldl",
],
"@io_bazel_rules_go//go/platform:darwin": [
"-lwasmtime -lm -ldl",
],
"@io_bazel_rules_go//go/platform:dragonfly": [
"-lwasmtime -lm -ldl",
],
"@io_bazel_rules_go//go/platform:freebsd": [
"-lwasmtime -lm -ldl",
],
"@io_bazel_rules_go//go/platform:illumos": [
"-lwasmtime -lm -ldl",
],
"@io_bazel_rules_go//go/platform:ios": [
"-lwasmtime -lm -ldl",
],
"@io_bazel_rules_go//go/platform:js": [
"-lwasmtime -lm -ldl",
],
"@io_bazel_rules_go//go/platform:linux": [
"-lwasmtime -lm -ldl",
],
"@io_bazel_rules_go//go/platform:nacl": [
"-lwasmtime -lm -ldl",
],
"@io_bazel_rules_go//go/platform:netbsd": [
"-lwasmtime -lm -ldl",
],
"@io_bazel_rules_go//go/platform:openbsd": [
"-lwasmtime -lm -ldl",
],
"@io_bazel_rules_go//go/platform:plan9": [
"-lwasmtime -lm -ldl",
],
"@io_bazel_rules_go//go/platform:solaris": [
"-lwasmtime -lm -ldl",
],
"@io_bazel_rules_go//go/platform:windows": [
"-lwasmtime -luserenv -lole32 -lntdll -lws2_32 -lkernel32",
],
"//conditions:default": [],
}) + select({
"@io_bazel_rules_go//go/platform:android_amd64": [
"-Lbuild/linux-x86_64",
],
"@io_bazel_rules_go//go/platform:darwin_amd64": [
"-Lbuild/macos-x86_64",
],
"@io_bazel_rules_go//go/platform:ios_amd64": [
"-Lbuild/macos-x86_64",
],
"@io_bazel_rules_go//go/platform:linux_amd64": [
"-Lbuild/linux-x86_64",
],
"@io_bazel_rules_go//go/platform:windows_amd64": [
"-Lbuild/windows-x86_64",
],
"//conditions:default": [],
}),
cdeps = [":wasmtime"], # add wasmtime dep
copts = [
"-Ibuild/include",
] + select({
"@io_bazel_rules_go//go/platform:windows": [
"-DWASM_API_EXTERN= -DWASI_API_EXTERN=",
],
"//conditions:default": [],
}),
importpath = "github.com/bytecodealliance/wasmtime-go",
visibility = ["//visibility:public"],
)

go_test(
name = "go_default_test",
srcs = [
"config_test.go",
"doc_test.go",
"engine_test.go",
"exporttype_test.go",
"func_test.go",
"functype_test.go",
"global_test.go",
"globaltype_test.go",
"importtype_test.go",
"instance_test.go",
"linker_test.go",
"memorytype_test.go",
"module_test.go",
"slab_test.go",
"store_test.go",
"table_test.go",
"tabletype_test.go",
"trap_test.go",
"valtype_test.go",
"wasi_test.go",
"wasm2wat_test.go",
],
embed = [":go_default_library"],
)
16 changes: 16 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "io_bazel_rules_go",
sha256 = "e5de048e72612598c45f564202f6a3c74616be4ffd2dbd6f7bc75045f8ecbdce",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.23.4/rules_go-v0.23.4.tar.gz",
"https://github.com/bazelbuild/rules_go/releases/download/v0.23.4/rules_go-v0.23.4.tar.gz",
],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")

go_rules_dependencies()

go_register_toolchains()

0 comments on commit 05d2c8a

Please sign in to comment.