Skip to content

Make build directories as valid (empty) go packages.#45

Merged
alexcrichton merged 1 commit intobytecodealliance:mainfrom
koponen:build-empty-packages
Nov 25, 2020
Merged

Make build directories as valid (empty) go packages.#45
alexcrichton merged 1 commit intobytecodealliance:mainfrom
koponen:build-empty-packages

Conversation

@koponen-styra
Copy link
Copy Markdown
Contributor

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

@alexcrichton
Copy link
Copy Markdown
Member

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
@koponen-styra
Copy link
Copy Markdown
Contributor Author

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?

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.

@alexcrichton
Copy link
Copy Markdown
Member

Ah ok, well in any case this seems fine for now, thanks!

@alexcrichton alexcrichton merged commit e5fed01 into bytecodealliance:main Nov 25, 2020
olivierlemasle added a commit to olivierlemasle/wasmtime-go that referenced this pull request Jun 3, 2021
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.
alexcrichton pushed a commit that referenced this pull request Jun 4, 2021
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants