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
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ jobs:
bazelisk build --subcommands=pretty_print --verbose_failures --compiler=mingw-gcc :go_default_library
bazelisk test --subcommands=pretty_print --verbose_failures --compiler=mingw-gcc :go_default_test
if: matrix.os == 'windows-latest'
- name: Test vendoring on *nix
shell: bash
run: ./ci/test-vendoring.sh
if: matrix.os != 'windows-latest'

coverage:
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
/bazel-*
/bazel-*
test-vendoring-project
1 change: 1 addition & 0 deletions build/include/wasmtime/empty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package wasmtime
7 changes: 6 additions & 1 deletion ci/download-wasmtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import zipfile
import tarfile
import io
import sys
import os
import shutil
import glob
Expand Down Expand Up @@ -52,3 +51,9 @@
os.remove(dylib)
for dylib in glob.glob("build/**/*.so"):
os.remove(dylib)

for subdir, dirs, files in os.walk("build"):
dir_name = os.path.basename(os.path.normpath(subdir))
file_path = os.path.join(subdir, "empty.go")
with open(file_path, "w") as empty_file:
empty_file.write("package %s\n" % dir_name.replace("-", "_"))
27 changes: 18 additions & 9 deletions ci/local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,28 @@ if [ "$wasmtime" = "" ]; then
exit 1
fi

# Clean and re-create "build" directory hierarchy
rm -rf build
for d in "include" "include/wasmtime" "linux-x86_64" "macos-x86_64" "windows-x86_64"; do
path="build/$d"
mkdir -p "$path"
name=$(basename $d)
echo "package ${name/-/_}" > "$path/empty.go"
done

build=$wasmtime/target/release
if [ ! -d $build ]; then
build=$wasmtime/target/debug
build="$wasmtime/target/release"
if [ ! -d "$build" ]; then
build="$wasmtime/target/debug"
fi
# Use absolute path for symbolic links
build=$(readlink -f "$build")

if [ ! -f $build/libwasmtime.a ]; then
if [ ! -f "$build/libwasmtime.a" ]; then
echo 'Missing libwasmtime.a. Did you `cargo build -p wasmtime-c-api`?'
fi

mkdir -p build/{include,linux-x86_64,macos-x86_64}
ln -s $build/libwasmtime.a build/linux-x86_64/libwasmtime.a
ln -s $build/libwasmtime.a build/macos-x86_64/libwasmtime.a
cp $wasmtime/crates/c-api/include/*.h build/include
cp $wasmtime/crates/c-api/wasm-c-api/include/*.h build/include
ln -s "$build/libwasmtime.a" build/linux-x86_64/libwasmtime.a
ln -s "$build/libwasmtime.a" build/macos-x86_64/libwasmtime.a
cp "$wasmtime"/crates/c-api/include/*.h build/include
cp -r "$wasmtime"/crates/c-api/include/wasmtime build/include
cp "$wasmtime"/crates/c-api/wasm-c-api/include/*.h build/include
42 changes: 42 additions & 0 deletions ci/test-vendoring.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# This script tests the usage of wasmtime-go in a Go project
# that vendors its dependencies. This is used to check if
# all the header files and binaries are well copied in the
# vendor directory.

# Create a test directory
rm -rf test-vendoring-project
mkdir test-vendoring-project && cd test-vendoring-project || return 1

# Initialize a Go project
go mod init "test-vendoring-project"

# Add dependency to wasmtime-go
cat << E0F >> go.mod
require "github.com/bytecodealliance/wasmtime-go" v0.0.0
replace "github.com/bytecodealliance/wasmtime-go" v0.0.0 => "../"
E0F

# Add a basic test which uses wasmtime-go
cat << "E0F" >> main_test.go
package main

import (
"testing"

"github.com/bytecodealliance/wasmtime-go"
)

func TestMain(t *testing.T) {
wasmtime.NewStore(wasmtime.NewEngine())
}
E0F

# Vendor dependency
go mod vendor

# Then execute the test
go test .

echo "Success"
18 changes: 18 additions & 0 deletions includebuild.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// +build includebuild

package wasmtime

// This file is not built and not included in BUILD.bazel;
// it is only used to prevent "go mod vendor" to prune the
// build directory.

import (
// Import these build directories in order to have them
// included in vendored dependencies.
// Cf. https://github.com/golang/go/issues/26366
_ "github.com/bytecodealliance/wasmtime-go/build/include"
_ "github.com/bytecodealliance/wasmtime-go/build/include/wasmtime"
_ "github.com/bytecodealliance/wasmtime-go/build/linux-x86_64"
_ "github.com/bytecodealliance/wasmtime-go/build/macos-x86_64"
_ "github.com/bytecodealliance/wasmtime-go/build/windows-x86_64"
)