Skip to content

Commit

Permalink
allow building on Tinygo
Browse files Browse the repository at this point in the history
This commit adds package internal/tinygostub that contains
stubs for some of the standard library functions that are not
available in Tinygo.

This allows most of the module to be built with Tinygo.
  • Loading branch information
diamondburned committed Aug 3, 2024
1 parent 793d364 commit 3ff6fcd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
10 changes: 10 additions & 0 deletions internal/tinygostub/samefile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build !(tinygo && wasm)

package tinygostub

import "os"

// SameFile calls [os.SameFile].
func SameFile(fi1, fi2 os.FileInfo) bool {
return os.SameFile(fi1, fi2)
}
10 changes: 10 additions & 0 deletions internal/tinygostub/samefile_tinygo_wasm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build tinygo && wasm

package tinygostub

import "os"

// SameFile returns false.
func SameFile(fi1, fi2 os.FileInfo) bool {
return false
}
3 changes: 2 additions & 1 deletion interp/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"golang.org/x/term"

"mvdan.cc/sh/v3/expand"
"mvdan.cc/sh/v3/internal/tinygostub"
"mvdan.cc/sh/v3/syntax"
)

Expand Down Expand Up @@ -88,7 +89,7 @@ func (r *Runner) binTest(ctx context.Context, op syntax.BinTestOperator, x, y st
if err1 != nil || err2 != nil {
return false
}
return os.SameFile(info1, info2)
return tinygostub.SameFile(info1, info2)
case syntax.TsEql:
return atoi(x) == atoi(y)
case syntax.TsNeq:
Expand Down

0 comments on commit 3ff6fcd

Please sign in to comment.