Make build directories as valid (empty) go packages.#45
Make build directories as valid (empty) go packages.#45alexcrichton merged 1 commit intobytecodealliance:mainfrom
Conversation
|
Oh dear I wasn't aware of these gotchas, thanks for the PR! Would it be possible to test this on CI somehow? I think, for example, this is missing the windows directory? |
go mod vendor will not copy the header and library directory contents
not referred in any go source code. A common workaround is to add "_"
imports to such directories with necessary cgo files, but doing so
requires rendering such directories as valid go packages. This patch
does exactly that.
With this patch, one can vendor the C headers and libraries by
introducing the following imports in the code using the wasmtime-go
bindings.
import (
_ "github.com/bytecodealliance/wasmtime-go/build/include"
_ "github.com/bytecodealliance/wasmtime-go/build/linux-x86_64"
_ "github.com/bytecodealliance/wasmtime-go/build/macos-x86_64"
_ "github.com/bytecodealliance/wasmtime-go/build/windows-x86_64"
)
Optionally, one could consider introducing these imports to the
"github.com/bytecodealliance/wasmtime-go" package itself.
For more information about the underlying limitation of vendoring, see
for example: golang/go#26366
5269774 to
535e9e9
Compare
Just updated the PR to include the windows package. About testing this. Automated testing of this would require having a little go project that vendors wasmtime-go. I'd think that would be only bulletproof way of checking all the files are brought in and one can compile and link the project with wasmtime-go dependency. I don't recall seeing good testing practices around this issue in other projects. |
|
Ah ok, well in any case this seems fine for now, thanks! |
Following the update to Wasmtime's new C API in bytecodealliance#81, the header files are now not only in build/local, but also in build/local/wasmtime. This commit adds the directory "build/include/wasmtime" as a valid empty go package, like it was done in bytecodealliance#45 for the other build directories. It also addapts `ci/local.sh` to: - copy the additional header files in build/include/wasmtime - stop this script from removing the "empty.go" files.
* Add build/include/wasmtime Following the update to Wasmtime's new C API in #81, the header files are now not only in build/local, but also in build/local/wasmtime. This commit adds the directory "build/include/wasmtime" as a valid empty go package, like it was done in #45 for the other build directories. It also addapts `ci/local.sh` to: - copy the additional header files in build/include/wasmtime - stop this script from removing the "empty.go" files. * Import build packages + add CI test for vendoring - Import build packages, to prevent `go mod vendor` from pruning the build directories; - Update download-wasmtime.py to re-create the "empty.go" files and keep the Go packages in "build" - Add a CI test to check that wasmtime-go can be used by Go projects using dependency vendoring * Fix for Bazel
go mod vendor will not copy the header and library directory contents
not referred in any go source code. A common workaround is to add "_"
imports to such directories with necessary cgo files, but doing so
requires rendering such directories as valid go packages. This patch
does exactly that.
With this patch, one can vendor the C headers and libraries by
introducing the following imports in the code using the wasmtime-go
bindings.
import (
_ "github.com/bytecodealliance/wasmtime-go/build/include"
_ "github.com/bytecodealliance/wasmtime-go/build/linux-x86_64"
_ "github.com/bytecodealliance/wasmtime-go/build/macos-x86_64"
)
Optionally, one could consider introducing these imports to the
"github.com/bytecodealliance/wasmtime-go" package itself.
For more information about the underlying limitation of vendoring, see
for example: golang/go#26366