Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow building with Tinygo #1078

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,34 @@ jobs:
- name: Test as root, without cgo, and with busybox
run: docker run -v="$PWD:/pwd" -w=/pwd -e=CGO_ENABLED=0 golang:1.22.0-alpine go test ./...

test-tinygo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Tinygo
uses: acifani/setup-tinygo@v2
with:
tinygo-version: 0.32.0

- name: Create temporary main package
run: |
mkdir _tinygo && cat<<EOF > _tinygo/main.go
package main

import (
_ "mvdan.cc/sh/v3/expand"
_ "mvdan.cc/sh/v3/interp"
_ "mvdan.cc/sh/v3/syntax"
)

func main() {}
EOF

- name: Build with Tinygo natively
run: tinygo build -o /dev/null ./_tinygo
- name: Build with Tinygo on WASM
run: tinygo build -o /dev/null -target wasm ./_tinygo

docker:
name: Build and test Docker images
# Only deploy if previous stages pass.
Expand Down
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