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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed
- Omit the default `//go:build !wasip1` build tags from generated Go files. This enables `wit-bindgen-go` to target `GOOS=wasip1` (fixes [#147](https://github.com/ydnar/wasm-tools-go/issues/147)).

## [v0.1.4] — 2024-07-16

### Added
Expand Down
8 changes: 4 additions & 4 deletions internal/go/gen/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ type File struct {
// Leave empty to omit the "Code generated by ..." header.
GeneratedBy string

// Build contains build tags, serialized as //go:build ...
// GoBuild contains build tags, serialized as //go:build ...
// Ignored if this is not a Go file.
Build string
GoBuild string

// PackageDocs are doc comments that preceed the package declaration.
// These will be wrapped and each line prefixed with // when serialized.
Expand Down Expand Up @@ -106,9 +106,9 @@ func (f *File) Bytes() ([]byte, error) {
b.WriteString("\n\n")
}

if f.Build != "" {
if f.GoBuild != "" {
b.WriteString("//go:build ")
b.WriteString(f.Build)
b.WriteString(f.GoBuild)
b.WriteString("\n\n")
}

Expand Down
2 changes: 1 addition & 1 deletion internal/go/gen/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestFileHasContent(t *testing.T) {

negatives := []File{
{Name: "empty.go", GeneratedBy: "package testing"},
{Name: "build_tag_only.go", Build: "!wasip1"},
{Name: "build_tag_only.go", GoBuild: "!wasip1"},
{Name: "named_imports.go", Imports: map[string]string{"unsafe": "unsafe"}},
{Name: "assembly.s", Content: nil},
}
Expand Down
8 changes: 2 additions & 6 deletions wit/bindgen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import (
)

const (
BuildDefault = "!wasip1"
cmPackage = "github.com/ydnar/wasm-tools-go/cm"
emptyAsm = `// This file exists for testing this package without WebAssembly,
cmPackage = "github.com/ydnar/wasm-tools-go/cm"
emptyAsm = `// This file exists for testing this package without WebAssembly,
// allowing empty function bodies with a //go:wasmimport directive.
// See https://pkg.go.dev/cmd/compile for more information.
`
Expand Down Expand Up @@ -2110,23 +2109,20 @@ func (g *generator) ensureEmptyAsm(pkg *gen.Package) error {
func (g *generator) abiFile(pkg *gen.Package) *gen.File {
file := pkg.File("abi.go")
file.GeneratedBy = g.opts.generatedBy
file.Build = BuildDefault
return file
}

func (g *generator) fileFor(id wit.Ident) *gen.File {
pkg := g.packageFor(id)
file := pkg.File(id.Extension + ".wit.go")
file.GeneratedBy = g.opts.generatedBy
file.Build = BuildDefault
return file
}

func (g *generator) exportsFileFor(id wit.Ident) *gen.File {
pkg := g.packageFor(id)
file := pkg.File(id.Extension + ".exports.go")
file.GeneratedBy = g.opts.generatedBy
file.Build = BuildDefault
if len(file.Header) == 0 {
exports := file.GetName("Exports")
var b strings.Builder
Expand Down