bugst / go-serial

A cross-platform serial library for go-lang.
BSD 3-Clause "New" or "Revised" License
617 stars 188 forks source link

fix: add shims for GOARCH=wasm with GOOS=js and GOOS=wasip1 #176

Closed paralin closed 3 months ago

paralin commented 4 months ago

Fixes build errors:

GOOS=js GOARCH=wasm go build GOOS=wasip1 GOARCH=wasm go build

cmaglie commented 4 months ago

@paralin what's the purpose of this patch? since nativeOpen is not implemented the library will not be available on wasm anyway.

paralin commented 4 months ago

When the library is used as a dependency it is best to have it compile cleanly when that GOOS is used with stubs that return errors instead of failing to build entirely. This is for a dependency of https://github.com/aperturerobotics/bifrost

cmaglie commented 4 months ago

@paralin I'd like to ask you these changes:

  1. Remove the files with the shims for js and wasip1. Since both OS/ARCH pairs wasm/js and wasm/wasip1 belongs to the same ARCH wasm, it should be possible to reduce the number of files by simply leveraging the selection on the OS //go:build wasm.

  2. Remove the go:build flags. I think we could avoid the go:build tags altogether by simply naming the source file with the suffix *_wasm.go.

    
    If a file's name, after stripping the extension and a possible _test suffix,
    matches any of the following patterns:

_GOOS _GOARCH *_GOOS_GOARCH (example: source_windows_amd64.go) where GOOS and GOARCH represent any known operating system and architecture values respectively, then the file is considered to have an implicit build constraint requiring those terms (in addition to any explicit constraints in the file).



3. Please add the license header to all files.
paralin commented 4 months ago

You were right on the build tags, I fixed the PR according to your request.