-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from NetAppLabs/wasip1_support
Adding support for wasm/wasip1
- Loading branch information
Showing
12 changed files
with
169 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
on: [push, pull_request] | ||
name: Test wasip1 | ||
permissions: {} | ||
jobs: | ||
test: | ||
strategy: | ||
matrix: | ||
go-version: [1.21.x] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
|
||
- name: Install wasirun | ||
run: | | ||
go install github.com/stealthrocket/wasi-go/cmd/wasirun@latest | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Test | ||
run: make wasitest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
//go:build !js | ||
// +build !js | ||
//go:build !wasm | ||
// +build !wasm | ||
|
||
/* | ||
Copyright 2022 The Flux authors. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
//go:build !js | ||
// +build !js | ||
//go:build !wasm | ||
// +build !wasm | ||
|
||
package osfs | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
//go:build !js | ||
// +build !js | ||
//go:build !wasm | ||
// +build !wasm | ||
|
||
package osfs | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//go:build wasip1 | ||
// +build wasip1 | ||
|
||
package osfs | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
) | ||
|
||
func (f *file) Lock() error { | ||
f.m.Lock() | ||
defer f.m.Unlock() | ||
return nil | ||
} | ||
|
||
func (f *file) Unlock() error { | ||
f.m.Lock() | ||
defer f.m.Unlock() | ||
return nil | ||
} | ||
|
||
func rename(from, to string) error { | ||
return os.Rename(from, to) | ||
} | ||
|
||
// umask sets umask to a new value, and returns a func which allows the | ||
// caller to reset it back to what it was originally. | ||
func umask(new int) func() { | ||
old := syscall.Umask(new) | ||
return func() { | ||
syscall.Umask(old) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//go:build wasip1 | ||
// +build wasip1 | ||
|
||
package osfs | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/go-git/go-billy/v5" | ||
"github.com/go-git/go-billy/v5/test" | ||
|
||
. "gopkg.in/check.v1" | ||
) | ||
|
||
func Test(t *testing.T) { TestingT(t) } | ||
|
||
type OSSuite struct { | ||
test.FilesystemSuite | ||
path string | ||
tempCounter int | ||
} | ||
|
||
var _ = Suite(&OSSuite{}) | ||
|
||
func (s *OSSuite) SetUpTest(c *C) { | ||
s.tempCounter++ | ||
s.path = fmt.Sprintf("test_%d", s.tempCounter) | ||
s.FilesystemSuite = test.NewFilesystemSuite(New(s.path)) | ||
} | ||
|
||
func (s *OSSuite) TestOpenDoesNotCreateDir(c *C) { | ||
_, err := s.FS.Open("dir/non-existent") | ||
c.Assert(err, NotNil) | ||
|
||
_, err = s.FS.Stat(filepath.Join(s.path, "dir")) | ||
c.Assert(os.IsNotExist(err), Equals, true) | ||
} | ||
|
||
func (s *OSSuite) TestCapabilities(c *C) { | ||
_, ok := s.FS.(billy.Capable) | ||
c.Assert(ok, Equals, true) | ||
|
||
caps := billy.Capabilities(s.FS) | ||
c.Assert(caps, Equals, billy.DefaultCapabilities) | ||
} | ||
|
||
func TestDefault(t *testing.T) { | ||
want := Default | ||
got := Default | ||
|
||
if reflect.TypeOf(got) != reflect.TypeOf(want) { | ||
t.Errorf("wanted Default to be %T got %T", want, got) | ||
} | ||
} | ||
|
||
func TestNewAPI(t *testing.T) { | ||
_ = New("/") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
# | ||
# Wrapper script for wasirun to be executable by go test -exec | ||
# | ||
|
||
which wasirun || go install github.com/stealthrocket/wasi-go/cmd/wasirun@latest | ||
|
||
# Make temp dir for for mapping into wasirun | ||
map_dir=$(mktemp -d) | ||
|
||
main_wasm=$1 | ||
shift | ||
|
||
wasirun --dir=${map_dir} ${main_wasm} -- $* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// +build !windows | ||
//go:build !windows && !wasip1 | ||
// +build !windows,!wasip1 | ||
|
||
package test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//go:build wasip1 | ||
// +build wasip1 | ||
|
||
package test | ||
|
||
import "os" | ||
|
||
var ( | ||
customMode os.FileMode = 0600 | ||
expectedSymlinkTarget = "/dir/file" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters