internal/abi: add a dummy Go file for go mod vendor (#32)
Before this change, the package `internal/abi` was ignored by `go mod vendor` as there was no Go file there. Then building purego failed as `internal/abi` didn't exist under the `vendor` directory. This change fixes this issue by adding a dummy Go file to `internal/abi` and adding an explicit import to it, but with a `dummy` build tag. I referred a change https://github.com/goccy/go-graphviz/pull/37 for this hack. Updates #31
- commit
- aeed57cda74433391c1ebcd6c8ce5630cf944056
- author
- Hajime Hoshi · · 2022-09-05 07:56 UTC
- committer
- GitHub · · 2022-09-05 07:56 UTC
- parent
- 0acfce6
- signature
- GPG Unverified
4AEE18F83AFDEB23The key is unknown
3 files · +38 -0
M .github/workflows/test.yml +15 -0
| @@ -56,6 +56,21 @@ jobs: | |||
| 56 | 56 | # Check cross-compiling Windows binaries. | |
| 57 | 57 | env GOOS=windows GOARCH=arm64 go build -v ./... | |
| 58 | 58 | ||
| 59 | + | - name: go mod vendor | |
| 60 | + | run: | | |
| 61 | + | mkdir /tmp/vendoring | |
| 62 | + | cd /tmp/vendoring | |
| 63 | + | go mod init foo | |
| 64 | + | echo 'package main' > main.go | |
| 65 | + | echo 'import (' >> main.go | |
| 66 | + | echo ' _ "github.com/ebitengine/purego"' >> main.go | |
| 67 | + | echo ')' >> main.go | |
| 68 | + | echo 'func main() {}' >> main.go | |
| 69 | + | go mod edit -replace github.com/ebitengine/purego=$GITHUB_WORKSPACE | |
| 70 | + | go mod tidy | |
| 71 | + | go mod vendor | |
| 72 | + | go build -v . | |
| 73 | + | ||
| 59 | 74 | - name: go test | |
| 60 | 75 | if: ${{ !startsWith(matrix.go, '1.15.') }} # TODO: Remove this condition after #27 is fixed. | |
| 61 | 76 | run: | | |
| @@ -56,6 +56,21 @@ jobs: | |||||
| 56 | # Check cross-compiling Windows binaries. | 56 | # Check cross-compiling Windows binaries. | ||
| 57 | env GOOS=windows GOARCH=arm64 go build -v ./... | 57 | env GOOS=windows GOARCH=arm64 go build -v ./... | ||
| 58 | 58 | ||||
| 59 | + | - name: go mod vendor | |||
| 60 | + | run: | | |||
| 61 | + | mkdir /tmp/vendoring | |||
| 62 | + | cd /tmp/vendoring | |||
| 63 | + | go mod init foo | |||
| 64 | + | echo 'package main' > main.go | |||
| 65 | + | echo 'import (' >> main.go | |||
| 66 | + | echo ' _ "github.com/ebitengine/purego"' >> main.go | |||
| 67 | + | echo ')' >> main.go | |||
| 68 | + | echo 'func main() {}' >> main.go | |||
| 69 | + | go mod edit -replace github.com/ebitengine/purego=$GITHUB_WORKSPACE | |||
| 70 | + | go mod tidy | |||
| 71 | + | go mod vendor | |||
| 72 | + | go build -v . | |||
| 73 | + | ||||
| 59 | - name: go test | 74 | - name: go test | ||
| 60 | if: ${{ !startsWith(matrix.go, '1.15.') }} # TODO: Remove this condition after #27 is fixed. | 75 | if: ${{ !startsWith(matrix.go, '1.15.') }} # TODO: Remove this condition after #27 is fixed. | ||
| 61 | run: | | 76 | run: | | ||
A dummy.go +15 -0
| @@ -0,0 +1,15 @@ | |||
| 1 | + | // SPDX-License-Identifier: Apache-2.0 | |
| 2 | + | // SPDX-FileCopyrightText: 2022 The Ebitengine Authors | |
| 3 | + | ||
| 4 | + | //go:build dummy | |
| 5 | + | // +build dummy | |
| 6 | + | ||
| 7 | + | // This file exists purely to prevent the Go toolchain from stripping | |
| 8 | + | // away the C source directories and files when `go mod vendor` is used | |
| 9 | + | // to populate a `vendor/` directory of a project depending on this package. | |
| 10 | + | ||
| 11 | + | package purego | |
| 12 | + | ||
| 13 | + | import ( | |
| 14 | + | _ "github.com/ebitengine/purego/internal/abi" | |
| 15 | + | ) | |
| @@ -0,0 +1,15 @@ | |||||
| 1 | + | // SPDX-License-Identifier: Apache-2.0 | |||
| 2 | + | // SPDX-FileCopyrightText: 2022 The Ebitengine Authors | |||
| 3 | + | ||||
| 4 | + | //go:build dummy | |||
| 5 | + | // +build dummy | |||
| 6 | + | ||||
| 7 | + | // This file exists purely to prevent the Go toolchain from stripping | |||
| 8 | + | // away the C source directories and files when `go mod vendor` is used | |||
| 9 | + | // to populate a `vendor/` directory of a project depending on this package. | |||
| 10 | + | ||||
| 11 | + | package purego | |||
| 12 | + | ||||
| 13 | + | import ( | |||
| 14 | + | _ "github.com/ebitengine/purego/internal/abi" | |||
| 15 | + | ) | |||
A internal/abi/dummy.go +8 -0
| @@ -0,0 +1,8 @@ | |||
| 1 | + | // SPDX-License-Identifier: Apache-2.0 | |
| 2 | + | // SPDX-FileCopyrightText: 2022 The Ebitengine Authors | |
| 3 | + | ||
| 4 | + | //go:build dummy | |
| 5 | + | // +build dummy | |
| 6 | + | ||
| 7 | + | // Package abi is a dummy package that prevents go tooling from stripping the C dependencies. | |
| 8 | + | package abi | |
| @@ -0,0 +1,8 @@ | |||||
| 1 | + | // SPDX-License-Identifier: Apache-2.0 | |||
| 2 | + | // SPDX-FileCopyrightText: 2022 The Ebitengine Authors | |||
| 3 | + | ||||
| 4 | + | //go:build dummy | |||
| 5 | + | // +build dummy | |||
| 6 | + | ||||
| 7 | + | // Package abi is a dummy package that prevents go tooling from stripping the C dependencies. | |||
| 8 | + | package abi | |||